/* Ringtrace (rework v1): the loop board is the hero.
   Phone = one column (header, mode row, meter, board, readout, actions); desktop and landscape put the
   board on the left and the controls in a side column. The visual language is a midnight loom plate:
   faint edge slots show every legal segment, a traced line is warm gold thread with a soft glow, an
   exclusion is a slate ×, a satisfied clue plate turns mint, and a broken rule is painted coral with a
   glyph plus a sentence, never colour alone. */
:root{
  color-scheme:dark;
  --bg:#080d21;--bg-2:#0c1430;--panel:#111a3a;--panel-2:#17234c;--line:#26335f;--line-strong:#3c5088;
  --ink:#eef1ff;--muted:#aab6da;--accent:#ffc46b;--accent-ink:#2a1700;
  --loop:#ffe1a4;--loop-core:#fff8e6;--exclude:#7d89b5;--ok:#6ff0c0;--ok-deep:#0f3f31;
  --danger:#ff9086;--hint:#b8a3ff;--gold:#ffc46b;
  --radius:16px;--trace-ms:220ms;--wave-ms:900ms;--shake-ms:320ms;
  font-family:"Segoe UI",system-ui,-apple-system,"Helvetica Neue",Arial,sans-serif;
}
*{box-sizing:border-box}
[hidden]{display:none!important}
html,body{margin:0;min-height:100%;background:radial-gradient(120% 80% at 50% -12%,#16224f 0,var(--bg) 56%,#05081a 100%) fixed;color:var(--ink);overflow-x:hidden}
body{min-height:100svh;-webkit-font-smoothing:antialiased;position:relative}
/* Decorative catalog art is bound through CSS only; gameplay never depends on it. */
body::before{content:"";position:fixed;inset:0;z-index:-1;pointer-events:none;background:url("assets/shared/ambient-backdrop.png") center/cover no-repeat;opacity:.22;mix-blend-mode:screen}
button,select,input{font:inherit;color:inherit}
button{cursor:pointer;touch-action:manipulation}
button:disabled{cursor:default}
:focus-visible{outline:3px solid var(--gold);outline-offset:2px}
.sr-only{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}

/* ---------- shell ---------- */
.app{
  display:grid;grid-template-columns:minmax(0,1fr);
  grid-template-areas:"top" "hud" "meter" "stage" "readout" "actions" "legend";
  grid-template-rows:auto auto auto minmax(0,1fr) auto auto auto;
  align-content:stretch;gap:8px;max-width:640px;margin:0 auto;height:100vh;height:100svh;min-height:0;
  padding:max(8px,env(safe-area-inset-top)) max(10px,env(safe-area-inset-right)) max(10px,env(safe-area-inset-bottom)) max(10px,env(safe-area-inset-left));
}
.topbar{grid-area:top;display:flex;align-items:center;justify-content:space-between;gap:8px;min-height:48px}
.brand{display:flex;align-items:center;gap:10px;min-width:0}
.brand-mark{position:relative;flex:none;display:grid;place-items:center;width:32px;height:32px;border-radius:50%;border:2px solid var(--accent);background:url("assets/shared/loop-emblem.png") center/22px 22px no-repeat;box-shadow:inset 0 0 12px rgba(255,196,107,.28)}
.brand-mark i{width:6px;height:6px;border-radius:50%;background:var(--accent);opacity:.8}
.brand-name{margin:0;font-size:22px;font-weight:800;letter-spacing:-.02em;white-space:nowrap}
.brand-name em{font-style:normal;color:var(--accent)}
.utilities{display:flex;gap:4px;flex:none}
.icon-btn{display:grid;place-items:center;width:44px;height:44px;border-radius:12px;border:1px solid var(--line);background:rgba(17,26,58,.86);padding:0;transition:background .15s ease,border-color .15s ease,color .15s ease}
.icon-btn:hover{border-color:var(--line-strong);background:var(--panel-2)}
.icon-glyph{font-size:20px;font-weight:800;line-height:1}
.mute-button[aria-pressed="true"]{border-color:var(--danger);color:var(--danger);background:rgba(255,144,134,.13)}

/* ---------- mode row + meter ---------- */
.hud{grid-area:hud;display:flex;align-items:center;gap:8px;min-height:44px}
.mode-switch{display:flex;flex:none;padding:3px;border-radius:14px;background:rgba(6,11,30,.85);border:1px solid var(--line)}
.mode-switch button{min-width:70px;min-height:44px;padding:0 14px;border:0;border-radius:11px;background:transparent;font-size:16px;font-weight:700;color:var(--muted)}
.mode-switch button[aria-pressed="true"]{background:var(--accent);color:var(--accent-ink);box-shadow:0 2px 12px rgba(255,196,107,.25)}
.context-chip{display:flex;flex-direction:column;justify-content:center;margin:0 0 0 auto;min-height:44px;text-align:right;line-height:1.15;min-width:0}
.context-chip strong{font-size:16px;white-space:nowrap}
.context-chip span{font-size:14px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:clip}
.tier-select{margin-left:auto;display:flex;min-width:0}
.tier-select select{min-height:44px;max-width:170px;padding:0 10px;border-radius:12px;border:1px solid var(--line-strong);background:var(--panel);font-size:16px;font-weight:600}
.meter{grid-area:meter;display:flex;align-items:center;gap:10px;min-height:26px;font-size:14px;color:var(--muted)}
.meter-count{font-size:16px;font-weight:700;color:var(--ink);white-space:nowrap;font-variant-numeric:tabular-nums}
.progress-track{position:relative;flex:1;min-width:36px;height:8px;border-radius:999px;background:rgba(255,255,255,.09);overflow:hidden}
.progress-fill{position:absolute;inset:0 auto 0 0;width:0;border-radius:inherit;background:linear-gradient(90deg,var(--accent),var(--ok));transition:width .24s ease}
.meter-edges{white-space:nowrap;font-variant-numeric:tabular-nums}
.meter-time{white-space:nowrap;font-variant-numeric:tabular-nums;font-size:14px}
.assist-chip{padding:1px 8px;border-radius:999px;border:1px solid var(--hint);color:var(--hint);font-weight:700;white-space:nowrap}
.meter[data-complete="true"] .meter-count{color:var(--ok);font-weight:800}

/* ---------- board ---------- */
/* The stage is a size container: the board takes the largest square that fits the space left by the
   chrome, so the actions below it never leave a phone screen. */
.stage{grid-area:stage;display:flex;justify-content:center;align-items:center;min-width:0;min-height:0;container-type:size;position:relative}
.board-wrap{
  --cols:5;--rows:5;position:relative;container-type:inline-size;
  /* Sized from the viewport, never from sibling content: a longer feedback sentence must not resize or
     shift the board mid-gesture. The 360px budget is the phone chrome (header, mode, meter, readout,
     actions, gaps and safe-area padding). */
  width:min(calc(100cqw - 10px),calc(100svh - 360px),680px);
  aspect-ratio:var(--cols)/var(--rows);
  border-radius:22px;border:2px solid var(--line-strong);
  background:
    radial-gradient(circle at 50% 42%,rgba(94,126,255,.16),transparent 58%),
    linear-gradient(160deg,#0e1738,#0a1029 55%,#080d22);
  box-shadow:0 20px 44px rgba(0,0,0,.42),inset 0 0 0 1px rgba(255,255,255,.045),inset 0 0 46px rgba(0,0,0,.34);
  touch-action:none;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none;
}
.board-wrap::before{
  content:"";position:absolute;inset:6px;border-radius:16px;pointer-events:none;
  border:1px dashed rgba(122,146,238,.16);
}
.board-grid{position:absolute;inset:0;border-radius:20px;outline-offset:4px}
.board-grid[data-ambiguous="true"]{cursor:crosshair}
.board-svg{position:absolute;inset:0;display:block;width:100%;height:100%;overflow:visible;pointer-events:none}

/* Every legal edge shows as a faint slot so the grid is legible before the first tap. */
.edge-visual .edge-slot{stroke:#1d2a56;stroke-width:9;stroke-linecap:round}
.edge-visual .edge-line{stroke:var(--loop);stroke-width:14;stroke-linecap:round;opacity:0;filter:drop-shadow(0 0 6px rgba(255,209,120,.55))}
.edge-visual .edge-line-core{stroke:var(--loop-core);stroke-width:5;stroke-linecap:round;opacity:0}
.edge-visual .edge-x{stroke:var(--exclude);stroke-width:6;stroke-linecap:round;opacity:0}
.edge-visual .edge-halo{stroke:var(--accent);stroke-width:16;stroke-linecap:round;opacity:0}
.edge-visual.is-line .edge-slot{stroke:#2a2450}
.edge-visual.is-line .edge-line{opacity:1}
.edge-visual.is-line .edge-line-core{opacity:.9}
.edge-visual.is-excluded .edge-slot{stroke:#161f42;stroke-dasharray:2 11}
.edge-visual.is-excluded .edge-x{opacity:.95}
.edge-visual.is-new .edge-line,.edge-visual.is-new .edge-line-core{animation:trace-in var(--trace-ms) ease-out both}
.edge-visual.is-preview .edge-halo{opacity:.34}
.edge-visual.is-cursor .edge-halo{opacity:.55;stroke-dasharray:4 8}
.edge-visual.is-ambiguous .edge-halo{stroke:var(--hint);opacity:.5;stroke-dasharray:8 8}
.edge-visual.is-nudge-evidence .edge-slot{stroke:var(--hint);opacity:.9}
.edge-visual.is-nudge-target .edge-halo{stroke:var(--hint);opacity:.85;stroke-dasharray:6 7}
.edge-visual.is-conflict .edge-slot{stroke:var(--danger);opacity:.92}
.edge-visual.is-conflict .edge-halo{stroke:var(--danger);stroke-width:21;opacity:.5;stroke-dasharray:none}
.edge-visual.is-wave .edge-line{animation:trace-wave var(--wave-ms) ease-out both;animation-delay:var(--wave-delay,0ms)}
.edge-visual.is-wave .edge-line-core{animation:trace-wave-core var(--wave-ms) ease-out both;animation-delay:var(--wave-delay,0ms)}
.vertex-dot{fill:#41528c;opacity:.75}
.vertex-dot.is-join{fill:var(--loop);opacity:1}
.vertex-dot.is-conflict{fill:var(--danger);opacity:1}
.clue-plate{fill:rgba(26,37,78,.96);stroke:#33437a;stroke-width:2}
.clue{fill:#e8edff;font-size:40px;font-weight:800;text-anchor:middle;dominant-baseline:central;font-variant-numeric:tabular-nums}
.clue-cell.is-satisfied .clue-plate{fill:rgba(21,74,58,.96);stroke:var(--ok)}
.clue-cell.is-satisfied .clue{fill:#c9ffe9}
.clue-cell.is-conflict .clue-plate{fill:rgba(88,26,28,.96);stroke:var(--danger)}
.clue-cell.is-conflict .clue{fill:#ffd9d4}
.clue-cell{transition:opacity .2s ease}

.won-stamp{
  position:absolute;left:50%;top:50%;z-index:4;margin:0;transform:translate(-50%,-50%) scale(.86);
  display:flex;align-items:center;gap:8px;padding:10px 18px;border-radius:999px;
  border:2px solid var(--ok);background:rgba(6,32,26,.94);color:#d8fff0;
  font-size:16px;font-weight:800;letter-spacing:.03em;text-transform:lowercase;
  box-shadow:0 12px 34px rgba(0,0,0,.55),0 0 0 6px rgba(111,240,192,.12);
  opacity:0;pointer-events:none;animation:stamp-in 520ms cubic-bezier(.2,.9,.3,1.15) 240ms both;
}
.won-stamp span{font-size:20px;line-height:1}
.board-wrap[data-complete="true"]{border-color:var(--ok);box-shadow:0 0 0 3px rgba(111,240,192,.24),0 20px 44px rgba(0,0,0,.42),inset 0 0 60px rgba(111,240,192,.09)}
.board-wrap::after{content:"";position:absolute;inset:0;z-index:2;border-radius:inherit;pointer-events:none;background:url("assets/shared/loop-glow-accent.png") center/contain no-repeat;opacity:0;mix-blend-mode:screen;transition:opacity .45s ease}
.board-wrap[data-complete="true"]::after{opacity:.4}
.board-wrap[data-complete="true"]::before{border-color:rgba(111,240,192,.35)}
.board-wrap.is-refused{animation:refuse var(--shake-ms) ease-in-out}

.empty-state{display:grid;justify-items:center;gap:10px;padding:20px;text-align:center;border-radius:18px;border:1px dashed var(--line-strong);background:rgba(255,255,255,.03);font-size:16px}
.empty-state span{color:var(--muted);font-size:14px}

/* ---------- readout ---------- */
.readout{grid-area:readout;display:grid;gap:2px;align-content:center;min-height:96px;padding:6px 12px;border-radius:14px;border:1px solid var(--line);background:rgba(9,15,36,.62);text-align:center}
.status-headline{display:flex;align-items:center;justify-content:center;gap:8px;margin:0;font-size:16px;font-weight:700;line-height:1.3}
.status-glyph{display:grid;place-items:center;flex:none;width:24px;height:24px;border-radius:8px;background:rgba(255,255,255,.07);font-size:15px;line-height:1}
.status-detail{margin:0;font-size:14px;line-height:1.35;color:var(--muted);min-height:19px}
.readout[data-tone="error"]{border-color:var(--danger);background:rgba(58,14,20,.6)}
.readout[data-tone="error"] .status-glyph{background:rgba(255,144,134,.2);color:#ffd9d4}
.readout[data-tone="error"] .status-headline{color:#ffd9d4}
.readout[data-tone="success"] .status-glyph{background:rgba(111,240,192,.16);color:#c9ffe9}
.readout[data-tone="hint"]{border-color:var(--hint)}
.readout[data-tone="hint"] .status-glyph{background:rgba(184,163,255,.2);color:#e2d9ff}
.link-btn{justify-self:center;min-height:44px;margin-top:2px;padding:0 14px;border-radius:10px;border:1px solid var(--line-strong);background:rgba(255,255,255,.05);font-size:16px;font-weight:600;color:#e2d9ff}

/* ---------- result ---------- */
/* The closed board stays visible: the card sits under it on phones that have room, or as a bottom
   sheet on short phones and landscape. */
.result-card{grid-area:readout;position:relative;z-index:6;display:grid;gap:6px;padding:12px 14px 14px;border-radius:18px;background:rgba(8,20,34,.97);border:2px solid var(--ok);box-shadow:0 18px 40px rgba(0,0,0,.5);text-align:center;animation:card-in 360ms cubic-bezier(.2,.9,.3,1.1) both}
.result-kicker{font-size:14px;color:var(--muted);font-weight:600}
.result-title{margin:0;font-size:26px;line-height:1.1;font-weight:800;color:var(--ok)}
.result-detail{margin:0;font-size:16px;line-height:1.3}
.result-stats{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:6px}
.result-stat{display:grid;gap:2px;padding:6px 4px;border-radius:10px;background:rgba(255,255,255,.06)}
.result-stat strong{font-size:18px;font-variant-numeric:tabular-nums}
.result-stat span{font-size:14px;color:var(--muted)}
.result-actions{display:grid;grid-template-columns:1fr;gap:8px}
@media (max-height:719px) and (max-width:599px),(orientation:landscape) and (max-height:600px) and (min-width:560px){
  .result-card{position:fixed;left:max(10px,env(safe-area-inset-left));right:max(10px,env(safe-area-inset-right));bottom:max(10px,env(safe-area-inset-bottom));max-width:520px;margin:0 auto;z-index:20}
}

/* ---------- actions ---------- */
.actions{grid-area:actions;display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:6px}
.act-btn{display:grid;justify-items:center;align-content:center;gap:1px;min-height:56px;padding:4px 2px;border-radius:12px;border:1px solid var(--line);background:rgba(17,26,58,.94);font-size:16px;font-weight:700;transition:background .15s ease,transform .1s ease,border-color .15s ease}
.act-btn:hover:not(:disabled){background:var(--panel-2);border-color:var(--line-strong)}
.act-btn:active:not(:disabled){transform:translateY(1px)}
.act-btn:disabled{opacity:.42}
.act-icon{font-size:18px;line-height:1}
.act-label{font-size:16px;line-height:1.1;white-space:nowrap}
.app[data-complete="true"] .actions{display:none}
.app-btn{min-height:48px;padding:0 16px;border-radius:12px;border:1px solid var(--line-strong);background:var(--panel);font-size:16px;font-weight:700}
.app-btn.primary{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.app-btn.danger{width:100%;margin-top:8px;background:rgba(255,144,134,.13);border-color:var(--danger);color:#ffd9d4}
.key-legend{grid-area:legend;display:none;margin:0;font-size:14px;line-height:1.4;color:var(--muted);text-align:center}

/* ---------- tips ---------- */
.game-tip{position:fixed;left:50%;bottom:max(14px,env(safe-area-inset-bottom));z-index:24;display:flex;align-items:center;gap:10px;width:max-content;max-width:min(92vw,480px);min-height:44px;padding:10px 16px;border-radius:16px;border:1px solid var(--line-strong);background:#141f45;font-size:16px;text-align:left;box-shadow:0 12px 30px rgba(0,0,0,.45);transform:translate(-50%,16px);opacity:0;pointer-events:none;transition:opacity .3s ease,transform .3s ease}
.game-tip.is-visible{opacity:1;transform:translate(-50%,0);pointer-events:auto}
.game-tip.is-fading{opacity:0;transform:translate(-50%,10px)}
.game-tip-icon{color:var(--gold)}

/* ---------- dialogs ---------- */
.app-dialog{width:min(560px,calc(100vw - 20px));max-height:calc(100svh - 20px);padding:0;border:1px solid var(--line-strong);border-radius:20px;background:#0d1738;color:var(--ink);box-shadow:0 30px 70px rgba(0,0,0,.62)}
.app-dialog::backdrop{background:rgba(2,5,16,.76)}
.dialog-card{display:flex;flex-direction:column;max-height:calc(100svh - 22px)}
.dialog-header{display:flex;align-items:flex-start;justify-content:space-between;gap:10px;padding:16px 16px 8px}
.dialog-header h2{margin:2px 0 0;font-size:22px;line-height:1.15}
.dialog-kicker{font-size:14px;font-weight:600;color:var(--muted)}
.dialog-close{flex:none;width:44px;height:44px;border-radius:12px;border:1px solid var(--line);background:var(--panel);font-size:24px;line-height:1}
.dialog-content{padding:4px 16px 8px;overflow:auto;font-size:16px;line-height:1.45}
.dialog-content p{margin:8px 0}
.dialog-content strong{font-size:16px}
.dialog-actions{display:flex;flex-wrap:wrap;justify-content:flex-end;gap:8px;padding:10px 16px 16px;border-top:1px solid var(--line)}
.dialog-actions .app-btn{flex:1 1 140px}
.dialog-note{margin:10px 0 0;font-size:14px;line-height:1.45;color:var(--muted)}
.tutorial-presentation-mount{display:grid;place-items:center;min-height:240px;padding:6px;border-radius:16px;background:rgba(0,0,0,.24)}
.demo-caption{min-height:44px;margin:6px 0 0;text-align:center;font-size:16px;font-weight:600}
.rule-list{display:grid;gap:8px;margin:8px 0;padding:0;list-style:none}
.rule-list li{display:grid;grid-template-columns:44px 1fr;align-items:center;gap:10px}
.rule-list b{display:grid;place-items:center;min-height:36px;border-radius:10px;background:var(--panel-2);font-size:16px}
.rule-list span{font-size:16px;line-height:1.35}
.check-row{display:flex;align-items:center;gap:10px;min-height:44px;margin-top:8px;font-size:16px;cursor:pointer}
.check-row input{width:22px;height:22px;accent-color:var(--accent)}
.settings{display:grid;gap:8px}
.setting-row{display:flex;align-items:center;justify-content:space-between;gap:12px;min-height:60px;padding:6px 10px;border-radius:12px;background:rgba(255,255,255,.05);cursor:pointer}
.setting-copy{display:grid;gap:2px;min-width:0}
.setting-copy strong{font-size:16px}
.setting-copy small{font-size:14px;color:var(--muted)}
.setting-row select{min-height:44px;border-radius:10px;border:1px solid var(--line-strong);background:var(--panel);padding:0 8px;font-size:16px}
.setting-row input[type="checkbox"]{appearance:none;-webkit-appearance:none;flex:none;position:relative;width:52px;height:30px;margin:0;border-radius:999px;background:#34406b;border:1px solid var(--line-strong);transition:background .15s ease;cursor:pointer}
.setting-row input[type="checkbox"]::after{content:"";position:absolute;top:3px;left:3px;width:22px;height:22px;border-radius:50%;background:#e9edff;transition:transform .15s ease}
.setting-row input[type="checkbox"]:checked{background:var(--accent)}
.setting-row input[type="checkbox"]:checked::after{transform:translateX(22px)}

/* ---------- How to Play demo + portal preview (demo/presentation.js) ---------- */
.rtr-demo{display:grid;gap:10px;justify-items:center;width:100%;max-width:420px;color:var(--ink)}
.rtr-demo-board{position:relative;width:min(100%,272px);aspect-ratio:1;border-radius:18px;border:2px solid var(--line-strong);background:linear-gradient(160deg,#0e1738,#0a1029 60%,#080d22);box-shadow:inset 0 0 30px rgba(0,0,0,.4)}
.rtr-demo-board[data-complete="true"]{border-color:var(--ok);box-shadow:0 0 0 3px rgba(111,240,192,.24),inset 0 0 30px rgba(111,240,192,.1)}
.rtr-demo-board svg{position:absolute;inset:0;width:100%;height:100%;overflow:visible}
.rtr-demo-board .slot{stroke:#1d2a56;stroke-width:9;stroke-linecap:round}
.rtr-demo-board .thread{stroke:var(--loop);stroke-width:14;stroke-linecap:round;opacity:0;filter:drop-shadow(0 0 6px rgba(255,209,120,.55));transition:opacity .18s ease}
.rtr-demo-board .thread-core{stroke:var(--loop-core);stroke-width:5;stroke-linecap:round;opacity:0;transition:opacity .18s ease}
.rtr-demo-board .thread.is-on{opacity:1}
.rtr-demo-board .thread-core.is-on{opacity:.9}
.rtr-demo-board .thread.is-fresh{animation:trace-in 260ms ease-out both}
.rtr-demo-board .plate{fill:rgba(26,37,78,.96);stroke:#33437a;stroke-width:2}
.rtr-demo-board .plate.is-done{fill:rgba(21,74,58,.96);stroke:var(--ok)}
.rtr-demo-board .clue{fill:#e8edff;font-size:40px;font-weight:800;text-anchor:middle;dominant-baseline:central}
.rtr-demo-board .clue.is-done{fill:#c9ffe9}
.rtr-demo-finger{position:absolute;z-index:4;width:24px;height:24px;margin:-12px 0 0 -12px;border-radius:50%;background:rgba(255,255,255,.85);box-shadow:0 0 0 7px rgba(255,196,107,.28);transition:left .2s ease,top .2s ease;pointer-events:none}
.rtr-demo-caption{margin:0;min-height:44px;font-size:16px;line-height:1.35;text-align:center;font-weight:600}
.rtr-demo[data-presentation-surface="preview"]{position:fixed;inset:0;z-index:9999;grid-template-columns:272px minmax(0,1fr);grid-template-areas:"board head" "board caption";align-items:center;justify-items:start;gap:8px 26px;max-width:none;width:100%;padding:26px 34px;overflow:hidden;background:radial-gradient(circle at 82% 10%,rgba(255,196,107,.16),transparent 42%),radial-gradient(circle at 10% 92%,rgba(111,240,192,.12),transparent 38%),linear-gradient(150deg,#0c1430,#080d21 70%,#05081a)}
.rtr-demo[data-presentation-surface="preview"] .rtr-demo-board{grid-area:board;width:272px}
.rtr-demo-head{display:grid;gap:4px;grid-area:head;align-self:end}
.rtr-demo-kicker{margin:0;font-size:14px;font-weight:800;letter-spacing:.16em;color:var(--accent)}
.rtr-demo-title{margin:0;font-size:32px;line-height:1.05;font-weight:800}
.rtr-demo-title em{font-style:normal;color:var(--accent)}
.rtr-demo[data-presentation-surface="preview"] .rtr-demo-caption{grid-area:caption;text-align:left;align-self:start;font-size:18px;font-weight:600}

/* ---------- motion ---------- */
@keyframes trace-in{from{opacity:0;stroke-width:2}to{opacity:1}}
@keyframes trace-wave{0%{stroke:var(--loop);filter:drop-shadow(0 0 6px rgba(255,209,120,.55))}35%{stroke:#ffffff;filter:drop-shadow(0 0 16px rgba(255,255,255,.9))}100%{stroke:var(--loop);filter:drop-shadow(0 0 6px rgba(255,209,120,.55))}}
@keyframes trace-wave-core{0%{stroke:var(--loop-core)}40%{stroke:#ffffff}100%{stroke:var(--loop-core)}}
@keyframes stamp-in{from{opacity:0;transform:translate(-50%,-50%) scale(.7)}to{opacity:1;transform:translate(-50%,-50%) scale(1)}}
@keyframes refuse{0%,100%{transform:translateX(0)}20%{transform:translateX(-6px)}40%{transform:translateX(5px)}60%{transform:translateX(-3px)}80%{transform:translateX(2px)}}
@keyframes card-in{from{transform:translateY(14px);opacity:0}to{transform:none;opacity:1}}
html[data-motion-profile="swift"] .result-card{animation-duration:220ms}
html[data-motion-profile="swift"] .won-stamp{animation-duration:260ms;animation-delay:120ms}
html[data-motion-profile="instant"] *,html[data-motion-profile="instant"] *::before,html[data-motion-profile="instant"] *::after{animation:none!important;transition:none!important}
@media (prefers-reduced-motion:reduce){
  html[data-motion="system"] *,html[data-motion="system"] *::before,html[data-motion="system"] *::after{animation:none!important;transition:none!important}
}

/* ---------- responsive ---------- */
@media (max-width:359px){
  .brand-mark{display:none}
  .brand-name{font-size:20px}
  .mode-switch button{min-width:58px;padding:0 10px}
  .meter{gap:8px}
  .progress-track{display:none}
  .meter-edges{margin-left:auto}
}
@media (min-width:600px){
  .app{gap:10px}
  .brand-name{font-size:24px}
  .readout{min-height:80px}
}
/* Desktop and landscape: board on the left, controls in a side column. */
@media (min-width:900px) and (min-height:560px),(orientation:landscape) and (max-height:600px) and (min-width:560px){
  .app{
    max-width:1240px;grid-template-columns:minmax(0,1fr) minmax(280px,380px);
    grid-template-areas:"top top" "stage hud" "stage meter" "stage readout" "stage actions" "stage legend";
    grid-template-rows:auto auto auto auto auto 1fr;
    column-gap:24px;align-content:start;
  }
  .stage{align-items:flex-start}
  .board-wrap{width:min(calc(100cqw - 10px),calc(100cqh - 10px),900px)}
  .hud{flex-wrap:wrap}
  .readout{text-align:left;min-height:96px}
  .status-headline{justify-content:flex-start}
  .key-legend{display:block}
  .actions{grid-template-columns:repeat(3,minmax(0,1fr))}
}
@media (orientation:landscape) and (max-height:600px) and (min-width:560px){
  .topbar{min-height:44px}
  .key-legend{display:none}
  .readout{min-height:66px}
  .act-btn{min-height:48px}
}
/* Portal fullscreen: drop the ordinary width cap and let the board take the height. */
html[data-webgames-display-mode="fullscreen"] .app{max-width:none}
@media (min-width:900px) and (min-height:560px){
  html[data-webgames-display-mode="fullscreen"] .app{grid-template-columns:minmax(0,1fr) minmax(300px,400px)}
  html[data-webgames-display-mode="fullscreen"] .board-wrap{width:min(calc(100cqw - 10px),calc(100cqh - 10px),1180px)}
}
html[data-presentation="preview"],html[data-presentation="preview"] body{overflow:hidden}
