:root {
  --ink: #070806;
  --bone: #f2f0e7;
  --acid: #d9ff52;
  --burn: #ff5a3c;
  --steel: #565b58;
  --line: rgba(242, 240, 231, .24);
  --ease-cut: cubic-bezier(.2, .9, .25, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; overflow: hidden; background: var(--ink); }
body {
  color: var(--bone);
  font-family: "Trebuchet MS", "Microsoft YaHei", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  text-wrap: pretty;
}
button, a { font: inherit; }
button { color: inherit; }

#stage { position: fixed; inset: 0; isolation: isolate; background: var(--ink); }
#game { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.hidden { display: none !important; }

/* HUD */
#hud {
  position: absolute;
  z-index: 5;
  left: max(20px, env(safe-area-inset-left));
  right: max(20px, env(safe-area-inset-right));
  top: max(16px, env(safe-area-inset-top));
  display: grid;
  grid-template-columns: 150px minmax(240px, 480px) 150px;
  justify-content: space-between;
  align-items: start;
  pointer-events: none;
}
.hud-block strong { display: flex; align-items: baseline; gap: 5px; font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif; font-weight: 400; }
.hud-loop strong { font-size: 42px; line-height: .9; letter-spacing: -.02em; }
.hud-loop strong i { font: 12px/1 Consolas, monospace; color: var(--steel); font-style: normal; }
.hud-kicker { display: block; color: var(--steel); font: 700 9px/1 Consolas, monospace; letter-spacing: .2em; margin-bottom: 6px; }
.hud-center { padding-top: 1px; text-align: center; }
#ui-boss-name { font: 700 10px/1 Consolas, monospace; letter-spacing: .28em; color: var(--burn); }
.boss-track { height: 4px; margin-top: 9px; background: rgba(255, 90, 60, .13); overflow: hidden; }
.boss-track i { display: block; width: 100%; height: 100%; background: var(--burn); transform-origin: left; transition: transform .1s linear; box-shadow: 0 0 10px rgba(255, 90, 60, .55); }
.hud-time { text-align: right; }
.hud-time strong { display: block; font-size: 42px; line-height: .9; color: var(--acid); font-variant-numeric: tabular-nums; }

#side-ui {
  position: absolute;
  z-index: 5;
  left: max(20px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 22px;
  pointer-events: none;
}
.hp-pips { display: flex; gap: 5px; }
.hp-pips i { width: 20px; height: 7px; display: block; background: var(--bone); transition: opacity .12s, transform .12s; }
.hp-pips i.off { opacity: .16; transform: scaleX(.7); }
.sync-wrap { display: grid; grid-template-columns: auto 92px 34px; gap: 8px; align-items: center; font: 700 9px/1 Consolas, monospace; letter-spacing: .12em; }
.sync-wrap > i { height: 3px; background: rgba(242, 240, 231, .16); }
.sync-wrap > i b { display: block; width: 0; height: 100%; background: var(--acid); transition: width .1s; }
.sync-wrap em { color: var(--acid); font-style: normal; font-variant-numeric: tabular-nums; }

#game-actions {
  position: absolute;
  z-index: 7;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  display: flex;
  gap: 10px;
  align-items: end;
}
.square-btn, .phase-btn {
  position: relative;
  border: 1px solid var(--line);
  background: rgba(7, 8, 6, .62);
  backdrop-filter: blur(8px);
  cursor: pointer;
  overflow: hidden;
}
.square-btn { width: 44px; height: 44px; font: 700 15px Consolas, monospace; }
.phase-btn { width: 92px; height: 54px; color: var(--acid); font: 800 10px Consolas, monospace; letter-spacing: .14em; }
.phase-btn span { position: relative; z-index: 2; }
.phase-btn i { position: absolute; inset: 0; background: rgba(217, 255, 82, .18); transform: translateY(100%); transition: transform .1s linear; }
.phase-btn.ready { border-color: var(--acid); box-shadow: inset 0 0 0 1px rgba(217, 255, 82, .15); }
.phase-btn:active, .square-btn:active { transform: translateY(2px); }

/* overlays */
.overlay {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: auto;
  background: rgba(7, 8, 6, .82);
  backdrop-filter: blur(12px);
}
.overlay.show { display: flex; animation: reveal .24s var(--ease-cut) both; }
@keyframes reveal { from { opacity: 0; } }
.overlay::before, .overlay::after {
  content: "";
  position: absolute;
  pointer-events: none;
}
.overlay::before { inset: 20px; border: 1px solid var(--line); }
.overlay::after { left: 0; right: 0; top: 50%; height: 1px; background: rgba(242, 240, 231, .06); }

.menu-shell {
  position: relative;
  z-index: 2;
  width: min(820px, 92vw);
  padding: 10px 0 10px 8%;
}
.edition, .eyebrow { color: var(--acid); font: 700 10px/1 Consolas, monospace; letter-spacing: .28em; }
.menu-shell h1 {
  display: flex;
  flex-direction: column;
  margin: 20px 0 0;
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  font-size: clamp(76px, 15vw, 178px);
  font-weight: 400;
  line-height: .68;
  letter-spacing: -.03em;
}
.menu-shell h1 span:last-child { color: transparent; -webkit-text-stroke: 1px var(--bone); transform: translateX(.34em); }
.zh-mark { position: absolute; top: 44%; left: 1.4%; writing-mode: vertical-rl; color: var(--acid); font-weight: 800; letter-spacing: .45em; }
.tagline { margin: 38px 0 22px; font: 700 clamp(12px, 1.5vw, 16px)/1.5 Consolas, monospace; letter-spacing: .1em; }
.primary-btn {
  width: min(330px, 100%);
  min-height: 58px;
  border: 0;
  background: var(--acid);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  cursor: pointer;
  font: 900 12px/1 Consolas, monospace;
  letter-spacing: .12em;
  clip-path: polygon(0 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 0 100%);
  transition: transform .12s, background .12s;
}
.primary-btn:hover { background: var(--bone); transform: translateX(4px); }
.primary-btn:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--bone); outline-offset: 3px; }
.primary-btn b { font-size: 22px; }
.secondary-btn {
  width: min(330px, 100%); min-height: 50px; margin-top: 9px;
  border: 1px solid var(--line); background: rgba(7,8,6,.7); color: var(--bone);
  display: flex; align-items: center; justify-content: space-between; padding: 0 18px;
  cursor: pointer; font: 900 11px/1 Consolas, monospace; letter-spacing: .1em;
}
.secondary-btn:hover { border-color: var(--acid); color: var(--acid); }
.secondary-btn.compact { width: auto; min-height: 42px; margin: 0; white-space: nowrap; }
.how-grid { display: grid; grid-template-columns: repeat(3, minmax(100px, 180px)); gap: 1px; margin-top: 24px; max-width: 560px; background: var(--line); }
.how-grid div { min-height: 64px; background: var(--ink); padding: 10px; display: flex; gap: 10px; }
.how-grid b { color: var(--acid); font: 700 9px Consolas, monospace; }
.how-grid span { color: #9b9d96; font: 700 9px/1.45 Consolas, monospace; letter-spacing: .06em; }
.menu-meta { margin-top: 18px; display: flex; flex-wrap: wrap; gap: 16px; }
.menu-meta button, .menu-meta a, .text-btn {
  border: 0;
  background: none;
  color: #8d908a;
  cursor: pointer;
  text-decoration: none;
  font: 700 9px/1 Consolas, monospace;
  letter-spacing: .12em;
}
.menu-meta button:hover, .menu-meta a:hover, .text-btn:hover { color: var(--bone); }
.menu-time { position: absolute; z-index: 1; right: 7%; bottom: 7%; display: flex; align-items: end; gap: 10px; color: var(--burn); transform: rotate(-5deg); }
.menu-time span { font: 400 clamp(70px, 12vw, 150px)/.7 Impact, sans-serif; }
.menu-time i { font: 700 9px/1.3 Consolas, monospace; font-style: normal; letter-spacing: .1em; }

/* story chapters */
.story-shell {
  position: relative; z-index: 2; width: min(920px, 92vw); min-height: min(640px, 82vh);
  padding: clamp(24px, 5vw, 66px); display: flex; flex-direction: column; justify-content: center;
}
.story-index {
  position: absolute; right: 3%; top: 1%; color: transparent; -webkit-text-stroke: 1px rgba(242,240,231,.15);
  font: 400 clamp(120px, 25vw, 300px)/1 Impact, sans-serif; pointer-events: none;
}
.story-sector { position: relative; color: var(--acid); font: 700 9px/1 Consolas, monospace; letter-spacing: .24em; }
.story-shell h2 {
  position: relative; max-width: 780px; margin: 18px 0 0; color: var(--bone);
  font: 400 clamp(48px, 9vw, 118px)/.82 Impact, Haettenschweiler, sans-serif; letter-spacing: .01em;
}
.story-name { position: relative; margin-top: 12px; color: var(--burn); font: 700 11px Consolas, monospace; letter-spacing: .2em; }
.story-copy { position: relative; max-width: 620px; margin: 34px 0 20px; color: #a1a39d; font-size: clamp(14px, 1.4vw, 18px); line-height: 1.7; }
.story-objective { position: relative; max-width: 620px; border-left: 2px solid var(--acid); padding: 4px 0 4px 14px; margin-bottom: 26px; }
.story-objective span { color: var(--acid); font: 700 8px Consolas, monospace; letter-spacing: .2em; }
.story-objective p { margin-top: 5px; color: var(--bone); font: 700 10px/1.5 Consolas, monospace; letter-spacing: .05em; }
.story-shell > .text-btn { width: min(330px, 100%); margin-top: 14px; text-align: left; }

/* chapter archive */
.archive-shell { position: relative; z-index: 2; width: min(1120px, 94vw); max-height: 88vh; overflow-y: auto; padding: 12px 4px 24px; scrollbar-width: thin; }
.archive-head { display: flex; align-items: end; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 12px 0 18px; }
.archive-head h2 { font: 400 clamp(42px, 7vw, 82px)/.85 Impact, sans-serif; }
.archive-close { width: 44px; height: 44px; border: 1px solid var(--line); background: none; cursor: pointer; font-size: 24px; }
.archive-close:hover { border-color: var(--acid); color: var(--acid); }
.archive-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; margin-top: 18px; background: var(--line); }
.chapter-card {
  position: relative; min-height: 126px; border: 0; background: var(--ink); color: var(--bone); text-align: left;
  padding: 14px; cursor: pointer; overflow: hidden; transition: background .12s, color .12s;
}
.chapter-card:hover:not(:disabled), .chapter-card.current { background: var(--acid); color: var(--ink); }
.chapter-card:disabled { cursor: not-allowed; opacity: .28; }
.chapter-card .ch-num { display: block; font: 400 34px/1 Impact, sans-serif; }
.chapter-card .ch-boss { display: block; margin-top: 15px; font: 700 9px/1.3 Consolas, monospace; letter-spacing: .12em; }
.chapter-card .ch-state { display: block; margin-top: 7px; font: 700 7px Consolas, monospace; opacity: .62; }
.fragment-panel { margin-top: 18px; border: 1px solid var(--line); padding: 16px; }
.fragment-head { color: var(--burn); font: 700 9px Consolas, monospace; letter-spacing: .18em; }
.fragment-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.fragment-item { min-height: 64px; padding: 10px; background: rgba(242,240,231,.035); font: 700 8px/1.5 Consolas, monospace; color: #797c76; }
.fragment-item.found { color: var(--acid); background: rgba(217,255,82,.06); }
.fragment-item b { display: block; margin-bottom: 4px; color: inherit; letter-spacing: .1em; }

/* branch selection */
.branch-shell { position: relative; z-index: 2; width: min(960px, 94vw); }
.branch-shell h2, .pause-shell h2 {
  margin: 12px 0 8px;
  font: 400 clamp(38px, 6vw, 74px)/.95 Impact, Haettenschweiler, sans-serif;
  letter-spacing: .01em;
}
#branch-summary { color: #8e918b; font: 11px/1.5 Consolas, monospace; letter-spacing: .07em; }
.branch-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 28px; }
.branch-card {
  min-height: 220px;
  border: 1px solid var(--line);
  background: rgba(7, 8, 6, .76);
  color: var(--bone);
  padding: 18px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  clip-path: polygon(0 0, calc(100% - 18px) 0, 100% 18px, 100% 100%, 0 100%);
  transition: background .12s, color .12s, transform .12s;
  animation: card-rise .3s var(--ease-cut) backwards;
}
.branch-card:nth-child(2) { animation-delay: .06s; }
.branch-card:nth-child(3) { animation-delay: .12s; }
@keyframes card-rise { from { opacity: 0; transform: translateY(24px); } }
.branch-card:hover, .branch-card:focus-visible { background: var(--acid); color: var(--ink); transform: translateY(-5px); border-color: var(--acid); }
.branch-card .card-num { font: 700 9px Consolas, monospace; letter-spacing: .18em; opacity: .62; }
.branch-card .card-glyph { margin: 25px 0 18px; font: 400 44px/1 Impact, sans-serif; }
.branch-card h3 { font: 400 25px/1 Impact, sans-serif; letter-spacing: .03em; }
.branch-card p { margin-top: 8px; font: 10px/1.5 Consolas, monospace; opacity: .7; }
.branch-card .card-stat { margin-top: auto; padding-top: 18px; font: 700 9px Consolas, monospace; letter-spacing: .09em; }

/* result + pause */
.result-shell, .pause-shell { position: relative; z-index: 2; width: min(620px, 92vw); }
.result-shell h2 {
  margin: 16px 0 20px;
  font: 400 clamp(58px, 10vw, 118px)/.76 Impact, Haettenschweiler, sans-serif;
}
.result-shell h2.failed { color: transparent; -webkit-text-stroke: 1px var(--burn); }
.score-lockup { display: flex; align-items: end; gap: 10px; border-top: 1px solid var(--line); padding-top: 12px; }
.score-lockup span { font: 400 clamp(48px, 8vw, 82px)/1 Impact, sans-serif; color: var(--acid); font-variant-numeric: tabular-nums; }
.score-lockup i { margin-bottom: 8px; color: var(--steel); font: 700 9px Consolas, monospace; font-style: normal; letter-spacing: .16em; }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin: 16px 0 22px; background: var(--line); }
.result-grid div { background: var(--ink); padding: 10px; }
.result-grid b { display: block; font: 400 25px Impact, sans-serif; }
.result-grid span { color: var(--steel); font: 700 8px Consolas, monospace; letter-spacing: .12em; }
.result-shell .text-btn, .pause-shell .text-btn { display: block; margin-top: 16px; padding: 8px 0; }
.result-story { max-width: 580px; margin: 4px 0 20px; color: #a1a39d; font-size: 13px; line-height: 1.65; }
.submit-row { display: flex; gap: 8px; margin-top: 14px; max-width: 430px; }
.text-input { flex: 1; min-width: 0; min-height: 42px; border: 1px solid var(--line); background: rgba(7,8,6,.7); color: var(--bone); padding: 0 12px; font: 700 11px Consolas, monospace; outline: none; }
.text-input:focus { border-color: var(--acid); }
.submit-status { min-height: 18px; margin-top: 6px; color: var(--steel); font: 9px/1.4 Consolas, monospace; }
.board-card { max-width: 500px; margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.board-title { color: var(--steel); font: 700 8px Consolas, monospace; letter-spacing: .16em; margin-bottom: 5px; }
.board-row { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center; padding: 4px 0; font: 9px Consolas, monospace; }
.board-rank { color: var(--acid); }.board-name { color: var(--bone); }.board-meta { color: var(--steel); font-size: 7px; }.board-score { color: var(--bone); }
.board-empty { color: var(--steel); font: 9px Consolas, monospace; padding: 5px 0; }
.pause-shell { text-align: left; }

/* rewind + toasts */
#rewind { position: absolute; z-index: 50; inset: 0; display: none; pointer-events: none; background: var(--bone); color: var(--ink); overflow: hidden; }
#rewind.play { display: block; animation: rewind-flash .72s steps(1) both; }
#rewind i { position: absolute; inset: 0; background: repeating-linear-gradient(90deg, transparent 0 8%, rgba(7,8,6,.16) 8% 8.25%); transform: skewX(-16deg) scaleX(1.5); }
#rewind b { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font: 400 clamp(70px, 18vw, 210px)/1 Impact, sans-serif; letter-spacing: .04em; }
@keyframes rewind-flash {
  0% { opacity: 0; }
  8% { opacity: 1; }
  35% { opacity: 1; transform: translateX(0); }
  48% { opacity: .82; transform: translateX(-3%); }
  65% { opacity: .45; transform: translateX(2%); }
  100% { opacity: 0; }
}
#toast { position: absolute; z-index: 12; left: 50%; top: 21%; transform: translate(-50%, -12px); opacity: 0; color: var(--acid); font: 700 10px Consolas, monospace; letter-spacing: .18em; pointer-events: none; transition: .18s; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 720px) {
  #hud { grid-template-columns: 72px minmax(110px, 1fr) 82px; left: 12px; right: 12px; top: 10px; gap: 10px; }
  .hud-loop strong, .hud-time strong { font-size: 30px; }
  #ui-boss-name { font-size: 8px; letter-spacing: .13em; white-space: nowrap; }
  .hud-kicker { font-size: 7px; letter-spacing: .1em; }
  #side-ui { left: 12px; bottom: 12px; gap: 10px; }
  .sync-wrap { grid-template-columns: auto 52px 28px; gap: 5px; font-size: 7px; }
  #game-actions { right: 12px; bottom: 12px; }
  .menu-shell { padding-left: 4%; }
  .menu-shell h1 { font-size: clamp(65px, 23vw, 116px); }
  .tagline { margin-top: 28px; }
  .menu-time { opacity: .45; right: 5%; bottom: 9%; }
  .branch-cards { grid-template-columns: 1fr; max-height: 58vh; overflow-y: auto; }
  .branch-card { min-height: 128px; display: grid; grid-template-columns: 58px 1fr; gap: 4px 12px; }
  .branch-card .card-num { grid-column: 2; }
  .branch-card .card-glyph { grid-column: 1; grid-row: 1 / span 4; margin: 16px 0 0; font-size: 32px; }
  .branch-card h3, .branch-card p, .branch-card .card-stat { grid-column: 2; }
  .branch-card h3 { font-size: 21px; }
  .branch-card p { margin-top: 2px; }
  .branch-card .card-stat { padding-top: 5px; }
  .story-shell { min-height: auto; padding: 20px 4px; }
  .story-shell h2 { font-size: clamp(52px, 17vw, 78px); }
  .story-copy { margin-top: 24px; font-size: 14px; }
  .archive-grid { grid-template-columns: repeat(2, 1fr); }
  .fragment-list { grid-template-columns: 1fr; }
  .submit-row { flex-direction: column; }
  .secondary-btn.compact { width: 100%; }
}

@media (max-height: 540px) {
  .menu-shell h1 { font-size: clamp(60px, 18vh, 96px); }
  .menu-shell { padding-left: 8%; }
  .tagline { margin: 24px 0 14px; }
  .how-grid { margin-top: 12px; }
  .menu-meta { margin-top: 10px; }
  .branch-card { min-height: 170px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  #rewind.play { background: rgba(242, 240, 231, .88); }
}
