:root {
  --bg: #f3f2ef;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #666666;
  --border: #e0dfdc;
  --accent: #0a66c2;
  --accent-text: #ffffff;
  --orange: #e8642c;
  --visited: #fbd9c3;
  --cell: #fafafa;
  --grid-line: #c9c9c9;
  --clue: #111111;
  --clue-text: #ffffff;
  --you: #fff4e8;
  --error: #b3261e;
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1f23;
    --surface: #24292e;
    --text: #f0f0f0;
    --muted: #a8adb3;
    --border: #3a4047;
    --accent: #70b5f9;
    --accent-text: #0b1a2a;
    --visited: #5a3626;
    --cell: #2c3238;
    --grid-line: #49515a;
    --clue: #f4f4f4;
    --clue-text: #111111;
    --you: #3b2c20;
    --error: #ff8a80;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); }
h1, h2 { line-height: 1.2; margin: 0 0 12px; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.player-chip {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  max-width: 55vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app { max-width: 560px; margin: 0 auto; padding: 16px 16px 48px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.site-footer { text-align: center; padding: 0 16px 32px; font-size: 0.85rem; }
.site-footer a { color: var(--muted); }
.legal h2 { margin-top: 20px; }
.legal ul { padding-left: 20px; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.eyebrow { color: var(--orange); font-weight: 600; margin: 0 0 4px; text-transform: capitalize; }
.hero { padding: 12px 4px 20px; }
.crumbs { margin: 0 0 12px; }
.crumbs a { text-decoration: none; font-weight: 600; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 999px;
  padding: 10px 20px;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: 1.5px solid var(--accent);
  min-height: 44px;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-danger { background: var(--error); border-color: var(--error); color: var(--surface); }
.danger-zone summary { cursor: pointer; font-weight: 600; color: var(--error); padding: 10px 0; }
.btn-large { font-size: 1.1rem; padding: 12px 40px; }
.full { width: 100%; margin-top: 16px; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }

/* Startseite */
.game-list { display: grid; gap: 12px; }
.game-card {
  display: flex;
  gap: 16px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  color: var(--text);
  text-decoration: none;
  transition: transform 0.15s, box-shadow 0.15s;
}
.game-card:not(.is-soon):hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgb(0 0 0 / 0.08); }
.game-card h2 { margin: 0 0 4px; }
.game-card p { margin: 0 0 8px; color: var(--muted); font-size: 0.92rem; }
.game-card.is-soon { opacity: 0.6; }
.game-card.is-soon p { margin: 0; }
.game-icon { flex: none; width: 64px; height: 64px; border-radius: 14px; background: var(--border); }
.game-icon-zip {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M9 9h14L9 23h14' fill='none' stroke='%23fff' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
    center / 70% no-repeat,
    linear-gradient(135deg, #e85d26, #f6a840);
}
.game-icon-queens {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M6 23 4 10l7 6 5-9 5 9 7-6-2 13z' fill='%23fff'/%3E%3Crect x='6' y='25' width='20' height='3' rx='1.5' fill='%23fff'/%3E%3C/svg%3E")
    center / 68% no-repeat,
    linear-gradient(135deg, #7b4bd6, #c08cf0);
}
.game-icon-tango {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Ccircle cx='8.5' cy='16' r='5.5' fill='%23fff'/%3E%3Cpath d='M24 8A8 8 0 1 0 24 24 10 10 0 0 1 24 8z' fill='%23fff'/%3E%3C/svg%3E")
    center / 72% no-repeat,
    linear-gradient(135deg, #f2a81d, #2f6fd6);
}
.game-icon-sudoku {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M5 5h22v22H5zM16 5v22M5 12.3h22M5 19.7h22' fill='none' stroke='%23fff' stroke-width='2.5' stroke-linejoin='round'/%3E%3C/svg%3E")
    center / 70% no-repeat,
    linear-gradient(135deg, #12907a, #5fd0b4);
}
.game-icon-patches {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect x='5' y='5' width='13' height='9' rx='2' fill='%23fff'/%3E%3Crect x='20' y='5' width='7' height='22' rx='2' fill='%23fff' opacity='.75'/%3E%3Crect x='5' y='16' width='13' height='11' rx='2' fill='%23fff' opacity='.9'/%3E%3C/svg%3E")
    center / 70% no-repeat,
    linear-gradient(135deg, #d6457a, #f59ab8);
}
.badge {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--visited);
  color: var(--text);
}

/* Spielmenü */
.rules { margin: 0; padding-left: 20px; }
.rules li { margin-bottom: 8px; }
.difficulty-list { display: grid; gap: 10px; }
.difficulty {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: 'name status' 'size status';
  align-items: center;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
}
.difficulty:hover { border-color: var(--orange); }
.difficulty-name { grid-area: name; font-weight: 700; }
.difficulty-size { grid-area: size; color: var(--muted); font-size: 0.85rem; }
.difficulty-status { grid-area: status; font-weight: 600; color: var(--accent); font-size: 0.9rem; text-align: right; }
.difficulty.is-done { background: var(--you); }
.difficulty.is-done .difficulty-status { color: var(--orange); }

/* Spielfeld */
.play-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-bottom: 14px;
}
.play-header .stat:last-child { text-align: right; }
.play-title { display: flex; flex-direction: column; align-items: center; }
.play-title span { color: var(--muted); font-size: 0.85rem; }
.stat { display: flex; flex-direction: column; }
.stat-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.stat-value { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.board-stage { position: relative; }
.board-wrap.is-hidden { min-height: min(92vw, 480px); }
.board-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
}
.board-overlay p { margin: 0; color: var(--muted); max-width: 32ch; }

.zip-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);
  width: min(100%, 480px);
  aspect-ratio: var(--cols) / var(--rows);
  margin: 0 auto;
  border: 2px solid var(--grid-line);
  border-radius: 18px;
  overflow: hidden;
  background: var(--cell);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  outline: none;
  cursor: pointer;
}
.zip-board:focus-visible { box-shadow: 0 0 0 3px var(--accent); }
.zip-cell {
  position: relative;
  border-right: 1px solid var(--grid-line);
  border-bottom: 1px solid var(--grid-line);
  display: grid;
  place-items: center;
  transition: background-color 0.12s;
}
.zip-cell.is-last-col { border-right: 0; }
.zip-cell.is-last-row { border-bottom: 0; }
.zip-cell.is-visited { background: var(--visited); }
.zip-path {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}
.zip-path line { stroke-width: 0.66; stroke-linecap: round; }
.zip-clue {
  position: relative;
  z-index: 2;
  width: 46%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--clue);
  color: var(--clue-text);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: clamp(0.8rem, 4.5vw, 1.25rem);
  pointer-events: none;
}
.zip-cell.is-head::after {
  content: '';
  position: absolute;
  inset: 22%;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgb(255 255 255 / 0.85);
  z-index: 2;
  pointer-events: none;
}
.zip-board.is-solved { animation: solved 0.6s ease; border-color: var(--orange); }
@keyframes solved {
  40% { transform: scale(1.03); }
}

/* Raster-Spiele (Queens, Tango, Mini-Sudoku, Patches) */
.grid-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);
  width: min(100%, 480px);
  aspect-ratio: var(--cols) / var(--rows);
  margin: 0 auto;
  border: 2px solid var(--grid-line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--cell);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  outline: none;
  cursor: pointer;
}
.grid-board:focus-visible { box-shadow: 0 0 0 3px var(--accent); }
.grid-cell {
  position: relative;
  display: grid;
  place-items: center;
  border-right: 1px solid var(--grid-line);
  border-bottom: 1px solid var(--grid-line);
  font-weight: 700;
  font-size: clamp(0.9rem, 5vw, 1.5rem);
  line-height: 1;
}
.grid-cell.is-last-col { border-right: 0; }
.grid-cell.is-last-row { border-bottom: 0; }
.grid-board:focus-visible .grid-cell.is-cursor { box-shadow: inset 0 0 0 3px var(--accent); }
.grid-board.is-solved { animation: solved 0.6s ease; border-color: var(--orange); }

/* Queens */
.queens-board .grid-cell { color: #1d1d1f; }
.queens-board .grid-cell.edge-r { border-right: 2.5px solid #1d1d1f; }
.queens-board .grid-cell.edge-b { border-bottom: 2.5px solid #1d1d1f; }
.queens-board .grid-cell.is-mark { font-size: clamp(0.7rem, 3.5vw, 1rem); color: rgb(0 0 0 / 0.45); }
.queens-board .grid-cell.is-queen { font-size: clamp(1.1rem, 6vw, 1.9rem); }
.queens-board .grid-cell.is-conflict { color: var(--error); background-image: repeating-linear-gradient(45deg, rgb(179 38 30 / 0.22) 0 4px, transparent 4px 9px); }
.region-0 { background: #f5c77e; }
.region-1 { background: #b4d4f5; }
.region-2 { background: #c8e6a8; }
.region-3 { background: #f0a8a0; }
.region-4 { background: #d9c3f0; }
.region-5 { background: #f7e59a; }
.region-6 { background: #a8e0dc; }
.region-7 { background: #e2e2e2; }
.region-8 { background: #f5bfd9; }

/* Tango */
.tango-board .grid-cell { overflow: visible; }
.tango-board .grid-cell.is-given { background: var(--border); }
.tango-board .grid-cell.is-conflict { background-image: repeating-linear-gradient(45deg, rgb(179 38 30 / 0.25) 0 4px, transparent 4px 9px); }
.tango-symbol { width: 56%; aspect-ratio: 1; border-radius: 50%; }
.tango-symbol.is-sun { background: radial-gradient(circle at 35% 35%, #ffd36b, #f08a1c); box-shadow: 0 0 0 2px #e07a10; }
.tango-symbol.is-moon { background: transparent; box-shadow: inset -0.5em -0.15em 0 0 #3a6fd8; transform: rotate(-20deg); }
.tango-edge {
  position: absolute;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 1.3em;
  height: 1.3em;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font-size: clamp(0.65rem, 3vw, 0.85rem);
  font-weight: 700;
  pointer-events: none;
}
.tango-edge.is-right { right: 0; top: 50%; transform: translate(50%, -50%); }
.tango-edge.is-below { bottom: 0; left: 50%; transform: translate(-50%, 50%); }

/* Queens: Umschalter „Erster Tipp“ (zwei aneinanderliegende Hälften) */
.queens-mode {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  margin: 0 auto 10px;
}
.queens-mode-label { font-size: 0.85rem; color: var(--muted); margin-right: 8px; white-space: nowrap; }
.queens-mode-btn {
  min-height: 44px;
  padding: 0 12px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.queens-mode-btn:first-of-type { border-radius: 999px 0 0 999px; border-right-width: 0; }
.queens-mode-btn:last-of-type { border-radius: 0 999px 999px 0; }
.queens-mode-btn[aria-pressed='true'] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.queens-mode-error { flex-basis: 100%; text-align: center; font-size: 0.85rem; color: var(--error); }

/* Mini-Sudoku */
.sudoku-board .grid-cell.edge-r { border-right: 2.5px solid var(--text); }
.sudoku-board .grid-cell.edge-b { border-bottom: 2.5px solid var(--text); }
.sudoku-board .grid-cell { color: var(--accent); font-weight: 600; }
.sudoku-board .grid-cell.is-given { color: var(--text); font-weight: 800; }
.sudoku-board .grid-cell.is-related { background: var(--you); }
.sudoku-board .grid-cell.is-same { background: var(--visited); }
.sudoku-board .grid-cell.is-selected { background: var(--visited); box-shadow: inset 0 0 0 3px var(--orange); }
.sudoku-board .grid-cell.is-conflict { color: var(--error); background-image: repeating-linear-gradient(45deg, rgb(179 38 30 / 0.2) 0 4px, transparent 4px 9px); }
.sudoku-wrap { position: relative; }
.sudoku-ring {
  position: absolute;
  z-index: 20;
  width: 0;
  height: 0;
  display: none;
}
.sudoku-ring.is-open { display: block; }
.sudoku-ring-disc,
.sudoku-ring-key {
  position: absolute;
  transform: translate(-50%, -50%);
  animation: ring-in 140ms ease-out;
}
.sudoku-ring-disc {
  left: 0;
  top: 0;
  width: var(--disc);
  height: var(--disc);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.25), 0 0 0 1px var(--border);
}
.sudoku-ring-key {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 0;
  padding: 0;
  background: rgb(10 102 194 / 0.12);
  color: var(--text);
  font: inherit;
  font-size: 1.35rem;
  font-weight: 700;
  cursor: pointer;
}
.sudoku-ring-key.is-used { background: var(--bg); color: var(--muted); font-weight: 600; }
.sudoku-ring-key.is-current { background: var(--accent); color: var(--accent-text); }
.sudoku-ring-key.is-eraser { left: 0; top: 0; width: 44px; height: 44px; background: var(--bg); color: var(--muted); border: 1px solid var(--border); font-size: 1.1rem; }
@keyframes ring-in { from { opacity: 0; transform: translate(-50%, -50%) scale(0.4); } }
@media (prefers-reduced-motion: reduce) { .sudoku-ring-disc, .sudoku-ring-key { animation: none; } }

/* Patches */
.patches-board .grid-cell { z-index: 2; border-color: rgb(127 127 127 / 0.35); }
.patch {
  position: relative;
  z-index: 1;
  margin: 3px;
  border-radius: 8px;
  border: 2.5px solid rgb(0 0 0 / 0.35);
  pointer-events: none;
}
.patch.is-empty { background: rgb(127 127 127 / 0.25); }
.patch.is-conflict { border: 3px dashed var(--error); }
.patches-clue {
  display: grid;
  place-items: center;
  color: #1d1d1f;
  font-size: clamp(0.75rem, 3.8vw, 1.05rem);
  border: 2.5px solid rgb(0 0 0 / 0.55);
  pointer-events: none;
}
.patches-clue.shape-square { width: 58%; height: 58%; border-radius: 5px; }
.patches-clue.shape-wide { width: 74%; height: 46%; border-radius: 5px; }
.patches-clue.shape-tall { width: 46%; height: 74%; border-radius: 5px; }
.patches-clue.shape-any { width: 58%; height: 58%; border-radius: 50%; }
.color-0 { background: #f5c77e; }
.color-1 { background: #b4d4f5; }
.color-2 { background: #c8e6a8; }
.color-3 { background: #f0a8a0; }
.color-4 { background: #d9c3f0; }
.color-5 { background: #f7e59a; }
.color-6 { background: #a8e0dc; }
.color-7 { background: #f5bfd9; }
.color-8 { background: #d8c8a8; }
.color-9 { background: #bfc8f5; }
.color-10 { background: #e3f0a0; }
.color-11 { background: #f5d0b4; }

.play-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: min(100%, 480px);
  margin: 16px auto 0;
}
.play-actions .btn { padding: 10px 4px; font-size: 0.92rem; white-space: nowrap; }
.grid-cell.is-hint, .zip-cell.is-hint { animation: hint 1.6s ease; }
@keyframes hint {
  0%, 60% { box-shadow: inset 0 0 0 4px #f5b400, 0 0 14px #f5b400; }
}

/* Ergebnis & Bestenliste */
.result-emoji { font-size: 2.6rem; }
.result-stats { display: flex; justify-content: center; gap: 40px; margin: 8px 0 12px; }
.result-stats > div { display: flex; flex-direction: column; }
.rank { font-size: 1.1rem; margin: 0; }
.notice { background: var(--you); border-radius: 10px; padding: 10px 14px; margin: 8px 0 0; font-size: 0.92rem; }
.notice.is-error { color: var(--error); }

.tabs { display: flex; gap: 6px; margin: 12px 0; flex-wrap: wrap; }
.tab {
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 999px;
  padding: 6px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.tab.is-active { background: var(--text); color: var(--surface); border-color: var(--text); }
.leaderboard { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.leaderboard th { text-align: left; font-size: 0.78rem; text-transform: uppercase; color: var(--muted); padding: 6px 8px; }
.leaderboard td { padding: 9px 8px; border-top: 1px solid var(--border); }
.leaderboard .num { text-align: right; }
.leaderboard .pos { width: 2.5em; }
.leaderboard .name { overflow-wrap: anywhere; }
.leaderboard tr.is-you td { background: var(--you); font-weight: 600; }
.leaderboard tr.gap td { text-align: center; color: var(--muted); }
.you { color: var(--muted); font-weight: 400; }

/* Konto & Formulare */
.narrow { max-width: 420px; margin-left: auto; margin-right: auto; }
.form { display: grid; gap: 14px; }
.form .full { margin-top: 4px; }
.field { display: grid; gap: 4px; }
.field > span { font-weight: 600; font-size: 0.92rem; }
.field input {
  width: 100%;
  padding: 12px;
  font: inherit;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
.field input:focus { outline: none; border-color: var(--accent); }
.form-links { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 0.92rem; }
.notice.is-success { background: #e3f4e6; color: #1e5b2b; }
@media (prefers-color-scheme: dark) {
  .notice.is-success { background: #1f3a26; color: #b5e3c0; }
}
.account { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0 0 8px; }
.account dt { color: var(--muted); }
.account dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.row.left { justify-content: flex-start; }
a.player-chip { text-decoration: none; }
.notice.flash { margin: 0 0 16px; }
