:root {
  --sea-0: #07141e;
  --sea-1: #0c2233;
  --sea-2: #16344a;
  --foam: #f6f1e6;
  --foam-2: #fffdf8;
  --ink: #14202b;
  --ink-soft: #5c6b76;
  --line: #e4d9c8;
  --crest: #1f8f78;
  --crest-soft: #d7f4ec;
  --brass: #b6832f;
  --brass-2: #e4c27a;
  --brass-soft: #fff1d4;
  --coral: #c24b46;
  --coral-soft: #ffe4df;
  --shadow: 0 22px 50px rgba(0, 0, 0, 0.28);
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Outfit", "Avenir Next", "Segoe UI", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  font-family: var(--sans);
  font-weight: 400;
  color: var(--foam);
  background:
    radial-gradient(900px 480px at 50% -10%, #1c4d6b 0%, transparent 58%),
    linear-gradient(180deg, #0e2940 0%, var(--sea-0) 42%, #061018 100%);
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--brass-2); outline-offset: 2px; }

.sea {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 200px;
  z-index: 0;
  pointer-events: none;
}
.sea svg { width: 100%; height: 100%; display: block; }
@media (prefers-reduced-motion: no-preference) {
  .sea svg { animation: tide 36s linear infinite; }
}
@keyframes tide {
  from { transform: translateX(0); }
  to { transform: translateX(-240px); }
}

.topbar, .layout, .footnote { position: relative; z-index: 1; }

.topbar {
  max-width: 1120px;
  margin: 0 auto;
  padding: 22px 20px 8px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.kicker {
  margin: 0 0 2px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--brass-2);
}
.brand h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 560;
  font-size: clamp(40px, 5vw, 58px);
  line-height: 0.86;
  letter-spacing: -0.03em;
  font-variation-settings: "SOFT" 30, "WONK" 1;
}
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; align-items: center; }
.seg { display: flex; border: 1px solid rgba(246, 241, 230, 0.22); border-radius: 999px; overflow: hidden; }
.toolbar button, .seg button {
  background: transparent;
  border: 1px solid rgba(246, 241, 230, 0.22);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 14px;
  color: var(--foam);
}
.seg button { border: 0; border-radius: 0; }
.toolbar button[aria-pressed="true"],
.seg button[aria-selected="true"] {
  background: var(--foam);
  color: var(--ink);
}
.toolbar button:disabled { opacity: 0.45; cursor: default; }

.layout {
  max-width: 1120px;
  margin: 8px auto 28px;
  padding: 0 20px;
  display: grid;
  grid-template-columns: 280px minmax(0, 460px) 270px;
  gap: 22px;
  align-items: start;
  justify-content: center;
}

.poster {
  background:
    radial-gradient(120% 70% at 50% 0%, rgba(228, 194, 122, 0.16), transparent 52%),
    linear-gradient(180deg, #14344a 0%, #0c2233 100%);
  border: 1px solid rgba(228, 194, 122, 0.45);
  border-radius: 18px;
  padding: 28px 22px 20px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.poster::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid rgba(228, 194, 122, 0.28);
  border-radius: 12px;
  pointer-events: none;
}
.poster-kicker, .poster-meta, .poster-rule {
  position: relative;
  text-align: center;
}
.poster-kicker {
  margin: 6px 0 8px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--brass-2);
}
.poster h2 {
  position: relative;
  margin: 0;
  text-align: center;
  font-family: var(--serif);
  font-weight: 560;
  font-size: 62px;
  line-height: 0.84;
  letter-spacing: -0.035em;
}
.poster h2 em { font-style: italic; font-weight: 560; }
.poster-wave { display: block; width: 100%; height: 54px; margin: 8px 0 4px; }
.poster-label {
  position: relative;
  margin: 8px 0 8px;
  text-align: center;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--brass-2);
}
.poster-tiles, .tiles {
  display: flex;
  justify-content: center;
  gap: 8px;
}
.poster .tile {
  width: 48px;
  height: 56px;
  border-radius: 10px;
  background: rgba(246, 241, 230, 0.08);
  border: 1px solid rgba(246, 241, 230, 0.2);
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 28px;
  letter-spacing: 0;
  color: var(--foam);
}
.poster-rule {
  margin: 14px 0 0;
  color: #d5dde3;
  font-size: 15px;
}
.poster-meta {
  margin: 16px 0 0;
  color: var(--brass-2);
  font-size: 14px;
}
.poster .text-btn, .text-btn {
  position: relative;
  display: block;
  margin: 14px auto 0;
  background: transparent;
  border: 1px solid rgba(228, 194, 122, 0.45);
  color: var(--brass-2);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.board {
  background: linear-gradient(180deg, var(--foam-2), var(--foam));
  color: var(--ink);
  border-radius: 22px;
  padding: 18px 16px 14px;
  box-shadow: var(--shadow);
}
.board-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
}
#puzzle-label { margin: 0; font-size: 14px; letter-spacing: 0.04em; color: var(--ink-soft); }
.hard-flag {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brass);
}
.banner {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #e7f3f6;
  color: #18485a;
  font-size: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.banner button {
  border: 0;
  background: #18485a;
  color: white;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
}

#ladder {
  list-style: none;
  margin: 0;
  padding: 2px 0;
  max-height: 320px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.rung {
  display: grid;
  grid-template-columns: 52px auto 42px;
  justify-content: center;
  align-items: center;
  gap: 8px;
}
.rung-no {
  text-align: right;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.tile {
  width: 58px;
  height: 64px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: white;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 32px;
  line-height: 1;
  color: var(--ink);
  text-transform: uppercase;
  padding: 0;
}
button.tile { cursor: pointer; }
.tile.match { background: var(--crest-soft); color: var(--crest); border-color: #b7e6da; }
.tile.diff { box-shadow: inset 0 -3px 0 var(--brass-2); }
.tile.selected { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink); }
.tile.match.selected { box-shadow: 0 0 0 2px var(--crest); }
.move-badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 14px;
  background: var(--line);
  color: var(--ink-soft);
}
.move-badge.closer { background: var(--crest-soft); color: var(--crest); }
.move-badge.same { background: var(--brass-soft); color: var(--brass); }
.move-badge.farther { background: var(--coral-soft); color: var(--coral); }
.move-badge.hint { outline: 1px dashed var(--brass); }
.rung.shake { animation: shake 0.36s ease; }
@keyframes shake {
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

.meter {
  margin: 12px 8px 4px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}
.meter svg { width: 100%; height: 48px; display: block; }
.readout { text-align: right; min-width: 92px; }
.readout b {
  display: block;
  font-family: var(--serif);
  font-size: 34px;
  line-height: 0.9;
  font-weight: 560;
  color: var(--crest);
}
.readout span { font-size: 12px; color: var(--ink-soft); }

.horizon {
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px dashed #d9cdb8;
  display: grid;
  grid-template-columns: 52px auto 42px;
  justify-content: center;
  align-items: center;
  gap: 8px;
}
.horizon .tile {
  background: #123246;
  color: #d5efe8;
  border-color: #123246;
}
.horizon .tile.on { background: var(--crest); color: white; border-color: var(--crest); }
.horizon-label {
  text-align: right;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--crest);
}

.message {
  min-height: 1.3em;
  margin: 10px 0 0;
  text-align: center;
  color: var(--coral);
  font-size: 15px;
}
.message.calm { color: var(--ink-soft); }

.reveal {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #eef3f4;
}
.reveal h3 { margin: 0 0 8px; font-size: 14px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.reveal ol { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; }
.reveal li { font-family: var(--serif); letter-spacing: 0.18em; text-transform: uppercase; font-size: 16px; }

.result {
  margin-top: 12px;
  display: grid;
  justify-items: center;
  gap: 6px;
  text-align: center;
}
.stamp {
  width: 132px;
  height: 132px;
  border-radius: 50%;
  border: 2px dashed currentColor;
  display: grid;
  place-items: center;
  align-content: center;
  transform: rotate(-8deg);
  margin: 6px 0;
}
.stamp strong {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 560;
  line-height: 1;
  max-width: 9ch;
}
.stamp span { font-size: 11px; letter-spacing: 0.04em; margin-top: 4px; }
.stamp[data-rating="phase"] { color: var(--crest); }
.stamp[data-rating="guided"] { color: #1d6e86; }
.stamp[data-rating="harmonic"] { color: var(--brass); }
.stamp[data-rating="overtone"] { color: #8d5c12; }
.stamp[data-rating="cross"] { color: #c26a2d; }
.stamp[data-rating="fetch"] { color: var(--coral); }
.stamp[data-rating="flat"] { color: #6d7c88; }
.stamp[data-rating="resonance"] { color: #0e6b8a; }
.result-line { margin: 0; font-size: 16px; }
.countdown { margin: 0; color: var(--ink-soft); font-size: 14px; }
.result-actions, .dialog-actions, .actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

.actions { margin-top: 10px; }
.btn, .actions button {
  border: 0;
  background: var(--ink);
  color: var(--foam);
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 14px;
}
.btn.ghost, .actions button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn.danger { background: var(--coral); color: white; }
.actions button:disabled { opacity: 0.4; cursor: default; }

.keyboard { margin-top: 12px; display: grid; gap: 6px; user-select: none; }
.keyrow { display: grid; gap: 6px; }
.keyrow.top { grid-template-columns: repeat(10, 1fr); }
.keyrow.mid { grid-template-columns: repeat(9, 1fr); padding: 0 5%; }
.keyrow.bot { grid-template-columns: 1.5fr repeat(7, 1fr) 1.5fr; }
.key {
  height: 46px;
  border: 0;
  border-radius: 8px;
  background: #e7dfd0;
  color: var(--ink);
  font-weight: 650;
  font-size: 15px;
}
.key:hover { background: #efe7d8; }
.key:active { transform: translateY(1px); }
.key.wide { font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
.keyboard.off { opacity: 0.38; }
.keyboard.off .key { pointer-events: none; }

.log {
  background: rgba(8, 24, 36, 0.72);
  border: 1px solid rgba(246, 241, 230, 0.1);
  border-radius: 18px;
  padding: 16px;
  backdrop-filter: blur(8px);
}
.log h2 {
  margin: 0 0 10px;
  font-family: var(--serif);
  font-weight: 560;
  font-size: 28px;
}
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat {
  background: rgba(246, 241, 230, 0.05);
  border-radius: 12px;
  padding: 8px 10px;
}
.stat b { display: block; font-family: var(--serif); font-size: 26px; font-weight: 560; line-height: 1; }
.stat span { font-size: 12px; color: #b7c4cc; letter-spacing: 0.04em; }
.dist { margin: 14px 0; display: grid; gap: 4px; }
.dist-row { display: grid; grid-template-columns: 28px 1fr 24px; gap: 6px; align-items: center; font-size: 12px; color: #c5d0d6; }
.bar { height: 8px; background: rgba(246, 241, 230, 0.08); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--brass-2); border-radius: 99px; }
.yesterday { margin-top: 8px; }
.yesterday summary { cursor: pointer; color: var(--brass-2); }
.yesterday ol { margin: 8px 0 0; padding: 0; list-style: none; }
.yesterday li { font-family: var(--serif); letter-spacing: 0.14em; text-transform: uppercase; font-size: 15px; }
.badge-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 12px; }
.medal {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid rgba(228, 194, 122, 0.35);
  background: radial-gradient(circle at 40% 35%, #24506a, #102838);
  color: var(--brass-2);
  padding: 0;
  display: grid;
  place-items: center;
}
.medal svg { width: 62%; height: 62%; }
.medal.locked { filter: grayscale(1); opacity: 0.38; }
.medal-caption { margin: 8px 0 0; font-size: 12px; color: #b7c4cc; }

.footnote {
  max-width: 1120px;
  margin: 0 auto 28px;
  padding: 0 20px 12px;
  color: #93a6b2;
  font-size: 13px;
}

.toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: #102838;
  color: var(--foam);
  border: 1px solid rgba(228, 194, 122, 0.55);
  border-radius: 999px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
  max-width: min(92vw, 420px);
  text-align: center;
}

dialog {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--ink);
  max-width: min(640px, calc(100vw - 24px));
}
dialog::backdrop { background: rgba(5, 12, 18, 0.72); }
#archive-dialog { max-width: min(920px, calc(100vw - 24px)); }
.dialog-card {
  background: var(--foam);
  color: var(--ink);
  border-radius: 18px;
  padding: 20px;
  max-height: min(82vh, 860px);
  overflow: auto;
}
.dialog-card h2, .dialog-card h3 { font-family: var(--serif); font-weight: 560; margin: 0 0 8px; }
.dialog-card p { line-height: 1.45; }
.dialog-card ol.rules { margin: 8px 0 12px; padding-left: 18px; }
.ratings { width: 100%; border-collapse: collapse; font-size: 14px; margin: 8px 0 12px; }
.ratings th, .ratings td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.help-example { display: flex; gap: 14px; align-items: center; justify-content: center; margin: 10px 0; flex-wrap: wrap; }
.help-example .tiles { gap: 4px; }
.help-example .tile { width: 36px; height: 42px; font-size: 20px; }
.arrow { color: var(--ink-soft); }

.archive { display: grid; grid-template-columns: 1.3fr 0.8fr; gap: 16px; }
.months { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.month h3 { margin: 0 0 6px; font-size: 14px; letter-spacing: 0.08em; text-transform: uppercase; }
.dow, .days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.dow span { font-size: 10px; color: var(--ink-soft); text-align: center; }
.day {
  aspect-ratio: 1;
  border: 0;
  border-radius: 6px;
  background: #ece4d6;
  color: var(--ink);
  font-size: 11px;
  padding: 0;
}
.day.future { opacity: 0.35; }
.day.today { box-shadow: inset 0 0 0 2px var(--ink); }
.day.par { background: var(--crest); color: white; }
.day.plus1 { background: #e4c27a; }
.day.plus2 { background: #e0a15a; }
.day.plus3 { background: #d98060; color: white; }
.day.gave { background: transparent; box-shadow: inset 0 0 0 1.5px var(--coral); color: var(--coral); }
.day:disabled { cursor: default; }
.legend { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 0; font-size: 12px; color: var(--ink-soft); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.archive-detail .path { font-family: var(--serif); letter-spacing: 0.12em; text-transform: uppercase; margin: 4px 0; }

.badge-list { display: grid; gap: 10px; }
.badge-row { display: grid; grid-template-columns: 52px 1fr; gap: 10px; align-items: center; }
.badge-row .medal { width: 52px; }
.badge-row p { margin: 2px 0 0; color: var(--ink-soft); font-size: 14px; }
.badge-row.locked strong { color: var(--ink-soft); }

.poster-hold canvas { width: 100%; height: auto; border-radius: 12px; display: block; }
.poster-card { width: min(420px, 100%); }

@media (min-width: 1041px) {
  .poster, .log { position: sticky; top: 16px; }
}
@media (max-width: 1040px) {
  .layout { grid-template-columns: minmax(0, 520px); }
  .board { order: 1; }
  .poster { order: 2; display: grid; grid-template-columns: 1fr 1fr; column-gap: 12px; align-items: center; }
  .log { order: 3; }
  .poster h2 { font-size: 52px; }
  .archive { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .poster { display: block; }
  .tile { width: 52px; height: 58px; font-size: 28px; }
  .months { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; }
  #ladder { max-height: 240px; }
}
@media (prefers-reduced-motion: reduce) {
  .sea svg, .rung.shake { animation: none; }
}
