:root {
  --bg: #0f1117;
  --panel: #181b25;
  --panel-2: #1f2330;
  --line: #262b3a;
  --line-2: #323950;
  --ink: #e8eaf2;
  --ink-dim: #9aa0b4;
  --accent: #ffd166;
  --accent-2: #4cc9f0;
  --good: #3ddc84;
  --bad: #ff5d73;
  --cell: #f5f2e9;
  --cell-ink: #14161d;
  --cell-word: #ffedb8;
  --block: #0a0c10;
  --radius: 10px;
  font-size: 16px;
}

* { box-sizing: border-box; }

/* author display rules (flex/grid) must not defeat the hidden attribute */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent-2); }

button {
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

/* ---------- Header ---------- */

.site-header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.25rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #141724, #0f1117);
}

.brand h1 { margin: 0; font-size: 1.45rem; letter-spacing: 0.02em; color: var(--accent); }
.tagline { margin: 0.1rem 0 0; color: var(--ink-dim); font-size: 0.85rem; }

.controls { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }

.difficulty {
  display: flex;
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 999px;
  padding: 3px;
}

.difficulty button {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
  gap: 1px;
  border: none;
  background: none;
  color: var(--ink-dim);
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.difficulty button small { font-size: 0.62rem; font-weight: 400; opacity: 0.75; }

.difficulty button.active { background: var(--accent); color: #14161d; }

button.primary {
  background: var(--accent);
  color: #14161d;
  border: none;
  border-radius: 999px;
  padding: 0.5rem 1rem;
  font-weight: 700;
}

button.primary:hover { filter: brightness(1.08); }

/* ---------- Layout ---------- */

#app {
  flex: 1;
  display: grid;
  /* left track wide enough for 15 cells at the 46px cap */
  grid-template-columns: minmax(0, 730px) minmax(300px, 430px);
  gap: 1.25rem;
  padding: 1rem 1.25rem;
  align-items: start;
  justify-content: center;
}

.status { text-align: center; color: var(--ink-dim); padding: 3rem 1rem; }
.status.error { color: var(--bad); }

#play { display: flex; flex-direction: column; gap: 0.75rem; min-width: 0; }

/* ---------- Clue bar (the main clue surface) ---------- */

.cluebar {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 14px;
  padding: 0.5rem 0.6rem;
  position: sticky;
  top: 0.4rem;
  z-index: 20;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}

.cb-nav {
  flex: none;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--ink);
  font-size: 1.3rem;
  line-height: 1;
}

.cb-nav:hover { border-color: var(--accent); color: var(--accent); }

.cb-face {
  flex: none;
  width: 76px;
  height: 76px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  cursor: zoom-in;
  display: grid;
  place-items: center;
}

.cb-face img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
  display: block;
  opacity: 0;
  transition: opacity 0.25s;
}

.cb-face img.loaded { opacity: 1; }

.cb-info { min-width: 0; flex: 1; }

.cb-label { font-weight: 700; font-size: 0.95rem; }

.cb-sub { color: var(--ink-dim); font-size: 0.82rem; margin-top: 2px; }

.cb-hint { color: var(--accent-2); font-size: 0.82rem; font-style: italic; margin-top: 2px; }

.cb-hintbtn {
  flex: none;
  background: none;
  border: 1px solid var(--line-2);
  border-radius: 50%;
  width: 2rem;
  height: 2rem;
  font-size: 0.95rem;
}

.cb-hintbtn:hover { border-color: var(--accent); }

.stars { color: var(--accent); letter-spacing: 0.05em; font-size: 0.8rem; }

/* ---------- Grid ---------- */

#grid-wrap { overflow-x: auto; padding-bottom: 0.25rem; }

.grid {
  --size: 34px; /* actual size computed in JS from container width */
  display: grid;
  gap: 2px;
  background: var(--line);
  border: 3px solid var(--line);
  border-radius: 6px;
  width: max-content;
  margin: 0 auto;
}

.gcell { width: var(--size); height: var(--size); position: relative; }

.gcell.block { background: var(--block); }
.gcell.letter { background: var(--cell); }
.gcell.letter.in-word { background: var(--cell-word); }

.gcell .num {
  position: absolute;
  top: 1px;
  left: 3px;
  font-size: calc(var(--size) * 0.26);
  color: #555;
  pointer-events: none;
  z-index: 1;
}

.gcell input {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  text-align: center;
  font: inherit;
  font-weight: 700;
  font-size: max(16px, calc(var(--size) * 0.52)); /* ≥16px prevents iOS focus zoom */
  color: var(--cell-ink);
  text-transform: uppercase;
  caret-color: transparent;
  padding: 0;
}

.gcell input:focus {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
  border-radius: 2px;
}

.gcell.wrong input { color: var(--bad); }
.gcell.revealed input { color: #7a5af5; }
.gcell.correct input { color: #1c9d5b; }

/* ---------- Actions row ---------- */

.actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.actions .meta { color: var(--ink-dim); font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.actions .spacer { flex: 1; }

.actions button {
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 0.45rem 0.8rem;
  font-size: 0.85rem;
}

.actions button:hover { background: #2a3044; }
.actions button.danger:hover { background: #4a2230; border-color: #6e2a3d; }

/* ---------- Clue lists ---------- */

#clues {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  padding-right: 0.25rem;
  position: sticky;
  top: 0.4rem;
}

.clue-group h2 {
  margin: 0 0 0.45rem;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
}

.clue-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }

.clue {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.4rem 0.55rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.clue:hover { border-color: #3a4260; }
.clue.active { border-color: var(--accent); background: #221f14; }
.clue.solved { border-color: #1f5e40; background: #12211a; }

.clue-num {
  min-width: 2.1rem;
  font-weight: 700;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}

.clue.active .clue-num { color: var(--accent); }
.clue.solved .clue-num { color: var(--good); }

.face {
  position: relative;
  width: 56px;
  height: 56px;
  flex: none;
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
}

.face img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
  opacity: 0;
  transition: opacity 0.2s;
  display: block;
}

.face .qmark {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  color: var(--ink-dim);
  transition: opacity 0.2s;
}

.clue:hover .face img.loaded,
.clue.pinned .face img.loaded,
.clue.solved .face img.loaded { opacity: 1; }

.clue:hover .face .qmark,
.clue.pinned .face .qmark,
.clue.solved .face .qmark { opacity: 0; }

.clue-meta { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; flex: 1; }
.clue-len { color: var(--ink-dim); font-size: 0.8rem; }

.clue-name {
  display: none;
  font-weight: 600;
  color: var(--good);
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clue.solved .clue-name { display: block; }

/* ---------- Hover card (desktop: photo pops up over the grid) ---------- */

.hovercard {
  position: fixed;
  z-index: 40;
  display: flex;
  gap: 0.5rem;
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  padding: 0.45rem;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  animation: fadein 0.12s ease;
}

.hovercard .hc-item { display: flex; flex-direction: column; align-items: center; gap: 0.25rem; }

.hovercard img {
  width: 120px;
  height: 120px;
  object-fit: cover;
  object-position: top;
  border-radius: 8px;
  background: var(--panel-2);
  display: block;
}

.hovercard .hc-label { font-size: 0.75rem; color: var(--ink-dim); font-weight: 600; }
.hovercard .hc-label b { color: var(--ink); }

@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Lightbox ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(8, 9, 14, 0.88);
  display: grid;
  place-items: center;
  cursor: zoom-out;
}

.lightbox figure { margin: 0; text-align: center; max-width: min(92vw, 480px); }

.lightbox img {
  max-width: 100%;
  max-height: 70vh;
  border-radius: 14px;
  border: 1px solid var(--line-2);
}

.lightbox figcaption { color: var(--ink-dim); margin-top: 0.6rem; font-size: 0.9rem; }

/* ---------- Win overlay ---------- */

.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 14, 0.82);
  display: grid;
  place-items: center;
  z-index: 70;
  padding: 1rem;
}

.win-card {
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 16px;
  padding: 1.8rem 2.4rem;
  text-align: center;
  animation: pop 0.35s ease;
  max-width: 92vw;
}

.win-emoji { font-size: 3rem; }
.win-card h2 { margin: 0.5rem 0; color: var(--accent); }
.win-card p { color: var(--ink-dim); }

.win-actions { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; margin-top: 1rem; }

.win-actions button {
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 0.55rem 1rem;
}

@keyframes pop {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.site-footer {
  text-align: center;
  color: var(--ink-dim);
  font-size: 0.78rem;
  padding: 0.9rem;
  border-top: 1px solid #1d2130;
}

/* ---------- Responsive ---------- */

@media (max-width: 980px) {
  #app { grid-template-columns: 1fr; padding: 0.75rem; }
  #clues { max-height: none; position: static; }
  .site-header { padding: 0.6rem 0.9rem; }
  .brand h1 { font-size: 1.2rem; }
  .tagline { display: none; }
}

@media (max-width: 560px) {
  .cluebar { gap: 0.45rem; padding: 0.4rem 0.45rem; }
  .cb-face { width: 62px; height: 62px; }
  .cb-nav { width: 1.9rem; height: 1.9rem; font-size: 1.1rem; }
  .cb-hintbtn { width: 1.8rem; height: 1.8rem; font-size: 0.85rem; }
  .cb-label { font-size: 0.85rem; }
  .cb-sub, .cb-hint { font-size: 0.76rem; }
  .cb-info { overflow: hidden; }
}
