:root {
  /* Ink colors are set per match by game.js; these are fallbacks. */
  --me: #343bc4;
  --me-light: #9a9de2;
  --me-deep: #2a2f9d;
  --me-dark: #1a1e62;
  --me-text: #9a9de2;
  --me-on: #ffffff;
  --cpu: #df6624;
  --cpu-light: #efb392;
  --cpu-deep: #b2521d;
  --cpu-dark: #703312;
  --cpu-text: #e58450;
  --cpu-on: #ffffff;
  --bg: #1b1236;
  --bg-2: #261a4a;
  --ink-text: #ffffff;
  --muted: #b9b0d6;
  --floor: #e9e5f0;
  --navy: #120b28;
  --font-logo: "Bowlby One", "Dela Gothic One", system-ui, sans-serif;
  --font-head: "Dela Gothic One", "M PLUS Rounded 1c", system-ui, sans-serif;
  --font-body: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink-text);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 122, 26, 0.10), transparent 45%),
    radial-gradient(circle at 85% 90%, rgba(61, 92, 255, 0.16), transparent 50%),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.025) 0 14px, transparent 14px 28px),
    var(--bg);
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
button:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
/* Mice get a little lift on hover (touch screens keep their plain look). */
@media (hover: hover) and (pointer: fine) {
  .btn-big:hover, .btn-mid:hover { filter: brightness(1.08); }
  .btn-mid.ghost:hover { background-color: #41366a; }
  .btn-icon:hover, .btn-text:hover { background-color: rgba(255, 255, 255, 0.16); }
  .levels button:not([aria-checked="true"]):hover { color: #fff; }
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.screen { position: absolute; inset: 0; }

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

.btn-big {
  font-family: var(--font-head);
  font-size: clamp(20px, 6vmin, 30px);
  letter-spacing: 0.06em;
  padding: 0.5em 2.2em 0.55em;
  border-radius: 999px;
  background: var(--me);
  color: var(--me-on);
  box-shadow: 0 6px 0 var(--me-deep), 0 10px 22px rgba(0, 0, 0, 0.35);
  transform: rotate(-2deg);
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn-big:active { transform: rotate(-2deg) translateY(4px); box-shadow: 0 2px 0 var(--me-deep), 0 4px 10px rgba(0, 0, 0, 0.3); }

.btn-mid {
  font-family: var(--font-head);
  font-size: clamp(14px, 4.2vmin, 18px);
  padding: 0.55em 1.4em;
  border-radius: 999px;
  background: var(--cpu);
  color: var(--cpu-on);
  box-shadow: 0 4px 0 var(--cpu-dark);
  transition: transform 0.08s, box-shadow 0.08s, background 0.15s;
}
.btn-mid:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--cpu-dark); }
/* Solid, so the label stays readable over any ink splat behind it. */
.btn-mid.ghost { color: #fff; background: #352c55; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35); }
.btn-mid.ghost:active { box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35); }
.btn-mid.armed, .btn-icon.armed { color: #fff; background: #ff3b5c; box-shadow: 0 4px 0 #9a1030; }
.btn-mid:disabled { opacity: 0.4; pointer-events: none; }

.btn-text {
  font-family: var(--font-head);
  font-size: 14px;
  color: var(--muted);
  padding: 10px 16px;
  border-radius: 999px;
}
.btn-text:active { background: rgba(255, 255, 255, 0.08); }
.btn-text.nudge { color: #fff; animation: nudge 2.6s 1.2s ease-in-out infinite; }
@keyframes nudge {
  0%, 70%, 100% { transform: rotate(0); }
  76% { transform: rotate(-5deg) scale(1.06); }
  82% { transform: rotate(4deg) scale(1.06); }
  88% { transform: rotate(-2deg); }
}

.btn-icon {
  width: 42px;
  height: 42px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.10);
}
.btn-icon svg { width: 24px; height: 24px; }
.btn-icon:active { background: rgba(255, 255, 255, 0.2); }
#mute .cross { display: none; }
#mute[aria-pressed="true"] .cross { display: inline; }
#mute[aria-pressed="true"] .wave { display: none; }

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

#title { display: grid; place-items: center; }
.title-splats { position: absolute; inset: 0; width: 100%; height: 100%; }
.title-splats .sp { transform-box: fill-box; transform-origin: center; animation: splat-in 0.5s cubic-bezier(.2, 1.6, .4, 1) both; }

/* Until the fonts are in, the title stays hidden with its entrance on hold, so the logo
   doesn't pop in with a stand-in font and jump on a slow connection. */
.fonts-wait .title-body { visibility: hidden; }
.fonts-wait .title-body * { animation-play-state: paused; }

.title-body {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(10px, 2.6vmin, 18px);
  padding: 16px;
  width: 100%;
  max-width: 460px;
}

.logo {
  position: relative;
  margin: 0 0 4px;
  display: flex;
  align-items: center;
  font-family: var(--font-logo);
  font-weight: 400;
  font-size: clamp(64px, 24vmin, 132px);
  line-height: 1;
  letter-spacing: -0.02em;
}
.logo-splat {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 128%;
  transform: translate(-50%, -50%);
  z-index: 0;
  overflow: visible;
}
.glyph, .logo-stone { position: relative; z-index: 1; animation: pop-in 0.55s cubic-bezier(.2, 1.7, .4, 1) both; }
.glyph {
  color: #fff;
  -webkit-text-stroke: 0.09em var(--navy);
  paint-order: stroke fill;
  text-shadow: 0.04em 0.07em 0 var(--navy);
}
.g1 { transform: rotate(-9deg) translateY(0.04em); animation-delay: 0.05s; }
.g2 { transform: rotate(6deg) translateY(-0.06em); font-size: 1.08em; animation-delay: 0.12s; }
.g3 { transform: rotate(-5deg) translateY(0.02em); animation-delay: 0.33s; }
.logo-stone {
  width: 0.62em;
  height: 0.62em;
  margin: 0.14em 0.015em 0;
  border-radius: 50%;
  box-shadow: 0 0 0 0.075em var(--navy), 0.04em 0.07em 0 0.075em var(--navy);
}
.logo-stone.me {
  background: radial-gradient(circle at 34% 30%, #fff 0 9%, var(--me-light) 10%, var(--me) 42%, var(--me-deep) 100%);
  transform: rotate(-8deg) translateY(0.05em);
  animation: pop-in 0.55s 0.19s cubic-bezier(.2, 1.7, .4, 1) both, hop 3.2s 1.4s ease-in-out infinite;
}
.logo-stone.cpu {
  background: radial-gradient(circle at 34% 30%, #fff 0 9%, var(--cpu-light) 10%, var(--cpu) 42%, var(--cpu-deep) 100%);
  transform: translateY(-0.08em) scale(0.94);
  animation: pop-in 0.55s 0.26s cubic-bezier(.2, 1.7, .4, 1) both, hop 3.2s 3s ease-in-out infinite;
}
/* The two stones take turns hopping, like moves. */
@keyframes hop {
  0%, 22%, 100% { translate: 0 0; }
  8% { translate: 0 -0.12em; }
  14% { translate: 0 0.01em; }
}

.tagline {
  margin: 0 0 6px;
  font-family: var(--font-head);
  font-size: clamp(15px, 4.4vmin, 20px);
  letter-spacing: 0.12em;
  padding: 0.25em 0.9em 0.3em;
  background: var(--navy);
  border-radius: 6px;
  transform: rotate(-2deg);
}

.levels {
  display: flex;
  gap: 6px;
  padding: 5px;
  border-radius: 999px;
  background: rgba(18, 11, 40, 0.75);
}
.levels button {
  font-family: var(--font-head);
  font-size: clamp(14px, 4vmin, 17px);
  padding: 0.5em clamp(0.7em, 3.5vw, 1.1em);
  white-space: nowrap;
  border-radius: 999px;
  color: var(--muted);
  transition: background 0.15s, color 0.15s, transform 0.15s;
}
.levels button[aria-checked="true"] {
  background: var(--cpu);
  color: var(--cpu-on);
  transform: rotate(-2deg) scale(1.04);
}

.level-note { margin: -4px 0 2px; font-size: 13px; color: var(--muted); }
.level-record { margin: -10px 0 0; font-family: var(--font-head); font-size: 12px; letter-spacing: 0.04em; color: var(--muted); opacity: 0.85; }
.level-record:empty { display: none; }
.next-level { color: var(--me-text); margin-top: -4px; }

/* ---------- game ---------- */

#game {
  display: flex;
  flex-direction: column;
  padding: 10px 16px 14px;
  gap: 8px;
}

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

.meter { flex: 1; min-width: 0; }
.meter-bar {
  position: relative;
  display: flex;
  height: 22px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--navy);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}
.meter-fill { height: 100%; transition: flex-grow 0.5s cubic-bezier(.3, 1.3, .5, 1); }
.meter-fill.me { flex: 1 1 0; background: linear-gradient(180deg, var(--me-light), var(--me) 55%, var(--me-deep)); }
.meter-fill.cpu { flex: 1 1 0; background: linear-gradient(180deg, var(--cpu-light), var(--cpu) 55%, var(--cpu-deep)); }
.meter-fill.komi { flex: 0 1 0; }
.meter-fill.komi.me, .tally .komi.me { background: repeating-linear-gradient(135deg, var(--me) 0 5px, var(--me-light) 5px 9px); }
.meter-fill.komi.cpu, .tally .komi.cpu { background: repeating-linear-gradient(135deg, var(--cpu) 0 5px, var(--cpu-light) 5px 9px); }
.meter-bar::after {
  /* gloss */
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  top: 3px;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.35);
}
.meter-nums {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-family: var(--font-head);
  font-size: 16px;
  line-height: 1;
}
.num { display: inline-flex; align-items: center; gap: 6px; }
.level-chip { align-self: center; font-family: var(--font-body); font-size: 11px; color: var(--muted); opacity: 0.8; white-space: nowrap; }
.screen.enter { animation: screen-in 0.32s cubic-bezier(.2, .9, .3, 1) both; }
@keyframes screen-in {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
}
.num small { font-family: var(--font-body); font-size: 11px; color: var(--muted); white-space: nowrap; }

.pip { display: inline-block; width: 12px; height: 12px; border-radius: 50%; flex: none; }
.pip.me { background: var(--me); }
.pip.cpu { background: var(--cpu); }

.status {
  min-height: 1.4em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  font-family: var(--font-head);
  font-size: clamp(15px, 4.4vmin, 19px);
  letter-spacing: 0.06em;
}
.status .dots i { display: inline-block; animation: dot 1s infinite; font-style: normal; }
.status .dots i:nth-child(2) { animation-delay: 0.15s; }
.status .dots i:nth-child(3) { animation-delay: 0.3s; }
.status { transition: opacity 0.15s; }
.toasting .status { opacity: 0; }
.status.me { color: var(--me-text); }
.status.cpu { color: var(--cpu-text); }
.status .dots { margin-left: -5px; }
.turn-stone { flex: none; width: 1.5em; height: 1.5em; overflow: visible; animation: pop-in 0.35s cubic-bezier(.2, 1.7, .4, 1) both; }
.status.cpu .turn-stone { animation: pop-in 0.35s cubic-bezier(.2, 1.7, .4, 1) both, bob 1.1s 0.35s ease-in-out infinite; }

/* Prisoner trays (アゲハマ) */
.trays { display: flex; justify-content: space-between; gap: 10px; }
.tray {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(18, 11, 40, 0.75);
  font-family: var(--font-head);
}
.tray b { font-size: 16px; font-weight: 400; min-width: 1ch; text-align: center; }
.tray.me b { color: var(--me-text); }
.tray.cpu b { color: var(--cpu-text); }
.tray-label { font-family: var(--font-body); font-size: 11px; color: var(--muted); white-space: nowrap; }
.tray-stones { display: flex; min-width: 14px; }
.tray-stones i { width: 14px; height: 14px; border-radius: 50%; margin-left: -4px; box-shadow: 0 0 0 2px var(--navy); }
.tray-stones i:first-child { margin-left: 0; }
/* a tray holds the other side's stones */
.tray.me .tray-stones i { background: radial-gradient(circle at 35% 30%, var(--cpu-light), var(--cpu) 60%, var(--cpu-deep)); }
.tray.cpu .tray-stones i { background: radial-gradient(circle at 35% 30%, var(--me-light), var(--me) 60%, var(--me-deep)); }
.tray.bump { animation: tray-bump 0.3s cubic-bezier(.2, 1.8, .4, 1); }
.flyer {
  position: fixed;
  z-index: 30;
  border-radius: 50%;
  pointer-events: none;
  box-shadow: 0 0 0 3px var(--navy);
  transition: transform 0.6s cubic-bezier(.5, -0.3, .6, 1);
}
.flyer.me { background: radial-gradient(circle at 35% 30%, var(--me-light), var(--me) 60%, var(--me-deep)); }
.flyer.cpu { background: radial-gradient(circle at 35% 30%, var(--cpu-light), var(--cpu) 60%, var(--cpu-deep)); }
@keyframes tray-bump {
  from { transform: scale(1.18); }
  to { transform: scale(1); }
}

.board-wrap {
  flex: 1;
  min-height: 0;
  container-type: size;
  display: grid;
  place-items: center;
}
.board-stack {
  position: relative;
  width: min(100cqw, 100cqh, 620px);
  height: min(100cqw, 100cqh, 620px);
}
#board-ink, #board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  will-change: transform;
}
#board-ink { pointer-events: none; }
#board-ink.plain .sat { display: none; }
#board:focus { outline: none; }
#board:focus-visible { outline: 3px solid #fff; outline-offset: 4px; border-radius: 6%; }
#board {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#board .stone { transform-box: fill-box; transform-origin: center; }
.stamp {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  padding: 0.12em 0.6em 0.18em;
  border-radius: 0.3em;
  background: var(--navy);
  color: #fff;
  font-family: var(--font-head);
  font-size: clamp(30px, 11vmin, 64px);
  letter-spacing: 0.12em;
  white-space: nowrap;
  box-shadow: 0 0.12em 0 rgba(0, 0, 0, 0.35);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) rotate(-6deg) scale(0.4);
}
.stamp.show { animation: stamp 1.5s cubic-bezier(.2, 1.4, .4, 1) both; }
.stamp.cpu-pass { background: var(--cpu); color: var(--cpu-on); font-size: clamp(22px, 7vmin, 40px); letter-spacing: 0.04em; }
.stamp.cpu-pass.show { animation-duration: 1.4s; }
@keyframes stamp {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(-6deg) scale(1.8); }
  14% { opacity: 1; transform: translate(-50%, -50%) rotate(-6deg) scale(0.92); }
  22% { transform: translate(-50%, -50%) rotate(-6deg) scale(1); }
  78% { opacity: 1; transform: translate(-50%, -50%) rotate(-6deg) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) rotate(-6deg) scale(1.06); }
}
#board .stone.drop { animation: stone-drop 0.42s cubic-bezier(.2, 1.4, .4, 1) both; }
#board .stone.pop { animation: stone-pop 0.32s ease-in forwards; }

#board .ghost { opacity: 0.45; pointer-events: none; }

.controls { position: relative; display: flex; justify-content: center; gap: 12px; padding-bottom: 2px; }
/* With the undo and hint buttons too, the four share the row. */
.controls:has(.help:not([hidden])) { gap: 8px; }
.controls:has(.help:not([hidden])) .btn-mid { flex: 1 1 0; min-width: 0; max-width: 8em; padding-left: 0.4em; padding-right: 0.4em; white-space: nowrap; }
#hint.busy { animation: hint-busy 0.8s ease-in-out infinite alternate; }
@keyframes hint-busy { to { filter: brightness(1.5); } }
#board .hint-mark { transform-box: fill-box; transform-origin: center; animation: hint-glow 1.1s ease-in-out infinite alternate; }
@keyframes hint-glow { from { transform: scale(0.82); opacity: 0.55; } to { transform: scale(1.08); opacity: 1; } }
/* While the end is counted, the buttons give their place to a hint (same height, so the
   board doesn't move). */
.skip-hint { display: none; position: absolute; inset: 0; margin: 0; place-items: center; text-align: center; font-size: 13px; color: var(--muted); }
#game.judging .controls .btn-mid { visibility: hidden; }
#game.judging .skip-hint { display: grid; animation: fade-in 0.4s 1.2s both; }

/* ---------- overlays ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 10;
}
/* Result: shown around the board on the game screen */
.result-splat { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }
.result-splat path { transform-box: fill-box; transform-origin: center; animation: splat-in 0.45s cubic-bezier(.2, 1.5, .4, 1) both; }
#game > :not(.result-splat) { position: relative; z-index: 1; }
#game:not(.over) .result-splat,
#game:not(.over) .result-head,
#game:not(.over) .result-foot { display: none; }
#game.over .hud,
#game.over .status,
#game.over .controls { display: none; }

.result-head { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.result-word {
  margin: 0;
  font-family: var(--font-logo);
  font-size: clamp(44px, 12vmin, 84px);
  line-height: 1;
  color: #fff;
  -webkit-text-stroke: 0.08em var(--navy);
  paint-order: stroke fill;
  text-shadow: 0.04em 0.07em 0 var(--navy);
  transform: rotate(-5deg);
  animation: pop-in 0.6s 0.1s cubic-bezier(.2, 1.7, .4, 1) both;
}
.result-reason {
  margin: 0;
  font-family: var(--font-head);
  font-size: 15px;
  background: var(--navy);
  padding: 0.2em 0.8em;
  border-radius: 6px;
}
.result-reason:empty { display: none; }

.result-foot { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.tally { width: min(100%, 440px); }
.tally-bar {
  position: relative;
  display: flex;
  height: 22px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--navy);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}
.tally-bar i { flex: 0 1 0; height: 100%; transition: flex-grow 0.9s cubic-bezier(.3, 1.2, .5, 1); }
.tally-bar .me { background: var(--me); }
.tally-bar .cpu { background: var(--cpu); }
.tally .age.me { background: radial-gradient(circle, rgba(255,255,255,0.6) 2.5px, transparent 3px) 0 0 / 9px 9px, var(--me); }
.tally .age.cpu { background: radial-gradient(circle, rgba(255,255,255,0.6) 2.5px, transparent 3px) 0 0 / 9px 9px, var(--cpu); }
.tally-bar::after {
  /* the halfway line: whoever crosses it wins */
  content: "";
  position: absolute;
  left: calc(50% - 2px);
  top: 0;
  bottom: 0;
  width: 4px;
  background: #fff;
  box-shadow: 0 0 0 2px var(--navy);
}
.tally-caption { position: relative; height: 1.3em; margin-top: 4px; font-family: var(--font-head); font-size: 13px; line-height: 1.2; }
.tally-caption span { position: absolute; top: 0; left: 0; white-space: nowrap; }
.tally-caption span:empty { display: none; }
.tally-caption .k { color: #fff; font-size: 12px; }
.result-bars { width: min(100%, 440px); display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.rbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 8px 14px;
  border-radius: 14px;
  background: var(--navy);
  font-family: var(--font-head);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
  animation: slide-in 0.4s cubic-bezier(.2, 1.4, .4, 1) both;
}
.rbar span { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; flex: none; white-space: nowrap; }
.rbar span::before { content: ""; width: 12px; height: 12px; border-radius: 50%; }
.rbar b { font-size: 26px; font-weight: 400; }
.rbar { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "label total" "note note"; align-items: center; align-content: start; row-gap: 2px; }
.rbar span { grid-area: label; }
.rbar b { grid-area: total; }
.rbar small { grid-area: note; min-width: 0; text-align: left; font-family: var(--font-body); font-size: 11px; color: var(--muted); word-break: keep-all; }
.rbar.me { animation-delay: 0.2s; }
.rbar.me b { color: var(--me-text); }
.rbar.me span::before { background: var(--me); }
.rbar.cpu { animation-delay: 0.3s; }
.rbar.cpu b { color: var(--cpu-text); }
.rbar.cpu span::before { background: var(--cpu); }
.result-actions { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; }
.result-actions .btn-big { font-size: clamp(17px, 5vmin, 24px); padding: 0.45em 1.6em 0.5em; }

/* End-of-game cleanup on the board */
#board-ink .dry { opacity: 0; transition: opacity 0.6s; }
#board .dame-mark { animation: fade-in 0.35s both; }
#board .face { transform-box: fill-box; transform-origin: center; }
#board .face.changed { animation: face-pop 0.28s cubic-bezier(.2, 1.8, .4, 1); }
#board .stone.panic:not(.drop):not(.pop) { animation: panic 2.2s ease-in-out var(--sync, 0s) infinite; }
/* A tapped stone squishes (also one that is shivering in atari). */
#board .stone.poke:not(.drop):not(.pop) { animation: poke 0.34s ease-out; }
@keyframes poke {
  30% { transform: scale(1.1, 0.88); }
  65% { transform: scale(0.95, 1.06); }
}
#board .stone.dying { animation: shiver 0.45s ease-in-out 2; }
#board .dead-cover { opacity: 0.72; animation: fade-in 0.4s both; }
#board .atari { transform-box: fill-box; transform-origin: center; animation: atari 2.2s ease-in-out var(--sync, 0s) infinite; }
#board .ko-mark { animation: fade-in 0.3s both; }
#board .ripple { transform-box: fill-box; transform-origin: center; animation: ripple 0.65s ease-out both; }
#board .stone.cheer { animation: cheer 0.7s var(--d, 0s) cubic-bezier(.3, 1.5, .5, 1) 2 both; }
@keyframes cheer {
  0%, 100% { transform: none; }
  30% { transform: translateY(-14%) scale(0.94, 1.08); }
  55% { transform: translateY(0) scale(1.1, 0.88); }
  75% { transform: scale(0.97, 1.03); }
}
#board .nope { transform-box: fill-box; transform-origin: center; animation: nope 0.6s ease-out both; }
@keyframes ripple {
  from { transform: scale(0.8); opacity: 0.9; }
  to { transform: scale(1.7); opacity: 0; }
}
@keyframes nope {
  0% { transform: scale(0.5); opacity: 0; }
  15% { transform: scale(1.1); opacity: 1; }
  30%, 60% { transform: translateX(-8%) rotate(-8deg); }
  45% { transform: translateX(8%) rotate(8deg); }
  100% { transform: none; opacity: 0; }
}
#board .eye-mark { transform-box: fill-box; transform-origin: center; animation: pop-in 0.4s cubic-bezier(.2, 1.7, .4, 1) both; }
#board .eye-mark.lone path { stroke: #ff5a7a; }
#board .stone.pale { pointer-events: none; }
#board .fade { opacity: 0; transition: opacity 0.35s; }
#board .seki-mark { transform-box: fill-box; transform-origin: center; animation: pop-in 0.35s cubic-bezier(.2, 1.7, .4, 1) both; }

.sheet { background: rgba(10, 6, 24, 0.72); }
.sheet-card {
  width: min(100%, 400px);
  max-height: 100%;
  overflow: auto;
  background: var(--bg-2);
  border-radius: 22px;
  padding: 22px 22px 20px;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.sheet-card h2 { margin: 0 0 10px; font-family: var(--font-head); font-weight: 400; font-size: 22px; }
/* How to play: one step at a time, side by side, swiped or stepped with the arrows. */
.sheet-card { overflow: hidden; }
.sheet-card #howto-close { flex: none; }
#howto-list {
  display: flex;
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}
#howto-list::-webkit-scrollbar { display: none; }
#howto-list li { flex: 0 0 100%; scroll-snap-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
#howto-list p { margin: 0; min-height: 2.7em; font-family: var(--font-head); font-size: 16px; line-height: 1.35; text-align: center; text-wrap: balance; }
.howto-anim { width: min(100%, 300px, 42vh); aspect-ratio: 4 / 3; height: auto; overflow: visible; }
.howto-nav { display: flex; align-items: center; gap: 10px; margin: 6px 0 12px; }
.howto-nav .btn-icon:disabled { opacity: 0.25; }
.howto-dots { display: flex; gap: 7px; }
.howto-dots button { width: 9px; height: 9px; padding: 0; border-radius: 50%; background: rgba(255, 255, 255, 0.25); }
.howto-dots button.on { background: var(--me-light); transform: scale(1.25); }

.toast {
  --y: 70%;
  position: absolute;
  left: var(--x, 50%);
  top: var(--y);
  width: max-content;
  max-width: min(var(--w, calc(100% - 24px)), 440px);
  text-align: center;
  text-wrap: balance;
  line-height: 1.35;
  transform: translate(-50%, -100%) translateY(14px);
  padding: 9px 18px;
  border-radius: 999px;
  background: var(--navy);
  font-family: var(--font-head);
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}
.toast.show { opacity: 1; transform: translate(-50%, -100%); }
.toast.down { transform: translate(-50%, 0) translateY(-14px); }
.toast.down.show { transform: translate(-50%, 0); }

/* ---------- motion ---------- */

@keyframes pop-in {
  from { opacity: 0; scale: 0.3; }
  to { opacity: 1; scale: 1; }
}
@keyframes splat-in {
  from { transform: scale(0.2); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes slide-in {
  from { opacity: 0; translate: -30px 0; }
  to { opacity: 1; translate: 0 0; }
}
@keyframes stone-drop {
  0% { transform: scale(1.6); opacity: 0; }
  45% { transform: scale(0.82, 0.9); opacity: 1; }
  75% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
@keyframes stone-pop {
  0% { transform: scale(1); opacity: 1; }
  40% { transform: scale(1.25); }
  100% { transform: scale(0.1); opacity: 0; }
}
@keyframes face-pop {
  from { transform: scale(0.6); }
  to { transform: scale(1); }
}
@keyframes panic {
  /* a quick shiver, then still for a while: a constant shake repaints the board all the time */
  0%, 22%, 100% { transform: translateX(0); }
  4%, 12% { transform: translateX(-2.5%) rotate(-3deg); }
  8%, 16% { transform: translateX(2.5%) rotate(3deg); }
}

@keyframes shiver {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-10deg); }
  75% { transform: rotate(10deg); }
}
@keyframes fade-in {
  from { opacity: 0; }
}
@keyframes atari {
  /* two beats, then still (in step with the shivering stones) */
  0%, 40%, 100% { transform: scale(0.9); opacity: 0.75; }
  10%, 30% { transform: scale(1.08); opacity: 1; }
  20% { transform: scale(0.94); opacity: 0.85; }
}
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(0); }
  50% { transform: translateY(-2px) rotate(-8deg); }
}
@keyframes dot {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(-4px); }
}

@media (prefers-reduced-motion: reduce) {
  /* Endless loops run once, or they would flicker at this speed. */
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* Portrait phones (the main target): the board spans the width, and the turn, the
   prisoners, the board and the buttons sit together in the middle of the screen. */
@media (orientation: portrait) {
  #game {
    padding: max(10px, env(safe-area-inset-top)) 10px max(14px, env(safe-area-inset-bottom));
    gap: 10px;
  }
  .levels button { min-height: 46px; font-size: 17px; padding: 0 clamp(0.75em, 6vw - 5px, 1.1em); }
  .level-note { font-size: 14px; }
  .btn-text { font-size: 15px; padding: 12px 18px; }
  /* Spacers around the middle group, a little lower than centre (closer to the thumb). */
  .hud { order: -2; }
  #game::before { content: ""; order: -1; flex: 3 1 0; }
  #game::after { content: ""; order: 1; flex: 2 1 0; }
  .meter-nums { font-size: 19px; }
  .num small { font-size: 12px; }
  .trays { padding: 0 2px; }
  .tray-stones i { margin-left: -7px; }
  .board-wrap { flex: 0 1 min(calc(100vw - 20px), 620px); }
  .controls { padding-top: 6px; gap: 14px; }
  .controls .btn-mid { min-width: min(9em, calc(50vw - 24px)); min-height: 52px; font-size: 18px; }
  .result-foot { width: 100%; }
  .result-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    width: min(100%, 440px);
    padding-top: 4px;
  }
  .result-actions .btn-big { grid-column: 1 / -1; font-size: 24px; padding: 0.45em 0; }
  .result-actions .btn-mid { min-height: 48px; }
  .rbar { column-gap: 8px; padding: 8px 12px; }
  .rbar b { font-size: 30px; }
  .rbar small { font-size: 12px; }
}

/* Low portrait screens: tighter, and the result buttons on one row so the board stays big. */
@media (orientation: portrait) and (max-height: 720px) {
  #game { gap: 6px; }
  .result-word { font-size: clamp(36px, 10vw, 56px); }
  .result-foot { gap: 6px; }
  .tally-bar { height: 16px; }
  .rbar { padding: 5px 10px; }
  .rbar b { font-size: 24px; }
  .rbar small { font-size: 11px; }
  .result-actions { grid-template-columns: 1.3fr 1fr 1fr; gap: 8px; }
  .result-actions .btn-big { grid-column: auto; font-size: 17px; }
  .result-actions .btn-mid { min-height: 44px; font-size: 14px; padding: 0.4em 0.5em; }
  .controls .btn-mid { min-height: 46px; }
}

/* Short frames (e.g. an embedded card) */
@media (max-height: 520px) {
  #game { padding: 6px 12px 8px; gap: 4px; }
  .btn-icon { width: 36px; height: 36px; }
  .meter-bar { height: 16px; }
  .meter-nums { font-size: 14px; }
  .status { font-size: 14px; min-height: 1.2em; }
  .btn-mid { padding: 0.4em 1.2em; }
  .title-body { gap: 8px; }
  .logo { font-size: clamp(48px, 20vmin, 100px); }
}

/* Short and wide frames: the board on the left, everything else beside it */
@media (max-height: 520px) and (min-aspect-ratio: 5/4) {
  #game {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(200px, 36%);
    grid-template-rows: auto auto auto minmax(0, 1fr);
    grid-template-areas: "hud hud" "board status" "board trays" "board controls";
    column-gap: 14px;
    row-gap: 6px;
  }
  .hud { grid-area: hud; }
  .board-wrap { grid-area: board; }
  .status { grid-area: status; }
  .trays { grid-area: trays; flex-direction: column; align-items: stretch; gap: 6px; }
  .tray { justify-content: space-between; }
  .controls { grid-area: controls; flex-direction: column; justify-content: center; align-items: stretch; }
  .controls:has(.help:not([hidden])) { display: grid; grid-template-columns: 1fr 1fr; align-content: center; }
  .controls:has(.help:not([hidden])) .btn-mid { max-width: none; }
  #game.over {
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: "board head" "board trays" "board foot";
  }
  .result-head { grid-area: head; padding: 4px 0 8px; }
  .result-foot { grid-area: foot; justify-content: center; gap: 8px; padding-top: 6px; }
  .result-word { font-size: clamp(28px, 8vh, 42px); }
  .tally-bar { height: 14px; }
  .result-bars { grid-template-columns: 1fr 1fr; gap: 6px; }
  .rbar { padding: 4px 8px; }
  .rbar b { font-size: 20px; }
  .rbar small { font-size: 10px; }
  .result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; width: 100%; }
  .result-actions .btn-big { grid-column: 1 / -1; font-size: 17px; padding: 0.35em 0; }
  .result-actions .btn-mid { font-size: 13px; padding: 0.45em 0.4em; }
}

/* A narrow meter: the level label gives way to the scores. */
.meter { container-type: inline-size; }
@container (max-width: 250px) {
  .level-chip { display: none; }
}

/* Wide screens: the HUD, the trays and the buttons keep to the board's width. */
@media (orientation: landscape) and (min-height: 521px), (orientation: portrait) and (min-width: 700px) {
  #game > .hud, #game > .status, #game > .trays, #game > .controls, #game > .result-head, #game > .result-foot {
    width: min(100%, 640px);
    align-self: center;
  }
  /* The result: the trays line up with the score bar and cards under the board. */
  #game.over > .trays { width: min(100%, 440px); }
}

/* Scripts outside the Japanese fonts */
html[lang="ko"] {
  word-break: keep-all; /* break between words, not inside them */
  overflow-wrap: anywhere;
  --font-head: "Black Han Sans", "Dela Gothic One", system-ui, sans-serif;
  --font-body: "Jua", system-ui, sans-serif; /* rounded and lighter, for running text */
}
html[lang="zh-Hans"] {
  --font-head: "Noto Sans SC", "Dela Gothic One", system-ui, sans-serif;
  --font-body: "Noto Sans SC", system-ui, sans-serif;
}
html[lang="zh-Hant"] {
  --font-head: "Noto Sans TC", "Dela Gothic One", system-ui, sans-serif;
  --font-body: "Noto Sans TC", system-ui, sans-serif;
}
html[lang="zh-Hans"] .tagline, html[lang="zh-Hant"] .tagline,
html[lang="zh-Hans"] button, html[lang="zh-Hant"] button { font-weight: 900; }
