:root {
  --ink: #050507;
  --paper: #f4f1e8;
  --dim: rgba(244, 241, 232, 0.62);
  --faint: rgba(244, 241, 232, 0.28);
  --red: #ff4d4d;
  --round: 'M PLUS Rounded 1c', 'Hiragino Maru Gothic ProN', 'Arial Rounded MT Bold', sans-serif;
  --code: 'M PLUS 1 Code', ui-monospace, monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--ink); color: var(--paper);
  font-family: var(--code); -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; touch-action: none; overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
#stage { position: fixed; inset: 0; }
#gl, #fx { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#fx { pointer-events: none; mix-blend-mode: normal; }
#stage::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(120% 95% at 50% 45%, transparent 55%, rgba(0, 0, 0, 0.55) 100%);
}

#flash { position: fixed; inset: 0; background: var(--paper); opacity: 0; pointer-events: none; }
#flash.on { animation: flash 1.1s steps(6) forwards; }
@keyframes flash { 0% { opacity: 1; } 30% { opacity: 0.9; } 100% { opacity: 0; } }

/* instruments */
#hud { position: fixed; inset: 0; pointer-events: none; }
#inst {
  position: absolute; left: calc(18px + var(--safe-l)); top: calc(16px + var(--safe-t));
  display: grid; gap: 3px; font-size: 12px; letter-spacing: 0.06em; color: var(--dim);
}
#inst > div { display: grid; grid-template-columns: 4.2em 4.2em 3em; align-items: baseline; }
#inst span { color: var(--faint); }
#inst b { font-weight: 600; color: var(--paper); text-align: right; font-variant-numeric: tabular-nums; }
#inst i { font-style: normal; padding-left: 0.5em; color: var(--faint); font-size: 10px; }
#papi { display: inline-flex; gap: 4px; justify-content: flex-end; align-items: center; height: 1em; }
#papi i, #title .how i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; padding: 0; background: #fff3dc; }
#papi i.r, #title .how i.r { background: var(--red); box-shadow: 0 0 6px rgba(255, 60, 60, 0.7); }
#papi i.w, #title .how i.w { background: #fff3dc; box-shadow: 0 0 6px rgba(255, 240, 210, 0.6); }
#where {
  position: absolute; right: calc(18px + var(--safe-r)); top: calc(54px + var(--safe-t));
  font-family: var(--round); font-weight: 500; font-size: 12px; letter-spacing: 0.16em; color: var(--dim);
}

/* location card, like the bottom caption of an anime cut */
#caption {
  position: fixed; left: 0; right: 0; bottom: calc(4.5vh + var(--safe-b)); text-align: center;
  pointer-events: none; opacity: 0;
}
#caption.on { animation: cap 4.2s steps(1, end) forwards; }
@keyframes cap { 0% { opacity: 0; } 4% { opacity: 1; } 92% { opacity: 1; } 100% { opacity: 0; } }
#caption .jp {
  font-family: var(--round); font-weight: 800; font-size: clamp(34px, 7.5vw, 76px);
  letter-spacing: 0.2em; padding-left: 0.2em; line-height: 1.1;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.7);
}
#caption .en { margin-top: 10px; font-size: clamp(10px, 1.6vw, 13px); letter-spacing: 0.24em; color: var(--dim); padding: 0 16px; }

#callout {
  position: fixed; left: 0; right: 0; top: 28%; text-align: center; pointer-events: none;
  font-family: var(--round); font-weight: 800; font-size: clamp(22px, 4vw, 34px); letter-spacing: 0.14em;
  color: var(--paper); opacity: 0; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.7);
}
#callout.big { font-family: var(--code); font-weight: 600; font-size: clamp(20px, 3.4vw, 30px); }
#callout.on { animation: call 0.9s steps(1, end) forwards; }
#callout.big.on { animation-duration: 2.2s; }
@keyframes call { 0% { opacity: 1; } 85% { opacity: 1; } 100% { opacity: 0; } }

#warn {
  position: fixed; left: 0; right: 0; top: calc(16px + var(--safe-t)); text-align: center; pointer-events: none;
  font-family: var(--round); font-weight: 800; font-size: 15px; letter-spacing: 0.2em; color: var(--red); opacity: 0;
}
#warn.on { animation: blink 0.5s steps(2, jump-none) infinite; }
@keyframes blink { 0% { opacity: 1; } 100% { opacity: 0.15; } }

/* title */
#title {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding: calc(9vh + var(--safe-t)) 16px 0; text-align: center; cursor: pointer;
}
#title .jp {
  font-family: var(--round); font-weight: 800; font-size: clamp(34px, 8.4vw, 92px); letter-spacing: 0.12em;
  padding-left: 0.12em; line-height: 1.05; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.75);
}
#title .en { margin-top: 12px; font-size: clamp(11px, 1.7vw, 14px); letter-spacing: 0.5em; padding-left: 0.5em; color: var(--dim); }
#title .how {
  margin-top: 26px; display: grid; gap: 7px; font-size: 12px; letter-spacing: 0.06em;
  color: var(--dim); max-width: 420px;
}
#title .how b { color: var(--paper); font-weight: 600; margin: 0 0.35em 0 0.9em; }
#title .how b:first-child { margin-left: 0; }
#title .how i { margin: 0 2px; vertical-align: -1px; }
#title .go {
  margin-top: auto; margin-bottom: calc(6vh + var(--safe-b)); font-family: var(--round); font-weight: 800; font-size: 15px;
  letter-spacing: 0.4em; padding-left: 0.4em; animation: blink 1.2s steps(2, jump-none) infinite;
}
body:not(.touch) #title .go::after { content: ' · SPACE'; }

/* result card */
#result {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(420px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto;
  padding: 22px 22px 18px; background: rgba(5, 5, 7, 0.9); border: 1px solid var(--faint);
  text-align: center;
}
#result .where { font-family: var(--round); font-size: 11px; letter-spacing: 0.2em; color: var(--dim); }
#result .jp {
  margin-top: 12px; font-family: var(--round); font-weight: 800; font-size: clamp(40px, 11vw, 64px);
  letter-spacing: 0.16em; padding-left: 0.16em; line-height: 1.1;
}
#result.fail .jp { color: var(--red); }
#result .en { margin-top: 6px; font-size: 13px; letter-spacing: 0.32em; padding-left: 0.32em; color: var(--paper); }
#result p { margin: 10px 0 0; font-family: var(--round); font-size: 13px; color: var(--dim); letter-spacing: 0.04em; }
#rStats { margin: 16px 0 0; display: grid; gap: 4px; font-size: 12px; letter-spacing: 0.06em; }
#rStats div { display: flex; justify-content: space-between; border-top: 1px dashed rgba(244, 241, 232, 0.14); padding-top: 4px; }
#rStats dt { color: var(--faint); }
#rStats dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
#result .score { margin-top: 14px; display: flex; align-items: baseline; justify-content: center; gap: 10px; }
#result .score span { font-size: 11px; letter-spacing: 0.2em; color: var(--faint); }
#result .score b { font-family: var(--round); font-weight: 800; font-size: 34px; }
#result .score em { font-style: normal; font-size: 11px; letter-spacing: 0.14em; color: var(--dim); min-width: 5em; text-align: left; }
#result .btns { margin-top: 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
button {
  font: inherit; color: var(--paper); background: transparent; border: 1px solid var(--faint);
  padding: 10px 8px; cursor: pointer; border-radius: 0;
}
button:hover, button:focus-visible { border-color: var(--paper); outline: none; }
#result button { font-family: var(--round); font-weight: 800; font-size: 15px; letter-spacing: 0.1em; display: grid; gap: 3px; min-height: 52px; }
#result button small { font-family: var(--code); font-weight: 400; font-size: 10px; letter-spacing: 0.2em; color: var(--dim); }

#corner {
  position: fixed; right: calc(14px + var(--safe-r)); top: calc(12px + var(--safe-t)); display: flex; gap: 8px; z-index: 5;
}
#corner button { font-size: 10px; letter-spacing: 0.2em; padding: 6px 8px; color: var(--dim); border-color: rgba(244, 241, 232, 0.18); }
#mute.off { text-decoration: line-through; color: var(--faint); }
#title:not([hidden]) ~ #corner #menu { display: none; }

/* touch: floating stick and throttle lever */
#stick { position: fixed; width: 0; height: 0; pointer-events: none; opacity: 0; }
#stick.on { opacity: 1; }
#stick .ring, #stick .knob { position: absolute; left: 0; top: 0; border-radius: 50%; transform: translate(-50%, -50%); }
#stick .ring { width: 116px; height: 116px; border: 1px solid var(--faint); }
#stick .knob { width: 40px; height: 40px; border: 1.5px solid var(--paper); background: rgba(244, 241, 232, 0.08); }

#lever {
  --v: 0.55;
  position: fixed; right: calc(10px + var(--safe-r)); bottom: calc(12vh + var(--safe-b));
  width: 64px; height: min(42vh, 280px); display: none; touch-action: none;
}
body.touch #hud:not([hidden]) ~ #lever { display: block; }
#lever .track { position: absolute; left: 50%; top: 0; bottom: 22px; width: 2px; transform: translateX(-50%); background: var(--faint); }
#lever .fill { position: absolute; left: 0; right: 0; bottom: 0; height: calc(var(--v) * 100%); background: var(--paper); }
#lever .handle {
  position: absolute; left: 50%; bottom: calc(var(--v) * 100%); width: 46px; height: 18px;
  transform: translate(-50%, 50%); border: 1.5px solid var(--paper); background: var(--ink);
}
#lever .lbl { position: absolute; bottom: 0; left: 0; right: 0; text-align: center; font-size: 10px; letter-spacing: 0.2em; color: var(--dim); }
