:root {
  color-scheme: dark;
  --bg: #08090b;
  --surface: #101216;
  --surface-2: #171a20;
  --line: #30343b;
  --ink: #f4f1ea;
  --dim: #a8adb6;
  --accent: #72e6b1;
  --warn: #ffcb66;
  --bad: #ff6b6b;
  --radius: 7px;
  --font: Inter, "Hiragino Sans", "Yu Gothic UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--ink); font-family: var(--font); }
button { color: inherit; font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.rt-shell {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) calc(16px + env(safe-area-inset-bottom)) env(safe-area-inset-left);
  display: grid;
  gap: 10px;
}
@media (min-width: 900px) {
  .rt-shell { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .rt-head { grid-column: 1 / -1; }
  .rt-stage { position: sticky; top: 10px; }
}

.rt-head {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  min-height: 52px; padding: 0 10px; border-bottom: 1px solid var(--line);
}
.rt-back { color: var(--ink); font-size: 12px; font-weight: 800; text-decoration: none; min-height: 44px; display: inline-flex; align-items: center; }
.rt-back::before { content: "← "; color: var(--accent); }
.rt-title { font-size: 12px; letter-spacing: .16em; white-space: nowrap; }
.rt-lang { justify-self: end; display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.rt-lang button { min-width: 44px; min-height: 44px; padding: 0 7px; border: 0; background: transparent; color: var(--dim); font-size: 10px; font-weight: 850; }
.rt-lang button.on { color: var(--bg); background: var(--ink); }

.rt-stage {
  position: relative; margin: 0 10px; aspect-ratio: 3 / 4; max-height: 52svh; width: auto;
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #0c0d12;
  justify-self: center; width: min(100% - 20px, calc(52svh * .75));
}
@media (min-width: 900px) { .rt-stage { max-height: none; width: calc(100% - 20px); } }
.rt-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.rt-start {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 20px; text-align: center; background: rgba(5,6,8,.84);
}
.rt-start[hidden] { display: none; }
.rt-start strong { font-size: 15px; line-height: 1.5; }
.rt-start span { font-size: 12px; color: var(--dim); }
.rt-start-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; width: min(280px, 100%); }
.rt-primary, .rt-quiet { min-height: 48px; border-radius: var(--radius); font-weight: 800; }
.rt-primary { border: 0; background: var(--accent); color: #07110c; }
.rt-quiet { border: 1px solid var(--line); background: transparent; color: var(--dim); }
.rt-status {
  position: absolute; left: 8px; right: 8px; bottom: 8px; margin: 0; padding: 8px 10px;
  border-radius: var(--radius); background: rgba(8,9,11,.86); font-size: 12px; line-height: 1.45;
}
.rt-status:empty { display: none; }
.rt-status[data-tone="ok"] { color: var(--accent); }
.rt-status[data-tone="warn"] { color: var(--warn); }
.rt-flash {
  position: absolute; left: 0; right: 0; top: 38%; margin: 0; text-align: center;
  font-size: 30px; font-weight: 900; letter-spacing: .04em; opacity: 0; pointer-events: none;
  text-shadow: 0 2px 18px rgba(0,0,0,.8);
}
.rt-flash.show { animation: rt-flash .7s ease-out both; }
.rt-flash[data-tone="ok"] { color: var(--accent); }
.rt-flash[data-tone="other"] { color: var(--warn); font-size: 18px; }
@keyframes rt-flash { 0% { opacity: 0; transform: scale(.9); } 20% { opacity: 1; transform: scale(1.06); } 100% { opacity: 0; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .rt-flash.show { animation-duration: .01s; opacity: 1; } }

.rt-panel { display: grid; gap: 10px; padding: 0 10px; }
.rt-games { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.rt-game {
  min-height: 44px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
  color: var(--dim); font-size: 12px; font-weight: 850; letter-spacing: .06em;
}
.rt-game.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.rt-hint { margin: 0; font-size: 12px; line-height: 1.55; color: var(--dim); }
.rt-tests { display: grid; gap: 8px; }
.rt-test {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; align-items: center;
  width: 100%; min-height: 64px; padding: 10px 12px; text-align: left;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
.rt-test.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.rt-test.hit { animation: rt-hit .45s ease-out; }
@keyframes rt-hit { 0% { background: rgba(114,230,177,.35); } 100% { background: var(--surface); } }
.rt-test-name { font-size: 14px; font-weight: 800; }
.rt-test-count { font-size: 13px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--accent); white-space: nowrap; }
.rt-test-count .other { color: var(--warn); margin-left: 6px; }
.rt-bar { grid-column: 1 / -1; position: relative; height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.rt-bar i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--dim); border-radius: 5px; }
.rt-bar i.over { background: var(--accent); }
.rt-bar b { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--warn); }
.rt-bar em { position: absolute; top: 0; bottom: 0; width: 2px; left: -2px; background: rgba(244,241,234,.75); }
.rt-num { grid-column: 1 / -1; font-size: 11px; color: var(--dim); font-variant-numeric: tabular-nums; }
.rt-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.rt-actions button {
  min-height: 44px; border: 1px solid var(--line); border-radius: var(--radius); background: transparent;
  color: var(--dim); font-size: 11px; font-weight: 800;
}
.rt-details {
  margin: 0; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--dim); font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap; overflow-x: auto;
}
.rt-details[hidden] { display: none; }
