:root {
  color-scheme: dark;
  --bg: #0f172a;
  --bg-deep: #020617;
  --panel: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.1);
  --accent: #f29c38;
  --text: #f8fafc;
  --muted: #cbd5f5;
  --success: #22c55e;
  --danger: #f97316;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Nunito", sans-serif;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
  color: var(--text);
}

h1,
h2,
h3 {
  font-family: "Poppins", sans-serif;
  margin: 0 0 0.5rem;
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}

.eyebrow {
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0 0 0.25rem;
}

.subtitle {
  color: var(--muted);
  font-size: 1.05rem;
}

.hero {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.instructions {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem 1.5rem;
}

.instructions ul {
  padding-left: 1.1rem;
  margin: 0.5rem 0 0;
  color: var(--muted);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.5rem;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.35);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-weight: 600;
}

.field select,
.field button {
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0f1c3a;
  color: var(--text);
  font-size: 1rem;
}

.field button {
  cursor: pointer;
  font-weight: 700;
}

.field button[aria-pressed="true"] {
  background: rgba(242, 156, 56, 0.2);
  border-color: rgba(242, 156, 56, 0.5);
}

.category-preview {
  margin-top: 1.25rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.chip {
  border: 1px solid var(--border);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.9rem;
  background: rgba(2, 6, 23, 0.5);
}

.actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.note {
  color: var(--muted);
  margin: 0;
}

button.primary,
button.secondary,
button.ghost {
  padding: 0.75rem 1.4rem;
  font-size: 1rem;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 700;
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  color: #1e1b0d;
}

button.secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.2);
}

button.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}

.error {
  margin-top: 1rem;
  color: #ffb37b;
  background: rgba(251, 146, 60, 0.15);
  padding: 0.75rem 1rem;
  border-radius: 12px;
  border: 1px solid rgba(251, 146, 60, 0.4);
}

.game-area {
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

.board-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.board-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.status {
  display: flex;
  gap: 0.75rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 0.75rem;
  min-height: 520px;
}

.column {
  background: rgba(2, 6, 23, 0.6);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.column-header {
  padding: 0.75rem;
  font-weight: 700;
  text-align: center;
  background: rgba(255, 255, 255, 0.08);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.column-stack {
  flex: 1;
  display: grid;
  grid-template-rows: repeat(14, minmax(0, 1fr));
  gap: 0.35rem;
  padding: 0.75rem 0.6rem 0.9rem;
}

.tile {
  background: rgba(255, 255, 255, 0.95);
  color: #0f172a;
  border-radius: 10px;
  padding: 0.35rem 0.4rem 0.4rem;
  font-size: 0.85rem;
  line-height: 1.2;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  box-shadow: 0 6px 12px rgba(15, 23, 42, 0.25);
  border-left: 4px solid var(--accent);
}

.tile .tag {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  color: rgba(15, 23, 42, 0.7);
}

.tile.misconception {
  border-left-color: #ef4444;
}

.tile.function {
  border-left-color: #38bdf8;
}

.tile.example {
  border-left-color: #34d399;
}

.tile.prompt {
  border-left-color: #f29c38;
}

.falling {
  outline: 2px dashed rgba(242, 156, 56, 0.7);
  outline-offset: -2px;
}

.controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem;
}

.control-btn {
  padding: 0.75rem 0.5rem;
  font-size: 1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.8);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.stats .stat-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 1rem;
}

.stats .stat-grid.small {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: -0.5rem;
}

.stat {
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem;
}

.stat .label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.stat span:last-child {
  font-size: 1.2rem;
  font-weight: 700;
}

.buttons {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.legend {
  color: var(--muted);
  font-size: 0.9rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 2rem;
  transform: translateX(-50%);
  background: rgba(2, 6, 23, 0.95);
  border: 1px solid var(--border);
  padding: 0.85rem 1.2rem;
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.4);
  max-width: 640px;
  text-align: center;
  z-index: 10;
}

.toast.success {
  border-color: rgba(34, 197, 94, 0.6);
  color: #bbf7d0;
}

.toast.error {
  border-color: rgba(248, 113, 113, 0.6);
  color: #fecaca;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 20;
  pointer-events: auto;
}

.modal[hidden] {
  display: none;
  pointer-events: none;
}

.modal-content {
  max-width: 900px;
  width: 100%;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin: 1rem 0 1.5rem;
}

.summary-list {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--muted);
}

@media (max-width: 900px) {
  .game-area {
    grid-template-columns: 1fr;
  }

  .board {
    min-height: 480px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}
