:root {
  color-scheme: dark;
  --ink: #07090a;
  --paper: #eee2c8;
  --paper-dim: #afa58f;
  --vermilion: #c73327;
  --gold: #d7ae59;
  --jade: #78c7aa;
  --panel: rgba(8, 11, 12, .78);
  --display: "Yuji Syuku", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --body: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
}

::selection { background: transparent; color: inherit; }

html, body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: -webkit-fill-available;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #030405;
  color: var(--paper);
  font-family: var(--body);
}

button { border: 0; color: inherit; font: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid #fff2aa; outline-offset: 3px; }

#game-shell {
  display: grid;
  grid-template-rows: minmax(0, 70fr) minmax(188px, 30fr);
  width: 100vw;
  height: 100%;
  height: -webkit-fill-available;
  height: 100dvh;
  background: #07090a;
}

#game-view {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border-bottom: 2px solid #76502c;
  background: #0c1012;
  isolation: isolate;
}

#game-view::after {
  content: "";
  position: absolute;
  z-index: 2;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(255,255,255,.022) 1px, transparent 1px) 0 0 / 5px 100%,
    repeating-linear-gradient(0deg, transparent 0 3px, rgba(0,0,0,.08) 4px);
  mix-blend-mode: soft-light;
}

#gameCanvas { display: block; width: 100%; height: 100%; background: #101719; }

#hud {
  position: absolute;
  z-index: 8;
  top: max(8px, var(--safe-top));
  left: max(9px, var(--safe-left));
  right: max(9px, var(--safe-right));
  display: flex;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
}

.hud-block {
  min-height: 44px;
  padding: 7px 11px;
  border: 1px solid rgba(213, 183, 119, .34);
  border-left: 3px solid var(--gold);
  background: linear-gradient(110deg, rgba(4,6,7,.91), rgba(10,14,15,.7));
  box-shadow: 0 7px 18px rgba(0,0,0,.26), inset 0 1px rgba(255,255,255,.04);
  backdrop-filter: blur(8px);
  clip-path: polygon(0 0, calc(100% - 7px) 0, 100% 7px, 100% 100%, 0 100%);
}

.stage-block { min-width: 168px; }
.hud-block strong { display: block; font-size: clamp(12px, 1.7vw, 17px); letter-spacing: .08em; white-space: nowrap; }
.eyebrow { display: block; margin-bottom: 2px; color: var(--gold); font: 700 9px/1.2 var(--body); letter-spacing: .18em; text-transform: uppercase; }
.meters { width: min(242px, 25vw); min-width: 160px; }
.meter-row { display: grid; grid-template-columns: 22px 1fr 24px; align-items: center; gap: 6px; height: 15px; font: 700 10px/1 sans-serif; }
.meter-row i { height: 5px; overflow: hidden; background: #271917; box-shadow: inset 0 1px 2px #000; }
.meter-row i b { display: block; width: 100%; height: 100%; background: linear-gradient(90deg, #92251d, #e35a3d); transform-origin: left; transition: transform .18s; }
.meter-row.shadow i b { background: linear-gradient(90deg, #2d6860, #8de0bd); }
.meter-row em { color: #d8ccb2; font-style: normal; text-align: right; }
.mission-block { min-width: 195px; margin-left: auto; }
.mission-block #objectiveCount { display: block; margin-top: 2px; color: #9be7cf; font: 700 10px/1 sans-serif; }

.game-btn {
  min-height: 48px;
  cursor: pointer;
  transition: transform .08s ease, opacity .08s ease, filter .08s ease;
  will-change: transform;
  touch-action: manipulation;
}
.game-btn:active,
.game-btn.is-pressed {
  transform: scale(.92);
  opacity: .88;
  filter: brightness(1.28);
}
.primary-button {
  min-height: 56px;
}
.utility-button, .pause-button {
  position: relative;
  z-index: 10;
  display: grid;
  place-items: center;
  width: 37px;
  min-width: 37px;
  height: 37px;
  border: 1px solid rgba(215,174,89,.5);
  background: rgba(8,10,11,.82);
  color: #dbc99f;
  pointer-events: auto;
}

.pause-button { position: absolute; right: max(10px, var(--safe-right)); bottom: 12px; }

#stage-route {
  position: absolute;
  z-index: 7;
  top: max(69px, calc(var(--safe-top) + 62px));
  left: max(12px, var(--safe-left));
  display: flex;
  align-items: center;
  gap: 3px;
  filter: drop-shadow(0 3px 6px #000);
}

.route-node { display: grid; grid-template-columns: 20px auto; align-items: center; gap: 4px; opacity: .38; transition: opacity .25s, transform .25s; }
.route-node b { display: grid; place-items: center; width: 20px; height: 20px; border: 1px solid #b99958; border-radius: 50%; background: #101315; color: #dec786; font-size: 10px; }
.route-node small { display: none; color: #dfd4bc; font-size: 9px; white-space: nowrap; }
.route-node.current { opacity: 1; transform: scale(1.07); }
.route-node.current small { display: block; }
.route-node.done { opacity: .76; }
#stage-route > i { width: 12px; height: 1px; background: #8a754a; opacity: .45; }

#notice {
  position: absolute;
  z-index: 12;
  top: 22%;
  left: 50%;
  display: flex;
  align-items: stretch;
  max-width: 84vw;
  transform: translate(-50%, -30px);
  opacity: 0;
  pointer-events: none;
}

#notice.show { animation: notice-in 3.2s ease both; }
#noticeKicker { display: grid; place-items: center; padding: 9px 12px; background: var(--vermilion); color: #fff5db; font: 700 12px/1 var(--display); letter-spacing: .12em; }
#noticeText { padding: 10px 16px; border: 1px solid #8b6f3f; background: rgba(6,8,9,.92); color: #f0e5cb; font-size: clamp(12px, 2.6vw, 16px); max-width: min(72vw, 22em); line-height: 1.55; white-space: normal; }

#alert-vane {
  position: absolute;
  z-index: 7;
  left: max(12px, var(--safe-left));
  bottom: 12px;
  display: grid;
  grid-template-columns: auto min(170px, 27vw) 38px;
  align-items: center;
  gap: 7px;
  padding: 7px 9px;
  border: 1px solid rgba(232, 199, 129, .25);
  background: rgba(5,7,8,.7);
  font: 700 9px/1 sans-serif;
  letter-spacing: .08em;
}
#alert-vane > i { width: 100%; height: 4px; overflow: hidden; background: #251312; }
#alert-vane > i b { display: block; width: 100%; height: 100%; background: linear-gradient(90deg, #b88136, #df2e24); transform: scaleX(0); transform-origin: left; }
#alert-vane em { color: #d8b87a; font-style: normal; }

.screen-layer {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  place-items: center;
  padding: max(20px, var(--safe-top)) max(24px, var(--safe-right)) max(20px, var(--safe-bottom)) max(24px, var(--safe-left));
  background:
    linear-gradient(90deg, rgba(4,6,7,.32), rgba(4,6,7,.94) 62%),
    radial-gradient(circle at 25% 25%, #853727 0, #202726 30%, #07090a 70%);
}
.screen-layer.hidden { display: none; }

.title-art { position: relative; width: min(55vh, 42vw); aspect-ratio: 1; }
.title-art .moon { position: absolute; top: 3%; left: 8%; width: 60%; aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle at 39% 37%, #fff7c2 0 8%, #f2d24a 38%, #d49a18 64%, transparent 69%); box-shadow: 0 0 55px rgba(242, 196, 64, .42); }
.title-art .keep { position: absolute; right: 2%; bottom: 4%; width: 76%; height: 68%; background: #07090a; clip-path: polygon(8% 16%,25% 16%,28% 7%,52% 7%,55% 16%,73% 16%,77% 29%,88% 29%,92% 42%,82% 42%,86% 59%,98% 59%,100% 100%,0 100%,3% 59%,17% 59%,13% 42%,4% 42%,8% 29%,21% 29%); filter: drop-shadow(0 6px 0 #32150f); }
.title-art .keep::after { content: ""; position: absolute; inset: 29% 26% 12%; background: repeating-linear-gradient(90deg, #ab713e 0 4px, transparent 4px 23px), repeating-linear-gradient(0deg, #8b5631 0 3px, transparent 3px 27px); opacity: .43; }
.ninja-mark { position: absolute; left: 2%; bottom: 0; color: rgba(240,225,190,.08); font: 900 min(36vh, 30vw)/1 var(--display); transform: rotate(-8deg); }

.title-copy { position: relative; z-index: 2; max-width: 540px; justify-self: start; }
.seal { display: inline-grid; place-items: center; width: 34px; height: 47px; margin: 0 0 9px; border: 2px solid #db4938; color: #e4503f; font: 800 12px/1 var(--display); writing-mode: vertical-rl; transform: rotate(7deg); }
.overline { margin: 0 0 5px; color: #d4ae63; font: 700 10px/1 sans-serif; letter-spacing: .28em; }
.title-copy h1 { margin: 0; color: #f2e8d1; font: 900 clamp(54px, 10vw, 112px)/.94 var(--display); letter-spacing: .12em; text-shadow: 5px 5px 0 #6d201a, 0 18px 35px #000; }
.title-sub { margin: 18px 0 23px; color: #c4b9a1; font-size: clamp(12px, 1.5vw, 16px); line-height: 1.9; letter-spacing: .07em; }
.primary-button { min-width: 195px; padding: 14px 30px; border: 1px solid #ed7962; background: linear-gradient(165deg, #c83b2f, #761912); color: #fff1d4; box-shadow: 0 5px 0 #3d0b08, 0 12px 30px rgba(0,0,0,.4); font: 800 18px/1 var(--display); letter-spacing: .18em; transition: transform .08s, filter .08s; }
.primary-button:active { transform: translateY(4px); filter: brightness(1.2); box-shadow: 0 1px 0 #3d0b08; }
.title-meta { display: flex; align-items: center; gap: 18px; margin-top: 16px; color: #8e8779; font: 700 10px/1 sans-serif; letter-spacing: .1em; }
.title-meta b { color: #c9b47d; }
#techBtn { padding: 5px 8px; border-bottom: 1px solid #725b35; background: transparent; color: #bda873; font-size: 10px; pointer-events: auto; }

#result-screen { grid-template-columns: 1fr; background: radial-gradient(circle at 50% 40%, rgba(112,42,29,.7), rgba(5,7,8,.96) 60%); }
.result-card { width: min(570px, 90vw); padding: clamp(24px, 5vw, 50px); border: 1px solid #8d6b39; background: rgba(7,9,10,.84); text-align: center; box-shadow: 0 30px 90px #000; }
.result-card h2 { margin: 8px 0 13px; font: 900 clamp(38px, 8vw, 76px)/1 var(--display); letter-spacing: .1em; }
.result-card > p:not(.overline) { color: #bcb29c; line-height: 1.8; }
.result-stats { display: flex; justify-content: center; gap: 28px; margin: 20px 0; color: #a79b83; font-size: 12px; }
.result-stats b { color: #f1d994; font-size: 20px; }

#tech-panel {
  position: absolute;
  z-index: 30;
  top: 0;
  right: 0;
  width: min(430px, 92vw);
  height: 100%;
  padding: max(22px, var(--safe-top)) max(24px, var(--safe-right)) max(20px, var(--safe-bottom)) 25px;
  overflow: auto;
  background: rgba(7,10,11,.97);
  border-left: 1px solid #71582e;
  box-shadow: -22px 0 65px #000;
  transform: translateX(105%);
  transition: transform .28s cubic-bezier(.2,.75,.2,1);
}
#tech-panel.open { transform: translateX(0); }
.tech-head { display: flex; align-items: flex-start; justify-content: space-between; }
.tech-head span { color: #b99854; font: 700 9px/1 sans-serif; letter-spacing: .25em; }
.tech-head h2 { margin: 5px 0 12px; font: 800 26px/1.1 var(--display); }
#techClose { width: 37px; height: 37px; border: 1px solid #6a593c; background: #151819; font-size: 22px; }
#techList { margin: 8px 0; padding: 0; list-style: none; counter-reset: tech; }
#techList li { counter-increment: tech; position: relative; margin: 0; padding: 10px 8px 10px 42px; border-top: 1px solid rgba(220,189,119,.15); color: #bcb39f; font-size: 11px; line-height: 1.55; }
#techList li::before { content: counter(tech, decimal-leading-zero); position: absolute; top: 10px; left: 3px; color: #d34232; font: 800 12px/1 sans-serif; }
#techList strong { display: block; color: #eadfc7; font-size: 12px; letter-spacing: .05em; }
#techList .available { color: #86d1b4; }
#techList .fallback { color: #cfac6a; }

#pause-layer { position: absolute; z-index: 17; inset: 0; display: grid; place-content: center; gap: 8px; background: rgba(3,5,6,.76); text-align: center; backdrop-filter: blur(5px); }
#pause-layer.hidden { display: none; }
#pause-layer strong { font: 800 clamp(35px, 8vw, 70px)/1 var(--display); letter-spacing: .15em; }
#pause-layer span { color: #b6ac98; font-size: 12px; }

#controls {
  --pad: clamp(48px, 12.5vw, 58px);
  --stick: min(168px, calc(var(--pad) * 3 + 6px), 44vw, 38vh);
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  justify-items: center;
  min-height: 0;
  padding: 8px max(10px, var(--safe-right)) max(8px, var(--safe-bottom)) max(10px, var(--safe-left));
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% -80%, rgba(151,90,45,.32), transparent 60%),
    repeating-linear-gradient(97deg, transparent 0 42px, rgba(211,158,91,.025) 43px 44px),
    linear-gradient(#2b211b, #131719 43%, #090b0d);
  box-shadow: inset 0 2px rgba(232,181,108,.22), inset 0 8px 20px rgba(0,0,0,.5);
}

.dpad {
  justify-self: start;
  position: relative;
  width: var(--stick);
  height: var(--stick);
  margin-left: 4px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 28%, #3e4548, #14181a 62%, #0a0c0d 82%);
  box-shadow:
    inset 2px 2px rgba(255,255,255,.14),
    inset -4px -6px rgba(0,0,0,.55),
    0 4px 6px #000;
  touch-action: none;
  cursor: pointer;
}
.dpad > * { pointer-events: none; }
.dpad-bar {
  position: absolute;
  border-radius: 18%;
  background: linear-gradient(145deg, #5b6367, #1b2023 64%);
  box-shadow: inset 2px 2px rgba(255,255,255,.12), inset -3px -3px #080a0b;
}
.dpad-bar-x {
  left: 11%;
  right: 11%;
  top: 50%;
  height: 32%;
  transform: translateY(-50%);
}
.dpad-bar-y {
  top: 11%;
  bottom: 11%;
  left: 50%;
  width: 32%;
  transform: translateX(-50%);
}
.dpad-mark {
  position: absolute;
  z-index: 1;
  color: #c5cbc8;
  font: 800 13px/1 sans-serif;
  text-shadow: 0 1px 0 #000;
}
.dpad-mark small { display: block; margin-top: 2px; color: #d4b56e; font: 700 7px/1 var(--body); }
.dpad-mark-up { top: 10%; left: 50%; transform: translateX(-50%); }
.dpad-mark-down { bottom: 8%; left: 50%; transform: translateX(-50%); text-align: center; }
.dpad-mark-left { left: 11%; top: 50%; transform: translateY(-50%); }
.dpad-mark-right { right: 11%; top: 50%; transform: translateY(-50%); }
.dpad-nub {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 50%;
  width: 26%;
  height: 26%;
  margin: -13% 0 0 -13%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #6c7478, #1e2326 72%);
  box-shadow: inset 2px 2px rgba(255,255,255,.2), 0 2px 3px #000;
}
.dpad.is-up .dpad-mark-up,
.dpad.is-down .dpad-mark-down,
.dpad.is-left .dpad-mark-left,
.dpad.is-right .dpad-mark-right { color: #f0d59a; }
.dpad.is-pressed .dpad-bar { filter: brightness(1.18); }

.action-buttons {
  justify-self: end;
  position: relative;
  width: var(--stick);
  height: var(--stick);
  margin-right: 4px;
}
.action-buttons button {
  position: absolute;
  display: grid;
  place-content: center;
  width: calc(var(--stick) / 3);
  height: calc(var(--stick) / 3);
  min-width: 0;
  min-height: 0;
  border-radius: 50%;
  color: #fff4d8;
  box-shadow: inset 2px 2px rgba(255,255,255,.16), inset -4px -5px rgba(0,0,0,.35), 0 4px 5px #000;
}
.action-buttons b { font: 900 16px/1 sans-serif; }
.action-buttons small { margin-top: 2px; font: 700 7px/1 var(--body); }
.action-x { top: 0; left: calc(50% - var(--stick) / 6); background: radial-gradient(circle at 32% 28%, #d4b06a, #6a4a22 72%); }
.action-y { top: calc(50% - var(--stick) / 6); left: 0; background: radial-gradient(circle at 32% 28%, #4e7d74, #163230 72%); }
.action-a { top: calc(50% - var(--stick) / 6); right: 0; background: radial-gradient(circle at 32% 28%, #c45a42, #6e1a16 72%); }
.action-b { bottom: 0; left: calc(50% - var(--stick) / 6); color: #2c2618; background: radial-gradient(circle at 32% 28%, #efe6c8, #8d8064 74%); }
.action-buttons button:active,
.action-buttons button.is-pressed {
  transform: scale(.92);
  box-shadow: inset 2px 3px 6px #000;
}
.keyboard-help { position: absolute; right: 11px; bottom: max(3px, var(--safe-bottom)); color: #777065; font: 700 8px/1 sans-serif; letter-spacing: .04em; pointer-events: none; }

@keyframes notice-in {
  0% { opacity: 0; transform: translate(-50%, -28px); }
  12%, 74% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, 10px); }
}

@media (max-width: 760px) {
  #game-shell { grid-template-rows: minmax(0, 68fr) minmax(176px, 32fr); }
  .screen-layer { grid-template-columns: .72fr 1.28fr; padding-inline: 14px; }
  .title-copy h1 { font-size: clamp(45px, 13vw, 72px); }
  .title-sub { font-size: 10px; margin: 11px 0 15px; }
  .stage-block { min-width: 122px; }
  .hud-block { min-height: 39px; padding: 6px 8px; }
  .hud-block strong { font-size: 10px; }
  .meters { width: 132px; min-width: 132px; }
  .mission-block { min-width: 132px; }
  .mission-block #objectiveText { max-width: 132px; overflow: hidden; text-overflow: ellipsis; }
  .utility-button { width: 31px; min-width: 31px; height: 31px; font-size: 10px; }
  #stage-route { top: max(57px, calc(var(--safe-top) + 50px)); }
  #alert-vane { grid-template-columns: auto min(115px, 25vw) 34px; }
  #controls { --pad: clamp(48px, 12vw, 56px); }
  .keyboard-help { display: none; }
}

@media (max-width: 570px) {
  #hud { gap: 4px; }
  .meters { width: 112px; min-width: 112px; }
  .mission-block { display: none; }
  .stage-block { min-width: 128px; }
  #stage-route .route-node small { display: none; }
  #stage-route { gap: 1px; }
  #stage-route > i { width: 7px; }
  .screen-layer { grid-template-columns: .54fr 1.46fr; }
  .title-art { width: 48vw; transform: translateX(13%); }
  .title-copy { transform: translateX(-4%); }
  .title-copy h1 { font-size: clamp(42px, 15vw, 63px); }
  .title-sub br { display: none; }
  .title-meta { gap: 8px; }
  #controls { --pad: 48px; }
}

@media (orientation: portrait) and (max-width: 600px) {
  #game-shell { grid-template-rows: minmax(0, 64fr) minmax(196px, 36fr); }
  .screen-layer { grid-template-columns: 1fr; }
  .title-art { position: absolute; inset: 0; width: 100%; opacity: .5; }
  .title-copy { justify-self: center; text-align: center; transform: none; }
  .title-copy h1 { font-size: min(20vw, 84px); }
  .title-sub { font-size: 11px; }
  #controls { --pad: clamp(48px, 13.5vw, 56px); }
  #alert-vane {
    top: max(52px, calc(var(--safe-top) + 46px));
    right: max(8px, var(--safe-right));
    bottom: auto;
    left: auto;
  }
  .pause-button { width: 44px; min-width: 44px; height: 44px; }
}

@media (max-width: 380px) {
  #controls { --pad: 48px; }
  .dpad { justify-self: start; margin-left: 2px; }
  .action-buttons { justify-self: end; margin-right: 2px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  #game-shell { grid-template-rows: minmax(0, 62fr) minmax(148px, 38fr); }
  #controls { --pad: 48px; padding-top: 4px; padding-bottom: max(4px, var(--safe-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
