:root {
  --bg: #FFD43B;
  --ink: #111111;
  --paper: #FFFFFF;
  --card: #111111;
  --slot: #2A2A2A;
  --muted: #A8A8A8;
  --label: #C9C9C9;
  --wrong: #FF4D2E;
  --flash: #FF4D2E;
  --cell: 32px; /* set from JS to fit the longest word */
  --gutter: clamp(10px, 4vw, 16px);
  --font-display: Unbounded, "Arial Black", system-ui, sans-serif;
  --font-body: Manrope, system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

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

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

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.12s ease-out;
  overscroll-behavior: none;
}

body.flash { background: var(--flash); }

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

.app {
  min-height: 100vh;
  min-height: var(--app-h, 100dvh); /* --app-h follows the visual viewport when the keyboard is open */
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(12px, 3.5vh, 24px) 0 calc(clamp(8px, 2vh, 16px) + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 2.2vh, 18px);
}

/* ---------- header ---------- */
.top {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center;
  gap: 8px; padding: 0 var(--gutter);
}

.logo { margin: 0; display: flex; gap: clamp(3px, 1vw, 6px); }

.cap {
  width: clamp(24px, 7.6vw, 34px); aspect-ratio: 7 / 8;
  border-radius: 7px; border: 2px solid var(--ink);
  background: var(--paper); color: var(--ink);
  box-shadow: 0 3px 0 var(--ink);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 900; font-size: clamp(13px, 4.2vw, 19px);
  transition: transform 0.08s;
}
.cap--mid { transform: translateY(3px); box-shadow: none; }
.cap--ru { background: var(--ink); color: var(--bg); }

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

.streak {
  background: var(--ink); color: var(--bg);
  border-radius: 999px; padding: 6px 12px;
  font-weight: 800; font-size: clamp(12px, 3.4vw, 15px); white-space: nowrap;
}

.lives { display: flex; gap: 3px; }
.life {
  width: clamp(9px, 2.8vw, 13px); height: clamp(14px, 4.2vw, 20px);
  border-radius: 3px; border: 2px solid var(--ink); background: var(--paper);
}
.life--used { background: var(--wrong); }

/* ---------- phrase ---------- */
.main { display: flex; flex-direction: column; gap: clamp(10px, 2.2vh, 18px); }

.card {
  position: relative;
  margin: 0 var(--gutter);
  background: var(--card);
  border-radius: clamp(16px, 5vw, 28px);
  padding: clamp(14px, 4vw, 40px) clamp(12px, 3.6vw, 48px);
  box-shadow: 5px 5px 0 var(--paper);
  display: flex; flex-direction: column; gap: 12px;
}

.card--focused { box-shadow: 5px 5px 0 var(--paper), 0 0 0 3px var(--paper); }

/* Covers the card, fully transparent; 16px font stops iOS from zooming on focus. */
.typer {
  position: absolute; inset: 0; width: 100%; height: 100%;
  margin: 0; padding: 0; border: 0; border-radius: inherit;
  opacity: 0; background: transparent; color: transparent; caret-color: transparent;
  font-size: 16px; cursor: text;
}

.eyebrow {
  margin: 0; font-size: 12px; font-weight: 800; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--label);
}

.phrase {
  display: flex; flex-wrap: wrap;
  column-gap: calc(var(--cell) * 0.45); row-gap: calc(var(--cell) * 0.3);
  min-height: calc(var(--cell) * 4 / 3);
}

.word { display: flex; gap: calc(var(--cell) * 0.12); }

.cell {
  width: var(--cell); aspect-ratio: 3 / 4;
  border-radius: calc(var(--cell) * 0.22);
  background: var(--slot); color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-weight: 800; font-size: calc(var(--cell) * 0.52);
  line-height: 1; user-select: none;
}
.cell--current { color: var(--paper); box-shadow: inset 0 0 0 2px var(--paper); }
.cell--ok, .cell--revealed, .cell--wrong {
  font-family: var(--font-display); font-size: calc(var(--cell) * 0.56); color: var(--ink);
}
.cell--ok { background: var(--bg); }
.cell--given { background: transparent; color: var(--label); }
.cell--revealed { background: var(--paper); }
.cell--wrong {
  background: var(--wrong);
  box-shadow: inset 0 0 0 2px var(--paper);
  transform: rotate(-8deg) scale(1.08);
}
.cell--loading { animation: pulse 1s ease-in-out infinite alternate; }

@keyframes pulse { from { opacity: 0.35; } to { opacity: 0.9; } }

/* ---------- status ---------- */
.status {
  margin: 0 var(--gutter); min-height: 44px;
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
}
.status__title { margin: 0; font-family: var(--font-display); font-weight: 800; font-size: clamp(16px, 5vw, 24px); }
.status__text { margin: 0; font-weight: 700; font-size: clamp(14px, 3.8vw, 16px); }

.layout-warn {
  margin: 0 var(--gutter);
  background: var(--paper); border: 3px solid var(--ink); border-radius: 16px;
  padding: 12px 16px; display: flex; align-items: center; gap: 12px;
}
.layout-warn[hidden] { display: none; }
.layout-warn p { margin: 0; font-weight: 700; font-size: 15px; }
.layout-warn__badge {
  flex: none; width: 40px; height: 40px; border-radius: 10px; background: var(--wrong);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-weight: 800; font-size: 14px;
}

/* ---------- controls ---------- */
.controls {
  margin-top: auto;
  padding: 0 clamp(14px, 6vw, 28px);
  display: flex; flex-direction: column; gap: clamp(8px, 1.6vh, 12px);
}

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

.btn {
  flex: 1; min-height: 44px; height: clamp(44px, 6vh, 52px);
  border-radius: 14px; border: 2px solid var(--ink);
  font-family: var(--font-body); font-weight: 800; font-size: clamp(14px, 4vw, 17px);
  cursor: pointer; touch-action: manipulation;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn--light { background: var(--paper); color: var(--ink); }
.btn--dark { background: var(--ink); color: var(--bg); box-shadow: 0 4px 0 var(--paper); }
.btn:focus-visible, .key:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.btn kbd { display: none; font-family: var(--font-mono); font-size: 12px; opacity: 0.7; margin-left: 6px; }

.kb {
  background: var(--ink); border-radius: 18px;
  padding: clamp(8px, 1.4vh, 12px) clamp(5px, 1.6vw, 8px);
  display: flex; flex-direction: column; gap: clamp(5px, 1.2vh, 8px);
  user-select: none; -webkit-user-select: none;
  transition: opacity 0.15s;
}
.kb[hidden] { display: none; }
.kb--off { opacity: 0.45; }

.kb-toggle {
  align-self: center; min-height: 44px; padding: 0 12px;
  border: 0; background: transparent; color: var(--ink);
  font-family: var(--font-body); font-weight: 700; font-size: 14px;
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}
.kb__row { display: flex; gap: clamp(3px, 0.9vw, 5px); }
.kb__row:nth-child(2) { padding: 0 4%; }
.kb__row:nth-child(3) { padding: 0 12%; }

.key {
  flex: 1 1 0; min-width: 0; height: clamp(40px, 6.2vh, 52px); padding: 0;
  border: 0; border-radius: 7px;
  background: var(--paper); color: var(--ink); box-shadow: 0 3px 0 #000;
  font-family: var(--font-body); font-weight: 800; font-size: clamp(15px, 4.4vw, 20px);
  cursor: pointer; touch-action: manipulation;
}
.key:active { transform: translateY(2px); box-shadow: 0 1px 0 #000; }
.key:disabled { cursor: default; }

/* ---------- desktop: physical keyboard ---------- */
@media (hover: hover) and (pointer: fine) {
  .kb, .kb-toggle { display: none; }
  .btn kbd { display: inline; }
}

@media (min-width: 720px) {
  :root { --gutter: 48px; }
  .app { padding-top: 40px; gap: 32px; }
  .cap { width: 58px; font-size: 30px; border-width: 3px; border-radius: 12px; box-shadow: 0 5px 0 var(--ink); }
  .cap--mid { transform: translateY(5px); box-shadow: none; }
  .life { width: 14px; height: 22px; border-width: 3px; }
  .card { box-shadow: 8px 8px 0 var(--paper); gap: 20px; }
  .card--focused { box-shadow: 8px 8px 0 var(--paper), 0 0 0 3px var(--paper); }
  .controls { padding: 0 var(--gutter); max-width: 720px; width: 100%; margin-left: auto; margin-right: auto; }
  .btn { height: 64px; border-width: 3px; border-radius: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  body, .cap, .kb { transition: none; }
  .cell--loading { animation: none; }
  .cell--wrong { transform: none; }
}
