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

:root {
  --bg:       #ffffff;
  --s1:       #f4f6f9;
  --s2:       #eaecf0;
  --s3:       #dde1e7;
  --border:   #c8cdd6;
  --text:     #111827;
  --muted:    #6b7280;
  --accent:   #5b7bfe;
  --hard:     #ff5c5c;
  --medium:   #ffa837;
  --easy:     #4ecb71;
  --radius:   13px;
  --max-w:    680px;
}

[data-dark="true"] {
  --bg:     #12141c;
  --s1:     #1c1f2e;
  --s2:     #252839;
  --s3:     #2e3245;
  --border: #3a3f58;
  --text:   #e2e8f0;
  --muted:  #8b93b0;
}

html { font-size: 16px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Loading overlay ──────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
  padding: 20px;
}
.overlay.show { opacity: 1; pointer-events: all; }

.loading-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: #fff;
  font-size: .95rem;
}

.spinner {
  width: 40px; height: 40px;
  border: 3px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Modal ────────────────────────────────────────────────── */
.modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px 28px;
  width: 100%;
  max-width: 420px;
  text-align: center;
  position: relative;
  transform: translateY(20px) scale(.97);
  transition: transform .35s cubic-bezier(.34,1.56,.64,1);
  box-shadow: 0 20px 60px rgba(0,0,0,.18);
}
.overlay.show .modal { transform: translateY(0) scale(1); }

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--s2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 50%;
  width: 30px; height: 30px;
  font-size: .8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .2s, border-color .2s, background .2s;
  line-height: 1;
}
.modal-close:hover { color: var(--text); border-color: var(--accent); background: var(--s1); }

.modal-emoji  { font-size: 2.4rem; margin-bottom: 8px; }
.modal-title  { font-size: 1.5rem; font-weight: 800; margin-bottom: 6px; color: var(--text); }
.modal-sub    { color: var(--muted); font-size: .88rem; margin-bottom: 20px; }
.modal-hint   { font-size: .75rem; color: var(--muted); margin-top: 16px; opacity: .7; }

.answer-block { margin-bottom: 16px; }
.answer-flag  { font-size: 4rem; line-height: 1; margin-bottom: 8px; }
.answer-name  { font-size: 1.6rem; font-weight: 900; letter-spacing: -.02em; color: var(--text); }

.stat-row {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-bottom: 24px;
}
.stat-box { text-align: center; }
.stat-num { font-size: 2rem; font-weight: 900; color: var(--text); }
.stat-lbl { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-top: 2px; }

/* help modal site link */
.help-site-link {
  margin: 12px 0 8px;
  font-size: .82rem;
}

/* help list */
.help-list {
  text-align: left;
  font-size: .88rem;
  color: var(--muted);
  line-height: 2;
  margin: 16px 0 24px;
  padding-left: 20px;
}
.help-list strong { color: var(--text); }
.help-divider { list-style: none; border-top: 1px solid var(--border); margin: 8px 0; padding: 0; }
.help-example { background: var(--surface); border-radius: 8px; padding: 10px 12px; list-style: none; line-height: 1.7; margin-top: 4px; }

/* ── Difficulty tags ──────────────────────────────────────── */
.tag {
  display: inline-block;
  font-size: .58rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .07em;
  white-space: nowrap;
}
.tag.hard   { background: rgba(255,92,92,.12);  color: #d93030; border: 1px solid rgba(255,92,92,.3); }
.tag.medium { background: rgba(255,168,55,.12); color: #d97706; border: 1px solid rgba(255,168,55,.3); }
.tag.easy   { background: rgba(78,203,113,.12); color: #16a34a; border: 1px solid rgba(78,203,113,.3); }

/* ── Logo banner ──────────────────────────────────────────── */
.logo-section {
  width: 100%;
  max-width: var(--max-w);
  padding: 36px 20px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
}

.site-logo {
  height: 68px;
  width: auto;
  display: block;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.logo-side-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.logo-side-btn {
  background: var(--s1);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: border-color .2s, color .2s, background .2s;
}
.logo-side-btn:hover { border-color: var(--accent); color: var(--text); background: var(--s2); }

/* ── Sticky game bar ──────────────────────────────────────── */
header {
  width: 100%;
  max-width: var(--max-w);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  border-top: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 20;
}

.header-guesses {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-guesses-label {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted);
}

/* ── Points display ───────────────────────────────────────── */
.points-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.points-label-left {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted);
}

.points-box {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--easy);
  color: #fff;
  font-size: .9rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .3s;
  flex-shrink: 0;
}
.points-box[data-state="warning"]  { background: var(--medium); }
.points-box[data-state="critical"] { background: var(--hard); animation: pulse 1s ease infinite; }

@keyframes pulse {
  0%,100% { opacity: 1; }
  50%      { opacity: .45; }
}

.icon-btn {
  background: var(--s1);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 50%;
  width: 32px; height: 32px;
  font-size: .85rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .2s, color .2s, background .2s;
  flex-shrink: 0;
}
.icon-btn:hover { border-color: var(--accent); color: var(--text); background: var(--s2); }

/* ── Main & sections ──────────────────────────────────────── */
main {
  width: 100%;
  max-width: var(--max-w);
  padding: 0 16px 80px;
  flex: 1;
}

.section { margin-top: 20px; }

.section-label {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--muted);
  margin-bottom: 10px;
}

/* ── 3×3 Clue grid ────────────────────────────────────────── */
.clue-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 160px;
  gap: 8px;
}

.grid-cell {
  background: var(--s1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  position: relative;
}

/* difficulty accent on top edge */
.hard-cell   { border-top: 3px solid var(--hard); }
.medium-cell { border-top: 3px solid var(--medium); }
.easy-cell   { border-top: 3px solid var(--easy); }

/* ── Locked (hidden) cell ─────────────────────────────────── */
.grid-cell.hidden {
  cursor: pointer;
  transition: border-color .18s, background .18s;
}
.grid-cell.hidden:hover:not(.cant-afford) {
  background: var(--s2);
  border-color: var(--accent);
}
.grid-cell.hidden:hover:not(.cant-afford) .cell-icon-lg {
  transform: scale(1.15);
}
.grid-cell.cant-afford {
  opacity: .35;
  cursor: not-allowed;
}

/* ── Revealed cell ────────────────────────────────────────── */
.grid-cell.revealed {
  cursor: default;
  animation: popIn .35s cubic-bezier(.34,1.56,.64,1);
  color: #111;
}
.grid-cell.revealed.hard-cell   { background: var(--hard);   border-color: var(--hard); }
.grid-cell.revealed.medium-cell { background: var(--medium); border-color: var(--medium); }
.grid-cell.revealed.easy-cell   { background: var(--easy);   border-color: var(--easy); }

.grid-cell.revealed .cell-attr-name { color: rgba(0,0,0,.6); }
.grid-cell.revealed .cell-value     { color: #111; }
.grid-cell.revealed .tag {
  background: rgba(0,0,0,.15);
  color: rgba(0,0,0,.7);
  border-color: rgba(0,0,0,.2);
}
.grid-cell.revealed .tier-badge {
  background: rgba(0,0,0,.12);
  color: rgba(0,0,0,.65);
}

@keyframes popIn {
  from { transform: scale(.9); opacity: 0; }
  to   { transform: scale(1);  opacity: 1; }
}

/* ── Shared cell inner layout ─────────────────────────────── */
.cell-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.cell-cost-badge {
  font-size: .65rem;
  font-weight: 700;
  color: var(--muted);
}
.cell-mid {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex: 1;
  text-align: center;
}
.cell-icon-lg {
  font-size: 1.5rem;
  line-height: 1;
  transition: transform .2s cubic-bezier(.34,1.56,.64,1);
}
.cell-attr-name {
  font-size: .7rem;
  color: var(--muted);
  font-weight: 600;
  line-height: 1.2;
}
.cell-hidden-bar {
  height: 7px;
  background: var(--border);
  border-radius: 4px;
  width: 65%;
  margin: 0 auto;
  flex-shrink: 0;
  opacity: .6;
}
.cell-value {
  font-size: .82rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.5;
  color: var(--text);
  flex-shrink: 0;
  white-space: pre-line;
}

/* ── Tier badges ──────────────────────────────────────────── */
.tier-badge {
  display: inline-block;
  font-size: .6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 1px 5px;
  border-radius: 4px;
  vertical-align: middle;
  margin-left: 3px;
}
.tier-badge.tier-low  { color: #d93030; background: rgba(255,92,92,.12); }
.tier-badge.tier-mid  { color: #d97706; background: rgba(255,168,55,.12); }
.tier-badge.tier-high { color: #16a34a; background: rgba(78,203,113,.12); }
.tier-badge.tier-cold { color: #2563eb; background: rgba(59,130,246,.12); }
.tier-badge.tier-warm { color: #d97706; background: rgba(255,168,55,.12); }
.tier-badge.tier-hot  { color: #dc2626; background: rgba(239,68,68,.12); }

/* ── Guess meta row ───────────────────────────────────────── */
.guess-meta {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.guess-meta-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.guess-pips {
  display: flex;
  gap: 7px;
}

/* Numbered guess boxes */
.guess-pip {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: .9rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .25s cubic-bezier(.34,1.56,.64,1);
  flex-shrink: 0;
}
.guess-pip.used {
  background: var(--s2);
  color: var(--muted);
  font-size: .75rem;
}

/* ── Search input ─────────────────────────────────────────── */
.search-wrap { position: relative; }

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1rem;
  pointer-events: none;
  z-index: 1;
}

.search-input {
  width: 100%;
  padding: 14px 90px 14px 42px;
  background: var(--s1);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  outline: none;
  transition: border-color .2s;
  -webkit-appearance: none;
  appearance: none;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--muted); }
.search-input:disabled { opacity: .35; cursor: not-allowed; }

.btn-guess {
  position: absolute;
  right: 7px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 9px;
  padding: 9px 16px;
  font-size: .88rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s;
  white-space: nowrap;
}
.btn-guess:hover:not(:disabled) { background: #7090ff; }
.btn-guess:disabled { opacity: .35; cursor: not-allowed; }

/* ── Autocomplete ─────────────────────────────────────────── */
.ac-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  z-index: 50;
  display: none;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 10px 32px rgba(0,0,0,.12);
}
.ac-list.open { display: block; }

.ac-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 16px;
  cursor: pointer;
  transition: background .12s;
}
.ac-item:hover, .ac-item.active { background: var(--s1); }
.ac-flag { font-size: 1.3rem; line-height: 1; flex-shrink: 0; }
.ac-name { font-size: .93rem; color: var(--text); }

.error-msg {
  font-size: .8rem;
  color: #d93030;
  margin-top: 7px;
}

/* ── Guess history ────────────────────────────────────────── */
.guess-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  background: var(--s1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  animation: slideUp .25s ease;
}
.guess-row.correct { border-color: #16a34a; background: rgba(78,203,113,.08); }
.guess-row.penalised { border-color: #d93030; background: rgba(255,92,92,.06); }

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

.g-flag { font-size: 1.4rem; line-height: 1; flex-shrink: 0; }
.g-name { flex: 1; font-weight: 500; font-size: .95rem; color: var(--text); }
.g-icon { font-size: 1.1rem; flex-shrink: 0; }
.g-penalty { font-size: .75rem; color: #d93030; font-weight: 600; flex-shrink: 0; }

/* ── Footer / reset ───────────────────────────────────────── */
footer {
  width: 100%;
  max-width: var(--max-w);
  padding: 12px 16px 24px;
  display: flex;
  justify-content: center;
}

.btn-reset {
  background: var(--s1);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 28px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .2s, color .2s;
}
.btn-reset:hover { border-color: var(--accent); color: var(--text); }

/* ── Shared button ────────────────────────────────────────── */
.btn-primary {
  display: block;
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 14px;
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s;
  margin-top: 4px;
}
.btn-primary:hover { background: #7090ff; }

/* ── Play Again bar ───────────────────────────────────────── */
.play-again-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px 16px 24px;
  background: linear-gradient(to top, var(--bg) 65%, transparent);
  z-index: 15;
  display: flex;
  justify-content: center;
  animation: slideUp .3s ease;
}
.play-again-inner {
  width: 100%;
  max-width: var(--max-w);
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: 0 -4px 24px rgba(0,0,0,.1);
}
.play-again-label {
  flex: 1;
  font-size: .9rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.play-again-btn-bar {
  display: inline-block;
  width: auto;
  margin-top: 0;
  padding: 10px 24px;
  white-space: nowrap;
  flex-shrink: 0;
  border-radius: 999px;
}

/* ── Site link bar ────────────────────────────────────────── */
.site-link-bar {
  width: 100%;
  max-width: var(--max-w);
  padding: 20px 16px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.site-link-caption {
  font-size: .72rem;
  color: var(--muted);
}
.site-link {
  font-size: .88rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}
.site-link:hover { text-decoration: underline; }


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

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 480px) {
  .site-logo     { height: 42px; }
  main           { padding: 0 10px 80px; }
  .modal         { padding: 24px 16px; }
  .stat-row      { gap: 16px; }
  .clue-grid     { gap: 6px; grid-auto-rows: 140px; }
  .grid-cell     { padding: 8px 7px; }
  .cell-icon-lg  { font-size: 1.2rem; }
  .cell-attr-name{ font-size: .62rem; }
  .cell-value    { font-size: .72rem; }
  .cell-cost-badge{ font-size: .58rem; }
}

@media (max-width: 360px) {
  .site-logo   { height: 34px; }
  .clue-grid   { gap: 4px; grid-auto-rows: 120px; }
  .grid-cell   { padding: 6px 5px; }
  .cell-icon-lg{ font-size: 1rem; }
  .cell-attr-name{ font-size: .58rem; }
  .cell-value  { font-size: .66rem; }
}
