/* Henny Penny by Brownfox, SIL Open Font License 1.1 (https://openfontlicense.org).
   Stored in the site so players don't load anything from Google. Used for the casting sayings. */
@font-face {
  font-family: 'Henny Penny';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/HennyPenny-Regular.woff2') format('woff2');
}

:root {
  --bg: #0e1220;
  --bg2: #151b2e;
  --panel: #1b2238;
  --panel2: #232b45;
  --line: #34405f;
  --text: #eef1f8;
  --muted: #9aa5c2;
  --gold: #f5c451;
  --gold-dim: #b8902f;
  --ok: #4fd08a;
  --warn: #f0a742;
  --bad: #ff6b6b;
  --info: #6aa8ff;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 30% -10%, #1f2a4a 0%, var(--bg) 60%) fixed;
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--gold); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .4; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; flex-wrap: wrap; gap: 16px 24px; align-items: center; justify-content: space-between;
  padding: 16px 24px; border-bottom: 1px solid var(--line); background: rgba(14, 18, 32, .7);
  backdrop-filter: blur(6px); position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; gap: 12px; align-items: center; }
.logo {
  display: grid; place-items: center; width: 46px; height: 46px; border-radius: 12px;
  border: 3px solid var(--gold); color: var(--gold); font-weight: 800; font-size: 17px; letter-spacing: -.5px;
}
.brand h1 { margin: 0; font-size: 22px; letter-spacing: .3px; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

.setup { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.setup label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.setup input, .setup select {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-width: 0;
  text-transform: none; letter-spacing: 0; font-size: 15px;
}
.setup input { width: 88px; }

.primary, .actions button, .icon, .setup button {
  border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); padding: 9px 16px; font-weight: 600;
}
.primary, .setup .primary, .actions .primary { background: var(--gold); border-color: var(--gold); color: #1a1405; }
.primary:hover:not(:disabled) { filter: brightness(1.08); }
.icon, .setup .icon {
  width: 40px; height: 40px; padding: 0; font-size: 17px; line-height: 1;
  display: inline-grid; place-items: center;
}
.icon svg { width: 20px; height: 20px; display: block; }
.icon:hover, .actions button:not(.primary):hover { background: var(--line); }

.demo-banner {
  background: #2a2140; border-bottom: 1px solid #4b3a72; color: #d9cdf7; padding: 8px 24px; font-size: 14px;
}

/* ---------- layout ---------- */
.layout {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 24px;
  padding: 24px; max-width: 1240px; width: 100%; margin: 0 auto;
}
@media (max-width: 960px) { .layout { grid-template-columns: 1fr; } }

.footer { color: var(--muted); font-size: 12px; padding: 16px 24px 24px; text-align: center; }

/* ---------- board ---------- */
.board-col { display: flex; flex-direction: column; gap: 20px; align-items: center; }
.board-wrap { position: relative; width: min(100%, 580px); }
.board {
  position: relative; width: 100%; aspect-ratio: 1 / 1.12; border-radius: 24px; /* keep in step with BOARD_ASPECT in rules.js */
  background: linear-gradient(160deg, var(--bg2), #10152a); border: 1px solid var(--line);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .35);
}

/* ---------- casting ---------- */
/* While corner actors are found: a stardust vortex (drawn by js/cosmos.js) inside the box between
   the corners, and one saying in gold. The board and panels behind are blurred (.layout.casting).
   .on fades the vortex in; taking .on away fades it out while the board comes into focus.
   Nothing flashes. */
.cast-stage {
  position: absolute; inset: 0; z-index: 20; border-radius: 24px; overflow: hidden;
  opacity: 0; transition: opacity .7s ease;
}
.cast-stage[hidden] { display: none; }
.cast-stage.on { opacity: 1; transition-duration: .35s; } /* quick in, slow out */
.cast-sky { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.layout .board, .layout .status, .layout .editor { transition: filter .8s ease; }
/* The blur comes in quickly (before the new actors are placed) and goes out slowly. */
.layout.casting .board { filter: blur(9px) brightness(.6); transition-duration: .35s; }
.layout.casting .status, .layout.casting .editor { filter: blur(6px) brightness(.7); pointer-events: none; transition-duration: .35s; }
/* The words sit in the eye of the vortex (--vy is set from the board's layout in app.js), on a
   soft pool of darkness so they read over the center star. */
.cast-words {
  position: absolute; left: 50%; top: var(--vy, 42%); z-index: 1; width: 66%; text-align: center;
  transform: translate(-50%, -50%);
}
.cast-words::before {
  content: ""; position: absolute; inset: -30% -8%; z-index: -1; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(5, 12, 30, .78), rgba(5, 12, 30, .45) 60%, transparent);
}
.cast-kicker {
  margin: 0 0 14px; display: flex; align-items: center; justify-content: center; gap: 14px;
  font: 600 11px/1 system-ui, sans-serif; letter-spacing: .42em; text-indent: .42em; text-transform: uppercase;
  color: rgba(214, 200, 255, .72);
  opacity: 0; transition: opacity .9s ease .2s;
}
.cast-kicker::before, .cast-kicker::after {
  content: ""; width: 40px; height: 1px; background: linear-gradient(90deg, transparent, rgba(245, 196, 81, .75));
}
.cast-kicker::after { transform: scaleX(-1); }
.cast-stage.on .cast-kicker { opacity: 1; }
.cast-line {
  margin: 0; color: #f3d690; text-wrap: balance;
  font-family: 'Henny Penny', "Palatino Linotype", Palatino, Georgia, serif;
  font-size: clamp(19px, 3.8vw, 29px); line-height: 1.3; letter-spacing: .01em;
}
/* The saying arrives letter by letter, each drifting up out of a blur at a slight tilt, then a
   glint of light runs along it every few seconds. app.js wraps each letter in a .ch span. */
.cast-line .w { display: inline-block; white-space: nowrap; }
.cast-line .ch {
  display: inline-block;
  text-shadow: 0 0 14px rgba(245, 196, 81, .35), 0 2px 8px rgba(0, 0, 0, .85);
  animation: ch-in .5s cubic-bezier(.2, .7, .2, 1) both, ch-glint 3s ease-in-out infinite;
  animation-delay: calc(var(--i) * 12ms + 80ms), calc(var(--i) * 25ms + 1.2s);
}
@keyframes ch-in {
  from { opacity: 0; filter: blur(7px); transform: translateY(14px) rotate(var(--r)) scale(.85); }
}
@keyframes ch-glint {
  0%, 72%, 100% { color: #f3d690; }
  80% {
    color: #fffaf0;
    text-shadow: 0 0 10px rgba(255, 246, 220, .95), 0 0 26px rgba(245, 196, 81, .6), 0 2px 8px rgba(0, 0, 0, .85);
  }
}
@media (prefers-reduced-motion: reduce) {
  .cast-line .ch { animation: none; }
}
.lines { position: absolute; inset: 0; width: 100%; height: 100%; }
.ln { stroke: var(--line); stroke-width: 4; vector-effect: non-scaling-stroke; stroke-linecap: round; transition: stroke .2s; }
.ln.building, .ln.checking { stroke: var(--warn); stroke-dasharray: 8 8; }
.ln.broken { stroke: var(--bad); stroke-dasharray: 4 8; }
.ln.complete { stroke: var(--ok); }
.ln.sel { stroke-width: 7; }
.ln.sel.open { stroke: var(--info); }
.hit { stroke: transparent; stroke-width: 26; vector-effect: non-scaling-stroke; cursor: pointer; pointer-events: stroke; }

.badge {
  position: absolute; transform: translate(-50%, -50%); z-index: 3;
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px;
  border: 2px solid var(--line); background: var(--panel); font-size: 13px; font-weight: 700; white-space: nowrap;
}
.badge .bi:empty { display: none; }
.badge.complete { border-color: var(--ok); color: var(--ok); }
.badge.building, .badge.checking { border-color: var(--warn); color: var(--warn); }
.badge.broken { border-color: var(--bad); color: var(--bad); }
.badge.sel { box-shadow: 0 0 0 4px rgba(106, 168, 255, .45); }

.xmark {
  position: absolute; transform: translate(-50%, -20px); z-index: 4; /* centre the icon, not the caption, on the crossing */
  display: flex; flex-direction: column; align-items: center; gap: 4px; max-width: 26%;
  text-align: center; font-size: 12px; color: var(--muted); pointer-events: none;
}
.xmark .xicon {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%;
  border: 2px dashed var(--line); background: var(--bg2); font-size: 18px;
}
.xmark.ok { color: var(--gold); font-weight: 700; }
.xmark.ok .av { box-shadow: 0 0 0 3px var(--gold); }

.bcorner {
  position: absolute; transform: translate(-50%, -38px); z-index: 5; width: 132px;
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px;
}
/* A newly cast corner drifts out from the middle of the box to its place, growing and fading in,
   one corner after another. --dx/--dy (the start offset) and --k (its order) come from app.js.
   It uses the separate translate/scale properties so it doesn't disturb the corner's transform. */
.bcorner.arrive { animation: corner-arrive 1.8s cubic-bezier(.2, .7, .2, 1) both; animation-delay: calc(var(--k) * .25s); }
@keyframes corner-arrive {
  from { opacity: 0; translate: var(--dx) var(--dy); scale: .4; filter: blur(4px); }
  60% { opacity: 1; filter: none; }
}
@media (prefers-reduced-motion: reduce) {
  .bcorner.arrive { animation-name: corner-fade; }
  @keyframes corner-fade { from { opacity: 0; } }
}
.bcorner .cname { font-weight: 700; font-size: 14px; line-height: 1.2; text-shadow: 0 1px 4px #000; }
.bcorner .cknown { font-size: 11px; color: var(--muted); line-height: 1.2; }
.bcorner .reroll {
  position: absolute; top: -4px; right: 18px; width: 26px; height: 26px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--panel2); font-size: 14px; line-height: 1; padding: 0;
  opacity: 0; transition: opacity .15s;
}
.bcorner:hover .reroll, .bcorner .reroll:focus-visible { opacity: 1; }
@media (hover: none) { .bcorner .reroll { opacity: 1; } }

.empty {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 40px; gap: 6px;
}
.empty h2 { margin: 0; }
.empty p { color: var(--muted); max-width: 380px; }
.empty .big-x { font-size: 64px; color: var(--gold); line-height: 1; margin-bottom: 8px; }

/* ---------- avatars ---------- */
.av {
  width: 44px; height: 44px; border-radius: 50%; object-fit: cover; flex: none; background: var(--panel2);
  display: inline-grid; place-items: center; font-weight: 700; font-size: 15px; color: var(--muted);
}
.av.lg { width: 76px; height: 76px; font-size: 24px; border: 3px solid var(--gold); box-shadow: 0 6px 20px rgba(0, 0, 0, .5); }
.av.sm { width: 34px; height: 34px; font-size: 12px; }
.av.xs { width: 22px; height: 22px; font-size: 9px; }

/* ---------- status ---------- */
.status { width: min(100%, 580px); }
/* On wide screens, also keep the whole board within the window's height. */
@media (min-width: 961px) {
  .board-wrap, .status { width: min(100%, 580px, max(440px, calc((100vh - 140px) / 1.12))); }
}
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.stats > div { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.result-btn { display: block; width: 100%; margin: 0 0 12px; padding: 11px 14px; font-size: 15px; }
.stats .k { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.stats b { font-size: 22px; font-variant-numeric: tabular-nums; }
.checklist { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
.checklist button {
  width: 100%; display: flex; align-items: center; gap: 8px; text-align: left; padding: 8px 12px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--panel); font-size: 14px;
}
.checklist button:hover { background: var(--panel2); }
.checklist em { margin-left: auto; font-style: normal; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55%; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); flex: none; }
.complete .dot { background: var(--ok); }
.building .dot, .checking .dot { background: var(--warn); }
.broken .dot { background: var(--bad); }

/* ---------- editor ---------- */
.editor {
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 18px;
  align-self: start; position: sticky; top: 100px; max-height: calc(100vh - 120px); overflow: auto;
}
.editor:focus { outline: none; }
.side-head { display: flex; align-items: center; gap: 10px; }
.side-head .side-title { flex: 1; min-width: 0; }
.drawer-close, .drawer-shade { display: none; }
/* Narrow screens: the editor is a panel that slides in from the right over the page, so the page
   underneath never moves. Picking a side opens it (openDrawer in app.js); ✕, a tap on the dimmed
   page or Esc closes it. */
@media (max-width: 960px) {
  .layout .editor {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 50; width: min(440px, calc(100vw - 40px));
    max-height: none; align-self: stretch; overflow-y: auto; overscroll-behavior: contain;
    border-radius: 20px 0 0 20px; border-right: 0; box-shadow: -18px 0 50px rgba(0, 0, 0, .5);
    transform: translateX(105%); visibility: hidden;
    transition: transform .3s cubic-bezier(.3, .7, .2, 1), visibility 0s .3s, filter .8s ease;
  }
  .layout .editor.open { transform: none; visibility: visible; transition: transform .3s cubic-bezier(.3, .7, .2, 1), filter .8s ease; }
  .drawer-shade {
    display: block; position: fixed; inset: 0; z-index: 49; background: rgba(5, 8, 16, .6);
    opacity: 0; pointer-events: none; transition: opacity .3s ease;
  }
  .drawer-shade.on { opacity: 1; pointer-events: auto; }
  body.drawer-open { overflow: hidden; }
  /* The side's name and ✕ stay at the top while the panel scrolls. */
  .side-head { position: sticky; top: -18px; z-index: 2; background: var(--panel); margin: 0 -18px; padding: 0 18px; }
  .drawer-close {
    display: inline-flex; align-items: center; justify-content: center; flex: none; width: 36px; height: 36px;
    border-radius: 50%; border: 1px solid var(--line); background: transparent; color: var(--text); font-size: 16px; cursor: pointer;
  }
}
@media (max-width: 960px) and (prefers-reduced-motion: reduce) {
  .layout .editor, .layout .editor.open, .drawer-shade { transition: none; }
}
/* All six sides on one row: four words, then the two diagonals as small box pictures. */
.tabs { display: grid; grid-template-columns: repeat(4, 1fr) auto auto; gap: 6px; margin-bottom: 14px; }
.tabs button {
  border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 4px 8px; font-size: 12px; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; min-height: 28px;
}
.tabs button .side-ic { width: 18px; height: 18px; margin: 0 4px; }
.side-ic { flex: none; }
.side-ic line { stroke: currentColor; stroke-linecap: round; }
.side-ic .faint { stroke-width: 1.2; opacity: .3; }
.side-ic .bold { stroke-width: 2.6; }
.side-title { display: flex; align-items: center; gap: 10px; }
.side-title .side-ic { width: 24px; height: 24px; color: var(--gold); }
.tabs button.on { background: var(--info); border-color: var(--info); color: #071226; font-weight: 700; }
.tabs button.complete:not(.on) { border-color: var(--ok); color: var(--ok); }
.editor h2 { margin: 0 0 2px; font-size: 20px; }
.summary { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.summary .st { font-weight: 700; }
.summary .st.complete { color: var(--ok); }
.summary .st.building, .summary .st.checking { color: var(--warn); }
.summary .st.broken { color: var(--bad); }

.chain { list-style: none; margin: 0; padding: 0; }
.chain .actor {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px;
  background: var(--panel2); border: 1px solid transparent;
}
.chain .actor.corner { border-color: var(--gold-dim); }
.chain .actor.shared { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(245, 196, 81, .25); }
.who { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.who b { font-size: 15px; }
.who small { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actor.shared .who small { color: var(--gold); }
.tools { display: flex; gap: 4px; }
.tools button { width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--line); background: transparent; padding: 0; font-size: 13px; }
.tools button:hover:not(:disabled) { background: var(--line); }

.chain .link {
  display: flex; align-items: center; gap: 8px; margin-left: 30px; padding: 8px 0 8px 18px;
  border-left: 2px solid var(--line); font-size: 13px; color: var(--muted); min-height: 38px;
}
.chain .link.ok { border-left-color: var(--ok); color: var(--text); }
.chain .link.none { border-left: 2px dashed var(--warn); color: var(--warn); }
.chain .link.error { color: var(--bad); }
.chain .link.pending { border-left-style: dotted; }
.li-ic { width: 18px; text-align: center; flex: none; }
.more { color: var(--muted); text-decoration: underline dotted; cursor: help; }
.linklike { background: none; border: none; color: var(--gold); text-decoration: underline; padding: 0; }

.adder { position: relative; margin: 8px 0 0 30px; padding-left: 18px; border-left: 2px dashed var(--line); }
.adder input {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg2); font-size: 14px;
}
.adder input:focus { outline: 2px solid var(--info); border-color: transparent; }
.adder .full { color: var(--muted); font-size: 13px; padding: 6px 0; margin: 0; }
.results {
  position: absolute; left: 18px; right: 0; top: calc(100% + 4px); z-index: 30; list-style: none; margin: 0; padding: 6px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 16px 40px rgba(0, 0, 0, .5);
  max-height: 320px; overflow: auto;
}
.results li { display: flex; gap: 10px; align-items: center; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.results li div { display: flex; flex-direction: column; min-width: 0; }
.results li small { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results li.active, .results li:hover { background: var(--panel2); }
.results li.none { color: var(--muted); cursor: default; }

.cross { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.cross h3 { margin: 0 0 4px; font-size: 15px; }
.cross p { margin: 0 0 10px; font-size: 13px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel2); padding: 3px 10px 3px 3px; font-size: 13px;
}
.chip.on { border-color: var(--gold); color: var(--gold); }
.chip:hover:not(:disabled) { background: var(--line); }

.ed-empty h2 { margin-top: 0; }

/* ---------- dialogs ---------- */
dialog {
  border: 1px solid var(--line); border-radius: 18px; background: var(--panel); color: var(--text);
  padding: 0; max-width: min(520px, calc(100vw - 32px)); width: 100%;
}
dialog::backdrop { background: rgba(5, 8, 16, .7); }
.dlg { padding: 22px 24px; }
.dlg h2 { margin: 0 0 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.field input { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg2); }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0 14px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; margin: 10px 0; }
.check input { margin-top: 3px; }
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
#confirmDlg { max-width: min(440px, calc(100vw - 32px)); }
.confirm-body p { margin: 0 0 10px; line-height: 1.5; color: var(--muted); }
.confirm-body p:first-child { color: var(--text); }
.rules { padding-left: 20px; line-height: 1.5; }
.rules li { margin-bottom: 8px; }
.tour-btn {
  border-radius: 10px; border: 1px solid var(--gold-dim); background: transparent; color: var(--gold);
  padding: 9px 14px; font-weight: 600;
}
.tour-btn:hover { background: rgba(245, 196, 81, .08); }

/* ---------- how to play: one rule at a time, with a picture (js/tutorial.js) ---------- */
.tour-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.tour-count { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.tour-copy { min-height: 118px; }
.tour-copy h3 { margin: 16px 0 6px; font-size: 18px; color: var(--gold); }
.tour-copy p { margin: 0; line-height: 1.5; color: var(--text); }
.tour-dots { display: flex; justify-content: center; gap: 8px; margin-top: 12px; }
.tour-dots button { width: 9px; height: 9px; padding: 0; border-radius: 50%; border: 0; background: var(--line); }
.tour-dots button[aria-current="step"] { background: var(--gold); width: 22px; border-radius: 999px; }
.tour-actions { align-items: center; margin-top: 16px; }
.tour-actions .tour-skip { margin-right: auto; background: transparent; border-color: transparent; color: var(--muted); }
.tour-actions .tour-skip:hover { background: transparent; color: var(--text); }
@media (max-width: 560px) { .tour { padding: 18px; } }

/* The picture: a 320 × 250 grid (see tutorial.js). --u is one grid unit. */
.tour-stage {
  --u: calc(100cqw / 320);
  position: relative; aspect-ratio: 320 / 250; container-type: inline-size; overflow: hidden;
  border-radius: 16px; border: 1px solid var(--line); background: linear-gradient(160deg, var(--bg2), #10152a);
  transition: opacity .5s ease; touch-action: pan-y; user-select: none;
}
.tour-stage.fade { opacity: 0; }
.tour-stage.still, .tour-stage.still * { transition: none !important; animation: none !important; }
.t-svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.t-ln {
  fill: none; stroke: var(--line); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round;
  transition: stroke .4s, stroke-dashoffset .7s ease, opacity 0s;
}
.t-ln.slow { transition-duration: .4s, 1s, 0s; }
.t-ln.drawable { stroke-dasharray: 1 2; stroke-dashoffset: 1; }
.t-ln.drawable:not(.drawn) { opacity: 0; transition-delay: 0s, 0s, .7s; }
.t-ln.drawable.drawn { stroke-dashoffset: 0; }
.t-ln.faint { opacity: .5; }
.t-ln.sel { stroke: var(--info); stroke-width: 4; }
.t-ln.ok, .t-ln.link { stroke: var(--ok); }
.t-ln.link { stroke-width: 4; }
.t-ln.gold { stroke: var(--gold); }

.t-actor, .t-tag, .t-pill, .t-pips {
  position: absolute; left: calc(var(--x) * 100% / 320); top: calc(var(--y) * 100% / 250); translate: -50% -50%;
}
.t-actor {
  width: calc(var(--u) * 24); height: calc(var(--u) * 24); border-radius: 50%; z-index: 1;
  display: grid; place-items: center; background: var(--panel2); border: calc(var(--u) * 1.5) solid var(--line);
  font-weight: 700; font-size: calc(var(--u) * 8.5); color: var(--muted);
  transition: left .9s cubic-bezier(.4, 0, .2, 1), top .9s cubic-bezier(.4, 0, .2, 1), opacity .4s, scale .4s cubic-bezier(.3, 1.4, .5, 1),
    border-color .3s, box-shadow .3s, color .3s;
}
.t-actor.corner {
  width: calc(var(--u) * 36); height: calc(var(--u) * 36); border: calc(var(--u) * 2.5) solid var(--gold);
  font-size: calc(var(--u) * 11); color: var(--text); box-shadow: 0 4px 12px rgba(0, 0, 0, .5);
}
.t-name {
  position: absolute; top: 100%; left: 50%; translate: -50% 0; margin-top: calc(var(--u) * 3); white-space: nowrap;
  font-size: calc(var(--u) * 10); font-weight: 700; color: var(--text); text-shadow: 0 1px 3px #000, 0 0 6px #000;
}
.t-actor:not(.corner) .t-name { font-size: calc(var(--u) * 9); font-weight: 600; color: var(--muted); }
.t-actor.pre { opacity: 0; scale: .3; }
.t-actor.gone { opacity: 0; scale: .5; }
.t-actor.ok { border-color: var(--ok); }
.t-actor.x {
  border-color: var(--gold); color: var(--gold);
  box-shadow: 0 0 0 calc(var(--u) * 3) rgba(245, 196, 81, .3), 0 0 calc(var(--u) * 14) rgba(245, 196, 81, .6);
}
.t-actor.ghost { border-style: dashed; border-color: var(--info); color: var(--info); z-index: 2; }
.t-actor.no { border-color: var(--bad); color: var(--bad); animation: t-shake .45s ease; }
.t-actor.no::after {
  content: "✕"; position: absolute; top: calc(var(--u) * -6); right: calc(var(--u) * -6);
  width: calc(var(--u) * 12); height: calc(var(--u) * 12); border-radius: 50%; display: grid; place-items: center;
  background: var(--bad); color: #2a0707; font-size: calc(var(--u) * 7);
}
@keyframes t-shake { 20%, 60% { transform: translateX(calc(var(--u) * -4)); } 40%, 80% { transform: translateX(calc(var(--u) * 4)); } }

.t-tag {
  z-index: 3; white-space: nowrap; padding: calc(var(--u) * 3) calc(var(--u) * 9); border-radius: 999px;
  background: var(--panel); border: calc(var(--u) * 1.5) solid var(--line); box-shadow: 0 4px 14px rgba(0, 0, 0, .45);
  font-size: calc(var(--u) * 10.5); font-weight: 600; transition: opacity .35s, scale .35s;
}
.t-tag.pre { opacity: 0; scale: .85; }
.t-tag.ok { border-color: var(--ok); color: var(--ok); }
.t-tag.warn { border-color: var(--warn); color: var(--warn); }
.t-tag.bad { border-color: var(--bad); color: var(--bad); }
.t-tag.gold { border-color: var(--gold); color: var(--gold); }
.t-tag.info { border-color: var(--info); color: var(--info); }
.t-tag.q { padding: 0; width: calc(var(--u) * 16); height: calc(var(--u) * 16); display: grid; place-items: center; font-weight: 800; }

.t-pill {
  z-index: 3; white-space: nowrap; padding: calc(var(--u) * 6) calc(var(--u) * 16); border-radius: calc(var(--u) * 8);
  background: var(--gold); color: #1a1405; font-size: calc(var(--u) * 10.5); font-weight: 700;
  transition: opacity .35s, scale .35s;
}
.t-pill.alt { background: var(--panel2); color: var(--text); border: calc(var(--u) * 1.5) solid var(--line); }
.t-pill.press { animation: t-press .35s ease; }
.t-pill.gone { opacity: 0; scale: .85; }
@keyframes t-press { 40% { scale: .9; filter: brightness(1.25); } }

.t-pips {
  z-index: 3; display: flex; align-items: center; gap: calc(var(--u) * 4); white-space: nowrap;
  font-size: calc(var(--u) * 9); text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
}
.t-pips span { margin-right: calc(var(--u) * 3); }
.t-pips i {
  width: calc(var(--u) * 8); height: calc(var(--u) * 8); border-radius: 50%;
  border: calc(var(--u) * 1.5) solid var(--gold-dim); transition: background .3s, border-color .3s;
}
.t-pips i.on { background: var(--gold); border-color: var(--gold); }
.t-pips.press { animation: t-press .5s ease 2; }
.win { text-align: center; }
.win-mark {
  width: 64px; height: 64px; border-radius: 50%; margin: 0 auto 8px; display: grid; place-items: center;
  background: var(--ok); color: #062814; font-size: 34px; font-weight: 800;
}
.win .actions { justify-content: center; }
.win-stats { display: flex; justify-content: center; gap: 28px; margin: 8px 0 14px; }
.win-stats b { display: block; font-size: 28px; }
.win-stats span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.win p { color: var(--muted); font-size: 14px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  background: #2b3450; border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5); font-size: 14px; max-width: calc(100vw - 32px);
}

@media (max-width: 560px) {
  .topbar { padding: 12px 14px; }
  .layout { padding: 14px; }
  .bcorner { width: 92px; transform: translate(-50%, -28px); }
  .av.lg { width: 56px; height: 56px; font-size: 18px; }
  .bcorner .cname { font-size: 12px; }
  .bcorner .cknown { display: none; }
  .bcorner .reroll { right: 6px; }
  .badge { font-size: 11px; padding: 2px 7px; }
  .xmark span:not(.xicon) { display: none; }
}

/* ---------- checks & attempts ---------- */
.ln.drafted { stroke: var(--muted); stroke-dasharray: 6 7; }
.drafted .dot { background: var(--muted); }
.tabs button.broken:not(.on) { border-color: var(--bad); color: var(--bad); }

.chain .link.blank { min-height: 18px; padding: 0; border-left-style: dashed; }

.pips { display: inline-flex; gap: 5px; vertical-align: middle; }
.pips i { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--gold-dim); }
.pips i.on { background: var(--gold); border-color: var(--gold); }
.stats .pips { margin-top: 8px; }
.stats .pips i { width: 15px; height: 15px; }
.stats b.lost { color: var(--bad); font-size: 18px; }

.checkbar { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.check-btn { width: 100%; padding: 11px 16px; font-size: 15px; }
.check-note { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }

.feedback { margin-top: 14px; padding: 10px 12px; border-radius: 12px; font-size: 14px; border: 1px solid; }
.feedback small { display: block; margin-top: 2px; color: var(--muted); }
.feedback.miss { border-color: var(--warn); color: var(--warn); background: rgba(240, 167, 66, .08); }
.feedback.ok { border-color: var(--ok); color: var(--ok); background: rgba(79, 208, 138, .08); }
.feedback.bad { border-color: var(--bad); color: var(--bad); background: rgba(255, 107, 107, .08); }

.xmark.draft { opacity: .65; }
.win-mark.lost { background: var(--bad); color: #2a0707; }
.grid {
  display: inline-block; text-align: left; margin: 0 auto 6px; padding: 10px 14px; border-radius: 10px;
  background: var(--bg2); border: 1px solid var(--line); font: 14px/1.5 ui-monospace, Consolas, monospace;
}
.check-note.warn { color: var(--warn); }

/* ---------- check history ---------- */
.tries { margin-top: 16px; }
.tries h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.tries ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.tries li {
  display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: center;
  padding: 7px 10px; border-radius: 10px; background: var(--bg2); border-left: 4px solid; font-size: 13px;
}
.tries li.miss { border-left-color: var(--bad); }
.tries li.hit { border-left-color: var(--ok); }
.try-n { color: var(--muted); font-variant-numeric: tabular-nums; text-align: center; }
.try-chain { line-height: 1.4; }
.try-chain .arr { color: var(--muted); }
.try-corner { color: var(--muted); font-style: italic; }
.tries-hint { margin: -2px 0 8px; font-size: 12px; line-height: 1.4; color: var(--muted); }
.try-res { font-weight: 700; white-space: nowrap; font-size: 12px; }
.tries li.miss .try-res { color: var(--bad); }
.tries li.hit .try-res { color: var(--ok); }
.tools .lock { width: 28px; height: 28px; display: inline-grid; place-items: center; font-size: 13px; opacity: .8; }

/* ---------- reopening a solved side ---------- */
.reopenbar { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.reopenbar button {
  align-self: flex-start; border-radius: 10px; border: 1px solid var(--line); background: transparent;
  padding: 8px 14px; font-weight: 600; font-size: 14px;
}
.reopenbar button:hover:not(:disabled) { background: var(--panel2); }
.reopenbar small { color: var(--muted); font-size: 12px; }
.tries li.reopen { border-left-color: var(--info); color: var(--info); }
