/* ── Imports ──────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Reset ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button { cursor: pointer; font: inherit; border: none; background: none; }
input  { font: inherit; }

/* ── Tokens ───────────────────────────────────────────────── */
:root {
  --canvas:        #232d3a;
  --surface:       #2f3948;
  --surface2:      #344152;
  --surface3:      #3d4d61;
  --surface4:      #4a5c73;
  --text:          #eef3f9;
  --text-secondary:#b8c5d6;
  --text-muted:    #7a8fa6;
  --accent:        #3ea894;
  --accent-dim:    rgba(62,168,148,.18);
  --accent-hover:  #2f8a79;
  --red:           #e05c5c;
  --red-dim:       rgba(224,92,92,.18);
  --green:         #3ae87a;
  --green-dim:     rgba(58,232,122,.18);
  --border:        rgba(255,255,255,.07);
  --border-accent: rgba(62,168,148,.3);
  --shadow:        0 4px 16px rgba(0,0,0,.32);
  --shadow-lg:     0 14px 36px rgba(0,0,0,.48);
  --radius:        14px;
  --radius-sm:     8px;
  --radius-xs:     4px;
  --font-ui:       "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --font-mono:     "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
  --transition:    180ms cubic-bezier(.4,0,.2,1);
}

/* ── Base ─────────────────────────────────────────────────── */
html { font-size: 16px; }
body {
  font-family: var(--font-ui);
  background: var(--canvas);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Shell ────────────────────────────────────────────────── */
.shell {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 20px 80px;
}

/* ── Header ───────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0 0;
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
  margin-bottom: 28px;
  gap: 12px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.logo-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent), #116d63);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
}
.logo-text {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}
.logo-text .accent { color: var(--accent); }

.header-center {
  flex: 1;
  text-align: center;
}
.tagline {
  font-size: 0.78rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 500;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.icon-btn:hover {
  background: var(--surface2);
  color: var(--text);
  border-color: rgba(255,255,255,.12);
}
.icon-btn svg { width: 16px; height: 16px; fill: currentColor; }

/* ── Puzzle header ────────────────────────────────────────── */
.puzzle-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.puzzle-label {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.clue-pips {
  display: flex;
  gap: 6px;
}
.pip {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--surface3);
  transition: var(--transition);
}
.pip.seen   { background: var(--red); }
.pip.active { background: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }
.pip.won    { background: var(--green); }

/* ── Clues ────────────────────────────────────────────────── */
.clues-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.clue-card {
  background: var(--surface);
  border-radius: var(--radius);
  border-left: 3px solid var(--surface4);
  padding: 16px 20px;
  animation: clue-in 0.35s cubic-bezier(.22,1,.36,1) both;
}
.clue-card.past    { border-left-color: rgba(224,92,92,.45); }
.clue-card.current { border-left-color: var(--accent); box-shadow: 0 0 0 1px var(--border-accent); }
.clue-card.won     { border-left-color: var(--green); box-shadow: 0 0 0 1px rgba(58,232,122,.25); }

.clue-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.clue-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  opacity: 0.75;
}
.clue-card.past .clue-label { color: var(--red); opacity: 0.6; }
.clue-card.won  .clue-label { color: var(--green); opacity: 0.8; }

.wrong-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  background: var(--red-dim);
  border: 1px solid rgba(224,92,92,.25);
  border-radius: 20px;
  font-size: 0.72rem;
  color: var(--red);
  font-family: var(--font-mono);
}
.wrong-badge::before { content: '✗ '; font-size: 0.75em; }

.clue-text {
  color: var(--text-secondary);
  font-size: 0.925rem;
  line-height: 1.65;
}
.clue-card.current .clue-text { color: var(--text); }

.clue-text code {
  font-family: var(--font-mono);
  font-size: 0.82em;
  background: var(--surface3);
  color: #9fdfff;
  padding: 1px 6px;
  border-radius: var(--radius-xs);
  border: 1px solid rgba(159,223,255,.12);
}

@keyframes clue-in {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Guess area ───────────────────────────────────────────── */
.guess-area {
  position: relative;
}
.guess-row {
  display: flex;
  gap: 10px;
}
.guess-input-wrap {
  flex: 1;
  position: relative;
}
.guess-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: var(--transition);
}
.guess-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.guess-input::placeholder { color: var(--text-muted); }
.guess-input:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* shake on wrong */
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}
.shake { animation: shake 0.35s ease; }

/* Autocomplete */
.autocomplete {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  overflow: hidden;
  max-height: 260px;
  overflow-y: auto;
}
.autocomplete.hidden { display: none; }
.autocomplete-item {
  padding: 11px 16px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
}
.autocomplete-item:hover,
.autocomplete-item.active {
  background: var(--surface3);
  color: var(--text);
}
.autocomplete-item .match-highlight { color: var(--accent); font-weight: 600; }
.autocomplete-empty {
  padding: 12px 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
}

/* Buttons */
.btn-primary {
  padding: 12px 22px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
  transition: var(--transition);
}
.btn-primary:hover  { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-outline {
  padding: 10px 20px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  transition: var(--transition);
}
.btn-outline:hover { background: var(--accent-dim); }

.btn-ghost {
  padding: 10px 20px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  transition: var(--transition);
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); }

/* Feedback line */
.feedback {
  margin-top: 10px;
  font-size: 0.85rem;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
}
.feedback.hidden  { display: none; }
.feedback.wrong   { background: var(--red-dim); color: var(--red); border: 1px solid rgba(224,92,92,.2); }
.feedback.correct { background: var(--green-dim); color: var(--green); border: 1px solid rgba(58,232,122,.2); }

/* Game over state */
.gameover-reveal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
}
.gameover-reveal p {
  color: var(--text-muted);
  font-size: 0.9rem;
}
.gameover-reveal.hidden { display: none; }

/* ── Overlay ──────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,20,30,.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 200;
  animation: fade-in 0.2s ease;
}
.overlay.hidden { display: none; }

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.overlay-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px 28px;
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  position: relative;
  animation: card-in 0.3s cubic-bezier(.22,1,.36,1);
  max-height: 90dvh;
  overflow-y: auto;
}
@keyframes card-in {
  from { opacity: 0; transform: scale(.96) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.close-btn {
  position: absolute;
  top: 14px;
  right: 16px;
  font-size: 1.4rem;
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xs);
  transition: var(--transition);
}
.close-btn:hover { color: var(--text); background: var(--surface2); }

/* ── Results overlay ──────────────────────────────────────── */
.result-icon {
  font-size: 2.8rem;
  text-align: center;
  margin-bottom: 10px;
  line-height: 1;
}
.result-title {
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}
.result-title.won-title  { color: var(--green); }
.result-title.lost-title { color: var(--red); }

.result-subtitle {
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.answer-block {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  margin-bottom: 20px;
}
.answer-block .label {
  font-size: 0.68rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.answer-block .answer {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--font-mono);
}

/* Emoji grid */
.emoji-grid {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 18px;
}
.emoji-pip {
  font-size: 1.5rem;
}

/* Percentile */
.percentile-block {
  text-align: center;
  margin-bottom: 20px;
  padding: 14px 20px;
  background: var(--accent-dim);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-sm);
}
.percentile-block .pct-number {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}
.percentile-block .pct-label {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-top: 4px;
}
.percentile-block.lost-pct {
  background: var(--red-dim);
  border-color: rgba(224,92,92,.25);
}
.percentile-block.lost-pct .pct-number { color: var(--red); }

/* Stats grid */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}
.stat-box {
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 12px 8px;
  text-align: center;
  border: 1px solid var(--border);
}
.stat-box .stat-num {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  margin-bottom: 4px;
}
.stat-box .stat-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Guess distribution */
.dist-title {
  font-size: 0.72rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.dist-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  font-size: 0.82rem;
}
.dist-num  { color: var(--text-muted); font-family: var(--font-mono); width: 14px; text-align: right; }
.dist-bar-wrap { flex: 1; }
.dist-bar {
  height: 20px;
  background: var(--surface3);
  border-radius: 3px;
  min-width: 4px;
  display: flex;
  align-items: center;
  padding: 0 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
  transition: width 0.5s ease 0.2s;
}
.dist-bar.current-bar {
  background: var(--accent);
  color: #fff;
}

/* Result actions */
.result-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
}
.result-actions .btn-primary,
.result-actions .btn-ghost { flex: 1; text-align: center; }

/* Next puzzle timer */
.next-timer {
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.next-timer .timer-val {
  font-family: var(--font-mono);
  color: var(--text-secondary);
  font-weight: 500;
}

/* ── Help modal ───────────────────────────────────────────── */
.help-card { max-width: 420px; }
.help-card h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 16px;
  padding-right: 28px;
}
.help-card p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 14px;
}
.help-card ul {
  list-style: none;
  margin-bottom: 18px;
}
.help-card ul li {
  font-size: 0.875rem;
  color: var(--text-secondary);
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  padding-left: 18px;
  position: relative;
}
.help-card ul li::before {
  content: '→';
  position: absolute;
  left: 0;
  color: var(--accent);
  font-size: 0.8em;
}
.help-card ul li:last-child { border-bottom: none; }
.emoji-legend {
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.emoji-legend div {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.emoji-legend span { font-size: 1.1rem; line-height: 1; }
.help-note {
  font-size: 0.8rem !important;
  color: var(--text-muted) !important;
  text-align: center;
  margin-bottom: 0 !important;
}

/* ── Result site link ─────────────────────────────────────── */
.result-site-link {
  text-align: center;
  margin-top: 10px;
}
.result-site-link a {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
  font-family: var(--font-mono);
  transition: var(--transition);
}
.result-site-link a:hover { color: var(--accent); }

/* ── Copy toast ───────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: var(--surface3);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.85rem;
  padding: 10px 20px;
  border-radius: 24px;
  box-shadow: var(--shadow);
  z-index: 500;
  animation: toast-in 0.25s ease, toast-out 0.25s ease 1.75s forwards;
  pointer-events: none;
}
@keyframes toast-in  { from { opacity:0; transform:translateX(-50%) translateY(12px); } to { opacity:1; transform:translateX(-50%) translateY(0); } }
@keyframes toast-out { from { opacity:1; } to { opacity:0; } }

/* ── Divider ──────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 18px 0;
}

/* ── Utility ──────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 520px) {
  .shell { padding: 0 14px 60px; }
  .header { margin-bottom: 20px; }
  .tagline { display: none; }
  .guess-row { flex-direction: column; }
  .btn-primary { width: 100%; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .overlay-card { padding: 24px 18px; }
}
