/* ===================== Farben & Themes ===================== */
:root {
  --bg: #ffffff;
  --text: #1a1a1b;
  --muted: #6b6f72;
  --line: #d3d6da;
  --tile-border: #d3d6da;
  --tile-border-filled: #878a8c;
  --key-bg: #d3d6da;
  --key-text: #1a1a1b;
  --correct: #6aaa64;
  --present: #c9b458;
  --absent: #787c7e;
  --on-color: #ffffff;
  --modal-bg: #ffffff;
  --backdrop: rgba(255, 255, 255, 0.6);
  --toast-bg: #1a1a1b;
  --toast-text: #ffffff;
  --shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
  --accent: #6aaa64;
}

html[data-theme="dark"] {
  --bg: #121213;
  --text: #f8f8f8;
  --muted: #9a9ea3;
  --line: #3a3a3c;
  --tile-border: #3a3a3c;
  --tile-border-filled: #565758;
  --key-bg: #818384;
  --key-text: #ffffff;
  --correct: #538d4e;
  --present: #b59f3b;
  --absent: #3a3a3c;
  --modal-bg: #1c1c1e;
  --backdrop: rgba(0, 0, 0, 0.55);
  --toast-bg: #f8f8f8;
  --toast-text: #121213;
  --shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
  --accent: #538d4e;
}

html[data-contrast="true"] {
  --correct: #f5793a;
  --present: #85c0f9;
  --accent: #f5793a;
}

/* ===================== Grundlayout ===================== */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Helvetica Neue", Arial, system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.2s, color 0.2s;
}

button { font-family: inherit; color: inherit; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
header h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.header-side { display: flex; gap: 2px; width: 90px; }
.header-side.right { justify-content: flex-end; }

.icon-btn {
  background: none;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.icon-btn:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }
.icon-btn svg, .btn svg {
  width: 24px; height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Modus-Umschalter */
#modes {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 10px 12px 0;
  flex-shrink: 0;
}
.mode {
  background: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.15s;
}
.mode.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

/* ===================== Spielfeld ===================== */
#board-container {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
}

#board {
  --tile: 62px;
  display: grid;
  grid-template-rows: repeat(6, var(--tile));
  gap: 5px;
}
.row {
  display: grid;
  grid-template-columns: repeat(5, var(--tile));
  gap: 5px;
}
.row.shake { animation: shake 0.6s; }

.tile {
  width: var(--tile);
  height: var(--tile);
  border: 2px solid var(--tile-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--tile) * 0.52);
  font-weight: 800;
  text-transform: uppercase;
  user-select: none;
  color: var(--text);
}
.tile[data-filled] { border-color: var(--tile-border-filled); animation: pop 0.1s; }
.tile[data-state] { border-color: transparent; color: var(--on-color); }
.tile[data-state="correct"] { background: var(--correct); }
.tile[data-state="present"] { background: var(--present); }
.tile[data-state="absent"] { background: var(--absent); }
.tile.flip { animation: flip 0.5s ease-in-out; }
.tile.bounce { animation: bounce 1s; }

.tile.small {
  --tile: 38px;
  font-size: 20px;
  border-color: var(--tile-border-filled);
}
.tile.small[data-state] { border-color: transparent; }

@keyframes pop {
  0% { transform: scale(0.85); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}
@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(-90deg); }
  100% { transform: rotateX(0); }
}
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}
@keyframes bounce {
  0%, 20% { transform: translateY(0); }
  40% { transform: translateY(-30px); }
  50% { transform: translateY(5px); }
  60% { transform: translateY(-15px); }
  80% { transform: translateY(2px); }
  100% { transform: translateY(0); }
}

/* ===================== Tastatur ===================== */
#keyboard {
  padding: 0 6px 10px;
  flex-shrink: 0;
  user-select: none;
}
.kb-row {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin-bottom: 7px;
}
.key {
  flex: 1;
  max-width: 44px;
  height: 56px;
  border: none;
  border-radius: 5px;
  background: var(--key-bg);
  color: var(--key-text);
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  transition: background-color 0.2s, transform 0.05s;
}
.key:active { transform: scale(0.94); }
.key.wide { flex: 1.6; max-width: 70px; font-size: 12px; }
.key svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.key[data-state] { color: var(--on-color); }
.key[data-state="correct"] { background: var(--correct); }
.key[data-state="present"] { background: var(--present); }
.key[data-state="absent"] { background: var(--absent); }
html:not([data-theme="dark"]) .key[data-state="absent"] { color: #fff; }

/* ===================== Toasts ===================== */
#toasts {
  position: fixed;
  top: 110px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}
.toast {
  background: var(--toast-bg);
  color: var(--toast-text);
  padding: 12px 16px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 14px;
  box-shadow: var(--shadow);
  text-align: center;
  max-width: 90vw;
  transition: opacity 0.3s;
}
.toast.fade { opacity: 0; }

/* ===================== Modals ===================== */
.modal {
  position: fixed;
  inset: 0;
  background: var(--backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal.open { opacity: 1; pointer-events: auto; }
.modal-card {
  position: relative;
  background: var(--modal-bg);
  color: var(--text);
  border-radius: 10px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 440px;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 28px 24px 24px;
  transform: translateY(20px);
  transition: transform 0.2s;
}
.modal.open .modal-card { transform: translateY(0); }
.modal h2 { font-size: 22px; margin-bottom: 14px; text-align: center; }
.modal h3 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.06em; margin: 18px 0 10px; }
.modal p { font-size: 15px; line-height: 1.45; margin: 6px 0; }
.modal ul { padding-left: 20px; margin: 10px 0; font-size: 15px; line-height: 1.5; }
.modal hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
.muted { color: var(--muted); font-size: 14px !important; }
.close {
  position: absolute;
  top: 8px; right: 12px;
  background: none;
  border: none;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}
.example { display: flex; gap: 4px; margin-top: 12px; }

/* Statistik */
.stats-row { display: flex; justify-content: center; gap: 8px; text-align: center; }
.stat { flex: 1; max-width: 90px; }
.stat .num { font-size: 34px; font-weight: 400; font-variant-numeric: tabular-nums; }
.stat .lbl { font-size: 12px; line-height: 1.2; }

#distribution { display: flex; flex-direction: column; gap: 4px; }
.dist-row { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.dist-row .n { width: 12px; font-weight: 700; }
.dist-row .bar {
  background: var(--absent);
  color: #fff;
  font-weight: 700;
  padding: 2px 8px;
  text-align: right;
  min-width: 26px;
  transition: width 0.5s ease-out;
}
.dist-row .bar.highlight { background: var(--correct); }

#stats-footer { margin-top: 20px; }
#next-info { text-align: center; font-size: 14px; margin-bottom: 12px; }
#next-info .countdown { display: block; font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
#next-info .answer { font-size: 18px; letter-spacing: 0.15em; font-weight: 800; }
.footer-buttons { display: flex; gap: 10px; justify-content: center; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 12px 22px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  flex: 1;
  max-width: 190px;
}
.btn.secondary { background: none; color: var(--text); border: 2px solid var(--line); }
.btn.danger { background: none; color: #d64545; border: 2px solid currentColor; margin-top: 18px; width: 100%; max-width: none; }
.btn svg { width: 20px; height: 20px; }
.btn:hover { filter: brightness(1.08); }
.hidden { display: none !important; }

/* Einstellungen */
.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.setting span { display: flex; flex-direction: column; gap: 2px; font-size: 16px; }
.setting small { color: var(--muted); font-size: 12px; }
.setting input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  flex-shrink: 0;
  width: 40px; height: 22px;
  border-radius: 999px;
  background: var(--tile-border-filled);
  position: relative;
  transition: background 0.2s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}
.setting input:checked + .switch { background: var(--accent); }
.setting input:checked + .switch::after { transform: translateX(18px); }
.setting input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-height: 640px) {
  .key { height: 48px; }
  header h1 { font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  .tile.flip, .tile.bounce, .row.shake, .tile[data-filled] { animation-duration: 0.01s; }
}
