/* ==========================================================================
   Kurtstaben – Styles
   Eigenständiges, poliertes Dark-Design im Kurt-Look.
   ========================================================================== */

:root {
  --bg-0: #0c1015;
  --bg-1: #121821;
  --bg-2: #18212d;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-strong: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.22);
  --text: #eef2f7;
  --text-dim: #9aa7b6;
  --text-faint: #5d6b7c;

  --correct: #5aab5a;
  --correct-glow: rgba(90, 171, 90, 0.55);
  --present: #d6a23a;
  --present-glow: rgba(214, 162, 58, 0.5);
  --absent: #353f4c;

  --accent: #6fcf6f;
  --accent-2: #45c4d6;
  --danger: #e2604f;

  --tile: clamp(48px, 14vw, 64px);
  --radius: 14px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;

  --flip-speed: 320ms;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1100px 700px at 50% -10%, rgba(111, 207, 111, 0.10), transparent 60%),
    radial-gradient(900px 600px at 85% 110%, rgba(69, 196, 214, 0.08), transparent 55%),
    linear-gradient(160deg, var(--bg-0), var(--bg-1) 55%, var(--bg-2));
  background-attachment: fixed;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ---- Header ------------------------------------------------------------- */
.app {
  width: 100%;
  max-width: 520px;
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0 12px 16px;
}

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 4px 10px;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand .logo {
  width: 34px;
  height: 34px;
  flex: none;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.4));
}

.brand h1 {
  font-size: clamp(20px, 6vw, 26px);
  letter-spacing: 0.5px;
  margin: 0;
  font-weight: 800;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  white-space: nowrap;
}

.icon-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  font-size: 19px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.18s, transform 0.12s, border-color 0.18s;
}
.icon-btn:hover { background: var(--surface-strong); border-color: var(--border-strong); }
.icon-btn:active { transform: scale(0.92); }
.topbar-actions { display: flex; gap: 8px; }

/* ---- Mode switch -------------------------------------------------------- */
.mode-switch {
  display: flex;
  gap: 4px;
  margin: 12px auto 4px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.mode-switch button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  padding: 7px 18px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.18s, background 0.25s;
}
.mode-switch button.active {
  color: #0c130c;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  box-shadow: 0 4px 14px rgba(111, 207, 111, 0.28);
}

/* ---- Board -------------------------------------------------------------- */
.board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 0;
}

.board {
  display: grid;
  grid-template-rows: repeat(6, var(--tile));
  gap: 7px;
}
.row {
  display: grid;
  grid-template-columns: repeat(5, var(--tile));
  gap: 7px;
}
.tile {
  width: var(--tile);
  height: var(--tile);
  display: grid;
  place-items: center;
  font-size: calc(var(--tile) * 0.46);
  font-weight: 800;
  text-transform: uppercase;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: transparent;
  color: var(--text);
  perspective: 600px;
  transition: border-color 0.12s, transform 0.08s;
}
.tile.filled {
  border-color: var(--border-strong);
  animation: pop 0.12s ease;
}
@keyframes pop {
  0% { transform: scale(0.86); }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* Flip reveal */
.tile.reveal {
  animation: flip var(--flip-speed) ease forwards;
}
@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(-90deg); }
  100% { transform: rotateX(0); }
}
.tile.correct {
  background: var(--correct);
  border-color: var(--correct);
  color: #fff;
}
.tile.present {
  background: var(--present);
  border-color: var(--present);
  color: #fff;
}
.tile.absent {
  background: var(--absent);
  border-color: var(--absent);
  color: #d7dee6;
}

/* Win bounce */
.row.win .tile {
  animation: bounce 0.6s ease;
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  30% { transform: translateY(-22px) scale(1.05); }
  50% { transform: translateY(4px); }
  70% { transform: translateY(-8px); }
}

/* Invalid shake */
.row.shake {
  animation: shake 0.45s ease;
}
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

/* ---- Toast -------------------------------------------------------------- */
.toast-layer {
  position: fixed;
  top: 78px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: #f4f6f9;
  color: #14181d;
  font-weight: 700;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: toastIn 0.18s ease, toastOut 0.3s ease forwards;
  animation-delay: 0s, 1.4s;
}
.toast.checking { background: #2a3744; color: var(--text); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px); } }

/* ---- Keyboard ----------------------------------------------------------- */
.keyboard {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 8px 2px env(safe-area-inset-bottom, 4px);
  width: 100%;
}
.krow {
  display: flex;
  justify-content: center;
  gap: 5px;
}
.key {
  appearance: none;
  border: 0;
  flex: 1;
  min-width: 0;
  max-width: 44px;
  height: 56px;
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.18s, transform 0.08s, color 0.18s;
  display: grid;
  place-items: center;
}
.key:active { transform: translateY(1px) scale(0.96); }
.key.wide {
  flex: 1.6;
  max-width: 64px;
  font-size: 12px;
}
.key svg { width: 22px; height: 22px; }
.key.correct { background: var(--correct); color: #fff; }
.key.present { background: var(--present); color: #fff; }
.key.absent { background: var(--absent); color: var(--text-faint); }
.key.flash { animation: keyflash 0.3s ease; }
@keyframes keyflash { 50% { transform: scale(1.18); } }

/* ---- Overlay / modals --------------------------------------------------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(5, 8, 11, 0.6);
  backdrop-filter: blur(8px);
}
.overlay.open { display: flex; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  width: 100%;
  max-width: 420px;
  background: linear-gradient(180deg, rgba(30, 40, 52, 0.96), rgba(18, 24, 33, 0.98));
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 22px 22px 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  animation: sheetIn 0.32s cubic-bezier(0.2, 0.9, 0.25, 1);
  max-height: calc(100dvh - 36px);
  overflow-y: auto;
}
@keyframes sheetIn {
  from { opacity: 0; transform: translateY(24px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.sheet h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
}
.sheet .sub { color: var(--text-dim); font-size: 14px; margin: 2px 0 0; }
.sheet p { color: var(--text-dim); font-size: 14px; line-height: 1.5; }

.result-word {
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 4px;
  text-align: center;
  margin: 6px 0 4px;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.definition {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  margin: 12px 0;
  min-height: 20px;
  animation: fadeIn 0.5s ease;
}
.definition .pos { color: var(--accent-2); font-weight: 700; font-style: italic; margin-right: 6px; }
.definition.loading { color: var(--text-faint); font-style: italic; }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 14px 0 18px;
}
.stat { text-align: center; }
.stat .num { font-size: 26px; font-weight: 800; line-height: 1; }
.stat .lbl { font-size: 10.5px; color: var(--text-dim); margin-top: 5px; line-height: 1.25; }

.dist { margin-bottom: 18px; }
.dist h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); margin: 0 0 8px; }
.dist-row { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 5px; }
.dist-row .n { width: 12px; color: var(--text-dim); }
.dist-bar {
  background: var(--absent);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 6px;
  min-width: 26px;
  text-align: right;
  transition: width 0.6s ease;
}
.dist-bar.cur { background: var(--correct); }

.btn-row { display: flex; gap: 10px; margin-top: 6px; }
.btn {
  flex: 1;
  appearance: none;
  border: 0;
  border-radius: 12px;
  padding: 13px 16px;
  font: inherit;
  font-weight: 800;
  font-size: 15px;
  cursor: pointer;
  transition: transform 0.1s, filter 0.18s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: linear-gradient(120deg, var(--accent), var(--accent-2)); color: #0c130c; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: var(--surface-strong); color: var(--text); border: 1px solid var(--border); }

.countdown { text-align: center; font-size: 13px; color: var(--text-dim); margin-top: 14px; }
.countdown b { color: var(--text); font-variant-numeric: tabular-nums; }

/* How-to example tiles */
.example { display: flex; gap: 5px; margin: 6px 0 14px; }
.example .tile { --tile: 38px; perspective: none; }
.example .tile.correct, .example .tile.present, .example .tile.absent { animation: none; }
.howto-line { font-size: 14px; color: var(--text-dim); line-height: 1.45; margin: 0 0 4px; }
.howto-line b { color: var(--text); }

/* ---- Confetti ----------------------------------------------------------- */
#confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 90;
}

/* ---- Reduced motion ----------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .tile.reveal,
  .tile.filled,
  .row.win .tile,
  .row.shake,
  .key.flash,
  .sheet,
  .overlay.open,
  .toast,
  .definition {
    animation: none !important;
  }
  .tile.reveal { transition: background 0.2s, border-color 0.2s, color 0.2s; }
}

@media (max-width: 360px) {
  :root { --tile: clamp(42px, 16vw, 56px); }
  .key { height: 50px; font-size: 14px; }
}
