/* Wormillion - retro earth-tone chrome around a pixel-art dig scene. */

:root {
  --soil-900: #150d07;
  --soil-800: #21150d;
  --soil-700: #2c1c11;
  --soil-600: #3b2617;
  --line: #6d4a2c;
  --line-soft: #4a3120;
  --cream: #f6ead6;
  --cream-dim: #c3ab8c;
  --amber: #ffb648;
  --worm: #e0705a;
  --good: #9ed45c;
  --warn: #ffcf5c;
  --bad: #ff8163;
  --font: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", "Roboto Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(120% 80% at 50% 0%, #2a1a10 0%, var(--soil-900) 70%),
    var(--soil-900);
  color: var(--cream);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: none;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px clamp(10px, 2vw, 20px) 16px;
  gap: 12px;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--line-soft);
}

.logo {
  margin: 0;
  font-size: clamp(20px, 4.4vw, 30px);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--amber);
  text-shadow: 0 2px 0 #7a3b12, 0 4px 0 rgba(0, 0, 0, 0.45);
}

.best-chip {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cream-dim);
  white-space: nowrap;
}

.best-chip span { color: var(--cream); }

/* ---------- layout ---------- */
.stage {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 400px);
  grid-template-rows: minmax(0, 1fr);
  gap: 14px;
}

@media (max-width: 860px) {
  .stage {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(160px, 34dvh) minmax(0, 1fr);
  }
}

/* ---------- scene ---------- */
.scene {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #0d0805;
  border: 2px solid var(--line);
  box-shadow: inset 0 0 0 2px #0d0805, 0 6px 0 rgba(0, 0, 0, 0.45);
}

#scene {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.scene-hud {
  position: absolute;
  inset: 8px 8px auto 8px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  pointer-events: none;
}

.depth-readout {
  background: rgba(12, 7, 4, 0.72);
  border: 2px solid var(--line-soft);
  padding: 4px 8px;
  text-align: center;
  min-width: 62px;
}

.depth-readout span {
  display: block;
  font-size: 20px;
  line-height: 1;
  color: var(--amber);
}

.depth-readout small {
  display: block;
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--cream-dim);
}

.stratum-badge {
  --band: var(--amber);
  --band-bg: #3b2617;
  background: color-mix(in srgb, var(--band-bg) 80%, #000);
  border: 2px solid var(--band);
  color: var(--cream);
  padding: 4px 8px;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.stratum-badge.big {
  display: inline-block;
  font-size: 13px;
  padding: 6px 12px;
  margin: 0 0 12px;
}

/* ---------- "ONE IN WORMILLION" (an answer at 85%+ obscurity) ---------- */
.jackpot {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  /* set by ui.js from the scene's width so the word always fits */
  --jackpot-size: 48px;
}

.jackpot[hidden] { display: none; }

.jackpot-fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.jackpot-text {
  position: relative;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  text-transform: uppercase;
  text-align: center;
  color: var(--amber);
  /* a fat pixel outline plus a drop, so it reads over any stratum */
  text-shadow:
    3px 0 0 #0d0805, -3px 0 0 #0d0805, 0 3px 0 #0d0805, 0 -3px 0 #0d0805,
    3px 3px 0 #0d0805, -3px 3px 0 #0d0805, 3px -3px 0 #0d0805, -3px -3px 0 #0d0805,
    0 7px 0 rgba(0, 0, 0, 0.55);
  animation:
    jackpot-slam 0.45s steps(5) both,
    jackpot-strobe 0.18s steps(2) 0.45s 10 alternate,
    jackpot-bob 1.1s steps(4) 2.3s infinite alternate;
}

.jackpot-line-1 {
  font-size: calc(var(--jackpot-size) * 0.42);
  letter-spacing: 0.32em;
  margin-bottom: 0.25em;
  color: var(--cream);
}

.jackpot-line-2 {
  font-size: var(--jackpot-size);
  font-weight: 700;
  letter-spacing: 0.06em;
}

@keyframes jackpot-slam {
  from { transform: scale(3.2) rotate(-4deg); opacity: 0; }
  60% { transform: scale(0.92); opacity: 1; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes jackpot-strobe {
  from { color: var(--amber); }
  to { color: #ffffff; }
}

@keyframes jackpot-bob {
  from { transform: translateY(0); }
  to { transform: translateY(-4px); }
}

/* ---------- 0% obscurity: the opposite of the jackpot ---------- */
.dud {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  /* Low in the scene, not centred: the worm sits about half-way down and the
     whole point is to see it looking rotten. Room is left under the words
     for the drips to hang into. */
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 16%;
  box-sizing: border-box;
  pointer-events: none;
  --dud-size: 48px; /* set by ui.js from the scene's width, like --jackpot-size */
}

.dud[hidden] { display: none; }

/* The mess is drawn OVER the words so the drips hang from the letters. */
.dud-fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.dud-text {
  position: relative;
  z-index: 1;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  text-transform: uppercase;
  text-align: center;
  color: #b3bf62; /* sickly */
  text-shadow:
    3px 0 0 #101408, -3px 0 0 #101408, 0 3px 0 #101408, 0 -3px 0 #101408,
    3px 3px 0 #101408, -3px 3px 0 #101408, 3px -3px 0 #101408, -3px -3px 0 #101408,
    0 7px 0 #5e0a0a; /* a blood-dark underside */
  animation:
    dud-flop 0.6s steps(6) both,
    dud-pulse 0.9s steps(2) 0.6s infinite alternate,
    dud-sag 2.4s steps(5) 0.6s infinite alternate;
}

.dud-line-1 {
  font-size: calc(var(--dud-size) * 0.42);
  letter-spacing: 0.28em;
  margin-bottom: 0.3em;
  color: #cfc9a8;
}

.dud-line-2 {
  font-size: var(--dud-size);
  font-weight: 700;
  letter-spacing: 0.06em;
}

/* Lands like something dropped, not something thrown. */
@keyframes dud-flop {
  from { transform: translateY(-45%) scale(1.15) rotate(2deg); opacity: 0; }
  55% { transform: translateY(6%) scale(0.96) rotate(-1deg); opacity: 1; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes dud-pulse {
  from { color: #b3bf62; }
  to { color: #8d9a4a; }
}

@keyframes dud-sag {
  from { transform: translateY(0) skewX(-2deg); }
  to { transform: translateY(5px) skewX(2deg); }
}

/* ---------- panel ---------- */
.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: linear-gradient(180deg, var(--soil-700), var(--soil-800));
  border: 2px solid var(--line);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.45);
  padding: 16px;
  overflow-y: auto;
}

.screen { display: flex; flex-direction: column; gap: 12px; }
.screen[hidden] { display: none; }

.screen-title {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--amber);
}

.lede { margin: 0; color: var(--cream-dim); font-size: 13px; }

.rules {
  margin: 0;
  padding-left: 16px;
  font-size: 12px;
  color: var(--cream-dim);
  display: grid;
  gap: 4px;
}

.rules li::marker { color: var(--worm); }

.footnote {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #8b7358;
}

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 11px 14px;
  border: 2px solid var(--line);
  background: var(--soil-600);
  color: var(--cream);
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.5);
  transition: transform 0.06s steps(2), background 0.15s;
}

.btn:hover { background: #4a2f1c; }

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.5);
}

.btn:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 2px;
}

.btn.primary {
  background: #a8442c;
  border-color: #e0705a;
  color: #fff3e6;
}

.btn.primary:hover { background: #bd4e33; }

.btn.ghost {
  background: transparent;
  color: var(--cream-dim);
  box-shadow: none;
}

.btn.ghost:hover { color: var(--cream); background: rgba(255, 255, 255, 0.04); }

.btn[disabled] {
  cursor: default;
  opacity: 0.55;
  transform: none;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.5);
}

/* ---------- mode pick (title) ---------- */
.mode-pick { display: grid; gap: 6px; }
.mode-pick .btn + .mode-note { margin-top: -2px; }
.mode-pick .mode-note + .btn { margin-top: 8px; }

.mode-note {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #8b7358;
}

.mode-note.played { color: var(--amber); }

/* "Daily · Sep 12" / "Endless" on the statusline and the summary */
.mode-chip {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--amber);
}

.mode-chip.summary-mode { margin: -6px 0 0; }

/* ---------- play ---------- */
.statusline {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cream-dim);
}

.timer { display: flex; align-items: center; gap: 10px; }

.timer-track {
  flex: 1;
  height: 12px;
  background: #150d07;
  border: 2px solid var(--line-soft);
  overflow: hidden;
}

.timer-bar {
  height: 100%;
  width: 100%;
  background: repeating-linear-gradient(90deg, #9ed45c 0 6px, #7fb648 6px 10px);
  transition: width 0.2s linear;
}

.timer-bar[data-state="warn"] {
  background: repeating-linear-gradient(90deg, #ffcf5c 0 6px, #e0a83c 6px 10px);
}

.timer-bar[data-state="critical"] {
  background: repeating-linear-gradient(90deg, #ff8163 0 6px, #d95a3c 6px 10px);
  animation: pulse 0.6s steps(2) infinite;
}

@keyframes pulse { 50% { opacity: 0.55; } }

.timer-num {
  min-width: 2.5ch;
  text-align: right;
  font-size: 18px;
  color: var(--amber);
}

.prompt-card {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: #170e08;
  border: 2px solid var(--line-soft);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.03);
}

.prompt-icon {
  width: 48px;
  height: 48px;
  flex: none;
  image-rendering: pixelated;
}

.prompt-category {
  margin: 0 0 2px;
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--worm);
}

.prompt-text {
  margin: 0;
  font-size: clamp(15px, 2.4vw, 19px);
  line-height: 1.25;
  color: var(--cream);
}

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

.answer-form input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 16px;
  padding: 11px 12px;
  background: #120b06;
  border: 2px solid var(--line);
  color: var(--cream);
}

.answer-form input::placeholder { color: #75604a; }

.answer-form input:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 1px;
}

.answer-form input:disabled { opacity: 0.5; }

.feedback {
  margin: 0;
  min-height: 2.6em;
  font-size: 13px;
  color: var(--cream-dim);
}

.feedback[data-kind="good"] { color: var(--good); }
.feedback[data-kind="fixed"] { color: var(--good); }
.feedback[data-kind="warn"] { color: var(--warn); }
.feedback[data-kind="bad"] { color: var(--bad); }

.last-answer {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #8b7358;
}

/* ---------- summary + stats ---------- */
.big-score {
  margin: 0;
  font-size: clamp(40px, 9vw, 60px);
  line-height: 1;
  color: var(--amber);
  text-shadow: 0 3px 0 #7a3b12, 0 6px 0 rgba(0, 0, 0, 0.5);
}

.sub-score {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cream-dim);
}

.new-best {
  margin: 0;
  padding: 8px 10px;
  background: #3d2a12;
  border: 2px dashed var(--amber);
  color: var(--amber);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.round-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 2px;
  max-height: 34vh;
  overflow-y: auto;
  border: 2px solid var(--line-soft);
  background: #170e08;
}

.round-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  font-size: 12px;
  border-bottom: 1px solid rgba(109, 74, 44, 0.35);
}

.round-list li:last-child { border-bottom: 0; }
.round-list li.miss .r-name { color: #9a8163; }
.round-list li.empty { justify-content: center; color: var(--cream-dim); }

.r-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.r-date { color: #8b7358; font-size: 11px; }
.r-points { color: var(--amber); flex: none; }

/* ---------- the obscurity ladder on the summary ---------- */
.list-title {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #8b7358;
}

/* name | bar | % | points, on one line; the bar takes whatever is left */
.round-list.ladder li {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(48px, 6fr) 6ch auto;
  align-items: center;
  gap: 8px;
}

.r-bar {
  position: relative;
  height: 10px;
  border: 2px solid var(--line-soft);
  background: #0d0805;
}

/* a segmented pixel meter, like the round timer */
.r-bar i {
  display: block;
  height: 100%;
  min-width: 0;
  background: repeating-linear-gradient(90deg, #a8875a 0 4px, #7d6340 4px 6px);
}

.r-pct {
  text-align: right;
  white-space: nowrap;
  color: var(--cream-dim);
  font-variant-numeric: tabular-nums;
}

.ladder li.miss .r-bar { border-color: #3a2716; }
.ladder li.miss .r-pct { color: #6f5b45; }

/* 85%+: one in Wormillion ("rare", not "jackpot" - that class is the overlay) */
.ladder li.rare .r-name,
.ladder li.rare .r-pct { color: var(--amber); }
.ladder li.rare .r-bar { border-color: var(--amber); }
.ladder li.rare .r-bar i {
  background: repeating-linear-gradient(90deg, var(--amber) 0 4px, #e0912a 4px 6px);
}
.ladder li.rare .r-pct::before { content: '★ '; }

/* 100%: the rarest thing in its category */
.ladder li.rarest .r-name,
.ladder li.rarest .r-pct { color: #ffffff; }
.ladder li.rarest .r-bar { border-color: #ffffff; }
.ladder li.rarest .r-bar i {
  background: repeating-linear-gradient(90deg, #ffffff 0 4px, var(--amber) 4px 6px);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 0;
}

.stat-grid div {
  background: #170e08;
  border: 2px solid var(--line-soft);
  padding: 8px 10px;
}

.stat-grid dt {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #8b7358;
}

.stat-grid dd {
  margin: 2px 0 0;
  font-size: 20px;
  color: var(--amber);
}

/* ---------- utility ---------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
