[hidden] { display: none !important; }

/* ------------------------------------------------------------------ tokens */
:root {
  color-scheme: light;
  --ground: #d9d5cc;
  --groove: rgba(84, 74, 58, 0.2);
  --ridge: rgba(255, 255, 255, 0.55);
  --speck: rgba(64, 58, 48, 0.1);
  --ink: #1f1d1a;
  --ink-2: #57524a;
  --ink-3: #847e74;
  --paper: #f6f4ef;
  --paper-2: #ebe7df;
  --rule: #d3cdc2;
  --slot: rgba(60, 48, 30, 0.3);
  --gold: #a57a22;
  --gold-hi: #c28d2c;
  --glow: rgba(214, 164, 64, 0.55);
  --red: #c23a22;
  --blue: #2c4c8c;
  --danger: #bf2f17;
  --btn-bg: rgba(255, 255, 255, 0.5);
  --btn-bg-hover: rgba(255, 255, 255, 0.9);
  --primary-bg: #1f1d1a;
  --primary-ink: #f6f4ef;
  --switch-on: #1f1d1a;
  --scrim: rgba(28, 24, 18, 0.45);
  --shadow-rgb: 38, 30, 20;
  --card-paper: #f4eddc;
  --card-ink: #28231d;
  --card-line: #d2c5a6;
  --card-center: #a08d70;
  --wood: #e2c794;
  --wood-edge: rgba(92, 58, 20, 0.36);
  --wood-light: rgba(255, 247, 226, 0.5);
  --frame: #211c18;
  --frame-hi: #3d3229;
  --frame-ink: #c9ab6c;
  --mark-ink: rgba(40, 26, 12, 0.6);
  --display: "Shippori Mincho B1", "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", "Noto Serif CJK JP", Georgia, serif;
  --ui: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", "Noto Sans JP", system-ui, -apple-system, "Segoe UI", sans-serif;
  --brush: "Yuji Syuku", "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif CJK JP", serif;
  --board: 480px;
  --card-w: 150px;
  --card-h: 106px;
  --gap: 12px;
  --panel-w: 300px;
  --frame-w: calc(var(--board) * 0.05);
  --sq: calc((var(--board) - 2 * var(--frame-w)) / 5);
  --card-r: calc(var(--card-h) * 0.07);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ground: #16181b;
    --groove: rgba(0, 0, 0, 0.42);
    --ridge: rgba(255, 255, 255, 0.065);
    --speck: rgba(255, 255, 255, 0.04);
    --ink: #ece7dd;
    --ink-2: #b6afa3;
    --ink-3: #878176;
    --paper: #1f2125;
    --paper-2: #292b30;
    --rule: #383b41;
    --slot: rgba(255, 255, 255, 0.17);
    --gold: #d9b05a;
    --gold-hi: #e8c476;
    --glow: rgba(232, 188, 96, 0.5);
    --red: #e45f42;
    --blue: #7797dd;
    --danger: #ff6d4f;
    --btn-bg: rgba(255, 255, 255, 0.045);
    --btn-bg-hover: rgba(255, 255, 255, 0.1);
    --primary-bg: #ece7dd;
    --primary-ink: #17181b;
    --switch-on: #d9b05a;
    --scrim: rgba(0, 0, 0, 0.62);
    --shadow-rgb: 0, 0, 0;
    --card-paper: #e6dcc5;
    --card-ink: #26211b;
    --card-line: #c4b592;
    --card-center: #93806a;
    --wood: #cdb281;
    --wood-edge: rgba(58, 36, 10, 0.5);
    --wood-light: rgba(255, 240, 210, 0.3);
    --frame: #0d0c0b;
    --frame-hi: #29231e;
    --frame-ink: #b89a5f;
    --mark-ink: rgba(30, 20, 8, 0.66);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ground: #16181b;
  --groove: rgba(0, 0, 0, 0.42);
  --ridge: rgba(255, 255, 255, 0.065);
  --speck: rgba(255, 255, 255, 0.04);
  --ink: #ece7dd;
  --ink-2: #b6afa3;
  --ink-3: #878176;
  --paper: #1f2125;
  --paper-2: #292b30;
  --rule: #383b41;
  --slot: rgba(255, 255, 255, 0.17);
  --gold: #d9b05a;
  --gold-hi: #e8c476;
  --glow: rgba(232, 188, 96, 0.5);
  --red: #e45f42;
  --blue: #7797dd;
  --danger: #ff6d4f;
  --btn-bg: rgba(255, 255, 255, 0.045);
  --btn-bg-hover: rgba(255, 255, 255, 0.1);
  --primary-bg: #ece7dd;
  --primary-ink: #17181b;
  --switch-on: #d9b05a;
  --scrim: rgba(0, 0, 0, 0.62);
  --shadow-rgb: 0, 0, 0;
  --card-paper: #e6dcc5;
  --card-ink: #26211b;
  --card-line: #c4b592;
  --card-center: #93806a;
  --wood: #cdb281;
  --wood-edge: rgba(58, 36, 10, 0.5);
  --wood-light: rgba(255, 240, 210, 0.3);
  --frame: #0d0c0b;
  --frame-hi: #29231e;
  --frame-ink: #b89a5f;
  --mark-ink: rgba(30, 20, 8, 0.66);
}

/* -------------------------------------------------------------------- base */
html { box-sizing: border-box; height: 100%; }
body { height: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }

.garden { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }

.app {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding-inline: 16px;
  box-sizing: border-box;
}
.app.is-wide { padding-inline: 28px; }
.app:not(.is-wide) .wide-only, .app.is-wide .narrow-only { display: none !important; }

/* ------------------------------------------------------------------ topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  padding-block: 6px;
  flex: none;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 20px; height: 22px; flex: none; overflow: visible; }
.brand-word {
  font-family: var(--display);
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 0.36em;
  text-transform: uppercase;
  white-space: nowrap;
}
.tools { display: flex; align-items: center; gap: 4px; }
.tool {
  display: inline-flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 12px;
  border-radius: 9px; border: 1px solid transparent;
  background: transparent; color: var(--ink);
  font-size: 13.5px; font-weight: 500; cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.tool:hover { background: var(--btn-bg-hover); border-color: var(--rule); }
.tool:disabled { opacity: 0.4; cursor: default; background: transparent; border-color: transparent; }
.tool svg { width: 18px; height: 18px; flex: none; }
.tool.icon { width: 38px; padding: 0; justify-content: center; }
#btnSound .mute { display: none; }
#btnSound[aria-pressed="false"] .wave { display: none; }
#btnSound[aria-pressed="false"] .mute { display: inline; }

/* ------------------------------------------------------------------- stage */
.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 40px;
  overflow: auto;
  padding-block: 4px 14px;
}
.table {
  display: grid;
  justify-items: center;
  gap: var(--gap);
  width: var(--board);
  flex: none;
}
.app:not(.is-wide) .stage { align-items: flex-start; }
.app:not(.is-wide) .table { margin-block: auto; }

/* ------------------------------------------------------------------- seats */
.seat {
  display: flex; align-items: center; gap: 10px;
  width: 100%; min-height: 28px;
  font-size: 13px; color: var(--ink-2);
}
.seat .chip { width: 14px; height: 15px; flex: none; }
.seat .name { font-weight: 700; color: var(--ink); white-space: nowrap; }
.name-btn {
  display: inline-flex; align-items: center; gap: 4px;
  margin: -4px -6px; padding: 4px 6px;
  border: 0; border-radius: 7px;
  background: transparent; cursor: pointer;
  font: inherit; font-weight: 700; color: var(--ink);
}
.name-btn:hover, .name-btn[aria-expanded="true"] { background: var(--btn-bg-hover); box-shadow: inset 0 0 0 1px var(--rule); }
.name-btn svg { width: 14px; height: 14px; color: var(--ink-3); }
.level-menu {
  position: fixed; z-index: 82;
  width: min(300px, calc(100vw - 24px));
  box-sizing: border-box;
  padding: 6px;
  background: var(--paper); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 12px;
  box-shadow: 0 18px 44px -14px rgba(var(--shadow-rgb), 0.6);
  animation: rise 0.18s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.level-menu button {
  display: grid; gap: 2px; width: 100%;
  padding: 8px 10px 8px 30px;
  border: 0; border-radius: 8px;
  background: none; color: inherit; text-align: left; cursor: pointer;
  position: relative;
}
.level-menu button:hover, .level-menu button:focus-visible { background: var(--paper-2); }
.level-menu button[aria-checked="true"]::before {
  content: ""; position: absolute; left: 11px; top: 14px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--gold-hi);
}
.level-menu b { font-family: var(--display); font-weight: 800; font-size: 14.5px; }
.level-menu small { font-size: 12px; color: var(--ink-2); line-height: 1.35; }
.level-menu .lm-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.level-menu .lm-note { margin: 4px 10px 6px; font-size: 11.5px; color: var(--ink-3); }
.seat .meta { color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.seat .caps { display: flex; align-items: center; gap: 2px; margin-left: auto; min-height: 16px; }
.seat .caps svg { width: 11px; height: 12px; }
.seat .caps-label { font-size: 11px; color: var(--ink-3); margin-right: 5px; letter-spacing: 0.04em; }
.seat .turn {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase;
  padding: 4px 9px 3px; border-radius: 999px; white-space: nowrap;
  background: var(--primary-bg); color: var(--primary-ink);
}
.seat .turn.is-thinking { background: transparent; color: var(--ink-2); padding-inline: 0; letter-spacing: 0.06em; }
.seat .turn.is-danger { background: var(--danger); color: #fff; }
.dots { display: inline-flex; gap: 3px; margin-left: 6px; vertical-align: 2px; }
.dots i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; animation: dot 1.1s ease-in-out infinite; }
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

.status-line {
  margin: 0; width: 100%; min-height: 20px;
  text-align: center; font-size: 13px; color: var(--ink-2);
  display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap;
}
.status-line.is-danger { color: var(--danger); font-weight: 700; }

/* ------------------------------------------------------------------- cards */
.row {
  display: grid;
  grid-template-columns: repeat(3, var(--card-w));
  gap: var(--gap);
  height: var(--card-h);
}
.slot { position: relative; width: var(--card-w); height: var(--card-h); }
.slot-in::before {
  content: ""; position: absolute; inset: 0;
  border-radius: var(--card-r);
  border: 1.5px dashed var(--slot);
  background: rgba(255, 255, 255, 0.05);
}
.slot-label {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--ink-3); pointer-events: none;
}

.card {
  position: absolute; inset: 0;
  padding: 0; margin: 0; border: 0; background: none;
  transform: rotate(var(--rot, 0deg)) scale(var(--scale, 1));
  transform-origin: 50% 50%;
  perspective: 900px;
  cursor: default;
  z-index: 1;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}
.slot-in .card { --scale: 0.88; }
/* The side card is out of play until someone takes it, so it rests faded. It
   keeps full colour while it flies in, while its stamp is pointed out at the
   deal, and while someone inspects it. */
.slot-in .card:not(.is-flying, .is-pulse, .is-previewing, :hover) .card-face { filter: grayscale(0.6) contrast(0.9) brightness(0.97); }
.card.is-flying { z-index: 30; }
.card-inner {
  position: absolute; inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.22s cubic-bezier(0.3, 0.7, 0.4, 1);
}
.card-face, .card-back {
  position: absolute; inset: 0;
  border-radius: var(--card-r);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.card-face {
  container-type: size;
  background-color: var(--card-paper);
  background-image: var(--paper-tex);
  box-shadow:
    inset 0 0 0 1px rgba(120, 96, 54, 0.28),
    0 1px 1px rgba(var(--shadow-rgb), 0.18),
    0 6px 14px -6px rgba(var(--shadow-rgb), 0.45);
  color: var(--card-ink);
  overflow: hidden;
  transition: box-shadow 0.2s, filter 0.35s;
}
.card-face::before {
  content: ""; position: absolute; inset: 4.5cqh;
  border: 1px solid rgba(120, 96, 54, 0.22);
  border-radius: calc(var(--card-r) * 0.6);
  pointer-events: none;
}
.card-body {
  position: absolute; inset: 9cqh 9cqh 6.5cqh 9cqh;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: minmax(0, 1fr) auto;
  column-gap: 6cqh;
  row-gap: 4cqh;
}
.card-grid {
  grid-row: 1; grid-column: 1;
  height: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: max(1px, 0.9cqh);
  padding: max(1px, 0.9cqh);
  box-sizing: border-box;
  background: var(--card-line);
  border-radius: 2px;
}
.card-grid i { background: var(--card-paper); border-radius: 1px; }
.card-grid i.m { background: var(--card-ink); }
.card-grid i.c { background: var(--card-center); position: relative; }
.card-grid i.c::after {
  content: ""; position: absolute; inset: 26%;
  background: var(--card-paper);
  clip-path: polygon(50% 0, 100% 30%, 100% 100%, 0 100%, 0 30%);
}
.card-kanji {
  grid-row: 1; grid-column: 2;
  align-self: center; justify-self: center;
  font-family: var(--brush);
  font-size: min(46cqh, 30cqw);
  line-height: 1;
  color: var(--card-ink);
  padding-top: 4cqh;
}
.card-kanji.two { writing-mode: vertical-rl; font-size: min(29cqh, 19cqw); letter-spacing: -0.04em; padding-top: 0; }
.card-name {
  grid-row: 2; grid-column: 1 / -1;
  text-align: center;
  font-family: var(--display);
  font-weight: 800;
  font-size: max(8.5px, min(11cqh, 9cqw));
  letter-spacing: 0.18em;
  text-transform: uppercase;
  line-height: 1;
  white-space: nowrap;
  padding-left: 0.18em;
}
@container (max-aspect-ratio: 13 / 10) {
  .card-body { grid-template-columns: 1fr; }
  .card-grid { justify-self: center; }
  .card-kanji { display: none; }
}
.card-stamp {
  position: absolute; top: 6cqh; right: 6cqh;
  width: 13cqh; height: 13cqh;
  border-radius: 14%;
  display: grid; place-items: center;
  font-family: var(--display); font-weight: 800;
  font-size: 8.6cqh; line-height: 1;
  color: rgba(250, 242, 224, 0.95);
  transform: rotate(-7deg);
  box-shadow: inset 0 0 0 0.9cqh rgba(250, 242, 224, 0.28);
}
.card-stamp.s0 { background: #c23c26; }
.card-stamp.s1 { background: #2d4d8e; }
.card-back {
  transform: rotateY(180deg);
  background-color: #1d2a47;
  background-image: var(--back-tex);
  background-size: calc(var(--card-h) * 0.22) calc(var(--card-h) * 0.22);
  box-shadow: inset 0 0 0 1px rgba(201, 164, 92, 0.55), inset 0 0 0 5px #1d2a47, inset 0 0 0 6px rgba(201, 164, 92, 0.35), 0 6px 14px -6px rgba(0, 0, 0, 0.5);
}

/* card states */
.card.is-playable { cursor: pointer; }
.card.is-playable:hover .card-inner { transform: translateY(-4%); }
.card.is-playable:hover .card-face { box-shadow: inset 0 0 0 1px rgba(120, 96, 54, 0.32), 0 2px 2px rgba(var(--shadow-rgb), 0.16), 0 14px 22px -8px rgba(var(--shadow-rgb), 0.5); }
.card.is-selected .card-inner { transform: translateY(-8%); }
.card.is-selected .card-face {
  box-shadow: inset 0 0 0 1px rgba(120, 96, 54, 0.3), 0 0 0 2px var(--gold-hi), 0 0 18px 2px var(--glow), 0 16px 24px -10px rgba(var(--shadow-rgb), 0.55);
}
.card.is-hinted .card-face { animation: hintCard 1.3s ease-in-out infinite; }
.card.is-muted .card-face { filter: saturate(0.65) brightness(0.93); }
.card.is-previewing .card-face { box-shadow: inset 0 0 0 1px rgba(120, 96, 54, 0.3), 0 0 0 2px var(--pv, var(--ink-3)), 0 10px 20px -8px rgba(var(--shadow-rgb), 0.5); }
.card.is-used .card-inner { transform: translateY(-9%); }
.card.is-used .card-face { box-shadow: inset 0 0 0 1px rgba(120, 96, 54, 0.3), 0 0 0 2px var(--gold-hi), 0 18px 28px -10px rgba(var(--shadow-rgb), 0.6); }
.card.is-pulse .card-stamp { animation: stampPulse 1.2s ease-in-out 3; }
@keyframes hintCard {
  0%, 100% { box-shadow: inset 0 0 0 1px rgba(120, 96, 54, 0.3), 0 0 0 2px var(--gold-hi), 0 0 6px 0 var(--glow); }
  50% { box-shadow: inset 0 0 0 1px rgba(120, 96, 54, 0.3), 0 0 0 2px var(--gold-hi), 0 0 22px 4px var(--glow); }
}
@keyframes stampPulse { 0%, 100% { transform: rotate(-7deg) scale(1); } 50% { transform: rotate(-7deg) scale(1.35); } }

.card-static { position: relative; display: block; width: 100%; aspect-ratio: 1.42; }
.card-static .card-face { position: absolute; inset: 0; }

/* ------------------------------------------------------------------- board */
.board {
  position: relative;
  width: var(--board);
  height: var(--board);
  box-sizing: border-box;
  padding: var(--frame-w);
  border-radius: calc(var(--board) * 0.022);
  background:
    radial-gradient(120% 90% at 30% 0%, rgba(255, 236, 200, 0.07), transparent 60%),
    linear-gradient(165deg, var(--frame-hi), var(--frame) 58%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 0 0 1px rgba(0, 0, 0, 0.45),
    0 2px 3px rgba(var(--shadow-rgb), 0.25),
    0 28px 50px -18px rgba(var(--shadow-rgb), 0.6);
}
.board::before {
  content: ""; position: absolute;
  inset: calc(var(--frame-w) * 0.42);
  border: 1px solid rgba(201, 171, 108, 0.32);
  border-radius: calc(var(--board) * 0.012);
  pointer-events: none;
}
.coords {
  position: absolute; display: grid; place-items: center;
  font-family: var(--display); font-weight: 700;
  font-size: max(9px, calc(var(--frame-w) * 0.4));
  color: var(--frame-ink);
  pointer-events: none;
  opacity: 0.85;
}
.coords-files { left: var(--frame-w); right: var(--frame-w); bottom: 0; height: var(--frame-w); grid-template-columns: repeat(5, 1fr); }
.coords-ranks { top: var(--frame-w); bottom: var(--frame-w); left: 0; width: var(--frame-w); grid-template-rows: repeat(5, 1fr); }
.no-coords .coords { display: none; }

.surface {
  position: relative;
  width: 100%; height: 100%;
  border-radius: 3px;
  background-color: var(--wood);
  background-image:
    linear-gradient(180deg, rgba(255, 250, 235, 0.16), rgba(90, 50, 10, 0.1)),
    var(--wood-tex);
  background-size: 100% 100%, 100% 100%;
  box-shadow: inset 0 0 0 1px rgba(40, 20, 0, 0.45), inset 0 3px 8px rgba(40, 20, 0, 0.18);
}
.tiles, .marks, .hits, .fx-under {
  position: absolute; inset: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
}
.fx-over { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.fx-under { pointer-events: none; z-index: 1; }
.tile { position: relative; box-shadow: inset 1px 1px 0 var(--wood-light), inset -1px -1px 0 var(--wood-edge); }
.tile .torii { position: absolute; left: 21%; top: 19%; width: 58%; height: 58%; fill: currentColor; opacity: 0.2; }
.tile.temple-0 { color: var(--red); background: radial-gradient(circle at 50% 55%, rgba(194, 58, 34, 0.08), transparent 70%); }
.tile.temple-1 { color: var(--blue); background: radial-gradient(circle at 50% 55%, rgba(44, 76, 140, 0.08), transparent 70%); }
.tile::after { content: ""; position: absolute; inset: 0; opacity: 0; transition: opacity 0.25s; pointer-events: none; }
.tile.is-last-from::after { opacity: 1; background: rgba(120, 82, 30, 0.13); box-shadow: inset 0 0 0 2px rgba(120, 82, 30, 0.2); }
.tile.is-last-to::after { opacity: 1; background: rgba(216, 160, 56, 0.3); }
.tile.is-selected::after { opacity: 1; background: radial-gradient(circle, rgba(255, 216, 130, 0.9) 0 30%, rgba(255, 216, 130, 0) 72%); }
.tile.is-movable::before {
  content: ""; position: absolute; inset: 12%; border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(214, 164, 64, 0.5), 0 0 10px 1px rgba(214, 164, 64, 0.35);
}
.tile.is-danger::before {
  content: ""; position: absolute; inset: 5%;
  border-radius: 14%;
  background: radial-gradient(circle, rgba(226, 52, 24, 0.42), rgba(226, 52, 24, 0.08) 72%);
  box-shadow: inset 0 0 0 2px rgba(214, 48, 22, 0.85), 0 0 14px 3px rgba(226, 52, 24, 0.4);
  animation: danger 1.25s ease-in-out infinite;
}
.tile.is-reach { background-image: linear-gradient(135deg, var(--reach-c) 0 13%, transparent 13.5%), linear-gradient(-45deg, var(--reach-c) 0 13%, transparent 13.5%); }
.tile.reach-0 { --reach-c: rgba(194, 58, 34, 0.5); }
.tile.reach-1 { --reach-c: rgba(44, 76, 140, 0.55); }
@keyframes danger { 0%, 100% { opacity: 0.6; transform: scale(0.96); } 50% { opacity: 1; transform: scale(1.02); } }

.pieces { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.piece {
  position: absolute; left: 0; top: 0;
  width: 20%; height: 20%;
  display: grid; place-items: center;
  transform: translate(calc(var(--c) * 100%), calc(var(--r) * 100%));
  z-index: 1;
}
.piece.is-moving, .piece.is-dragging { z-index: 5; }
.piece.is-gone { display: none; }
.pc {
  width: 76%;
  height: auto;
  aspect-ratio: 100 / 106;
  overflow: visible;
  filter: drop-shadow(0 1.5px 1px rgba(30, 14, 0, 0.35)) drop-shadow(0 5px 5px rgba(30, 14, 0, 0.22));
  transition: transform 0.2s cubic-bezier(0.3, 0.7, 0.4, 1), filter 0.2s;
  transform-origin: 50% 75%;
}
.piece.master .pc { width: 90%; }
.piece.is-selected .pc, .piece.is-dragging .pc {
  transform: translateY(-8%) scale(1.08);
  filter: drop-shadow(0 3px 2px rgba(30, 14, 0, 0.3)) drop-shadow(0 12px 10px rgba(30, 14, 0, 0.28));
}
.pc-glyph { font-family: var(--display); font-weight: 800; }
.piece.ghost { opacity: 0.42; z-index: 0; }
.piece.ghost .pc { filter: none; }

.marks { pointer-events: none; z-index: 3; }
.mark { position: relative; }
.mark::before {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 22%; height: 22%;
  border-radius: 50%;
  background: var(--mark-ink);
  transform: translate(-50%, -50%) scale(0);
  opacity: 0;
  transition: transform 0.16s cubic-bezier(0.3, 0.8, 0.4, 1.3), opacity 0.16s;
}
.mark.is-target::before { transform: translate(-50%, -50%) scale(1); opacity: 1; }
.mark.is-target.is-hover::before { transform: translate(-50%, -50%) scale(1.35); }
.mark.is-capture::before {
  width: 86%; height: 86%;
  background: none;
  border: max(2px, calc(var(--sq) * 0.055)) solid rgba(40, 22, 8, 0.62);
  box-sizing: border-box;
}
.mark.is-capture.is-hover::before { transform: translate(-50%, -50%) scale(1.05); border-color: rgba(40, 22, 8, 0.8); }
.mark.is-preview::before {
  width: 30%; height: 30%;
  background: none;
  border: max(2px, calc(var(--sq) * 0.05)) solid var(--pv);
  box-sizing: border-box;
  transform: translate(-50%, -50%) scale(1); opacity: 0.85;
}
.mark.pv-0 { --pv: rgba(194, 58, 34, 0.85); }
.mark.pv-1 { --pv: rgba(44, 76, 140, 0.9); }
.mark.is-hint-from::after, .mark.is-hint-to::after {
  content: ""; position: absolute; inset: 5%;
  border-radius: 14%;
  border: 2px solid var(--gold-hi);
  animation: hintPulse 1.3s ease-in-out infinite;
}
.mark.is-hint-to::after { border-style: dashed; }
@keyframes hintPulse { 0%, 100% { box-shadow: 0 0 4px 0 var(--glow); opacity: 0.75; } 50% { box-shadow: 0 0 16px 3px var(--glow); opacity: 1; } }

.hits { z-index: 4; }
.hit {
  appearance: none; -webkit-appearance: none;
  border: 0; margin: 0; padding: 0;
  background: transparent;
  border-radius: 4px;
  cursor: default;
  touch-action: none;
}
.hit.is-actionable { cursor: pointer; }
.hit:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: -3px; }
.board.is-dragging .hit { cursor: grabbing; }

/* effects */
.fx-ring {
  position: absolute; left: 0; top: 0; width: 20%; height: 20%;
  transform: translate(calc(var(--c) * 100%), calc(var(--r) * 100%));
  pointer-events: none;
}
.fx-ring::before {
  content: ""; position: absolute; inset: 12%;
  border-radius: 50%;
  border: 2px solid var(--ring, rgba(70, 44, 14, 0.5));
  animation: ring 0.6s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}
@keyframes ring { from { transform: scale(0.55); opacity: 0.9; } to { transform: scale(1.45); opacity: 0; } }
.fx-ripple {
  position: absolute; left: 0; top: 0; width: 20%; height: 20%;
  transform: translate(calc(var(--c) * 100%), calc(var(--r) * 100%));
  pointer-events: none;
}
.fx-ripple i {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid rgba(80, 130, 190, 0.7);
  animation: ripple 2.2s cubic-bezier(0.1, 0.6, 0.3, 1) forwards;
  opacity: 0;
}
@keyframes ripple { 0% { transform: scale(0.3); opacity: 0.95; } 100% { transform: scale(6); opacity: 0; } }
.fx-drop {
  position: absolute; width: 2.2%; height: 2.2%;
  border-radius: 50%;
  background: var(--drop, #2a1d12);
  pointer-events: none;
}
.fx-half { position: absolute; left: 0; top: 0; width: 20%; height: 20%; display: grid; place-items: center; pointer-events: none; z-index: 7; }
.fx-half .pc { filter: drop-shadow(0 4px 4px rgba(30, 14, 0, 0.3)); }

/* online */
.presence { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--ink-3); opacity: 0.55; }
.presence.on { background: #3f9b5c; opacity: 1; box-shadow: 0 0 0 3px rgba(63, 155, 92, 0.2); }
.text-input {
  width: 100%; height: 40px; box-sizing: border-box;
  padding: 0 12px;
  border: 1px solid var(--rule); border-radius: 9px;
  background: var(--paper); color: var(--ink);
  font: inherit; font-size: 14px;
}
.text-input::placeholder { color: var(--ink-3); }
.text-input:focus { outline: 2px solid var(--gold-hi); outline-offset: 1px; }
.code-input { width: 8.5em; text-transform: uppercase; letter-spacing: 0.22em; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.join-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding-top: 16px; border-top: 1px solid var(--rule); }
.join-row label { margin-right: auto; font-size: 13.5px; color: var(--ink-2); }
.invite {
  position: absolute; z-index: 21;
  left: 50%; top: 50%;
  width: min(92%, 380px);
  transform: translate(-50%, -50%);
  box-sizing: border-box;
  padding: 18px 18px 14px;
  display: grid; gap: 10px;
  background: var(--paper); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 14px;
  box-shadow: 0 24px 50px -14px rgba(var(--shadow-rgb), 0.65);
  animation: pop 0.25s cubic-bezier(0.2, 0.8, 0.3, 1.2);
}
.invite-title { margin: 0; font-family: var(--display); font-weight: 800; font-size: 18px; }
.invite-note { margin: -4px 0 2px; font-size: 13px; color: var(--ink-2); }
.invite-link { display: flex; gap: 8px; }
.invite-link .text-input { font-size: 12.5px; min-width: 0; }
.invite-code { margin: 0; font-size: 12.5px; color: var(--ink-3); }
.invite-code b { margin-left: 4px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; letter-spacing: 0.2em; color: var(--ink); }
.invite-wait { margin: 0; display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--ink-2); }
.invite-wait .dots { margin: 0 6px 0 0; }
.invite-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* card chooser */
.chooser {
  position: absolute; z-index: 20;
  left: 50%; top: 50%;
  width: min(92%, 360px);
  transform: translate(-50%, -50%);
  box-sizing: border-box;
  padding: 16px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 14px;
  box-shadow: 0 24px 50px -14px rgba(var(--shadow-rgb), 0.65);
  animation: pop 0.2s cubic-bezier(0.2, 0.8, 0.3, 1.2);
}
.chooser-title { margin: 0; font-family: var(--display); font-weight: 700; font-size: 16px; }
.chooser-note { margin: 3px 0 12px; font-size: 12.5px; color: var(--ink-2); }
.chooser-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chooser-opt {
  display: block; width: 100%;
  padding: 0; border: 0; background: none; cursor: pointer;
  border-radius: 10px;
  transition: transform 0.15s;
}
.chooser-opt:hover { transform: translateY(-2px); }
.chooser-opt:hover .card-face, .chooser-opt:focus-visible .card-face { box-shadow: inset 0 0 0 1px rgba(120, 96, 54, 0.3), 0 0 0 2px var(--gold-hi), 0 10px 18px -8px rgba(var(--shadow-rgb), 0.5); }
.chooser-cancel { margin-top: 10px; width: 100%; height: 34px; border: 0; background: none; color: var(--ink-2); cursor: pointer; border-radius: 8px; font-size: 13px; }
.chooser-cancel:hover { background: var(--paper-2); }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -46%) scale(0.96); } }

/* result */
.result {
  position: absolute; inset: 0; z-index: 30;
  display: grid; place-items: center;
  border-radius: 3px;
  background: radial-gradient(circle at 50% 45%, rgba(14, 11, 8, 0.5), rgba(14, 11, 8, 0.72));
  animation: fade 0.5s ease both;
}
.result-card {
  position: relative;
  width: 88%;
  text-align: center;
  color: #f7f0e1;
  padding: 8px 0 0;
}
.enso {
  position: absolute; left: 50%; top: 30%;
  width: 62%; aspect-ratio: 1;
  transform: translate(-50%, -50%) rotate(-12deg);
  overflow: visible;
  pointer-events: none;
}
.enso-stroke {
  fill: none;
  stroke: var(--enso, #d6452b);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 620;
  stroke-dashoffset: 620;
  opacity: 0.9;
  animation: draw 1.35s cubic-bezier(0.55, 0.05, 0.3, 1) 0.15s forwards;
}
@keyframes draw { to { stroke-dashoffset: 0; } }
.result-kanji {
  position: relative;
  margin: 0;
  font-family: var(--brush);
  font-size: calc(var(--board) * 0.17);
  line-height: 1.2;
  color: #fbf4e6;
  text-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
  animation: rise 0.7s cubic-bezier(0.2, 0.8, 0.3, 1) 0.5s both;
}
.result-title {
  position: relative;
  margin: calc(var(--board) * 0.035) 0 0;
  font-family: var(--display); font-weight: 800;
  font-size: max(20px, calc(var(--board) * 0.066));
  letter-spacing: 0.24em; text-transform: uppercase;
  padding-left: 0.24em;
  animation: rise 0.6s cubic-bezier(0.2, 0.8, 0.3, 1) 0.8s both;
}
.result-way {
  margin: 4px 0 0;
  font-size: max(12px, calc(var(--board) * 0.028));
  letter-spacing: 0.18em; text-transform: uppercase;
  color: #e9c98a;
  animation: rise 0.6s cubic-bezier(0.2, 0.8, 0.3, 1) 0.95s both;
}
.result-detail {
  margin: 8px auto 0; max-width: 34ch;
  font-size: max(12.5px, calc(var(--board) * 0.029));
  color: rgba(247, 240, 225, 0.82);
  text-wrap: balance;
  animation: rise 0.6s cubic-bezier(0.2, 0.8, 0.3, 1) 1.05s both;
}
.result-actions {
  display: flex; justify-content: center; gap: 10px; flex-wrap: wrap;
  margin-top: calc(var(--board) * 0.045);
  animation: rise 0.6s cubic-bezier(0.2, 0.8, 0.3, 1) 1.2s both;
}
.result .btn { background: rgba(255, 255, 255, 0.1); color: #f7f0e1; border-color: rgba(255, 255, 255, 0.28); }
.result .btn:hover { background: rgba(255, 255, 255, 0.18); }
.result .btn-primary { background: #f3ead8; color: #1f1d1a; border-color: #f3ead8; }
.result .btn-primary:hover { background: #fff; }
.result-close {
  position: absolute; top: calc(var(--board) * -0.02); right: -2%;
  width: 34px; height: 34px; border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, 0.1); color: #f7f0e1; cursor: pointer;
  display: grid; place-items: center;
}
.result-close:hover { background: rgba(255, 255, 255, 0.2); }
.result-close svg { width: 18px; height: 18px; }

/* ------------------------------------------------------------------- panel */
.panel {
  width: var(--panel-w);
  height: var(--panel-h, 560px);
  flex: none;
  display: flex; flex-direction: column;
  box-sizing: border-box;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 14px;
  box-shadow: 0 24px 60px -30px rgba(var(--shadow-rgb), 0.55);
  overflow: hidden;
}
.app:not(.is-wide) .panel { display: none; }
.panel-status { padding: 18px 20px 16px; border-bottom: 1px solid var(--rule); min-height: 92px; box-sizing: border-box; }
.status-head {
  margin: 0;
  font-family: var(--display); font-weight: 700;
  font-size: 19px; line-height: 1.25;
  text-wrap: balance;
}
.status-head.is-danger { color: var(--danger); }
.status-detail { margin: 6px 0 0; color: var(--ink-2); font-size: 13.5px; text-wrap: pretty; }
.status-detail a, .status-line a, .link-btn {
  color: inherit; text-decoration: underline; text-decoration-color: var(--gold-hi); text-underline-offset: 3px;
  background: none; border: 0; padding: 0; cursor: pointer; font: inherit;
}
.review-ctrl { display: inline-flex; align-items: center; gap: 6px; margin-top: 10px; }
.status-line .review-ctrl { margin-top: 0; }
.rv-btn {
  width: 32px; height: 32px; display: grid; place-items: center;
  border: 1px solid var(--rule); border-radius: 8px;
  background: var(--btn-bg); color: var(--ink); cursor: pointer;
}
.rv-btn:hover { background: var(--btn-bg-hover); }
.rv-btn:disabled { opacity: 0.35; cursor: default; }
.rv-btn svg { width: 16px; height: 16px; }
.rv-exit { height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--rule); background: var(--primary-bg); color: var(--primary-ink); cursor: pointer; font-size: 12.5px; font-weight: 500; }

.panel-history { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.history-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 14px 20px 6px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-3);
}
.history-count { letter-spacing: 0.04em; font-weight: 500; text-transform: none; }
.history {
  list-style: none; margin: 0; padding: 0 10px 12px;
  overflow: auto; flex: 1;
  font-variant-numeric: tabular-nums;
}
.history li button {
  width: 100%;
  display: grid;
  grid-template-columns: 24px 9px minmax(0, 1fr) auto;
  align-items: center; gap: 9px;
  padding: 6px 10px;
  border: 0; border-radius: 8px;
  background: none; color: var(--ink);
  font-size: 13px; text-align: left; cursor: pointer;
}
.history li button:hover { background: var(--paper-2); }
.history li.is-current button { background: var(--paper-2); box-shadow: inset 2px 0 0 var(--gold-hi); }
.hist-n { color: var(--ink-3); font-size: 12px; }
.hist-dot { width: 9px; height: 9px; border-radius: 50%; }
.hist-dot.s0 { background: var(--red); }
.hist-dot.s1 { background: var(--blue); }
.hist-main { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.hist-card { font-weight: 700; white-space: nowrap; }
.hist-sq { color: var(--ink-2); white-space: nowrap; }
.hist-sq .pcg { font-family: var(--display); font-weight: 800; margin-right: 3px; color: var(--ink); }
.hist-tag { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; color: var(--ink-3); white-space: nowrap; }
.hist-tag.win { color: var(--gold); }
.history-empty { padding: 12px 10px; color: var(--ink-3); font-size: 13px; }
.panel-actions { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--rule); }
.panel-actions .btn { flex: 1; padding: 0 8px; }

/* ----------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 14px;
  border-radius: 9px;
  border: 1px solid var(--rule);
  background: var(--btn-bg);
  color: var(--ink);
  font-size: 13.5px; font-weight: 500; line-height: 1;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:hover { background: var(--btn-bg-hover); border-color: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.42; cursor: default; transform: none; }
.btn:disabled:hover { background: var(--btn-bg); border-color: var(--rule); }
.btn svg { width: 17px; height: 17px; flex: none; }
.btn-primary { background: var(--primary-bg); color: var(--primary-ink); border-color: var(--primary-bg); }
.btn-primary:hover { background: var(--primary-bg); border-color: var(--primary-bg); filter: brightness(1.15); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); filter: brightness(1.08); }
.btn-quiet { background: transparent; }
.btn.is-busy { pointer-events: none; }
.btn.is-busy svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; z-index: 80;
  top: calc(58px + env(safe-area-inset-top, 0px));
  transform: translate(-50%, -50%);
  max-width: min(420px, calc(100vw - 48px));
  box-sizing: border-box;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--primary-bg); color: var(--primary-ink);
  font-size: 13.5px; line-height: 1.4; text-align: center;
  box-shadow: 0 14px 30px -12px rgba(var(--shadow-rgb), 0.6);
  pointer-events: none;
  animation: toastIn 0.3s cubic-bezier(0.2, 0.8, 0.3, 1);
  transition: opacity 0.25s;
}
.toast.is-leaving { opacity: 0; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, calc(-50% + 8px)); } }

/* ------------------------------------------------------------------ modals */
.modal { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 16px; }
.modal-scrim { position: absolute; inset: 0; background: var(--scrim); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); animation: fade 0.2s ease; }
.modal-card {
  position: relative;
  width: min(540px, 100%);
  max-height: calc(100% - 8px);
  overflow: auto;
  box-sizing: border-box;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 16px;
  box-shadow: 0 40px 90px -30px rgba(var(--shadow-rgb), 0.7);
  --pad-x: 24px;
  --pad-b: 20px;
  padding: 22px var(--pad-x) var(--pad-b);
  animation: rise 0.28s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.modal-narrow { width: min(480px, 100%); }
.modal-small { width: min(400px, 100%); }
.modal-wide { width: min(800px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.modal-head h2, .modal-small h2 { margin: 0; font-family: var(--display); font-weight: 800; font-size: 22px; letter-spacing: 0.01em; }
.modal-x {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 50%; background: transparent; color: var(--ink-2); cursor: pointer;
}
.modal-x:hover { background: var(--paper-2); color: var(--ink); }
.modal-x svg { width: 20px; height: 20px; }
/* The dialog's buttons stay on screen however far the content scrolls. */
.modal-foot {
  position: sticky; bottom: calc(-1 * var(--pad-b)); z-index: 2;
  display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap;
  margin: 20px calc(-1 * var(--pad-x)) calc(-1 * var(--pad-b));
  padding: 14px var(--pad-x) var(--pad-b);
  background: var(--paper);
  border-top: 1px solid var(--rule);
}
.confirm-text { color: var(--ink-2); margin: 8px 0 0; }
.modal-sheet { place-items: end center; padding: 0; }
.sheet {
  width: min(480px, 100%);
  border-radius: 18px 18px 0 0;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  animation: sheetUp 0.28s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.sheet-tall { height: min(70vh, 560px); display: flex; flex-direction: column; padding-top: 16px; }
.sheet-tall .modal-head { padding: 0 8px; margin-bottom: 6px; }
.sheet-tall .history { padding: 0; }
.sheet-item {
  display: flex; align-items: center; gap: 14px;
  width: 100%; height: 50px; padding: 0 14px;
  border: 0; border-radius: 10px;
  background: none; color: var(--ink);
  font-size: 15px; font-weight: 500; text-align: left; cursor: pointer;
}
.sheet-item:hover { background: var(--paper-2); }
.sheet-item svg { width: 20px; height: 20px; color: var(--ink-2); }
.sheet-cancel { justify-content: center; color: var(--ink-2); margin-top: 4px; border-top: 1px solid var(--rule); border-radius: 0 0 10px 10px; }
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

/* new game */
.new-form { display: grid; gap: 18px; }
.field { border: 0; margin: 0; padding: 0; min-width: 0; }
.field legend {
  padding: 0; margin-bottom: 8px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-3);
}
.field-note { margin: 8px 0 0; font-size: 12.5px; color: var(--ink-3); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.seg label, .level { position: relative; display: block; }
.seg input, .level input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.seg span {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 8px;
  border-radius: 10px; border: 1px solid var(--rule);
  background: var(--btn-bg);
  font-weight: 500; font-size: 13.5px; text-align: center;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.seg input:checked + span, .level input:checked + span { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); background: var(--paper); }
.seg input:focus-visible + span, .level input:focus-visible + span { outline: 2px solid var(--gold-hi); outline-offset: 2px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.dot-red { background: var(--red); }
.dot-blue { background: var(--blue); }
.dot-both { background: linear-gradient(90deg, var(--red) 50%, var(--blue) 50%); }
.levels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.level > span {
  display: grid; gap: 3px;
  height: 100%; box-sizing: border-box;
  padding: 11px 12px 10px;
  border: 1px solid var(--rule); border-radius: 12px;
  background: var(--btn-bg);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.level-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.level b { font-family: var(--display); font-weight: 800; font-size: 15.5px; }
.pips { display: inline-flex; gap: 2px; }
.pips i { width: 7px; height: 8px; background: var(--rule); clip-path: polygon(50% 0, 100% 25%, 100% 100%, 0 100%, 0 25%); }
.pips i.on { background: var(--ink); }
.level small { font-size: 12px; color: var(--ink-2); line-height: 1.35; display: block; }
.level .rec { font-size: 11.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; display: block; margin-top: 2px; }
.field[disabled] { opacity: 0.4; }

/* settings */
.settings { display: grid; }
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
}
.switch-row b { display: block; font-weight: 500; font-size: 14px; }
.switch-row small { display: block; color: var(--ink-3); font-size: 12.5px; margin-top: 1px; }
.switch {
  appearance: none; -webkit-appearance: none;
  flex: none; position: relative;
  width: 42px; height: 24px; margin: 0;
  border-radius: 12px;
  background: var(--rule);
  cursor: pointer;
  transition: background 0.2s;
}
.switch::after {
  content: ""; position: absolute; left: 3px; top: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s cubic-bezier(0.3, 0.7, 0.4, 1);
}
.switch:checked { background: var(--switch-on); }
.switch:checked::after { transform: translateX(18px); }
.stats { margin-top: 16px; }
.stats h3 { margin: 0 0 8px; font-size: 11px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-3); }
.stats table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 13px; }
.stats th, .stats td { padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--rule); }
.stats th:first-child, .stats td:first-child { text-align: left; }
.stats th { font-weight: 500; color: var(--ink-3); font-size: 12px; }

/* rules */
.rules { display: grid; gap: 24px; }
.rules h3 { margin: 0 0 8px; font-family: var(--display); font-weight: 800; font-size: 17px; }
.rules p { margin: 0; color: var(--ink-2); max-width: 66ch; }
.rules p + p { margin-top: 8px; }
.rules .lede { font-size: 15.5px; color: var(--ink); line-height: 1.55; }
.glyph-chip {
  display: inline-grid; place-items: center;
  width: 1.5em; height: 1.5em; margin: 0 1px;
  border-radius: 4px;
  background: var(--paper-2); border: 1px solid var(--rule);
  font-family: var(--display); font-weight: 800; font-size: 0.85em;
  vertical-align: 0.05em;
}
.ways { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; }
.way {
  display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: start;
  padding: 14px;
  border: 1px solid var(--rule); border-radius: 12px;
  background: var(--paper-2);
}
.way p { margin: 0; }
.way-kanji { font-family: var(--brush); font-size: 36px; line-height: 1; color: var(--ink) !important; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 6px; color: var(--ink-2); max-width: 66ch; }
.steps li::marker { font-family: var(--display); font-weight: 800; color: var(--ink); }
.rules > .rule > p + .steps, .rules .steps + p { margin-top: 8px; }
.keys { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; color: var(--ink-2); }
kbd {
  display: inline-block;
  font: 600 11.5px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 3px 6px 2px;
  border: 1px solid var(--rule); border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--paper-2); color: var(--ink);
}
.deck { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 12px; }
.deck figure { margin: 0; }
.deck figcaption { margin-top: 6px; font-size: 12px; color: var(--ink-3); text-align: center; }

/* petals */
.petals { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 85; }

/* ------------------------------------------------------------- reduced motion */
.calm *, .calm *::before, .calm *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; animation-delay: 0s !important; }
.calm .tile.is-danger::before { animation: none; opacity: 0.85; }
.calm .mark.is-hint-from::after, .calm .mark.is-hint-to::after { animation: none; box-shadow: 0 0 10px 2px var(--glow); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; animation-delay: 0s !important; }
  .tile.is-danger::before { animation: none; opacity: 0.85; }
}

@media (max-width: 420px) {
  .brand-word { font-size: 16px; letter-spacing: 0.28em; }
  .modal-card { --pad-x: 16px; --pad-b: 16px; padding-top: 18px; }
  .levels { grid-template-columns: 1fr; }
  .tool.icon { width: 36px; }
}

@media (max-width: 385px) {
  .brand { gap: 8px; }
  .brand-word { font-size: 14px; letter-spacing: 0.2em; }
  .tools { gap: 0; }
  .tool.icon { width: 34px; }
}
