/* ── Reset & base ────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: #0f0f1a;
  color: #e0e0e0;
  font-family: 'Segoe UI', 'Consolas', monospace;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  overflow: hidden;
}

/* ── Wrapper ─────────────────────────────────────────── */
#game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

h1 {
  font-size: 2.4rem;
  letter-spacing: 0.6rem;
  color: #00e5ff;
  text-shadow: 0 0 12px #00e5ff88;
}

/* ── Main area ───────────────────────────────────────── */
#main-area {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  position: relative;
}

/* ── Board canvas ────────────────────────────────────── */
#board {
  border: 3px solid #00e5ff;
  border-radius: 4px;
  background: #111;
  box-shadow: 0 0 20px #00e5ff44;
}

/* ── Side panels ─────────────────────────────────────── */
#left-panel, #right-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 140px;
}

.panel-section {
  background: #1a1a2e;
  border: 2px solid #333;
  border-radius: 6px;
  padding: 10px 14px;
  text-align: center;
}

.panel-section h3 {
  font-size: 0.75rem;
  letter-spacing: 0.2rem;
  color: #888;
  margin-bottom: 6px;
}

.panel-section p {
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
}

.panel-section canvas {
  display: block;
  margin: 0 auto;
  background: #111;
  border-radius: 4px;
}

/* ── High scores ─────────────────────────────────────── */
.high-scores ol {
  text-align: left;
  padding-left: 18px;
  font-size: 0.8rem;
  line-height: 1.7;
  color: #ccc;
}
.high-scores ol li::marker {
  color: #00e5ff;
}

/* ── Overlay ─────────────────────────────────────────── */
.overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
  border-radius: 4px;
}
.overlay.hidden { display: none; }

#overlay-content {
  text-align: center;
}

#overlay-title {
  font-size: 2rem;
  color: #00e5ff;
  margin-bottom: 12px;
}

#overlay-message {
  font-size: 1rem;
  color: #ccc;
  animation: blink 1.2s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Game-over form */
#game-over-form {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
#game-over-form.hidden { display: none; }

#player-name {
  padding: 6px 10px;
  font-size: 1rem;
  border: 2px solid #00e5ff;
  border-radius: 4px;
  background: #1a1a2e;
  color: #fff;
  text-align: center;
  outline: none;
  width: 180px;
}
#player-name:focus {
  box-shadow: 0 0 8px #00e5ff66;
}

#save-score-btn {
  padding: 6px 18px;
  font-size: 0.9rem;
  border: none;
  border-radius: 4px;
  background: #00e5ff;
  color: #111;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
}
#save-score-btn:hover {
  background: #00bcd4;
}

/* ── Controls guide ──────────────────────────────────── */
#controls {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 0.75rem;
  color: #666;
}
#controls span {
  background: #1a1a2e;
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid #333;
}

/* ── Rules panel ─────────────────────────────────────── */
details.rules{background:#1a1a2e;border:1px solid #333;border-radius:8px;padding:0;margin:8px auto;max-width:420px;width:100%;font-size:.78rem;color:#aaa}
details.rules summary{cursor:pointer;padding:8px 14px;color:#888;font-size:.8rem;letter-spacing:.08rem;list-style:none;user-select:none}
details.rules summary::-webkit-details-marker{display:none}
details.rules summary::before{content:"▸ ";color:#00e5ff}
details.rules[open] summary::before{content:"▾ "}
details.rules .rules-body{padding:4px 14px 12px}
details.rules .rules-body h4{color:#00e5ff;font-size:.75rem;margin:8px 0 4px;letter-spacing:.06rem}
details.rules .rules-body ul{padding-left:16px;margin:0}
details.rules .rules-body li{margin:2px 0;line-height:1.5}
details.rules .rules-body kbd{background:#252542;border:1px solid #444;border-radius:3px;padding:1px 5px;font-size:.72rem;color:#ccc}

/* ── Mobile Touch Controls ────────────────────────────── */
#mobile-controls {
  display: none;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
  position: relative;
  z-index: 15;
}
.mc-row {
  display: flex;
  gap: 6px;
  justify-content: center;
}
.mc-spacer { flex: 1; }
.mc-btn {
  flex: 1;
  max-width: 72px;
  height: 52px;
  border: 2px solid #00e5ff;
  border-radius: 10px;
  background: #1a1a2e;
  color: #00e5ff;
  font-size: 1.3rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s, transform 0.1s;
}
.mc-btn:active {
  background: #00e5ff33;
  transform: scale(0.93);
}
.mc-btn.mc-accent {
  border-color: #f0a000;
  color: #f0a000;
}
.mc-btn.mc-accent:active {
  background: #f0a00033;
}
.mc-btn.mc-sm {
  font-size: 0.75rem;
  height: 38px;
  flex: 0 0 auto;
  padding: 0 18px;
  letter-spacing: 0.05rem;
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 680px) {
  html, body { overscroll-behavior: none; }
  body { overflow: hidden; align-items: flex-start; }

  #game-wrapper {
    height: 100vh;
    height: 100dvh;
    padding: 6px 8px 10px;
    gap: 4px;
    justify-content: flex-start;
    width: 100%;
  }

  h1 { font-size: 1.3rem; letter-spacing: 0.3rem; }
  details.rules { display: none; }

  #main-area {
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex: 1;
    min-height: 0;
  }

  #left-panel, #right-panel {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
  }

  .panel-section { padding: 4px 8px; min-width: auto; }
  .panel-section h3 { font-size: 0.6rem; margin-bottom: 2px; }
  .panel-section p { font-size: 1rem; }
  #next-canvas, #hold-canvas { width: 50px; height: 50px; }
  .high-scores { display: none; }

  #board {
    flex: 1;
    min-height: 0;
    height: calc(100dvh - 300px);
    width: calc((100dvh - 300px) / 2);
    max-height: 500px;
    max-width: 250px;
  }
  #board { touch-action: none; }

  #controls { display: none; }
  #mobile-controls { display: flex; }
}
