:root {
  --depth: 0; /* 0 = surface, 1 = trench floor (set from JS) */
  --ink: #eaf6ff;
  --muted: #9fc3da;
  --accent: #5ee7ff;
  --danger: #ff6b8a;
  --card: rgba(6, 22, 38, 0.72);
  --line: rgba(160, 220, 255, 0.18);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: #020812;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }

/* Ocean that darkens as you dive */
#bg {
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(120, 210, 255, calc(0.35 * (1 - var(--depth)))), transparent 70%),
    linear-gradient(180deg,
      hsl(calc(200 + 30 * var(--depth)), 70%, calc(26% - 22% * var(--depth))) 0%,
      hsl(calc(210 + 40 * var(--depth)), 75%, calc(12% - 10% * var(--depth))) 100%);
  transition: background 1.2s ease;
}
#bg::after { /* drifting particles */
  content: ""; position: absolute; inset: 0; opacity: .35;
  background-image:
    radial-gradient(1.5px 1.5px at 20% 30%, #cfefff 50%, transparent 51%),
    radial-gradient(1px 1px at 70% 60%, #cfefff 50%, transparent 51%),
    radial-gradient(1px 1px at 40% 80%, #cfefff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 85% 20%, #cfefff 50%, transparent 51%);
  background-size: 300px 300px;
  animation: drift 40s linear infinite;
}
@keyframes drift { to { background-position: 0 -600px; } }

/* Header */
.top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: max(14px, env(safe-area-inset-top)) 20px 14px;
}
.brand { font-weight: 800; letter-spacing: .18em; font-size: 14px; }
.brand span { color: var(--accent); }
#pips { list-style: none; display: flex; gap: 8px; margin: 0; padding: 0; }
#pips li {
  width: 12px; height: 12px; border-radius: 50%;
  border: 1.5px solid var(--line); background: transparent; transition: all .3s;
}
#pips li.current { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(94, 231, 255, .18); }
.depth { justify-self: end; font-family: var(--mono); text-align: right; line-height: 1.1; }
.depth b { font-size: 20px; }
.depth span { color: var(--muted); margin-left: 2px; }
.depth small { display: block; font-family: var(--sans); color: var(--muted); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; }

/* Screens */
#stage { position: relative; height: 100dvh; }
.screen { position: absolute; inset: 0; }
.card-screen { display: grid; place-items: center; padding: 80px 16px 24px; overflow-y: auto; }

.card {
  width: min(520px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 32px 28px;
  text-align: center;
  backdrop-filter: blur(10px);
  animation: rise .35s ease both;
}
.card.wide { width: min(620px, 100%); }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; }
.title { margin: 0 0 16px; font-size: clamp(30px, 6vw, 44px); line-height: 1.05; }
.rules { list-style: none; padding: 0; margin: 0 0 24px; display: flex; justify-content: center; gap: 18px; flex-wrap: wrap; color: var(--muted); }
.rules b { color: var(--ink); }
.hint { color: var(--muted); font-size: 13px; margin: 16px 0 0; }
.error { color: var(--danger); font-size: 14px; }
.detail { color: var(--muted); margin: 0 0 20px; }

button { font: inherit; cursor: pointer; }
.primary {
  background: var(--accent); color: #032033; border: 0; border-radius: 12px;
  padding: 14px 28px; font-weight: 800; font-size: 16px; letter-spacing: .02em;
  transition: transform .1s, filter .2s;
}
.primary:hover { filter: brightness(1.08); }
.primary:active { transform: scale(.97); }
.primary:disabled { opacity: .4; cursor: default; }
.ghost {
  background: transparent; color: var(--muted); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 14px; font-size: 14px;
}
.ghost:hover { color: var(--ink); border-color: var(--muted); }

/* Play screen: the input sits at the exact centre of the viewport */
#play .center {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(640px, calc(100vw - 32px));
  display: flex; align-items: center;
  background: rgba(2, 14, 26, .7);
  border: 2px solid var(--line); border-radius: 18px;
  transition: border-color .2s, box-shadow .2s;
}
#play .center:focus-within { border-color: var(--accent); box-shadow: 0 0 0 6px rgba(94, 231, 255, .12); }
#answer {
  flex: 1; min-width: 0; height: 76px; padding: 0 22px;
  background: transparent; border: 0; outline: 0; color: var(--ink);
  font: 600 clamp(22px, 4.5vw, 30px) var(--sans);
}
#answer::placeholder { color: rgba(159, 195, 218, .45); }
#play .center button {
  width: 56px; height: 56px; margin-right: 10px; border-radius: 12px; border: 0;
  background: rgba(94, 231, 255, .15); color: var(--accent); font-size: 22px;
}
#play .center.wrong { animation: shake .35s; border-color: var(--danger); }
@keyframes shake {
  20%, 60% { transform: translate(calc(-50% - 8px), -50%); }
  40%, 80% { transform: translate(calc(-50% + 8px), -50%); }
}

#play .above {
  position: absolute; left: 50%; bottom: calc(50% + 58px); transform: translateX(-50%);
  width: min(680px, calc(100vw - 32px)); text-align: center;
}
.round { margin: 0 0 10px; color: var(--muted); font-size: 13px; letter-spacing: .12em; text-transform: uppercase; }
.round b { color: var(--ink); }
#prompt { margin: 0; font-size: clamp(20px, 4vw, 30px); line-height: 1.25; font-weight: 700; text-wrap: balance; }

#play .below {
  position: absolute; left: 50%; top: calc(50% + 54px); transform: translateX(-50%);
  width: min(640px, calc(100vw - 32px));
}
.timer { height: 6px; border-radius: 6px; background: rgba(255, 255, 255, .08); overflow: hidden; }
#bar { height: 100%; width: 100%; background: var(--accent); transform-origin: left; border-radius: 6px; }
#bar.low { background: var(--danger); }
.row { display: flex; align-items: center; gap: 12px; margin-top: 12px; min-height: 36px; }
#secs { font-family: var(--mono); font-size: 18px; font-weight: 700; width: 2.2ch; }
#secs.low { color: var(--danger); }
#msg { flex: 1; color: var(--danger); font-size: 15px; }

/* Feedback */
#fbAnswer { margin: 0 0 6px; font-size: clamp(26px, 5vw, 36px); }
.popular { text-align: left; border-top: 1px solid var(--line); padding-top: 16px; margin-bottom: 22px; }
.label { margin: 0 0 8px; color: var(--muted); font-size: 12px; letter-spacing: .14em; text-transform: uppercase; }
#fbTop { margin: 0; padding-left: 22px; color: var(--muted); columns: 2; column-gap: 24px; }
#fbTop li { margin: 3px 0; break-inside: avoid; }
#fbTop li.mine { color: var(--ink); font-weight: 700; }
#fbTop span { font-family: var(--mono); font-size: 12px; opacity: .7; margin-left: 4px; }

/* Krillion tiers */
.t-plankton  { --tier: #9fb6c6; }
.t-tooclever { --tier: #ffb648; }
.t-schooler  { --tier: #4de3ff; }
.t-rare      { --tier: #ff5252; }
.t-deepcut   { --tier: #9d7bff; }
.t-krillion  { --tier: #ff5d8f; }
.t-miss      { --tier: #4a5d6c; }
.quip { margin: 0 0 6px; font-style: italic; color: var(--ink); opacity: .85; }
.better { margin: -8px 0 20px; color: var(--accent); font-weight: 700; }
#answer[readonly] { opacity: .5; }
#msg.info { color: var(--accent); }
#fbRarity { color: var(--tier); }
#pips li[class*="t-"] { background: var(--tier); border-color: var(--tier); }

/* Results */
#resList { list-style: none; margin: 0 0 24px; padding: 0; text-align: left; }
#resList li {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
  padding: 12px 0; border-top: 1px solid var(--line);
}
#resList .q { grid-column: 1 / -1; color: var(--muted); font-size: 13px; }
#resList .a { font-weight: 700; }
#resList .a i { font-style: normal; color: var(--tier); font-weight: 600; font-size: 13px; margin-left: 8px; }
#resList .p { font-family: var(--mono); color: var(--tier); }
.btns { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

@media (max-width: 520px) {
  .top { grid-template-columns: auto 1fr; row-gap: 10px; }
  #pips { grid-row: 2; grid-column: 1 / -1; justify-content: center; }
  .brand { font-size: 12px; }
  #fbTop { columns: 1; }
  .card { padding: 26px 20px; }
}
