:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --text: #e8eef5;
  --muted: #8b9bb4;
  --accent: #3ddc97;
  --focus: #6eb5ff;
  --danger: #ff6b6b;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(1200px 800px at 50% 0%, #1b2636, var(--bg));
  color: var(--text);
}

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: clamp(12px, 3vw, 24px);
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  padding: 12px 16px;
  background: var(--panel);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.topbar__back {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.88rem;
  transition: color 0.15s;
}

.topbar__back:hover {
  color: var(--accent);
}

.topbar__back:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: clamp(1.1rem, 2.5vw, 1.35rem);
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  margin-left: auto;
  font-size: 0.88rem;
  color: var(--muted);
}

.stats strong {
  color: var(--text);
  font-weight: 700;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  margin: 12px 0 10px;
  min-height: 1.3em;
}

.hint kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.06);
  font-family: inherit;
  font-size: 0.85em;
}

.game-layout {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
  align-items: flex-start;
}

.playfield {
  flex: 0 0 auto;
}

.board-wrap {
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: var(--panel);
  padding: 10px;
}

#boardCanvas {
  display: block;
}

.sidebar {
  flex: 0 0 auto;
  min-width: 120px;
}

.sidebar__panel {
  padding: 14px;
  background: var(--panel);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar__title {
  margin: 0 0 12px;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.next-queue {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.next-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 84px;
  padding: 6px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.next-canvas {
  display: block;
}

.status {
  text-align: center;
  min-height: 1.4em;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.status--combo {
  color: var(--accent);
  font-weight: 600;
  animation: statusPop 0.45s ease;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(8, 12, 18, 0.82);
  backdrop-filter: blur(6px);
  z-index: 100;
}

.overlay--hidden {
  display: none;
}

.overlay__panel {
  width: min(100%, 400px);
  padding: 28px 24px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.overlay__panel--compact {
  text-align: center;
}

.overlay__title {
  margin: 0 0 20px;
  font-size: 1.35rem;
  font-weight: 700;
}

.overlay__score {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 1.05rem;
}

.overlay__score strong {
  color: var(--text);
  font-size: 1.4rem;
}

.overlay__new-best {
  margin: 0 0 16px;
  color: var(--accent);
  font-weight: 600;
  animation: statusPop 0.45s ease;
}

.overlay__hint {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.overlay__hint kbd {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.06);
  font-family: inherit;
  font-size: 0.85em;
}

.overlay__actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

@keyframes statusPop {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.btn {
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.btn--primary {
  background: color-mix(in srgb, var(--accent) 25%, transparent);
  border-color: color-mix(in srgb, var(--accent) 50%, transparent);
}

.btn--primary:hover {
  background: color-mix(in srgb, var(--accent) 35%, transparent);
}

@media (max-width: 420px) {
  .game-layout {
    flex-direction: column;
    align-items: center;
  }

  .sidebar {
    width: 100%;
    max-width: 300px;
  }

  .next-queue {
    flex-direction: row;
    justify-content: center;
  }

  .next-slot {
    flex: 1;
    min-height: 72px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .status--combo,
  .overlay__new-best {
    animation: none;
  }
}
