/* ============================================================
   NeunMalNeun – Sudoku
   Design-Tokens (Light als Basis, Dark via prefers-color-scheme)
   Identität: ruhiges Indigo/Violett mit Bernstein-Akzent
   ============================================================ */

:root {
  --bg: #f4f3f8;
  --surface: #ffffff;
  --surface-2: #eae8f2;
  --text: #26243a;
  --text-muted: #6d6a85;
  --border: #d9d6e6;
  --primary: #5348c7;
  --primary-strong: #4238ad;
  --primary-soft: #e4e1fa;
  --accent: #d98b1f;
  --accent-soft: #fbedd6;
  --danger: #c24a52;
  --danger-soft: #f9e3e4;
  --success: #2f8f6b;
  --success-soft: #ddf1e8;
  --cell-bg: #ffffff;
  --cell-given: #eeecf6;
  --cell-peer: #f0eefa;
  --cell-same: #ddd9f5;
  --cell-selected: #c9c3f0;
  --grid-line: #cfcbe0;
  --grid-line-strong: #8b86a8;
  --shadow: 0 2px 12px rgba(38, 36, 58, 0.09);
  --radius: 14px;
  --radius-small: 8px;
  --font: "Outfit", "Segoe UI", system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171522;
    --surface: #201d30;
    --surface-2: #292540;
    --text: #e9e7f4;
    --text-muted: #a09cbd;
    --border: #383353;
    --primary: #8c81f0;
    --primary-strong: #a49af7;
    --primary-soft: #2c2752;
    --accent: #e6a94f;
    --accent-soft: #3c3020;
    --danger: #e0757c;
    --danger-soft: #43272c;
    --success: #5bbb92;
    --success-soft: #1f3a30;
    --cell-bg: #201d30;
    --cell-given: #2a2740;
    --cell-peer: #262239;
    --cell-same: #353057;
    --cell-selected: #443c74;
    --grid-line: #383353;
    --grid-line-strong: #6b6491;
    --shadow: 0 2px 14px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
}

h1, h2, h3 {
  line-height: 1.2;
  font-weight: 800;
  margin: 0 0 0.5rem;
}

h3 { font-size: 1.2rem; }

p { margin: 0 0 0.75rem; }

img { max-width: 100%; }

kbd {
  font-family: inherit;
  font-size: 0.78em;
  padding: 0.1em 0.4em;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-2);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Header / Footer ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
  color: var(--text);
  font-weight: 800;
  font-size: 1.08rem;
  letter-spacing: 0.01em;
}

.header-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.8rem 1rem 1.2rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.link-button {
  background: none;
  border: none;
  padding: 0;
  margin-left: 0.9rem;
  color: var(--text-muted);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.link-button:hover { color: var(--text); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-small);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); }

@media (prefers-color-scheme: dark) {
  .btn-primary { color: #171522; }
}

.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }

.btn-small { padding: 0.35rem 0.7rem; font-size: 0.88rem; }
.btn-tiny { padding: 0.15rem 0.45rem; font-size: 0.85rem; line-height: 1; }

/* ---------- Layout ---------- */

#main {
  flex: 1;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 0.9rem 0.9rem 1.5rem;
}

.game-layout {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

@media (min-width: 720px) {
  .game-layout {
    flex-direction: row;
    align-items: flex-start;
  }
  .board-wrap { flex: 1 1 60%; }
  .controls { flex: 1 1 40%; position: sticky; top: 4.2rem; }
}

/* ---------- Modus-Tabs & Leisten ---------- */

.mode-tabs {
  display: flex;
  gap: 0.35rem;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 0.25rem;
  margin-bottom: 0.6rem;
}

.mode-tab {
  flex: 1;
  padding: 0.5rem 0.6rem;
  border: none;
  border-radius: calc(var(--radius) - 4px);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.mode-tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.mode-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
  min-height: 2.1rem;
}

.daily-date { font-weight: 700; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.88rem;
  font-weight: 600;
}

.chip-done {
  background: var(--success-soft);
  color: var(--success);
}

#sel-difficulty {
  font: inherit;
  font-weight: 600;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-small);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

/* ---------- Info-Leiste ---------- */

.info-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.info-item { white-space: nowrap; }

.info-timer { display: inline-flex; align-items: center; gap: 0.25rem; }

.timer {
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-weight: 700;
}

/* ---------- Gitter ---------- */

.board-wrap {
  position: relative;
  max-width: 520px;
  margin: 0 auto;
  width: 100%;
}

.grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  aspect-ratio: 1 / 1;
  width: 100%;
  border: 2px solid var(--grid-line-strong);
  border-radius: 10px;
  overflow: hidden;
  background: var(--grid-line);
  box-shadow: var(--shadow);
  touch-action: manipulation;
}

.cell {
  position: relative;
  border: none;
  padding: 0;
  margin: 0;
  background: var(--cell-bg);
  color: var(--primary);
  font-family: var(--font);
  font-weight: 600;
  font-size: clamp(1.05rem, 4.2vw, 1.6rem);
  font-variant-numeric: tabular-nums;
  border-right: 1px solid var(--grid-line);
  border-bottom: 1px solid var(--grid-line);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.cell.b-right { border-right: 2px solid var(--grid-line-strong); }
.cell.b-bottom { border-bottom: 2px solid var(--grid-line-strong); }
.cell:nth-child(9n) { border-right: none; }
.cell:nth-child(n+73) { border-bottom: none; }

.cell.given {
  background: var(--cell-given);
  color: var(--text);
  font-weight: 700;
}

.cell.peer { background: var(--cell-peer); }
.cell.given.peer { background: var(--cell-given); }
.cell.same { background: var(--cell-same); }
.cell.selected { background: var(--cell-selected); }
.cell.given.selected, .cell.given.same { background: var(--cell-same); }

.cell.error { color: var(--danger); }
.cell.error::after {
  content: "";
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  background: var(--danger);
  opacity: 0.12;
  pointer-events: none;
}

.cell.hinted { color: var(--accent); }

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

.notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.notes span {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.42rem, 1.55vw, 0.62rem);
  font-weight: 600;
  color: var(--text-muted);
  line-height: 1;
}

/* ---------- Overlays (Pause / Laden) ---------- */

.board-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  text-align: center;
  padding: 1rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  border-radius: 10px;
  z-index: 3;
}

.overlay-title { font-size: 1.25rem; font-weight: 800; margin: 0; }
.overlay-sub { color: var(--text-muted); margin: 0 0 0.5rem; font-size: 0.9rem; }

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 4px solid var(--primary-soft);
  border-top-color: var(--primary);
  animation: spin 0.9s linear infinite;
  margin-bottom: 0.35rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Werkzeuge & Nummernpad ---------- */

.controls { width: 100%; max-width: 520px; margin: 0 auto; }

.action-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.35rem;
  margin-bottom: 0.6rem;
}

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.45rem 0.15rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.tool:hover { background: var(--surface-2); }
.tool:disabled { opacity: 0.45; cursor: not-allowed; }

.tool[aria-pressed="true"] {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

.tool-icon { font-size: 1.05rem; line-height: 1; }
.tool-label { font-size: 0.62rem; font-weight: 600; color: var(--text-muted); white-space: nowrap; }
.tool[aria-pressed="true"] .tool-label { color: var(--primary); }

.numpad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 0.3rem;
}

@media (min-width: 720px) {
  .numpad { grid-template-columns: repeat(3, 1fr); }
}

.num-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.05rem;
  padding: 0.55rem 0.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--primary);
  font-family: var(--font);
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background 0.12s ease;
}

.num-btn:hover { background: var(--surface-2); }
.num-btn:active { background: var(--primary-soft); }

.num-btn .num-count {
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--text-muted);
}

.num-btn.depleted { opacity: 0.35; }
.num-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.key-help {
  margin-top: 0.7rem;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-align: center;
}

@media (max-width: 719px) {
  .key-help { display: none; }
}

.status-msg {
  min-height: 1.4rem;
  text-align: center;
  color: var(--accent);
  font-weight: 600;
  margin-top: 0.8rem;
}

/* ---------- Gewinn-Animation (dezent, konfetti-frei) ---------- */

.grid.won .cell {
  animation: cell-glow 0.9s ease both;
  animation-delay: calc(var(--wave) * 55ms);
}

@keyframes cell-glow {
  0% { background: var(--cell-bg); }
  45% { background: var(--success-soft); }
  100% { background: var(--cell-bg); }
}

.grid.won .cell.given {
  animation-name: cell-glow-given;
}

@keyframes cell-glow-given {
  0% { background: var(--cell-given); }
  45% { background: var(--success-soft); }
  100% { background: var(--cell-given); }
}

/* ---------- Anzeige-Slot ---------- */

.ad-slot {
  width: 100%;
  max-width: 860px;
  margin: 0 auto 0.5rem;
  padding: 0.9rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
}

.ad-hint {
  color: var(--text-muted);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ---------- Modals ---------- */

.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 1.2rem 1.3rem;
  width: min(92vw, 460px);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.modal::backdrop {
  background: rgba(20, 17, 34, 0.5);
  backdrop-filter: blur(2px);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.todo-note {
  font-size: 0.82rem;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius-small);
  padding: 0.5rem 0.7rem;
}

.premium-list { margin: 0 0 0.75rem; padding-left: 1.2rem; }
.premium-list li { margin-bottom: 0.25rem; }
.premium-price { font-size: 1.05rem; }

/* Gewonnen-Dialog */

.win-sub { color: var(--text-muted); }

.win-glow {
  position: absolute;
  inset: -40% -20% auto;
  height: 55%;
  background: radial-gradient(ellipse at center, var(--primary-soft), transparent 70%);
  pointer-events: none;
}

.win-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin: 0.8rem 0 0.3rem;
}

.win-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.6rem 0.3rem;
  background: var(--surface-2);
  border-radius: var(--radius-small);
}

.win-value {
  font-size: 1.15rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.win-label { font-size: 0.72rem; color: var(--text-muted); font-weight: 600; }

.win-best {
  color: var(--success);
  font-weight: 700;
  text-align: center;
  margin: 0.5rem 0 0;
}

/* Statistik */

.stats-streak { color: var(--text-muted); }
.stats-streak strong { color: var(--text); }

.table-wrap { overflow-x: auto; }

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.stats-table th, .stats-table td {
  text-align: left;
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.stats-table th { font-size: 0.8rem; color: var(--text-muted); }

/* Einstellungen */

.settings-group {
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  padding: 0.6rem 0.8rem 0.7rem;
  margin: 0 0 0.8rem;
}

.settings-group legend {
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0 0.3rem;
}

.radio-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.25rem 0;
  font-size: 0.92rem;
  cursor: pointer;
}

.radio-row input { margin-top: 0.2rem; accent-color: var(--primary); }

/* ---------- Duell-Modus ---------- */

@media (max-width: 500px) {
  .mode-tab { font-size: 0.8rem; padding: 0.45rem 0.15rem; }
}

.duell-setup-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 0.4rem;
}

#duell-difficulty {
  font: inherit;
  font-weight: 600;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-small);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.duell-link-row {
  display: flex;
  gap: 0.4rem;
  width: 100%;
  max-width: 340px;
  margin-bottom: 0.6rem;
}

#duell-link {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 0.8rem;
  padding: 0.4rem 0.5rem;
  border-radius: var(--radius-small);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
}

.overlay-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.countdown-num {
  font-size: 4.5rem;
  font-weight: 800;
  color: var(--primary);
  margin: 0;
  font-variant-numeric: tabular-nums;
  animation: countdown-pop 0.8s ease infinite;
}

@keyframes countdown-pop {
  0% { transform: scale(0.7); opacity: 0.4; }
  30% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.duell-stats { grid-template-columns: repeat(2, 1fr); }

.duell-opp-row {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.duell-opp-row input {
  flex: 1 1 100px;
  min-width: 0;
  font: inherit;
  padding: 0.4rem 0.55rem;
  border-radius: var(--radius-small);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.duell-opp-msg {
  min-height: 1.2rem;
  font-size: 0.85rem;
  color: var(--success);
  font-weight: 600;
  margin: 0.4rem 0 0;
}

.modal-actions-left {
  justify-content: flex-start;
  margin-top: 0.2rem;
  margin-bottom: 0.8rem;
}

/* ---------- Sudoku-Schule ---------- */

.school-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.2rem;
}

.school-head h2 { margin: 0; font-size: 1.35rem; }

.school-tagline {
  color: var(--text-muted);
  margin-bottom: 0.8rem;
}

.school-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.9rem;
}

.school-tab {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  cursor: pointer;
}

.school-tab:hover { background: var(--surface-2); }

.school-tab.active {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

.school-tab.done { color: var(--success); }
.school-tab.done.active { color: var(--primary); }

.school-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1.2rem;
  box-shadow: var(--shadow);
}

.school-intro {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.school-board-wrap {
  max-width: 400px;
  margin: 0.8rem auto;
}

.school-grid .cell {
  cursor: default;
  font-size: clamp(0.85rem, 3.4vw, 1.25rem);
}

.school-grid.sc-interactive .cell:not(.given) { cursor: pointer; }

.school-grid .cell.sc-unit,
.school-grid .cell.given.sc-unit { background: var(--accent-soft); }

.school-grid .cell.sc-focus { box-shadow: inset 0 0 0 2px var(--accent); }

.school-grid .cell.selected { background: var(--cell-selected); }

.school-grid .cell.sc-good {
  background: var(--success-soft);
  color: var(--success);
  box-shadow: inset 0 0 0 2px var(--success);
}

.school-caption { font-weight: 600; }

.school-feedback {
  min-height: 1.4rem;
  font-weight: 600;
  margin: 0.5rem 0 0.3rem;
}

.school-feedback.is-ok { color: var(--success); }
.school-feedback.is-warn { color: var(--accent); }

.school-numpad {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  justify-content: center;
  margin: 0.6rem 0 0.2rem;
}

.num-btn-small {
  flex: 0 0 auto;
  width: 2.4rem;
  padding: 0.45rem 0;
}

.num-btn-small[aria-pressed="true"] {
  background: var(--primary-soft);
  border-color: var(--primary);
}

.school-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 0.4rem;
}

.school-complete {
  margin-top: 0.9rem;
  background: var(--success-soft);
  border: 1px solid var(--success);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  flex-wrap: wrap;
}

.school-complete p { margin: 0; }

.school-hint {
  text-align: center;
  margin: 0.6rem 0 0;
  font-size: 0.85rem;
}

/* ---------- Reduzierte Bewegung ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .spinner { animation: spin 1.5s linear infinite !important; animation-duration: 1.5s !important; }
}
