* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #1a1a2e;
  color: #eee;
  min-height: 100vh;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* --- Layout --- */

.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px;
  gap: 16px;
}

.title {
  font-family: 'Press Start 2P', monospace;
  font-size: 20px;
  font-weight: 400;
  text-align: center;
  color: #f1c40f;
}

.mobile-only { display: flex !important; }
.desktop-only { display: none !important; }
.panel-desktop { display: none !important; }
.hidden { display: none !important; }

.mobile-header {
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
}

/* --- Title bar --- */

.title-bar {
  display: flex;
  align-items: baseline;
  gap: 12px;
  width: 100%;
  max-width: 500px;
  justify-content: center;
  white-space: nowrap;
}

.solution-count-desktop {
  font-size: 13px;
  font-style: italic;
  font-family: 'Courier New', Courier, monospace;
  color: #888;
}

.solution-count-desktop.computing { color: #666; }

/* --- Grid --- */

.grid-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.grid {
  display: inline-grid;
  gap: 2px;
  background: #333;
  padding: 2px;
  border-radius: 4px;
}

.cell {
  background: #2a2a4a;
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.1s;
}

.cell.blocked {
  background: #111;
  cursor: default;
}

.cell.placed {
  cursor: grab;
}

.cell.highlight-ok {
  background: rgba(46, 204, 113, 0.35) !important;
  box-shadow: inset 0 0 0 2px rgba(46, 204, 113, 0.6);
}

.cell.highlight-bad {
  background: rgba(231, 76, 60, 0.25) !important;
  box-shadow: inset 0 0 0 2px rgba(231, 76, 60, 0.4);
}

/* --- Panel --- */

.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 500px;
}

.solution-count {
  font-size: 13px;
  font-style: italic;
  font-family: 'Courier New', Courier, monospace;
  color: #888;
}

.solution-count.computing { color: #666; }

/* --- Controls --- */

.controls {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.controls button {
  font-size: 22px;
  padding: 8px 12px;
  line-height: 1;
}

button {
  background: #16213e;
  color: #eee;
  border: 1px solid #444;
  padding: 8px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
}

button:hover { background: #1a3a5c; }
button:focus { outline: none; }
button:disabled { opacity: 0.3; cursor: default; }
button.active { background: #f1c40f; color: #111; font-weight: bold; }

.nav { display: flex; align-items: center; gap: 12px; justify-content: center; }
.nav span { font-size: 14px; color: #aaa; min-width: 80px; text-align: center; }

/* --- Carousel --- */

.carousel-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.carousel {
  display: flex;
  align-items: center;
  gap: 8px;
}

.carousel-arrow {
  font-size: 24px;
  padding: 4px 10px;
  line-height: 1;
  border: 1px solid #444;
}

.carousel-piece {
  display: inline-grid;
  gap: 2px;
  padding: 6px;
  background: #16213e;
  border-radius: 8px;
  border: 2px solid #444;
  cursor: grab;
  touch-action: none;
}

.carousel-piece.empty {
  opacity: 0.3;
  cursor: default;
}

.carousel-cell {
  border-radius: 3px;
}

/* --- Piece controls (rotate/flip) --- */

.piece-controls {
  display: flex;
  gap: 12px;
}

.piece-controls button {
  font-size: 22px;
  padding: 6px 14px;
}

/* --- Miniatures --- */

.miniatures {
  display: grid;
  grid-template-columns: repeat(6, auto);
  gap: 4px;
  justify-content: center;
}

.mini-thumb {
  display: inline-grid;
  gap: 1px;
  padding: 3px;
  border: 2px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  background: #16213e;
  transition: border-color 0.15s, opacity 0.15s;
}

.mini-thumb:hover { border-color: #888; }
.mini-thumb.active { border-color: #f1c40f; }
.mini-thumb.placed { opacity: 0.15; cursor: default; }

.mini-cell {
  border-radius: 1px;
}

/* --- QR overlay --- */

.grid-wrapper {
  position: relative;
}

.qr-overlay {
  position: absolute;
  inset: 0;
  background: #2a2a4a;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-radius: 4px;
  z-index: 10;
}

.qr-overlay img {
  width: 95%;
}

/* --- Help --- */

.help {
  font-size: 13px;
  color: #555;
  text-align: center;
  margin-top: 8px;
}

.help b { color: #888; }

/* --- Drag float --- */

.drag-float {
  position: fixed;
  pointer-events: none;
  z-index: 1000;
  display: grid;
  gap: 2px;
  opacity: 0.75;
}

.drag-cell {
  border-radius: 3px;
  pointer-events: none;
}

/* --- Desktop layout --- */

@media (min-width: 768px) {
  .container {
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    padding: 24px;
    gap: 32px;
  }

  .mobile-only { display: none !important; }
  .desktop-only { display: flex !important; }
  .panel-desktop { display: flex !important; }
  .panel-desktop.hidden { display: none !important; }

  .title-bar {
    justify-content: flex-start;
    margin-bottom: 4px;
  }

  .title-hr {
    border: none;
    border-top: 1px solid #333;
    width: 100%;
    margin-bottom: 8px;
  }

  .panel {
    min-width: 300px;
    max-width: 350px;
  }

  .controls { justify-content: center; }
}
