/* Palette: https://coolors.co/palette/ccd5ae-e9edc9-fefae0-faedcd-d4a373 */
:root {
  --sage: #ccd5ae;
  --sage-light: #e9edc9;
  --cream: #fefae0;
  --peach: #faedcd;
  --tan: #d4a373;

  --bg: var(--cream);
  --surface: #fffdf2;
  --surface-2: var(--peach);
  --border: #e6dcb8;
  --text: #34362a;
  --text-muted: #6e7158;
  --accent: var(--tan);
  --accent-strong: #b9804a;
  --on-accent: #2b2418;
  --success: #6f8a3a;
  --danger: #b5553c;

  --tag-lesen: var(--sage);
  --tag-mathe: var(--peach);
  --tag-default: var(--sage-light);

  --radius: 18px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgb(52 54 42 / 0.06), 0 6px 20px rgb(52 54 42 / 0.06);
  --shadow-hover: 0 2px 4px rgb(52 54 42 / 0.08), 0 12px 32px rgb(52 54 42 / 0.12);
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #1b1c16;
  --surface: #25271e;
  --surface-2: #2f3226;
  --border: #3b3e30;
  --text: #f4f1dc;
  --text-muted: #b3b597;
  --accent: var(--tan);
  --accent-strong: #e2b88c;
  --on-accent: #1b1c16;
  --success: #b5c98a;
  --danger: #e59a82;

  --tag-lesen: #4a5236;
  --tag-mathe: #5a4630;
  --tag-default: #3c4230;

  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 6px 20px rgb(0 0 0 / 0.25);
  --shadow-hover: 0 2px 4px rgb(0 0 0 / 0.35), 0 12px 32px rgb(0 0 0 / 0.35);

  color-scheme: dark;
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1.0625rem;
  line-height: 1.5;
  transition: background-color 0.2s ease, color 0.2s ease;
}

a {
  color: inherit;
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.container {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 20px;
}

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

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.25rem;
  text-decoration: none;
  letter-spacing: -0.01em;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 1rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.15s ease;
}

.icon-btn:hover {
  background: var(--surface-2);
}

.icon-btn:active {
  transform: scale(0.95);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.theme-toggle .icon-sun {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

:root[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 22px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.15s ease;
}

.btn:hover {
  background: var(--accent-strong);
}

.btn:active {
  transform: scale(0.97);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--sage-light);
}

:root[data-theme="dark"] .btn-secondary:hover {
  background: var(--border);
}

.btn-lg {
  padding: 16px 32px;
  font-size: 1.15rem;
}

/* ---------- Home ---------- */

.hero {
  padding: 48px 0 24px;
}

.hero h1 {
  margin: 0 0 8px;
  font-size: clamp(1.9rem, 4vw, 2.6rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.hero p {
  margin: 0;
  color: var(--text-muted);
  max-width: 56ch;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 24px;
}

.chip {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

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

.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
  padding-bottom: 64px;
}

.game-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-decoration: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

a.game-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
}

.game-card-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--tag-default);
  font-size: 1.75rem;
  font-weight: 800;
}

.game-card-icon svg {
  width: 44px;
  height: 44px;
}

.game-card[data-category="lesen"] .game-card-icon {
  background: var(--tag-lesen);
}

.game-card[data-category="mathe"] .game-card-icon {
  background: var(--tag-mathe);
}

.game-card h2 {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.25;
}

.game-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.97rem;
  flex: 1;
}

.game-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
}

.tag {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--tag-default);
  color: var(--text);
}

.game-card[data-category="lesen"] .tag {
  background: var(--tag-lesen);
}

.game-card[data-category="mathe"] .tag {
  background: var(--tag-mathe);
}

.game-card.is-placeholder {
  border-style: dashed;
  box-shadow: none;
  background: transparent;
  opacity: 0.75;
}

.empty {
  grid-column: 1 / -1;
  color: var(--text-muted);
}

/* ---------- Game page ---------- */

.game-header .container {
  height: auto;
  min-height: 64px;
  padding-top: 10px;
  padding-bottom: 10px;
  flex-wrap: wrap;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  text-decoration: none;
  color: var(--text-muted);
}

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

.stats {
  display: flex;
  gap: 8px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 92px;
  padding: 4px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.stat-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

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

.stat-timer.is-running .stat-value {
  color: var(--accent-strong);
}

.game-main {
  padding-top: 32px;
  padding-bottom: 64px;
}

.game-title {
  margin: 0 0 4px;
  font-size: clamp(1.6rem, 3.5vw, 2.2rem);
  letter-spacing: -0.02em;
}

.game-intro {
  margin: 0 0 24px;
  color: var(--text-muted);
}

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

.screen[hidden] {
  display: none;
}

.screen-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
  padding: 24px 0;
}

.result-time {
  font-size: clamp(2.6rem, 8vw, 3.6rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.result-delta {
  margin: 0;
  font-weight: 700;
}

.result-delta.is-better {
  color: var(--success);
}

.result-delta.is-worse {
  color: var(--danger);
}

.history {
  width: 100%;
  max-width: 360px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  text-align: left;
}

.history-title {
  margin: 8px 0 0;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.history li {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

.history li:last-child {
  border-bottom: 0;
}

.history .is-best {
  font-weight: 800;
}

.history-date {
  color: var(--text-muted);
}

.history-score {
  margin-left: auto;
  margin-right: 16px;
  color: var(--text-muted);
}

.result-score {
  margin: 0;
  font-weight: 700;
  color: var(--text-muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}
