/* IBM Plex Mono（SIL OFL 1.1，见 fonts/OFL.txt），随游戏包本地分发 */
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/ibm-plex-mono-400-latin.woff2) format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 500; font-display: swap; src: url(fonts/ibm-plex-mono-500-latin.woff2) format("woff2"); }

:root {
  --ink: oklch(94% .03 155);
  --muted: oklch(78% .06 155);
  --signal: oklch(87% .16 150);
  --danger: oklch(70% .2 25);
  --font-sans: ui-sans-serif, system-ui, "PingFang SC", "Noto Sans SC", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, "PingFang SC", monospace;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  color: var(--ink);
  font-family: var(--font-sans);
  font-weight: 300;
  line-height: 1.5;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.construct {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ---------- 屏幕（标题 / 暂停 / 结束） ---------- */
.screen {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: none;
  align-content: center;
  gap: 1.25rem;
  width: min(36rem, 100% - 2rem);
  margin-inline: auto;
  padding-block: 10vh 4rem;
  pointer-events: none;
}
.screen > * { pointer-events: auto; }
.screen::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: radial-gradient(ellipse at 30% 50%, #000c 0%, #0008 45%, transparent 75%);
  pointer-events: none;
}

body[data-state="title"] #title,
body[data-state="paused"] #paused,
body[data-state="over"] #over,
body[data-state="end"] #end { display: grid; animation: rise .8s cubic-bezier(.2,.7,.2,1) both; }

/* 结局：文字放到底部，把画面中央留给旋转的图腾 */
#end { align-content: end; padding-block: 0 max(2.5rem, 6vh); gap: .9rem; }
#end::before { background: linear-gradient(to top, #000d 0%, #0008 35%, transparent 60%); }
#end .code.small { font-size: clamp(2.4rem, 8vw, 4rem); }

@keyframes rise {
  from { opacity: 0; translate: 0 12px; filter: blur(6px); }
  to { opacity: 1; translate: 0 0; filter: none; }
}

.title { margin: 0; display: grid; gap: .75rem; font-weight: 500; }
.code {
  font-family: var(--font-mono);
  font-size: clamp(3.4rem, 15vw, 7.5rem);
  line-height: .95;
  letter-spacing: .02em;
  color: var(--signal);
  text-shadow: 0 0 .35em color-mix(in oklch, var(--signal), transparent 55%);
}
.code.small { font-size: clamp(3rem, 12vw, 6rem); }

.label, .ways, .stats dt {
  font-family: var(--font-mono);
  font-size: .8125rem;
  font-weight: 500;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}
.copy { margin: 0; max-width: 34ch; text-wrap: pretty; }

.ways ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; column-gap: 1.75rem; }
.ways button {
  all: unset;
  cursor: pointer;
  display: inline-grid;
  align-items: center;
  min-height: 44px;
  color: var(--ink);
  font: inherit;
  letter-spacing: inherit;
}
.ways button::before { content: "› "; color: transparent; transition: color .2s; }
.ways button:is(:hover, :focus-visible) { color: var(--signal); }
.ways button:is(:hover, :focus-visible)::before { color: var(--signal); }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 4px; }

.help, .stats {
  margin: 0;
  display: grid;
  gap: .6rem;
  font-size: .9rem;
  max-width: 40ch;
}
.help div, .stats div { display: grid; grid-template-columns: 4.5rem 1fr; gap: .75rem; }
.help dt { font-family: var(--font-mono); color: var(--signal); font-size: .8rem; letter-spacing: .1em; padding-top: .1em; }
.help dd, .stats dd { margin: 0; }
.help em { font-style: normal; color: var(--signal); }
.stats dd { font-family: var(--font-mono); color: var(--ink); }

/* ---------- HUD ---------- */
.hud {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  display: none;
  font-family: var(--font-mono);
}
body:is([data-state="play"], [data-state="kick"], [data-state="dying"]) .hud { display: block; }

.hud-layer { position: absolute; top: max(1rem, env(safe-area-inset-top)); left: 1.25rem; display: grid; gap: .1rem; }
.hud-code {
  font-size: clamp(2.4rem, 7vw, 3.6rem);
  line-height: 1;
  color: var(--signal);
  text-shadow: 0 0 .4em color-mix(in oklch, var(--signal), transparent 50%);
}
.hud-stats { position: absolute; top: max(1.1rem, env(safe-area-inset-top)); right: 4.5rem; display: grid; gap: .35rem; justify-items: end; }
.stat { display: flex; gap: .8rem; align-items: baseline; }
.stat > span:last-child { font-size: 1.05rem; color: var(--ink); min-width: 4.5ch; text-align: right; }
.stab { color: var(--signal) !important; letter-spacing: .15em; }
.stab.low { color: var(--danger) !important; animation: blink .5s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }

.hud-time {
  position: absolute;
  left: 1.25rem;
  bottom: max(1.25rem, env(safe-area-inset-bottom));
  display: grid;
  gap: .2rem;
  font-size: .95rem;
}
.hud-time div { display: flex; gap: .8rem; align-items: baseline; }
.hud-time .label { min-width: 7.5em; }

.hud-progress {
  position: absolute;
  left: 50%;
  top: max(1.4rem, env(safe-area-inset-top));
  translate: -50% 0;
  width: min(14rem, 30vw);
  height: 2px;
  background: color-mix(in oklch, var(--ink), transparent 85%);
}
.hud-progress i { display: block; height: 100%; width: 0%; background: var(--signal); box-shadow: 0 0 8px var(--signal); transition: width .3s; }

.hud-pause {
  all: unset;
  pointer-events: auto;
  cursor: pointer;
  position: absolute;
  top: max(1rem, env(safe-area-inset-top));
  right: 1rem;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  color: var(--muted);
  border: 1px solid color-mix(in oklch, var(--ink), transparent 80%);
}
.hud-pause:hover { color: var(--signal); }

.hud.hit { animation: shake .35s linear; }
@keyframes shake {
  20% { translate: -6px 2px; } 40% { translate: 5px -3px; } 60% { translate: -3px 1px; } 80% { translate: 2px 0; }
}
.pulse { animation: pulse .5s ease-out; }
@keyframes pulse { 0% { color: var(--signal); scale: 1.35; } 100% { scale: 1; } }

/* ---------- 中央提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  top: 38%;
  z-index: 3;
  translate: -50% -50%;
  pointer-events: none;
  text-align: center;
  font-family: var(--font-mono);
  color: var(--signal);
  opacity: 0;
  white-space: nowrap;
}
.toast.show { animation: toast 2.2s ease both; }
.toast b { display: block; font-size: clamp(2.6rem, 10vw, 5rem); font-weight: 500; line-height: 1; letter-spacing: .1em; text-shadow: 0 0 .4em var(--signal); }
.toast small { display: block; margin-top: .6rem; font-size: .85rem; letter-spacing: .3em; color: var(--muted); }
@keyframes toast {
  0% { opacity: 0; filter: blur(8px); scale: 1.15; }
  15% { opacity: 1; filter: none; scale: 1; }
  75% { opacity: 1; }
  100% { opacity: 0; filter: blur(4px); }
}

.nogl { position: fixed; inset: 0; display: grid; place-items: center; font-family: var(--font-mono); color: var(--danger); margin: 0; }

@media (max-width: 560px) {
  .hud-stats { right: 4rem; }
  .hud-progress { display: none; }
  .hud-time { font-size: .85rem; }
}
@media (prefers-reduced-motion: reduce) {
  .screen, .toast.show, .hud.hit { animation-duration: .01s !important; }
}

/* 循环梦境 */
.hud-loop { color: var(--signal); letter-spacing: .1em; }
.hud-loop:empty { display: none; }
.best { margin: 0; color: var(--signal); }
.best:empty { display: none; }

/* 游隙平台 */
body:not([data-embedded]) [data-embedded-only] { display: none !important; }
.player { margin: 0; }
.board { display: grid; gap: .5rem; max-width: 26rem; font-size: .9rem; }
.board p { margin: 0; }
.ranks { list-style: none; margin: 0; padding: 0; display: grid; gap: .2rem; font-family: var(--font-mono); }
.ranks li { display: grid; grid-template-columns: 2.5rem 1fr auto; gap: .75rem; }
.ranks li span:first-child { color: var(--signal); }
.ranks li span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
