:root { --bg: #0b1220; --card: #16213a; --edge: #2c3c5e; --text: #f1f5f9; --sub: #94a3b8; --accent: #7dd3fc; --amber: #f59e0b; --coral: #ff6b5e; --lime: #4ade80; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: system-ui, "Hiragino Sans", "Noto Sans JP", sans-serif; overflow: hidden; }
#view canvas { display: block; }
.overlay { position: fixed; z-index: 5; }
.center { inset: 0; display: grid; place-items: center; font-size: 20px; background: var(--bg); }
.card { left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(1100px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto;
  background: rgba(11, 18, 32, 0.94); border: 1px solid var(--edge); border-radius: 18px; padding: 24px 28px; }
.card.narrow { width: min(760px, calc(100vw - 32px)); }
h1 { margin: 0; font-size: 28px; } h1 span { color: var(--accent); font-weight: 600; }
header p { margin: 4px 0 18px; color: var(--sub); }
h2 { margin: 0 0 14px; font-size: 26px; } h2.ok { color: var(--lime); } h2.ng { color: var(--coral); }
h3 { grid-column: 1 / -1; margin: 6px 0 0; font-size: 15px; color: var(--accent); }
.columns { display: grid; grid-template-columns: 1fr 300px; gap: 22px; }
@media (max-width: 800px) { .columns { grid-template-columns: 1fr; } }
.scenarios { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; align-content: start; }
button { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--edge); border-radius: 12px; padding: 10px 14px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--amber); color: #0f172a; border-color: var(--amber); font-weight: 700; }
.tile { text-align: left; display: flex; flex-direction: column; gap: 2px; }
/* selected: sky fill with dark ink (10.7:1; subtitle 5.7:1), like the active part of a segmented control */
.tile.on { background: var(--accent); border-color: #e0f2fe; color: #0f172a; }
.tile small { color: var(--sub); } .tile.on small { color: #0c4a6e; }
aside { display: flex; flex-direction: column; gap: 12px; }
aside label { display: flex; flex-direction: column; gap: 6px; color: var(--sub); }
.body-inputs { display: flex; gap: 12px; flex-wrap: wrap; }
.body-inputs label span { display: flex; align-items: center; gap: 6px; color: var(--text); }
.body-note { font-size: 12px; }
input[type=number] { font: inherit; width: 90px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--edge); background: #0f172a; color: var(--text); }
.file input { font-size: 13px; }
.editor-link { color: var(--accent); font-size: 14px; text-decoration: none; }
.editor-link:hover { text-decoration: underline; }
.sel { margin: 0; color: var(--sub); } .sel b { color: var(--text); }
#start { font-size: 20px; padding: 14px; }
.help { font-size: 13px; color: var(--sub); margin: 0; line-height: 1.6; }
.hud { position: fixed; left: 16px; top: 16px; z-index: 4; display: flex; flex-direction: column; gap: 4px; padding: 10px 14px; border-radius: 12px; background: rgba(11, 18, 32, 0.6); }
.hud span { font-size: 13px; color: var(--sub); }
.bar { left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px 12px; padding: 12px 16px; border-radius: 16px; background: rgba(11, 18, 32, 0.9); border: 1px solid var(--edge); width: max-content; max-width: calc(100vw - 24px); }
.chip { background: var(--coral); color: #0f172a; font-weight: 800; letter-spacing: 3px; border-radius: 999px; padding: 4px 10px; font-size: 12px; }
.time { color: var(--accent); min-width: 130px; }
.views { display: inline-flex; border: 1px solid var(--edge); border-radius: 12px; overflow: hidden; }
.views button { border: 0; border-radius: 0; background: transparent; padding: 8px 12px; }
.views button.on { background: var(--accent); color: #0f172a; font-weight: 700; }
.replay-hint { flex-basis: 100%; font-size: 13px; color: var(--sub); text-align: center; }
#rlines p { margin: 6px 0; line-height: 1.5; }
.verdict { background: rgba(255, 107, 94, 0.15); border-left: 4px solid var(--coral); padding: 10px 12px; border-radius: 8px; }
.buttons { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
#flash { position: fixed; inset: 0; z-index: 3; pointer-events: none; background: #ff1a1a; opacity: 0; transition: opacity 0.6s; }
#flash.on { opacity: 0.55; transition: opacity 0.05s; }
#fps { position: fixed; right: 10px; bottom: 8px; z-index: 4; font-size: 12px; color: var(--sub); }

/* phones and tablets (body.touch is set from the main pointer, not the screen size) */
body:not(.touch) .touch-only, body.touch .desktop-only { display: none !important; }
#view canvas { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button { touch-action: manipulation; }
.hudbuttons { display: flex; gap: 8px; }
.hud button { margin-top: 6px; align-self: flex-start; padding: 8px 12px; font-size: 14px; pointer-events: auto; }
.touch-controls { position: fixed; left: 0; bottom: 0; z-index: 4; padding: 0 0 max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); pointer-events: none; }
.stick { width: 136px; height: 136px; border-radius: 50%; background: rgba(11, 18, 32, 0.35); border: 2px solid rgba(241, 245, 249, 0.55);
  display: grid; place-items: center; pointer-events: auto; touch-action: none; }
.knob { width: 58px; height: 58px; border-radius: 50%; background: rgba(241, 245, 249, 0.85); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35); pointer-events: none; }
.hud { padding-top: max(10px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left)); }
.card { max-height: calc(100dvh - 24px); }
@media (max-width: 700px), (max-height: 520px) {
  .card { padding: 14px 16px; border-radius: 14px; width: calc(100vw - 16px); max-height: calc(100dvh - 16px); }
  h1 { font-size: 20px; } h1 span { display: block; font-size: 16px; }
  header p { margin-bottom: 10px; font-size: 13px; }
  h2 { font-size: 20px; }
  .columns { gap: 12px; }
  .scenarios { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
  .tile { padding: 8px 10px; font-size: 14px; }
  #start { font-size: 18px; padding: 12px; }
  .hud { top: 8px; padding: 8px 10px; } .hud b { font-size: 14px; } .hud span { display: none; }
  .bar { bottom: max(10px, env(safe-area-inset-bottom)); padding: 8px 10px; gap: 6px 8px; font-size: 14px; }
  .time { min-width: 0; } .views { display: inline-flex; border: 1px solid var(--edge); border-radius: 12px; overflow: hidden; }
.views button { border: 0; border-radius: 0; background: transparent; padding: 8px 12px; }
.views button.on { background: var(--accent); color: #0f172a; font-weight: 700; }
.replay-hint { display: none; }
  .buttons { flex-wrap: wrap; } .buttons button { flex: 1 1 140px; }
  #rlines p { font-size: 14px; margin: 4px 0; }
  .stick { width: 120px; height: 120px; } .knob { width: 50px; height: 50px; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .columns { grid-template-columns: 1fr 220px; }
}

/* ---------------------------------------------------------------- loading screen */
.loading { inset: 0; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(ellipse at 50% 35%, #fff4dc 0%, #f4dcc0 45%, #c9b8d8 100%); color: #3a3350; transition: opacity 0.45s ease; }
.loading.leaving { opacity: 0; }
.loader { width: min(420px, 100%); text-align: center; }
.loader .scene { width: 100%; height: auto; overflow: visible; }
.loader h1 { font-size: 20px; margin: 10px 0 14px; color: #3a3350; }
.bar-track { height: 12px; border-radius: 999px; background: rgba(58, 51, 80, 0.15); overflow: hidden; }
.bar-fill { height: 100%; width: 100%; transform: scaleX(0); transform-origin: left; border-radius: inherit;
  background: linear-gradient(90deg, #4ea596, #e0b47c, #eba091); transition: transform 0.35s ease; }
.loader .step { margin: 10px 0 4px; font-size: 14px; }
.loader .tip { margin: 6px 0 0; font-size: 13px; color: #5d5470; min-height: 2.6em; }
.tip-label { display: inline-block; padding: 1px 8px; border-radius: 999px; background: #2f7a6e; color: #fff; font-size: 11px; font-weight: 700; margin-right: 4px; }
.loaderror { margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: #fff; color: #7a2a20; text-align: left; font-size: 14px; }
.loaderror p { margin: 0 0 10px; }
.loading.failed .bear { animation-play-state: paused; }
.bear { transform: translate(52px, 66px); animation: bear-cross 6.4s ease-in-out infinite; }
.bear .leg { transform-box: fill-box; transform-origin: 50% 0; animation: bear-step 0.5s ease-in-out infinite alternate; }
.bear .leg.r { animation-delay: -0.5s; }
.bear .head { transform-box: fill-box; transform-origin: 50% 90%; animation: bear-bob 0.5s ease-in-out infinite alternate; }
.bear .eye { transform-box: fill-box; transform-origin: center; animation: bear-blink 3.6s infinite; }
.car .lamp { animation: lamp 1s steps(2) infinite; }
@keyframes bear-cross { 0%, 8% { transform: translate(52px, 66px); } 78%, 100% { transform: translate(178px, 66px); } }
@keyframes bear-step { from { transform: rotate(-16deg); } to { transform: rotate(16deg); } }
@keyframes bear-bob { from { transform: translateY(0) rotate(-3deg); } to { transform: translateY(-1.5px) rotate(3deg); } }
@keyframes bear-blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(0.1); } }
@keyframes lamp { 50% { opacity: 0.25; } }
.noscript { position: fixed; inset: 0; z-index: 20; margin: 0; display: grid; place-items: center; padding: 24px; background: var(--bg); text-align: center; }

/* ---------------------------------------------------------------- accessibility */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 3px solid #fde68a; outline-offset: 2px; border-radius: 10px; }
button:focus-visible, input:focus-visible { box-shadow: 0 0 0 5px rgba(253, 230, 138, 0.35); }
.tile[aria-pressed="true"] { background: var(--accent); border-color: #e0f2fe; color: #0f172a; }
.tile[aria-pressed="true"] small { color: #0c4a6e; }
body.touch button { min-height: 44px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; animation-iteration-count: 1 !important; transition-duration: 0.001s !important; }
  .bear { animation: none; transform: translate(118px, 66px); }
  #flash.on { opacity: 0.25; }
}
@media (forced-colors: active) { .bar-fill { background: Highlight; } .tile[aria-pressed="true"] { outline: 2px solid Highlight; } }
