:root {
  --ink: #3b2416;
  --paper: #fff8e7;
  --yolk: #ffb81c;
  --orange: #ff7a1a;
  --shadow: 0 5px 0 var(--ink);
  --font: 'Fredoka', ui-rounded, 'Arial Rounded MT Bold', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #b9a7f0;
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

#world {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

main {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

main > * { pointer-events: auto; }

/* ---------- HUD ---------- */

#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 64px 0 14px;
  pointer-events: none;
}

.hud-block {
  display: flex;
  flex-direction: column;
  padding: 7px 14px 8px;
  background: rgba(40, 22, 12, 0.78);
  border-radius: 14px;
  color: #fff3d6;
  line-height: 1.1;
  min-width: 104px;
}

.hud-right { text-align: right; }
.hud-label { font-size: 11px; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase; opacity: 0.7; }
.hud-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.hud-sub { font-size: 12px; font-weight: 600; color: var(--yolk); letter-spacing: 0.04em; }

.icon-btn {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  z-index: 4;
  width: 42px;
  height: 42px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  font: 700 18px var(--font);
  cursor: pointer;
  box-shadow: 0 3px 0 var(--ink);
}

.icon-btn[aria-pressed='false'] { opacity: 0.55; text-decoration: line-through; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 22px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: var(--yolk);
  color: var(--ink);
  font: 700 17px var(--font);
  letter-spacing: 0.04em;
  text-decoration: none;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.08s, box-shadow 0.08s, background 0.15s;
}

.btn:hover:not(:disabled) { background: #ffc94a; }
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-big { width: 100%; padding: 18px 22px; font-size: 22px; letter-spacing: 0.12em; }
.btn-ghost { background: var(--paper); }

:focus-visible { outline: 3px solid #2a6df4; outline-offset: 3px; }

/* ---------- title ---------- */

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(28px, 8vh, 90px) 18px 22px;
  text-align: center;
}

.logo {
  margin: 0;
  display: flex;
  justify-content: center;
  font-size: clamp(40px, 10.5vw, 112px);
  font-weight: 700;
  line-height: 0.9;
  letter-spacing: 0.02em;
  color: #fffdf5;
  -webkit-text-stroke: clamp(2px, 0.5vw, 5px) var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 0.07em 0 var(--ink);
}

.logo span:last-child { color: var(--yolk); }

.tagline {
  margin: 20px 0 0;
  font-size: clamp(14px, 2.4vw, 20px);
  font-weight: 600;
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  color: var(--ink);
}

.pitch {
  margin: 12px 0 0;
  font-size: clamp(14px, 2vw, 18px);
  font-weight: 500;
  color: rgba(59, 36, 22, 0.85);
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.7);
}

.title-foot {
  margin-top: auto;
  width: min(100%, 460px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: rgba(255, 248, 231, 0.94);
  border: 3px solid var(--ink);
  border-radius: 22px;
  box-shadow: var(--shadow);
  text-align: left;
}

.how summary {
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 13px;
}

.how ul { margin: 10px 0 0; padding-left: 20px; font-size: 15px; line-height: 1.45; }
.how li + li { margin-top: 4px; }

.account-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; font-weight: 600; }
.account-actions { display: flex; gap: 6px; }
.no-accounts .account-row, .no-accounts [data-open-board], .no-accounts .save { display: none; }
button.chip-link { font: 600 13px var(--font); letter-spacing: 0.12em; text-transform: uppercase; cursor: pointer; }

.title-links { display: flex; align-items: center; justify-content: space-between; font-size: 13px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; }
#modes { display: flex; gap: 6px; }
.chip-link { padding: 5px 12px; border: 2px solid var(--ink); border-radius: 999px; color: var(--ink); text-decoration: none; background: #fff; }
.chip-link:hover { background: var(--yolk); }

/* ---------- prompt + result cards ---------- */

.card {
  position: absolute;
  top: clamp(74px, 11vh, 120px);
  left: 50%;
  width: min(calc(100% - 28px), 560px);
  transform: translateX(-50%);
  padding: 18px 20px 16px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 22px;
  box-shadow: var(--shadow);
  text-align: center;
  animation: pop 0.28s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes pop {
  from { opacity: 0; transform: translateX(-50%) translateY(-14px) scale(0.96); }
}

.eyebrow { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: 0.22em; text-transform: uppercase; color: rgba(59, 36, 22, 0.65); }

#prompt h2 { margin: 6px 0 14px; font-size: clamp(24px, 5vw, 36px); font-weight: 700; line-height: 1.12; text-wrap: balance; }

#answer-form { display: flex; gap: 8px; }

#answer {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: #fff;
  font: 600 19px var(--font);
  color: var(--ink);
}

#answer:disabled { background: #f0e6cf; }
#answer.shake { animation: shake 0.3s; border-color: #d2382c; }

@keyframes shake {
  25% { transform: translateX(-6px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

.timer-row { margin-top: 12px; display: flex; align-items: center; gap: 10px; }
.timer { flex: 1; height: 12px; border: 2px solid var(--ink); border-radius: 999px; background: #fff; overflow: hidden; }
#timer-fill { height: 100%; width: 100%; background: var(--yolk); transform-origin: left; }
#timer-fill.low { background: #e5482f; }
#timer-num { min-width: 1.6em; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
#timer-num.low { color: #d2382c; font-size: calc(20px + 12px * var(--pressure, 0)); animation: throb 0.5s infinite; }
@keyframes throb { 50% { transform: scale(1.18); } }

/* the last seconds: a red vignette closes in and the card rattles */
#danger {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: var(--pressure, 0);
  background: radial-gradient(ellipse at center, rgba(210, 40, 30, 0) 45%, rgba(210, 40, 30, 0.55) 100%);
  animation: pulse 0.6s infinite;
}
@keyframes pulse { 50% { filter: brightness(1.5); } }
.card.panic { animation: rattle 0.16s infinite; border-color: #d2382c; box-shadow: 0 5px 0 #d2382c; }
@keyframes rattle {
  25% { transform: translateX(calc(-50% - 2px)) rotate(-0.3deg); }
  75% { transform: translateX(calc(-50% + 2px)) rotate(0.3deg); }
}

.hint { margin: 9px 0 0; min-height: 1.3em; font-size: 14px; font-weight: 500; color: rgba(59, 36, 22, 0.7); }
.hint.bad { color: #c22f22; font-weight: 600; }

.ladder { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.ladder li {
  display: flex;
  justify-content: space-between;
  padding: 6px 14px;
  border: 2px solid rgba(59, 36, 22, 0.25);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: rgba(59, 36, 22, 0.45);
  transition: background 0.08s, color 0.08s, transform 0.08s;
}
.ladder li.on { border-color: var(--ink); background: var(--tier); color: var(--ink); transform: scale(1.03); }
.ladder li.hit { animation: hit 0.5s; }
@keyframes hit { 30% { transform: scale(1.09); } }

.tier-name {
  margin: 2px 0 0;
  display: inline-block;
  padding: 4px 16px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--tier, #ddd);
  font-size: clamp(20px, 4.4vw, 28px);
  font-weight: 700;
  letter-spacing: 0.08em;
}
.said { margin: 10px 0 0; font-size: clamp(20px, 4vw, 26px); font-weight: 600; text-transform: capitalize; }
.gain { margin: 4px 0 0; font-size: 15px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; }
.flavor { margin: 6px 0 0; font-size: 15px; color: rgba(59, 36, 22, 0.75); }
#next { margin-top: 14px; }

/* ---------- end ---------- */

.end { justify-content: flex-start; overflow-y: auto; padding-top: clamp(64px, 9vh, 96px); background: rgba(20, 10, 14, 0.5); }

.end-card {
  width: min(100%, 520px);
  padding: 20px 20px 22px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

#portrait { width: 132px; height: 132px; margin: 4px auto -4px; display: block; }
.end-card h2 { margin: 0; font-size: clamp(28px, 6vw, 40px); font-weight: 700; line-height: 1.05; }
.end-score { margin: 6px 0 0; font-size: 17px; font-weight: 500; }
.end-score b { font-size: 24px; }
.end-rank { margin: 4px 0 0; font-size: 14px; color: rgba(59, 36, 22, 0.75); min-height: 1.2em; }

.recap { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 6px; text-align: left; }
.recap li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 8px 12px; border: 2px solid rgba(59, 36, 22, 0.2); border-radius: 12px; background: #fff; }
.recap .q { grid-column: 1 / -1; font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: rgba(59, 36, 22, 0.6); }
.recap .a { font-size: 17px; font-weight: 600; text-transform: capitalize; }
.recap .t { align-self: center; padding: 2px 10px; border: 2px solid var(--ink); border-radius: 999px; background: var(--tier); font-size: 12px; font-weight: 700; letter-spacing: 0.06em; white-space: nowrap; }
.recap .g { grid-column: 1 / -1; font-size: 13px; color: rgba(59, 36, 22, 0.75); }
.recap .g b { text-transform: capitalize; }

.end-actions { margin-top: 16px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.end-card h3 { margin: 18px 0 0; font-size: 12px; font-weight: 600; letter-spacing: 0.2em; text-transform: uppercase; color: rgba(59, 36, 22, 0.62); text-align: left; }
.compare { text-align: left; }
.compare-headline { margin: 2px 0 0; font-size: 20px; font-weight: 700; }
.curve { position: relative; margin-top: 4px; }
.curve svg { display: block; width: 100%; height: auto; font-family: var(--font); touch-action: none; }
.chart-tip {
  position: absolute;
  top: -6px;
  transform: translateX(-50%);
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff8e7;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
}
.compare-note { margin: 2px 0 0; font-size: 13px; color: rgba(59, 36, 22, 0.72); }
.recap-title + .recap { margin-top: 8px; }
.recap .cmp { grid-column: 1 / -1; display: flex; align-items: flex-end; gap: 10px; margin-top: 4px; font-size: 13px; color: rgba(59, 36, 22, 0.8); }
.tier-bars { flex: none; }

.save { margin-top: 16px; padding: 12px; border: 2px dashed rgba(59, 36, 22, 0.35); border-radius: 14px; }
.save p { margin: 0 0 10px; font-size: 14px; }

/* ---------- dialogs ---------- */

.dialog {
  width: min(calc(100% - 28px), 400px);
  padding: 22px 22px 20px;
  border: 3px solid var(--ink);
  border-radius: 22px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  box-shadow: var(--shadow);
}
.dialog-wide { width: min(calc(100% - 28px), 520px); }
.dialog::backdrop { background: rgba(20, 10, 14, 0.55); }
.dialog h2 { margin: 0; font-size: 26px; font-weight: 700; }
.dialog-sub { margin: 4px 0 14px; font-size: 14px; color: rgba(59, 36, 22, 0.75); min-height: 1.2em; }
.dialog-note { margin: 0; font-size: 13px; color: rgba(59, 36, 22, 0.7); }
.dialog-error { margin: 0; min-height: 1.2em; font-size: 14px; font-weight: 600; color: #c22f22; }
.dialog-close { position: absolute; top: 10px; right: 12px; width: 34px; height: 34px; border: 0; border-radius: 50%; background: transparent; color: var(--ink); font: 700 24px var(--font); cursor: pointer; }
.dialog-close:hover { background: rgba(59, 36, 22, 0.1); }
.dialog form { display: grid; gap: 10px; }
.dialog label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
.dialog input { padding: 10px 12px; border: 2px solid var(--ink); border-radius: 12px; background: #fff; font: 500 17px var(--font); color: var(--ink); }
.link-btn { margin-top: 12px; padding: 0; border: 0; background: none; color: var(--ink); font: 600 14px var(--font); text-decoration: underline; cursor: pointer; }
.dialog-note .link-btn { margin: 0; }

.tabs { display: flex; gap: 6px; margin-top: 12px; }
.tabs button { flex: 1; padding: 8px 6px; border: 2px solid var(--ink); border-radius: 12px; background: #fff; color: var(--ink); font: 600 14px var(--font); cursor: pointer; }
.tabs button[aria-selected='true'] { background: var(--yolk); }
.board-scroll { max-height: min(52vh, 420px); overflow-y: auto; margin-bottom: 10px; }
.board-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.board-table th { padding: 4px 8px; font-size: 11px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; text-align: left; color: rgba(59, 36, 22, 0.6); }
.board-table td { padding: 7px 8px; border-top: 1px solid rgba(59, 36, 22, 0.14); }
.board-table .num { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.board-table .rank { width: 2.2em; font-weight: 700; font-variant-numeric: tabular-nums; }
.board-table .extra { font-size: 13px; color: rgba(59, 36, 22, 0.65); }
.board-table tr.you td { background: rgba(255, 184, 28, 0.3); }

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

#toast {
  position: fixed;
  left: 50%;
  bottom: 9vh;
  z-index: 5;
  transform: translate(-50%, 20px);
  padding: 10px 22px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--yolk);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.06em;
  white-space: nowrap;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}

#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 520px) {
  .hud-block { min-width: 88px; padding: 6px 10px; }
  .hud-value { font-size: 20px; }
  .card { top: 78px; padding: 14px 14px 12px; }
  .ladder li { padding: 4px 12px; font-size: 13px; }
  #toast { font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  .card, .card.panic, .ladder li.hit, #answer.shake, #danger, #timer-num.low { animation: none; }
  .btn, #toast { transition: none; }
}
