/* One in a Piece: parchment, ink and open sea. */
:root {
  --bg: #e9dcb8;
  --bg-2: #dccb9d;
  --paper: #f6ecd0;
  --paper-edge: #cdb98a;
  --ink: #2a1c10;
  --ink-soft: #5b4631;
  --sea: #0f6a8a;
  --sea-deep: #0a3f57;
  --sea-wave-a: #1b82a3;
  --sea-wave-b: #0f6a8a;
  --red: #b3322a;
  --gold: #d6a021;
  --field: #fffaf0;
  --shadow: 0 10px 30px rgba(60, 35, 10, .22);
  --t0: #8b8174; --t1: #2f7fd1; --t2: #8b4fc9; --t3: #e0652b; --t4: #e2b020;
  --font-display: "Pirata One", "Rockwell", "Georgia", serif;
  --font-body: "Alegreya", "Georgia", "Times New Roman", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1c2a;
    --bg-2: #0a1722;
    --paper: #1c2a35;
    --paper-edge: #38505f;
    --ink: #f1e6c8;
    --ink-soft: #b9ad92;
    --sea: #3aa6c8;
    --sea-deep: #072433;
    --sea-wave-a: #123d55;
    --sea-wave-b: #0d2e42;
    --field: #14212b;
    --shadow: 0 10px 30px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--bg) 0%, var(--bg-2) 70%) fixed,
    var(--bg-2);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 19px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- sea backdrop ---------- */
.sea { position: fixed; inset: auto 0 0 0; height: 140px; pointer-events: none; z-index: 0; overflow: hidden; }
.wave { position: absolute; bottom: 0; left: 0; width: 200%; height: 100%; }
.wave path { stroke: none; }
.wave-back { fill: var(--sea-wave-a); opacity: .45; animation: drift 22s linear infinite; }
.wave-front { fill: var(--sea-wave-b); opacity: .55; animation: drift 14s linear infinite reverse; height: 80%; }
@keyframes drift { from { transform: translateX(0); } to { transform: translateX(-50%); } }

/* ---------- layout ---------- */
#app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 28px 16px 120px;
  flex: 1;
}
.screen { animation: rise .45s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

h1, h2, .brand, .prompt, .poster-top, .tier-name, .poster-bounty, .seal-pts, dialog h2 {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: .02em;
}
.eyebrow {
  text-transform: uppercase;
  letter-spacing: .18em;
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0 0 6px;
  text-align: center;
}

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  min-height: 48px;
  padding: 10px 24px;
  border-radius: 12px;
  border: 2px solid var(--ink);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, background-color .12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, input:focus-visible { outline: 3px solid var(--sea); outline-offset: 2px; }
.btn.primary { background: var(--red); border-color: #6e1a14; color: #fff7e6; box-shadow: 0 4px 0 #6e1a14; }
.btn.primary:hover { box-shadow: 0 5px 0 #6e1a14; }
.btn.primary:active { box-shadow: 0 1px 0 #6e1a14; }
.btn.ghost { border-color: var(--paper-edge); color: var(--ink-soft); }
.btn[disabled] { opacity: .55; cursor: default; }

/* ---------- title ---------- */
#screen-title { text-align: center; }
.wheel { width: 132px; height: 132px; margin: 4px auto 0; display: block; color: var(--ink); }
.wheel-spin { animation: spin 60s linear infinite; transform-origin: 0 0; }
.wheel-rim { fill: none; stroke: currentColor; stroke-width: 9; }
.wheel-rim.thin { stroke-width: 3; opacity: .5; }
.wheel-hub { fill: var(--gold); stroke: currentColor; stroke-width: 4; }
.wheel-spokes line { stroke: currentColor; stroke-width: 6; stroke-linecap: round; }
.wheel-spokes circle { fill: currentColor; }
@keyframes spin { to { transform: rotate(360deg); } }

.brand { font-size: clamp(54px, 15vw, 88px); line-height: .95; margin: 4px 0 10px; text-shadow: 0 3px 0 rgba(255, 255, 255, .35); }
.tagline { font-size: 21px; color: var(--ink-soft); margin: 0 auto 22px; max-width: 28ch; }
.title-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.relax { display: inline-flex; gap: 10px; align-items: center; margin-top: 16px; color: var(--ink-soft); cursor: pointer; min-height: 44px; }
.relax input { width: 20px; height: 20px; accent-color: var(--red); }
.streak { margin: 10px 0 0; font-weight: 700; color: var(--red); }

.legend { list-style: none; padding: 0; margin: 26px auto 0; display: grid; gap: 8px; max-width: 360px; }
.legend li {
  display: flex; align-items: center; gap: 12px;
  background: var(--paper); border: 1px solid var(--paper-edge); border-radius: 12px;
  padding: 8px 14px; text-align: left; font-weight: 500;
}
.legend .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--tier); flex: none; }
.legend .pts { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--ink-soft); }

[data-tier="0"] { --tier: var(--t0); } [data-tier="1"] { --tier: var(--t1); }
[data-tier="2"] { --tier: var(--t2); } [data-tier="3"] { --tier: var(--t3); } [data-tier="4"] { --tier: var(--t4); }

/* ---------- play ---------- */
.hud { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.pips { display: flex; gap: 6px; }
.pip { width: 26px; height: 8px; border-radius: 4px; background: var(--paper-edge); transition: background-color .3s ease; }
.pip.done { background: var(--tier, var(--ink-soft)); }
.pip.now { background: var(--sea); }
.hud-bounty { font-family: var(--font-display); font-size: 24px; font-variant-numeric: tabular-nums; }

.timer { height: 10px; border-radius: 6px; background: var(--paper-edge); overflow: hidden; margin-bottom: 18px; }
.timer i { display: block; height: 100%; width: 100%; background: var(--sea); transform-origin: left center; border-radius: 6px; }
.timer.run i { animation: drain var(--dur, 25s) linear forwards, heat var(--dur, 25s) linear forwards; animation-delay: var(--delay, 0s); }
.timer.off { visibility: hidden; }
@keyframes drain { to { transform: scaleX(0); } }
@keyframes heat { 0% { background: var(--sea); } 60% { background: var(--gold); } 100% { background: var(--red); } }

.prompt { font-size: clamp(34px, 8.5vw, 50px); line-height: 1.05; text-align: center; margin: 8px 0 26px; text-wrap: balance; }
.field { display: flex; gap: 10px; }
.field input {
  flex: 1; min-width: 0;
  font: inherit; font-size: 22px;
  padding: 12px 16px; min-height: 54px;
  border-radius: 12px; border: 2px solid var(--ink);
  background: var(--field); color: var(--ink);
}
.field input::placeholder { color: var(--ink-soft); opacity: .7; }
.hint { min-height: 1.5em; margin: 10px 4px 0; color: var(--red); font-weight: 700; }
.secs { text-align: center; color: var(--ink-soft); font-variant-numeric: tabular-nums; margin: 6px 0 0; min-height: 1.4em; }
.skip-row { text-align: center; margin: 14px 0 0; }
.linkish { font: inherit; font-size: 16px; background: none; border: 0; color: var(--ink-soft); text-decoration: underline; cursor: pointer; min-height: 44px; padding: 0 8px; }
.linkish:hover { color: var(--ink); }
.linkish:focus-visible { outline: 3px solid var(--sea); outline-offset: 2px; border-radius: 4px; }
.shake { animation: shake .35s ease; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* ---------- reveal ---------- */
.reveal { text-align: center; padding-top: 34px; }
.seal {
  --size: 150px;
  width: var(--size); height: var(--size); margin: 0 auto 14px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--tier) 70%, #fff) 0%, var(--tier) 55%, color-mix(in srgb, var(--tier) 70%, #000) 100%);
  border: 6px double rgba(255, 255, 255, .75);
  box-shadow: 0 0 0 4px var(--tier), var(--shadow);
  color: #fffaf0;
  animation: stamp .55s cubic-bezier(.2, 1.4, .4, 1) both;
  position: relative;
}
.seal-pts { font-size: 62px; line-height: 1; text-shadow: 0 2px 0 rgba(0, 0, 0, .3); font-variant-numeric: tabular-nums; }
.seal[data-tier="4"]::before {
  /* a fine, fading sunburst (not blocky rays) */
  content: ""; position: absolute; inset: -34px; border-radius: 50%; z-index: -1;
  background: repeating-conic-gradient(from 0deg, rgba(255, 220, 110, .8) 0 2.2deg, transparent 2.2deg 10deg);
  -webkit-mask: radial-gradient(circle, transparent 44%, #000 50%, rgba(0, 0, 0, .35) 66%, transparent 74%);
  mask: radial-gradient(circle, transparent 44%, #000 50%, rgba(0, 0, 0, .35) 66%, transparent 74%);
  animation: spin 24s linear infinite;
}
.seal.miss { background: radial-gradient(circle at 35% 30%, #3b4a55, #1d2830); --tier: #2a3640; }
@keyframes stamp { 0% { transform: scale(2.4) rotate(-14deg); opacity: 0; } 60% { transform: scale(.94) rotate(3deg); opacity: 1; } 100% { transform: none; } }
.tier-name { font-size: 40px; margin: 0; color: var(--tier); text-shadow: 0 1px 0 rgba(255, 255, 255, .3); }
.reveal[data-tier="4"] .tier-name { background: linear-gradient(90deg, #96620a, #e0a416, #96620a); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmer 2.2s linear infinite; text-shadow: none; }
@keyframes shimmer { to { background-position: -200% 0; } }
.reveal-name { font-size: 26px; font-weight: 700; margin: 6px 0 0; overflow-wrap: anywhere; }
.reveal-sub { color: var(--ink-soft); margin: 2px 0 8px; }
.reveal-gain { font-family: var(--font-display); font-size: 30px; margin: 0 0 18px; font-variant-numeric: tabular-nums; }
.reveal > * { animation: rise .4s .15s cubic-bezier(.2, .8, .2, 1) both; }
.reveal > .seal { animation: stamp .55s cubic-bezier(.2, 1.4, .4, 1) both; }

/* ---------- result poster ---------- */
.poster {
  background:
    repeating-linear-gradient(0deg, rgba(120, 80, 30, .035) 0 2px, transparent 2px 5px),
    var(--paper);
  border: 3px solid var(--ink);
  outline: 2px solid var(--paper-edge); outline-offset: -10px;
  border-radius: 6px;
  padding: 22px 22px 18px;
  text-align: center;
  box-shadow: var(--shadow);
  transform: rotate(-.6deg);
  animation: pin .6s cubic-bezier(.2, 1.2, .3, 1) both;
}
@keyframes pin { from { transform: translateY(-30px) rotate(-4deg); opacity: 0; } to { transform: rotate(-.6deg); opacity: 1; } }
.poster-top { font-size: clamp(52px, 15vw, 78px); line-height: 1; margin: 0; letter-spacing: .12em; }
.poster-sub { margin: 0 0 8px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .16em; font-size: 13px; }
.poster-bounty { font-size: clamp(34px, 10vw, 54px); color: var(--red); margin: 4px 0 0; font-variant-numeric: tabular-nums; }
.poster-rank { margin: 0 0 12px; font-style: italic; color: var(--ink-soft); min-height: 1.4em; }
.rows { list-style: none; margin: 0; padding: 0; text-align: left; display: grid; gap: 6px; }
.rows li {
  display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: center;
  padding: 8px 10px; border-radius: 8px; background: rgba(255, 255, 255, .35);
  border-left: 5px solid var(--tier, var(--paper-edge));
  animation: rise .4s both;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .rows li { background: rgba(255, 255, 255, .05); } }
.rows .n { font-weight: 700; color: var(--ink-soft); }
.rows .q { font-size: 14px; color: var(--ink-soft); line-height: 1.2; display: block; }
.rows .a { font-weight: 700; line-height: 1.15; overflow-wrap: anywhere; }
.rows .p { font-family: var(--font-display); font-size: 20px; color: var(--tier, var(--ink-soft)); font-variant-numeric: tabular-nums; white-space: nowrap; }
.poster-foot { margin: 14px 0 0; font-size: 12px; letter-spacing: .3em; color: var(--ink-soft); }
.result-actions { display: flex; gap: 12px; justify-content: center; margin-top: 22px; flex-wrap: wrap; }
.next-in { text-align: center; color: var(--ink-soft); margin: 14px 0 0; }
.next-in b { font-variant-numeric: tabular-nums; color: var(--ink); }
#screen-result .streak { text-align: center; }

/* ---------- dialog, toast, footer ---------- */
dialog {
  border: 3px solid var(--ink); border-radius: 14px; background: var(--paper); color: var(--ink);
  max-width: min(480px, calc(100vw - 32px)); padding: 22px 22px 18px; box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(8, 20, 30, .6); }
dialog h2 { margin: 0 0 8px; font-size: 34px; }
.how { padding-left: 22px; margin: 0 0 16px; display: grid; gap: 8px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity .25s ease, transform .25s ease; z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.foot { position: relative; z-index: 1; max-width: 640px; margin: 0 auto; padding: 0 16px 18px; font-size: 13px; color: var(--ink-soft); text-align: center; }
.foot a { color: inherit; }
.foot p { margin: 0; padding: 8px 12px; border-radius: 10px; background: color-mix(in srgb, var(--bg) 82%, transparent); }

@media (max-width: 420px) {
  body { font-size: 18px; }
  .field { flex-direction: column; }
  .field .btn { width: 100%; }
  .seal { --size: 128px; }
  .seal-pts { font-size: 52px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .wave { animation: none !important; }
  /* the draining bar is information, not decoration: keep it moving */
  .timer.run i { animation-duration: var(--dur, 25s), var(--dur, 25s) !important; animation-iteration-count: 1 !important; }
}
