*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg-page); overflow: hidden; }
img { display: block; max-width: 100%; }
button, input { font: inherit; color: inherit; }
h1, h2, p, ol, ul, dl, dd { margin: 0; }
ol { padding: 0; list-style: none; }
[hidden] { display: none !important; }

.muted { color: var(--fg-3); }
.small { font-size: var(--fs-body-sm); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.eyebrow {
  font-size: var(--fs-eyebrow); font-weight: var(--fw-bold); letter-spacing: var(--tracking-wide);
  text-transform: uppercase; color: var(--mffu-blue-soft);
}
.glass {
  background: var(--glass-white-06);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-soft);
  backdrop-filter: var(--blur-glass);
  -webkit-backdrop-filter: var(--blur-glass);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: 11px var(--sp-6); border-radius: var(--r-lg); border: 1px solid transparent;
  font-weight: var(--fw-bold); cursor: pointer; text-decoration: none;
  transition: background 200ms ease, transform 120ms ease, box-shadow 200ms ease, opacity 200ms ease;
}
.btn.cta { background: var(--grad-brand-cta); color: var(--fg-inverse); }
.btn.cta:hover:not(:disabled) { background: var(--grad-brand); box-shadow: 0 0 24px rgba(58, 130, 247, 0.35); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.ghost { background: var(--glass-white-06); border-color: var(--border-soft); color: var(--fg-1); }
.btn.ghost:hover { background: var(--glass-white-10); }
.form-error { color: var(--danger); font-size: var(--fs-caption); min-height: 1em; }

/* One screen: header on top, the chart and the sidebar below. Only the picker scrolls. */
.app {
  position: relative; isolation: isolate; height: 100vh; height: 100dvh;
  display: grid; grid-template-rows: auto minmax(0, 1fr);
}
.app::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 60%; z-index: -1; pointer-events: none;
  background: var(--grad-table); opacity: 0.12;
  -webkit-mask-image: radial-gradient(closest-side, #000 30%, transparent);
  mask-image: radial-gradient(closest-side, #000 30%, transparent);
}

.topbar {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--sp-5);
  height: 64px; padding: 0 var(--sp-4); border-bottom: 1px solid var(--border-soft); background: rgba(15, 17, 26, 0.85);
}
.brand img { height: 32px; width: auto; }
.title-block { display: flex; align-items: baseline; gap: var(--sp-3); min-width: 0; padding-left: var(--sp-5); border-left: 1px solid var(--border-soft); }
.game-title { font-size: 22px; font-weight: var(--fw-heavy); letter-spacing: -0.01em; color: var(--fg-1); }
.game-title span { background: var(--grad-gold-logo); -webkit-background-clip: text; background-clip: text; color: transparent; }
.subtitle { font-size: var(--fs-body-sm); color: var(--fg-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modes { display: flex; align-items: center; gap: var(--sp-1); padding: 4px; border-radius: var(--r-pill); background: var(--glass-white-05); border: 1px solid var(--border-soft); }
.mode {
  padding: 6px var(--sp-4); border: 0; border-radius: var(--r-pill); background: transparent; color: var(--fg-3);
  font-size: var(--fs-body-sm); font-weight: var(--fw-semi); cursor: pointer; transition: background 200ms ease, color 200ms ease;
}
.mode:hover { color: var(--fg-1); }
.mode[aria-pressed="true"] { background: var(--grad-brand-cta); color: var(--fg-inverse); }
.icon-btn {
  width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--border-soft); background: var(--glass-white-06);
  font-weight: var(--fw-bold); cursor: pointer; margin-left: var(--sp-1);
}
.icon-btn:hover { background: var(--glass-white-10); }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: var(--sp-3); padding: var(--sp-3); min-height: 0; }

/* stage */
.stage { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.stage-bar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border-soft);
}
.clue-track { display: flex; gap: var(--sp-2); }
.clue-step {
  display: grid; grid-template-columns: auto auto; column-gap: var(--sp-2); align-items: center;
  padding: 5px var(--sp-3) 5px 5px; border-radius: var(--r-pill); border: 1px dashed var(--glass-white-20); color: var(--fg-3);
  transition: border-color 300ms ease, background 300ms ease, color 300ms ease;
}
.clue-num {
  grid-row: span 2; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--glass-white-06); font-size: 12px; font-weight: var(--fw-bold);
}
.clue-name { font-size: 12px; font-weight: var(--fw-semi); line-height: 1.2; }
.clue-hint { font-size: 10px; line-height: 1.2; color: var(--fg-3); }
.clue-step[data-open="true"] { border-style: solid; border-color: rgba(216, 174, 94, 0.6); background: rgba(216, 174, 94, 0.08); color: var(--fg-1); animation: clue-open 500ms cubic-bezier(0.2, 0.9, 0.3, 1.3); }
.clue-step[data-open="true"] .clue-num { background: var(--mffu-cream); color: var(--fg-inverse); }
.clue-step[data-open="true"] .clue-hint { color: var(--mffu-cream); }
@keyframes clue-open { from { transform: scale(0.9); } to { transform: scale(1); } }

.chart-wrap { position: relative; flex: 1; min-height: 220px; }
.chart-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.chart-status { position: absolute; inset: 0; display: grid; place-items: center; color: var(--fg-3); font-size: var(--fs-body-sm); padding: var(--sp-4); text-align: center; }

.clue-notes { display: grid; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border-soft); min-height: 52px; }
.clue-note { font-size: 13px; color: var(--fg-2); line-height: var(--lh-normal); animation: note-in 400ms ease both; }
.clue-note-title { display: inline-block; margin-right: var(--sp-2); color: var(--mffu-cream); font-weight: var(--fw-bold); }
.clue-empty { font-size: 13px; color: var(--fg-3); }
@keyframes note-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* sidebar */
.side { display: grid; grid-template-rows: auto minmax(0, 1fr); gap: var(--sp-3); min-height: 0; }
.card { padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3); min-height: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.card-title { font-size: var(--fs-body); font-weight: var(--fw-semi); }

.guess-list { display: grid; gap: 5px; }
.guess-row {
  display: grid; grid-template-columns: 44px minmax(0, 1fr); grid-template-areas: "id name" "id tags"; column-gap: var(--sp-3); align-items: center;
  min-height: 46px; padding: 6px var(--sp-3) 6px 6px; border-radius: var(--r-md); background: var(--glass-white-05); border: 1px solid transparent;
}
.guess-row.empty { grid-template-areas: "id name"; min-height: 28px; padding-block: 3px; background: transparent; border: 1px dashed var(--glass-white-10); }
.guess-row.empty .guess-id { height: 20px; background: transparent; color: var(--fg-6); font-size: 11px; }
.guess-id {
  grid-area: id; height: 34px; border-radius: var(--r-sm); display: grid; place-items: center;
  background: var(--glass-white-10); font-weight: var(--fw-heavy); font-size: 13px;
}
.guess-name { grid-area: name; font-size: 13px; font-weight: var(--fw-semi); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.guess-tags { grid-area: tags; display: flex; flex-wrap: wrap; gap: 4px; }
.tag { display: inline-flex; align-items: center; gap: 3px; padding: 1px 8px; border-radius: var(--r-pill); font-size: 11px; font-weight: var(--fw-semi); white-space: nowrap; }
.tag.ok { background: rgba(216, 174, 94, 0.16); color: var(--mffu-cream); }
.tag.no { background: var(--glass-white-06); color: var(--fg-3); }
.tag.vol { background: rgba(58, 130, 247, 0.16); color: var(--mffu-blue-soft); }
.guess-row[data-result="close"] .guess-id { background: rgba(216, 174, 94, 0.22); color: var(--mffu-cream); }
.guess-row[data-result="right"] { border-color: rgba(34, 197, 94, 0.5); background: rgba(34, 197, 94, 0.1); }
.guess-row[data-result="right"] .guess-id { background: var(--success); color: var(--fg-inverse); }
.guess-row[data-result="right"] .tag.ok { background: rgba(34, 197, 94, 0.2); color: var(--success); }
.guess-row.enter { animation: row-in 420ms cubic-bezier(0.2, 0.9, 0.3, 1.2) both; }
.guess-row.enter[data-result="wrong"] { animation: row-in 420ms cubic-bezier(0.2, 0.9, 0.3, 1.2) both, row-shake 380ms ease 420ms; }
.guess-row.enter[data-result="right"] { animation: row-in 420ms cubic-bezier(0.2, 0.9, 0.3, 1.2) both, row-win 900ms ease 300ms; }
@keyframes row-in { from { opacity: 0; transform: translateY(-8px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes row-shake { 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }
@keyframes row-win { 0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); } 100% { box-shadow: 0 0 0 12px rgba(34, 197, 94, 0); } }

.picker-card { gap: var(--sp-2); }
.input {
  width: 100%; padding: 12px var(--sp-4); border-radius: var(--r-lg); outline: none;
  background: var(--glass-white-05); border: 1px solid var(--glass-white-20); font-size: var(--fs-body); color: var(--fg-1);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
.input::placeholder { color: var(--fg-3); }
.input:focus { border-color: var(--mffu-blue); box-shadow: 0 0 0 3px rgba(58, 130, 247, 0.2); }
.suggestions { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; flex: 1; min-height: 0; overflow-y: auto; align-content: start; scrollbar-width: thin; }
.suggestion {
  display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; gap: var(--sp-3);
  padding: 6px var(--sp-3) 6px 6px; border-radius: var(--r-md); cursor: pointer; border: 1px solid transparent; background: var(--glass-white-05);
  animation: note-in 180ms ease both;
}
.suggestion:hover { background: var(--glass-white-10); }
.suggestion[aria-selected="true"] { border-color: var(--mffu-cream); background: rgba(216, 174, 94, 0.1); }
.suggestion.dim { opacity: 0.55; }
.suggestion-id { height: 32px; border-radius: var(--r-sm); display: grid; place-items: center; background: var(--glass-white-10); font-weight: var(--fw-heavy); font-size: 13px; }
.suggestion[aria-selected="true"] .suggestion-id { background: var(--mffu-cream); color: var(--fg-inverse); }
.suggestion-name { display: grid; font-size: 13px; font-weight: var(--fw-semi); min-width: 0; }
.suggestion-class { font-size: 11px; font-weight: var(--fw-regular); color: var(--fg-3); }
.suggestion-tag { font-size: 10px; color: var(--fg-3); text-transform: uppercase; letter-spacing: var(--tracking-wide); }
.picker-tip { font-size: 12px; color: var(--fg-3); }
.picker-foot { display: grid; gap: var(--sp-2); margin-top: auto; }
.picker-foot .btn { width: 100%; }
.form-error:empty { display: none; }

/* chart types */
.chart-types { display: flex; gap: 2px; padding: 3px; border-radius: var(--r-pill); background: var(--glass-white-05); border: 1px solid var(--border-soft); margin-right: auto; }
.chart-type {
  padding: 4px 12px; border: 0; border-radius: var(--r-pill); background: transparent; color: var(--fg-3);
  font-size: 12px; font-weight: var(--fw-semi); cursor: pointer; transition: background 160ms ease, color 160ms ease;
}
.chart-type:hover { color: var(--fg-1); }
.chart-type[aria-pressed="true"] { background: var(--glass-white-10); color: var(--fg-1); box-shadow: inset 0 0 0 1px var(--glass-white-20); }

/* Once a round ends the result card takes the room it needs, and the guesses shrink to one line each and scroll if space runs out. */
.side[data-over="true"] { grid-template-rows: minmax(0, 1fr) auto; }
.side[data-over="true"] .guesses-card { gap: var(--sp-2); }
.side[data-over="true"] .guess-list { min-height: 0; overflow-y: auto; scrollbar-width: thin; align-content: start; }
.side[data-over="true"] .guess-row { grid-template-columns: 36px minmax(0, 1fr) auto; grid-template-areas: "id name tags"; min-height: 0; padding: 4px var(--sp-2) 4px 4px; }
.side[data-over="true"] .guess-id { height: 26px; font-size: 12px; }
.side[data-over="true"] .guess-row .tag:not(.ok, .vol) { display: none; }
.side[data-over="true"] .guess-row.empty { display: none; }

.result-card { gap: 10px; overflow-y: auto; scrollbar-width: thin; animation: row-in 500ms cubic-bezier(0.2, 0.9, 0.3, 1.15) both; }
.result-card[data-status="solved"] { border-color: rgba(34, 197, 94, 0.45); box-shadow: 0 0 40px rgba(34, 197, 94, 0.15); }
.result-card[data-status="solved"] .eyebrow { color: var(--success); }
.result-card[data-status="failed"] .eyebrow { color: var(--mffu-cream); }
.result-title { font-size: 20px; font-weight: var(--fw-bold); line-height: var(--lh-snug); color: var(--fg-1); }
.result-id { display: inline-block; padding: 0 10px; margin-right: 4px; border-radius: var(--r-md); background: var(--mffu-cream); color: #0b0d14; }
.result-meta { font-size: 12.5px; color: var(--fg-1); opacity: 0.85; line-height: var(--lh-normal); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-2); }
.stats div { padding: 4px var(--sp-2); border-radius: var(--r-md); background: var(--glass-white-05); text-align: center; }
.stats dt { font-size: 10px; color: var(--fg-2); text-transform: uppercase; letter-spacing: var(--tracking-wide); }
.stats dd { font-size: var(--fs-body); font-weight: var(--fw-bold); }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
.result-actions .btn { padding: 11px var(--sp-2); font-size: var(--fs-body-sm); white-space: nowrap; }
/* Dark text on the gold-to-blue gradient fades out over the blue half, so buttons with longer labels are solid gold. */
.btn.gold { background: var(--mffu-cream); color: #0b0d14; }
.btn.gold:hover:not(:disabled) { background: #e4bd73; box-shadow: var(--shadow-yellow); }
#share-status { color: var(--fg-1); }
#share-status:empty { display: none; }
.plug { flex: none; padding: 10px var(--sp-3); border-radius: var(--r-lg); background: rgba(58, 130, 247, 0.08); border: 1px solid rgba(58, 130, 247, 0.25); display: grid; gap: var(--sp-2); }
.plug-copy { font-size: 12px; color: var(--fg-1); opacity: 0.85; line-height: var(--lh-normal); }
.plug-link { font-size: 12px; white-space: nowrap; font-weight: var(--fw-bold); color: var(--mffu-blue-soft); text-decoration: none; }
.plug-link:hover { text-decoration: underline; }

/* help */
.help { width: min(480px, calc(100% - 32px)); padding: 0; color: var(--fg-1); background: rgba(15, 17, 26, 0.97); }
.help::backdrop { background: rgba(2, 4, 14, 0.6); backdrop-filter: blur(3px); }
.help[open] { animation: row-in 360ms cubic-bezier(0.2, 0.9, 0.3, 1.15) both; }
.help form { padding: var(--sp-6); display: grid; gap: var(--sp-4); }
.help-title { font-size: var(--fs-h5); font-weight: var(--fw-bold); }
.help-list { padding-left: 18px; display: grid; gap: var(--sp-2); font-size: var(--fs-body-sm); color: var(--fg-2); line-height: var(--lh-normal); }
.help-list strong { color: var(--fg-1); }

@media (max-width: 1100px) {
  .layout { grid-template-columns: minmax(0, 1fr) 320px; }
  .clue-hint { display: none; }
  .clue-num { grid-row: auto; }
}

/* Phone and small tablet: the page scrolls, the chart keeps a fixed height. */
@media (max-width: 860px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100dvh; }
  .topbar { height: auto; grid-template-columns: auto 1fr; grid-template-areas: "brand modes" "title title"; padding: var(--sp-2) var(--sp-4); row-gap: var(--sp-2); }
  .brand { grid-area: brand; }
  .brand img { height: 26px; }
  .modes { grid-area: modes; justify-self: end; }
  .title-block { grid-area: title; padding-left: 0; border-left: 0; }
  .layout { grid-template-columns: minmax(0, 1fr); padding: var(--sp-2) var(--sp-4) var(--sp-6); }
  .chart-wrap { flex: none; height: 46vh; min-height: 240px; }
  .stage-bar { padding: var(--sp-2) var(--sp-3); }
  .clue-track { width: 100%; }
  .clue-step { flex: 1; padding-right: var(--sp-2); }
  .clue-name { font-size: 11px; }
  .side { display: flex; flex-direction: column; }
  .side[data-over="true"] > .result-card { order: -1; overflow: visible; }
  .guess-row.empty { display: none; }
  .suggestions { overflow: visible; }
  .chart-types { order: 3; }
}
@media (max-width: 480px) {
  .mode { padding: 6px var(--sp-3); }
  .guess-row { grid-template-columns: 40px minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.plug.plug-copy { display: block; }

/* five-step feedback: long labels while playing, short ones in the compact list after a round */
.tag.near { background: rgba(216, 174, 94, 0.16); color: var(--mffu-cream); }
.tag .short { display: none; }
.side[data-over="true"] .tag .long { display: none; }
.side[data-over="true"] .tag .short { display: inline; }

/* dialogs */
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.share-dialog { width: min(640px, calc(100% - 32px)); }
.card-image { width: 100%; height: auto; border-radius: var(--r-lg); border: 1px solid var(--border-soft); background: var(--bg-page); aspect-ratio: 1200 / 630; }
.share-text { margin: 0; padding: var(--sp-3); border-radius: var(--r-md); background: var(--glass-white-05); font-family: var(--font-sans); font-size: 13px; line-height: 1.5; white-space: pre-wrap; word-break: break-all; color: var(--fg-2); max-height: 160px; overflow: auto; }
.share-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.share-actions .btn { flex: 1 1 160px; padding: 11px var(--sp-3); font-size: var(--fs-body-sm); }
.archive-list { display: grid; gap: 6px; }
.archive-item {
  width: 100%; display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: var(--sp-3);
  padding: 10px var(--sp-3); border-radius: var(--r-md); border: 1px solid var(--border-soft); background: var(--glass-white-05); cursor: pointer; text-align: left;
}
.archive-item:hover { background: var(--glass-white-10); }
.archive-num { font-weight: var(--fw-heavy); }
.archive-date { font-size: var(--fs-body-sm); color: var(--fg-2); display: flex; gap: var(--sp-2); align-items: center; }
.archive-today { font-size: 10px; font-weight: var(--fw-bold); text-transform: uppercase; letter-spacing: var(--tracking-wide); color: var(--mffu-blue-soft); }
.archive-status { font-size: 12px; font-weight: var(--fw-semi); color: var(--fg-3); }
.archive-item[data-status="solved"] .archive-status { color: var(--success); }
.archive-item[data-status="failed"] .archive-status { color: var(--mffu-cream); }
.archive-item[data-status="started"] .archive-status { color: var(--mffu-blue-soft); }
@media (max-width: 480px) {
  #archive-open { padding: 6px var(--sp-2); }
}
