:root {
  /* Simple, inviting dark theme */
  --bg: #0f1320;
  --panel: #12182a;
  --ink: #e8ecf3;
  --ink-muted: #a9b1c1;
  --accent: #7be2b8;
  --accent-ink: #0b3b2a;
  --danger: #ff5d73;
  --tile: #161d30;
  --tile-hover: #1b2440;
  --ring: #67d8ff;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --display: 'Nunito', system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
}

/* Light theme variables */
:root.light {
  --bg: #f7f9fc;
  --panel: #ffffff;
  --ink: #1b2430;
  --ink-muted: #5a677a;
  --accent: #2f9e62;
  --accent-ink: #ffffff;
  --danger: #d63d4f;
  --tile: #eef2f7;
  --tile-hover: #e2e8f0;
  --ring: #2aa4de;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--display);
  background: var(--bg);
  color: var(--ink);
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
  padding-top: calc(20px + 20px);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.header { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }
.title {
  margin: 6px 0 0;
  text-align: center;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: clamp(24px, 4.8vw, 40px);
}
.subtitle { margin: 0; text-align: center; color: var(--ink-muted); font-weight: 400; }
.score-badge {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 0;
  padding: 6px 12px;
  font-family: var(--mono);
  font-size: 12px;
  white-space: nowrap;
  text-align: center;
}

.streak-badge {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 0;
  padding: 6px 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 12px;
}
.streak-icon { font-size: 14px; line-height: 1; }
.streak-icon.grey { filter: grayscale(1) brightness(0.7); opacity: 0.7; }
.streak-icon.colored { filter: none; opacity: 1; }
.streak-text { min-width: 10px; text-align: right; }

.flag-section { display: flex; justify-content: center; }
.flag-wrapper {
  position: relative;
  width: min(92vw, 780px);
  background: var(--panel);
  border-radius: 0;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}
.flag-image {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  filter: saturate(1);
}

.grid-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  gap: 0;
  padding: 0;
}
.grid-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  color: var(--ink-muted);
  font-family: var(--mono);
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.grid-overlay .tile {
  background: var(--tile);
  border-radius: 0;
  cursor: pointer;
  transition: background 120ms ease, transform 40ms ease;
}
.grid-overlay .tile:hover { background: var(--tile-hover); }
.grid-overlay .tile.revealed { background: transparent; pointer-events: none; }

.answer-section { text-align: center; }
.answer-display {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  justify-content: center;
  align-items: center;
  font-size: clamp(18px, 3.5vw, 28px);
  letter-spacing: 2px;
  min-height: 40px;
}
.answer-display .slot {
  display: inline-flex;
  min-width: 16px;
  padding: 2px 1px;
  border-bottom: 2px solid var(--ink-muted);
  text-transform: uppercase;
  justify-content: center;
}
.answer-display .slot.filled { border-bottom-color: var(--ink); }
.answer-display .space { border: none; width: 10px; }
.answer-display .dash { border: none; min-width: 10px; }

.message { margin-top: 8px; color: var(--ink-muted); min-height: 20px; }
.message.success { color: var(--accent); }
.message.error { color: var(--danger); }

.keyboard-section { display: flex; justify-content: center; }
.keyboard { display: flex; flex-direction: column; gap: 8px; width: min(92vw, 780px); }
.keyboard-row { display: grid; gap: 8px; }
.keyboard-row.row-1 { grid-template-columns: repeat(10, 1fr); }
.keyboard-row.row-2 { grid-template-columns: .5fr repeat(9, 1fr) .5fr; }
.keyboard-row.row-3 { grid-template-columns: .8fr repeat(7, 1fr) .8fr; }
.keyboard-row.row-4 { grid-template-columns: 1fr 2.5fr 1fr; }
.spacer { background: transparent; pointer-events: none; }
.key {
  background: var(--tile);
  color: var(--ink);
  padding: 12px 0;
  text-align: center;
  border-radius: 0;
  cursor: pointer;
  user-select: none;
  border: 1px solid rgba(255,255,255,0.10);
  box-shadow: none;
  transition: transform 0.04s ease, background 0.12s ease, border-color 0.12s ease;
  touch-action: manipulation; /* prevents double-tap zoom */
  -webkit-tap-highlight-color: transparent; /* remove iOS tap highlight */
  font-size: 16px; /* prevent iOS zoom on small text */
}
.key:hover { background: var(--tile-hover); border-color: rgba(255,255,255,0.18); }
.key:active { transform: translateY(1px); }
/* Stronger visible outlines for light mode */
.light .key { border-color: rgba(0,0,0,0.12); }
.light .key:hover { border-color: rgba(0,0,0,0.20); }
.key.backspace { }
.key.dash { }
.key.enter { }
.key.space { padding: 12px 0; }

/* Multiple-choice option feedback */
.key.right { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(123,226,184,0.22) inset; }
.key.wrong { border-color: var(--danger); box-shadow: 0 0 0 2px rgba(255,93,115,0.18) inset; }

.footer { text-align: center; color: var(--ink-muted); margin-top: 8px; }

.controls { display: flex; justify-content: center; }
.reset-btn {
  background: var(--panel);
  border: 1px dashed var(--ink-muted);
  color: var(--ink-muted);
  border-radius: 0;
  padding: 8px 14px;
  cursor: pointer;
  font-family: var(--mono);
  letter-spacing: 0.02em;
}
.reset-btn:hover { color: var(--ink); border-color: var(--ink); }

/* Toast */
.toast-root {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
}
.toast-root.open { display: flex; }
.toast-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 6, 10, 0.65);
  backdrop-filter: blur(2px);
  z-index: 0;
}
.toast {
  position: relative;
  z-index: 1;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 0;
  box-shadow: 0 14px 32px rgba(0,0,0,0.45);
  overflow: hidden;
  max-width: min(92vw, 760px);
  max-height: 86vh;
  pointer-events: auto;
  animation: toast-in 220ms cubic-bezier(.2,.9,.2,1);
}
@keyframes toast-in { from { transform: translateY(6px) scale(0.98); opacity: 0; } to { transform: translateY(0) scale(1); opacity: 1; } }
.toast-header { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.toast-title { font-weight: 700; letter-spacing: -0.01em; }
.toast-body { display: grid; grid-template-columns: 2fr 3fr; gap: 0; }
.toast-flag { position: relative; background: #000; }
.toast-flag .flag-preview { width: 100%; height: 100%; object-fit: cover; display: block; }
.toast-meta { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.toast-row { display: flex; justify-content: space-between; gap: 12px; font-family: var(--mono); color: var(--ink-muted); }
.toast-row strong { color: var(--ink); }
.points-section { margin: 8px 0; padding: 8px 0; border-top: 1px solid rgba(255,255,255,0.08); border-bottom: 1px solid rgba(255,255,255,0.08); display: grid; gap: 6px; }
.points-section .toast-row { color: var(--ink); }
.points-section .toast-row span { color: var(--ink-muted); }
.guess-list { display: flex; flex-wrap: wrap; gap: 8px; }
.guess-pill { padding: 6px 10px; border-radius: 0; font-family: var(--mono); font-size: 12px; border: 1px solid rgba(255,255,255,0.12); background: var(--panel); }
.guess-pill.wrong { background: rgba(255,93,115,0.12); color: #ff9aaa; border-color: rgba(255,93,115,0.3); }
.guess-pill.right { background: rgba(104,247,163,0.12); color: #a7ffd2; border-color: rgba(104,247,163,0.3); }
.toast-actions { padding: 10px 12px; border-top: 1px solid rgba(255,255,255,0.08); display: flex; justify-content: flex-end; gap: 8px; }
.toast-btn { background: var(--tile); color: var(--ink); border: 1px solid rgba(255,255,255,0.16); border-radius: 0; padding: 6px 10px; cursor: pointer; }
.toast-btn:hover { border-color: var(--ink); background: var(--tile-hover); }

@media (max-width: 720px) {
  .toast-body { grid-template-columns: 1fr; }
  .toast-flag { height: 160px; }
}
@media (max-width: 520px) {
  .keyboard-row.row-3 { grid-template-columns: .9fr repeat(7, 1fr) .9fr; }
  .keyboard-row.row-4 { grid-template-columns: 1fr 3fr 1fr; }
}

/* Slightly larger top offset on very small screens to avoid any overlap */
@media (max-width: 420px) {
  .container { padding-top: calc(20px + 52px); }
}


/* Top-right help button */
.help-btn {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 20;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0;
  border: 1px solid rgba(255,255,255,0.16);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
  text-decoration: none;
}
.help-btn:visited,
.help-btn:hover,
.help-btn:focus,
.help-btn:active { text-decoration: none; }
.theme-btn { right: 56px; }
.practice-btn { right: 88px; }
.faq-btn { right: 100px; }
.contact-btn { right: 144px; }
.home-btn { left: 12px; right: auto; }
.help-btn:hover { border-color: var(--ink); }

/* Top-right navigation layout */
.top-nav {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 20;
  display: flex;
  gap: 8px;
}
.top-nav .help-btn {
  position: static;
  top: auto;
  right: auto;
  font-size: 20px;
}

/* Allow text label button (Daily) to size naturally */
.daily-btn { width: 36px; padding: 0; font-family: var(--mono); }

/* FAQ accordion */
.faq-list { display: flex; flex-direction: column; gap: 10px; }
.faq-item { background: var(--panel); border: 1px solid rgba(255,255,255,0.12); }
.light .faq-item { border-color: rgba(0,0,0,0.12); }
.faq-question {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--ink);
  padding: 12px 14px;
  cursor: pointer;
  border: none;
  font: inherit;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.faq-question:hover { background: var(--tile); }
.faq-answer {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transform: translateY(-4px);
  transition: max-height 200ms ease, opacity 200ms ease, transform 200ms ease;
  padding: 0 14px;
}
.faq-answer.open { opacity: 1; transform: translateY(0); }
.faq-answer > p { margin: 10px 0 14px; color: var(--ink-muted); }