:root {
  --bg: #0d1210;
  --bg-raised: #131a17;
  --line: #26332e;
  --line-strong: #3a4d45;
  --ink: #d7ded9;
  --ink-dim: #8a978f;
  --ink-faint: #5c6a63;
  --amber: #e0a63a;
  --amber-dim: #7a5c22;
  --gray-tile: #23302a;
  --red: #c9614f;
  --font-mono: 'Courier New', ui-monospace, 'SF Mono', Consolas, monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* feedback colors — default palette (WCAG AA against --bg-raised at these
     lightness levels; still visually close for deuteranopia/protanopia,
     which is why a high-contrast override exists below) */
  --correct: #4caf7d;
  --correct-bg: #1c3327;
  --present: #cbb04a;
  --present-bg: #332e18;
}

/* colorblind-safe high-contrast palette: blue/orange instead of
   green/yellow, the same pairing used by Wordle's own high-contrast mode
   since it stays distinguishable across all common types of color
   vision deficiency. */
[data-contrast="high"] {
  --correct: #4d9fe0;
  --correct-bg: #16293a;
  --present: #e0812f;
  --present-bg: #3a2410;
}

* { box-sizing: border-box; }

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  min-height: 100vh;
}

body {
  display: flex;
  flex-direction: column;
}

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-raised);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-family: var(--font-mono);
}

.brand-mark {
  color: var(--amber);
  font-weight: bold;
}

.brand-name {
  letter-spacing: 0.12em;
  font-size: 15px;
  font-weight: bold;
  color: var(--ink);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ghost-btn {
  min-height: 44px;
  padding: 0 16px;
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
}
.ghost-btn:active { background: var(--line); }

.icon-btn {
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  border-radius: 4px;
  font-size: 18px;
  cursor: pointer;
}
.icon-btn:active { background: var(--line); }
.icon-btn[aria-pressed="true"] {
  border-color: var(--amber);
  color: var(--amber);
}

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

/* ---------- briefing (the seeded first guess) ---------- */

.board-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 16px 100px;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

.briefing {
  width: 100%;
  border: 1px dashed var(--line-strong);
  background: var(--bg-raised);
  border-radius: 6px;
  padding: 14px 16px;
  margin-bottom: 22px;
}

.briefing-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--amber);
  margin-bottom: 8px;
}

.seed-word {
  display: flex;
  gap: 6px;
}

.briefing-hint {
  margin: 10px 0 0;
  font-size: 12.5px;
  color: var(--ink-faint);
  line-height: 1.5;
}

/* ---------- grid ---------- */

.grid-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.grid {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 340px;
}

.row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.tile {
  aspect-ratio: 1;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: bold;
  font-size: clamp(18px, 5.5vw, 26px);
  border: 2px solid var(--line-strong);
  border-radius: 4px;
  background: var(--bg-raised);
  color: var(--ink);
  text-transform: uppercase;
  transition: transform 0.15s ease;
}

.tile.filled { border-color: var(--ink-faint); }

.tile.seed {
  border-color: var(--amber-dim);
}

.tile.correct { background: var(--correct-bg); border-color: var(--correct); color: var(--correct); }
.tile.present { background: var(--present-bg); border-color: var(--present); color: var(--present); }
.tile.absent  { background: var(--gray-tile); border-color: var(--line-strong); color: var(--ink-faint); }

/* redundant (non-color) coding so results don't depend on color alone */
.tile.correct, .tile.present { position: relative; }
.tile.correct::after, .tile.present::after {
  content: '';
  position: absolute;
  bottom: 3px;
  right: 3px;
  width: 6px;
  height: 6px;
}
.tile.correct::after { border-radius: 50%; background: var(--correct); }
.tile.present::after { border-radius: 1px; background: var(--present); transform: rotate(45deg); }

.tile.pop { animation: pop 0.12s ease; }
@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* currently-focused input position in the active row */
.tile.cursor {
  border-color: var(--amber);
  box-shadow: 0 0 0 2px var(--amber);
}

/* ---------- keyboard ---------- */

.keyboard {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  margin: 0 auto;
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  background: var(--bg-raised);
  border-top: 1px solid var(--line);
}

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

.key {
  flex: 1;
  max-width: 40px;
  min-width: 24px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  border: none;
  background: #2a3833;
  color: var(--ink);
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
}
.key:active { background: var(--line-strong); }
.key.wide { max-width: 60px; font-size: 11px; }

.key.correct { background: var(--correct); color: #0d1210; }
.key.present { background: var(--present); color: #0d1210; }
.key.absent  { background: #1a2320; color: var(--ink-faint); }

/* ---------- status / toast ---------- */

.status-line {
  min-height: 20px;
  font-size: 13px;
  color: var(--ink-dim);
  margin-top: 4px;
}

.toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
.modal-backdrop.hidden { display: none; }

.modal {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 12px 12px 0 0;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
}

@media (min-width: 540px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 12px; }
}

.modal h2 {
  margin: 0 0 6px;
  font-size: 20px;
  font-family: var(--font-mono);
}

.modal-sub {
  color: var(--ink-dim);
  font-size: 14px;
  margin: 0 0 16px;
}

.end-stats {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
}

.stat-card {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  text-align: center;
}
.stat-card .stat-num {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: bold;
  color: var(--amber);
}
.stat-card .stat-label {
  font-size: 11px;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
}

.submit-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}
.submit-form label {
  font-size: 12px;
  color: var(--ink-dim);
}
.submit-form input {
  min-height: 44px;
  padding: 0 12px;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  color: var(--ink);
  font-size: 15px;
}
.submit-form input:focus {
  outline: 2px solid var(--amber);
  outline-offset: 1px;
}

.primary-btn {
  min-height: 44px;
  background: var(--amber);
  color: #221a08;
  border: none;
  border-radius: 4px;
  font-weight: bold;
  font-size: 15px;
  cursor: pointer;
}
.primary-btn:active { opacity: 0.85; }

.submitted-note {
  color: var(--correct);
  font-size: 14px;
  margin: 0 0 12px;
}

.full-width { width: 100%; margin-top: 8px; }

.text-btn {
  background: transparent;
  border: none;
  color: var(--ink-dim);
  min-height: 44px;
  cursor: pointer;
  font-size: 14px;
}

.hidden { display: none !important; }

/* ---------- leaderboard list ---------- */

.lb-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
  max-height: 50vh;
  overflow-y: auto;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 6px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.lb-rank {
  font-family: var(--font-mono);
  color: var(--ink-faint);
  width: 24px;
  flex-shrink: 0;
}
.lb-row:nth-child(1) .lb-rank { color: var(--amber); }
.lb-row:nth-child(2) .lb-rank { color: var(--ink-dim); }
.lb-row:nth-child(3) .lb-rank { color: #a9784a; }

.lb-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-meta {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink-dim);
  white-space: nowrap;
}

.lb-empty {
  color: var(--ink-faint);
  font-size: 14px;
  padding: 20px 0;
  text-align: center;
}
