/* Wordrush — word typing game
   Deliberately styled like an ordinary indie browser game: warm accent,
   rounded cards, playful motion. Nothing here shares a look, a colour, or a
   name with anything else on this domain. */

:root {
  --bg: #0f1116;
  --bg-2: #161922;
  --card: #1c2029;
  --card-2: #232733;
  --line: rgba(255,255,255,0.08);
  --line-2: rgba(255,255,255,0.14);

  --text: #eef1f6;
  --text-2: rgba(238,241,246,0.62);
  --text-3: rgba(238,241,246,0.36);

  --accent: #ffb648;      /* amber — nothing to do with the other app */
  --accent-2: #ffcd7a;
  --green: #4ade80;
  --red: #f87171;
  --blue: #60a5fa;

  --r: 14px;
  --r-lg: 22px;
  --ease: cubic-bezier(0.34, 1.4, 0.64, 1);

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, Roboto,
          'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

body::before {
  content: '';
  position: fixed; inset: -20%;
  z-index: -1;
  background:
    radial-gradient(46% 40% at 20% 12%, rgba(255,182,72,.13), transparent 62%),
    radial-gradient(42% 38% at 82% 78%, rgba(96,165,250,.10), transparent 62%);
  filter: blur(30px);
}

.wrap {
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  max-width: 720px; margin: 0 auto;
  padding: 0 20px;
}

/* ── Top bar ── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 2px;
  flex-shrink: 0;
}

.logo {
  display: flex; align-items: center; gap: 9px;
  font-size: 17px; font-weight: 700; letter-spacing: -0.02em;
}
.logo svg { width: 20px; height: 20px; color: var(--accent); }

.ghost-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: none; background: transparent;
  border-radius: var(--r);
  color: var(--text-2); cursor: pointer;
  transition: background .15s, color .15s;
}
.ghost-btn:hover { background: var(--card); color: var(--text); }
.ghost-btn svg { width: 19px; height: 19px; }

/* ── Stage ── */
.stage {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 22px;
  min-height: 0;
  padding-bottom: 20px;
}

.scoreboard {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 10px; width: 100%;
}

.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 12px 8px;
  text-align: center;
}
.stat-value {
  display: block;
  font-family: var(--mono);
  font-size: 20px; font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat-label {
  display: block;
  font-size: 10.5px; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-3);
  margin-top: 3px;
}
#statBest { color: var(--accent); }
#statStreak { color: var(--green); }

/* ── Word panel ── */
.word-panel {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 30px 24px;
  text-align: center;
}

.word-define {
  font-size: 13.5px; color: var(--text-3);
  margin-bottom: 14px; min-height: 20px;
  font-style: italic;
}

.word-target {
  font-size: clamp(30px, 8vw, 46px);
  font-weight: 750;
  letter-spacing: 0.02em;
  margin-bottom: 20px;
  min-height: 56px;
  word-break: break-all;
}
.word-target .ok { color: var(--green); }
.word-target .bad { color: var(--red); text-decoration: underline wavy; }
.word-target .pending { color: var(--text-3); }
.word-target .cursor {
  color: var(--accent);
  border-bottom: 3px solid var(--accent);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { border-color: transparent; } }

.tiles {
  display: flex; flex-wrap: wrap; gap: 6px; justify-content: center;
  min-height: 34px;
}
.tile {
  width: 30px; height: 34px;
  display: grid; place-items: center;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 15px; font-weight: 600;
  color: var(--text-3);
  transition: transform .18s var(--ease), background .18s, color .18s, border-color .18s;
}
.tile.filled {
  background: var(--accent);
  border-color: var(--accent);
  color: #221600;
  transform: translateY(-3px);
}
.tile.wrong {
  background: rgba(248,113,113,.16);
  border-color: var(--red);
  color: var(--red);
  animation: shake .28s;
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* ── Progress ── */
.progress-track {
  width: 100%; height: 5px;
  background: var(--card);
  border-radius: 999px; overflow: hidden;
}
.progress-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 999px;
  transition: width .12s linear;
}

.result {
  min-height: 26px;
  font-size: 15px; font-weight: 600;
  text-align: center;
}
.result.good { color: var(--green); animation: pop .35s var(--ease); }
.result.record { color: var(--accent); animation: pop .45s var(--ease); }
@keyframes pop {
  from { transform: scale(.86); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* The capture field is intentionally invisible but focusable — it collects
   input from both a physical keyboard and the phone's on-screen keyboard. */
#capture {
  position: absolute;
  opacity: 0;
  width: 1px; height: 1px;
  border: 0; padding: 0;
  left: 50%; top: 50%;
  font-size: 16px; /* stops iOS zooming when it takes focus */
}

.tap-hint {
  display: none;
  padding: 12px 24px;
  border-radius: 999px;
  background: var(--accent);
  color: #221600;
  border: none;
  font-family: inherit;
  font-size: 15px; font-weight: 650;
  cursor: pointer;
}
body.needs-tap .tap-hint { display: block; }

.hint { font-size: 12.5px; color: var(--text-3); text-align: center; }
body.needs-tap .hint { display: none; }

.foot {
  padding: 14px 2px calc(18px + env(safe-area-inset-bottom));
  text-align: center;
  font-size: 11.5px;
  color: var(--text-3);
  flex-shrink: 0;
}

/* ── Stats modal ── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  opacity: 0; pointer-events: none;
  transition: opacity .22s;
  z-index: 50;
}
.modal-backdrop.on { opacity: 1; pointer-events: auto; }

.modal {
  position: fixed;
  left: 50%; top: 50%;
  transform: translate(-50%,-46%) scale(.96);
  width: min(380px, calc(100vw - 36px));
  background: var(--card);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  padding: 24px;
  opacity: 0; pointer-events: none;
  transition: opacity .22s, transform .22s var(--ease);
  z-index: 51;
}
.modal.on { opacity: 1; pointer-events: auto; transform: translate(-50%,-50%) scale(1); }
.modal h2 { font-size: 19px; margin-bottom: 16px; letter-spacing: -0.02em; }

.stat-rows { display: flex; flex-direction: column; gap: 2px; margin-bottom: 20px; }
.stat-row {
  display: flex; justify-content: space-between;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
}
.stat-row:nth-child(odd) { background: var(--card-2); }
.stat-row span:last-child { font-family: var(--mono); font-weight: 650; }

.modal-actions { display: flex; gap: 9px; }
.modal-actions button {
  flex: 1; padding: 11px;
  border-radius: var(--r);
  border: 1px solid var(--line);
  font-family: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer;
}
.modal-actions .secondary { background: var(--card-2); color: var(--text-2); }
.modal-actions .primary { background: var(--accent); color: #221600; border-color: transparent; }

/* ── Gate (revealed only on the correct sequence) ── */
.gate {
  position: fixed; inset: 0;
  background: var(--bg);
  display: none;
  align-items: center; justify-content: center;
  padding: 24px;
  z-index: 100;
}
.gate.on { display: flex; animation: gateIn .4s var(--ease); }
@keyframes gateIn { from { opacity: 0; } to { opacity: 1; } }

.gate-card {
  width: min(380px, 100%);
  background: var(--card);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  padding: 34px 28px 26px;
  text-align: center;
}

.gate-mark { color: var(--accent); margin-bottom: 14px; }
.gate-mark svg { width: 46px; height: 46px; }

.gate-card h2 { font-size: 21px; letter-spacing: -0.02em; margin-bottom: 5px; }
.gate-sub { font-size: 13px; color: var(--text-3); margin-bottom: 24px; }

.gate-card form { text-align: left; }
.gate-card label {
  display: block; font-size: 11px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-3); margin: 0 0 6px 2px;
}
.gate-card input {
  width: 100%; padding: 12px 14px; margin-bottom: 15px;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: rgba(0,0,0,.28);
  color: var(--text);
  font-family: inherit; font-size: 16px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.gate-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255,182,72,.18);
}
.gate-card button[type="submit"] {
  width: 100%; padding: 13px;
  border-radius: var(--r); border: none;
  background: var(--accent); color: #221600;
  font-family: inherit; font-size: 15px; font-weight: 680;
  cursor: pointer;
  margin-top: 4px;
}
.gate-card button[type="submit"]:disabled { opacity: .55; cursor: not-allowed; }

.gate-error { color: var(--red); font-size: 13px; margin-top: 12px; min-height: 18px; text-align: center; }

.gate-back {
  margin-top: 16px;
  background: none; border: none;
  color: var(--text-3);
  font-family: inherit; font-size: 12.5px;
  cursor: pointer;
  text-decoration: underline;
}

@media (max-width: 480px) {
  .scoreboard { grid-template-columns: repeat(2, 1fr); }
  .word-panel { padding: 24px 18px; }
  .stage { gap: 16px; }
}
