/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #111214;
  --surface:      #1c1e22;
  --border:       #3a3d44;
  --text:         #f0f0f0;
  --text-muted:   #888;
  --correct:      #c0392b;     /* iOS .red  */
  --misplaced:    #d4a017;     /* iOS .yellow (darker for readability) */
  --incorrect:    #3a3d44;
  --tile-empty:   transparent;
  --tile-border:  #4a4e58;
  --focused:      #5b8def;
  --accent:       #e05c4f;
  --key-bg:       #2e3138;
  --key-text:     #f0f0f0;
  --radius:       8px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  user-select: none;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Page layouts ────────────────────────────────────────────────────────── */
.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.site-header {
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 10px;
  border-bottom: 1px solid var(--border);
}

.site-header .logo {
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: -0.5px;
  color: var(--text);
}

.site-header .logo span { color: var(--accent); }

.header-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.header-meta #streak-display {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.back-link {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Main game area ──────────────────────────────────────────────────────── */
.game-area {
  flex: 1;
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 12px 0;
  gap: 8px;
  overflow-y: auto;
}

/* ── Toast ───────────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  background: var(--text);
  color: var(--bg);
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}
#toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Already-played banner ───────────────────────────────────────────────── */
#already-played {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: 0.85rem;
  color: var(--text-muted);
  align-items: center;
  gap: 8px;
  width: 100%;
  justify-content: center;
}

/* ── Grid ────────────────────────────────────────────────────────────────── */
#grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 5), 1fr);
  gap: 5px;
  width: min(calc(var(--cols, 5) * 64px + (var(--cols, 5) - 1) * 5px), 100%);
  flex-shrink: 0;
}

.tile {
  aspect-ratio: 1;
  max-width: 64px;
  border: 2px solid var(--tile-border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1rem, 5vw, 1.6rem);
  font-weight: 900;
  text-transform: uppercase;
  color: var(--text);
  background: var(--tile-empty);
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, transform 0.1s;
  will-change: transform;
}

.tile.filled   { transform: scale(1.06); }
.tile.pop      { animation: pop 0.12s ease; }
.tile.focused  { border-color: var(--focused); border-width: 2.5px; }
.tile.correct  { background: var(--correct);  border-color: var(--correct);  color: #fff; }
.tile.misplaced{ background: var(--misplaced);border-color: var(--misplaced);color: #fff; }
.tile.incorrect{ background: var(--incorrect);border-color: var(--incorrect);color: #fff; }

.tile.shake { animation: shake 0.45s ease; }

@keyframes pop {
  0%   { transform: scale(1.0); }
  60%  { transform: scale(1.14); }
  100% { transform: scale(1.06); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  18%  { transform: translateX(-6px); }
  36%  { transform: translateX(6px); }
  54%  { transform: translateX(-4px); }
  72%  { transform: translateX(4px); }
  90%  { transform: translateX(-2px); }
}

/* ── Keyboard ────────────────────────────────────────────────────────────── */
#keyboard {
  width: 100%;
  max-width: 480px;
  padding: 6px 4px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.kb-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.kb-key {
  height: 56px;
  min-width: 34px;
  flex: 1;
  max-width: 42px;
  border: none;
  border-radius: 6px;
  background: var(--key-bg);
  color: var(--key-text);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, transform 0.08s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.kb-key:active { transform: scale(0.93); }
.kb-key.wide   { min-width: 54px; max-width: 60px; font-size: 0.75rem; }

.kb-key.correct   { background: var(--correct);  color: #fff; }
.kb-key.misplaced { background: var(--misplaced);color: #fff; }
.kb-key.incorrect { background: #222428; color: #555; }

/* ── Win modal ───────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.visible { display: flex; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  position: relative;
  animation: slideUp 0.28s ease;
}

@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-close {
  position: absolute;
  top: 12px; right: 14px;
  background: none; border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  line-height: 1;
}

.modal-box h2 {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--correct);
}

.modal-box .the-word {
  font-size: 1.9rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  color: var(--text);
}

.modal-box .stat-row {
  display: flex;
  gap: 24px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.stat-item .val {
  font-size: 1.4rem;
  font-weight: 800;
}
.stat-item .lbl {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#emoji-grid {
  font-size: 1.2rem;
  line-height: 1.5;
  text-align: center;
  font-family: monospace;
}

.modal-actions {
  display: flex;
  gap: 10px;
  width: 100%;
}

.btn {
  flex: 1;
  padding: 13px;
  border: none;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
  letter-spacing: 0.03em;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary { background: var(--key-bg); color: var(--text); }
.btn-secondary:hover { filter: brightness(1.2); }

.ios-nudge {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
}
.ios-nudge a { color: var(--accent); }

/* ── Index / menu page ───────────────────────────────────────────────────── */
.menu-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.menu-header {
  width: 100%;
  max-width: 480px;
  padding: 28px 20px 16px;
  text-align: center;
}

.menu-logo {
  font-size: 2.4rem;
  font-weight: 900;
  letter-spacing: -1px;
}
.menu-logo span { color: var(--accent); }

.menu-tagline {
  margin-top: 6px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.game-cards {
  width: 100%;
  max-width: 480px;
  padding: 8px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.game-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 20px;
  text-decoration: none;
  color: var(--text);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  cursor: pointer;
}
.game-card:hover {
  background: #23262d;
  border-color: #555;
  text-decoration: none;
}
.game-card:active { transform: scale(0.98); }

.game-card.done {
  border-color: var(--correct);
  opacity: 0.85;
}

.card-left { display: flex; flex-direction: column; gap: 4px; }
.card-title { font-size: 1.2rem; font-weight: 800; }
.card-meta  { font-size: 0.78rem; color: var(--text-muted); }
.card-streak{ font-size: 0.9rem; font-weight: 600; }

.card-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.card-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.card-badge.play  { background: var(--accent);  color: #fff; }
.card-badge.done  { background: var(--correct);  color: #fff; }

/* ── iOS promo section ───────────────────────────────────────────────────── */
.ios-promo-strip {
  width: 100%;
  max-width: 480px;
  margin: 12px 20px 0;
  padding: 18px 20px;
  background: linear-gradient(135deg, #1a1d23, #22262f);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 16px;
  text-decoration: none;
  color: var(--text);
  transition: filter 0.15s;
}
.ios-promo-strip:hover { filter: brightness(1.12); text-decoration: none; }

.ios-icon {
  font-size: 2.4rem;
  flex-shrink: 0;
}

.ios-promo-text { flex: 1; }
.ios-promo-text h3 { font-size: 1rem; font-weight: 800; margin-bottom: 3px; }
.ios-promo-text p  { font-size: 0.78rem; color: var(--text-muted); line-height: 1.4; }

.ios-arrow { font-size: 1.2rem; color: var(--text-muted); flex-shrink: 0; }

/* ── iOS promo full page ─────────────────────────────────────────────────── */
.promo-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 20px;
  gap: 24px;
  max-width: 480px;
  margin: 0 auto;
}

.promo-icon { font-size: 5rem; }
.promo-page h1 { font-size: 2rem; font-weight: 900; text-align: center; }
.promo-page h1 span { color: var(--accent); }
.promo-page p { color: var(--text-muted); text-align: center; line-height: 1.6; max-width: 340px; }

.features-list {
  list-style: none;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.features-list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 0.95rem;
}
.features-list li .feat-icon { font-size: 1.5rem; flex-shrink: 0; }
.features-list li .feat-text  { display: flex; flex-direction: column; gap: 2px; }
.features-list li .feat-title { font-weight: 700; }
.features-list li .feat-desc  { font-size: 0.78rem; color: var(--text-muted); }

.appstore-btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  color: #000;
  padding: 14px 28px;
  border-radius: 14px;
  font-weight: 800;
  font-size: 1rem;
  text-decoration: none;
  transition: transform 0.1s, filter 0.15s;
}
.appstore-btn:hover { filter: brightness(0.92); text-decoration: none; }
.appstore-btn:active { transform: scale(0.97); }
.appstore-btn .apple-logo { font-size: 1.5rem; }

.back-to-play {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.back-to-play a { color: var(--accent); }

/* ── Footer ──────────────────────────────────────────────────────────────── */
.site-footer {
  width: 100%;
  max-width: 480px;
  padding: 20px;
  margin-top: auto;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}
.site-footer a { color: var(--text-muted); }

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-height: 700px) {
  .tile { max-width: 52px; font-size: clamp(0.85rem, 4vw, 1.3rem); }
  #keyboard { padding-bottom: 8px; }
  .kb-key { height: 46px; }
  .game-area { gap: 5px; }
}
@media (max-height: 580px) {
  .tile { max-width: 44px; }
  .kb-key { height: 40px; font-size: 0.78rem; }
}
