:root {
  --ink: #121623;
  --panel: rgba(13, 17, 29, 0.86);
  --panel-solid: #151a28;
  --line: rgba(240, 207, 158, 0.38);
  --cream: #f5dfbb;
  --muted: #b9b2a8;
  --ember: #ff922e;
  --ember-light: #ffd27a;
  --paper: #f3eee4;
  --touch-opacity: .9;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: #0d1321; }
html { overscroll-behavior: none; }

body {
  color: var(--cream);
  font-family: "Noto Sans SC", system-ui, sans-serif;
  background:
    radial-gradient(circle at 70% -20%, rgba(218, 101, 42, 0.18), transparent 42%),
    linear-gradient(160deg, #151b2d 0%, #090e19 72%);
}

html.is-playing, body.is-playing, body.is-playing .game-page {
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

button, a { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.game-page { width: min(100%, 1700px); margin: 0 auto; min-height: 100vh; }

.site-bar {
  min-height: 68px;
  padding: 10px clamp(14px, 3vw, 34px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: rgba(8, 12, 21, 0.88);
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand { color: #fff; text-decoration: none; display: inline-flex; align-items: center; gap: 11px; }
.brand img { width: 40px; height: 40px; border-radius: 10px; }
.brand span { display: flex; flex-direction: column; line-height: 1.1; }
.brand strong { font-family: "Ma Shan Zheng", cursive; font-size: 23px; font-weight: 400; }
.brand small { color: #8f98aa; font-size: 10px; letter-spacing: .08em; margin-top: 3px; }

.site-actions { display: flex; align-items: center; gap: 8px; }
.site-actions a, .site-actions button {
  color: #c9cfda;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px;
  background: rgba(255,255,255,.04);
  padding: 8px 13px;
  text-decoration: none;
  cursor: pointer;
  font-size: 13px;
}
.site-actions a:hover, .site-actions button:hover { color: #fff; border-color: rgba(255,210,122,.5); }

.game-frame {
  position: relative;
  width: min(100%, calc((100svh - 68px) * 16 / 9));
  aspect-ratio: 16 / 9;
  min-height: 0;
  margin: 0 auto;
  overflow: hidden;
  overflow: clip;
  background: #25334e;
  box-shadow: 0 28px 80px rgba(0,0,0,.42);
  isolation: isolate;
}

#gameCanvas { display: block; width: 100%; height: 100%; outline: none; touch-action: none; }

.hud { position: absolute; inset: 0 0 auto; display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 16px; padding: clamp(12px, 2vw, 24px); pointer-events: none; }
.hud-left { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.game-mark, .level-title, #pauseButton, .time {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: inset 0 0 0 2px rgba(0,0,0,.24), 0 7px 20px rgba(0,0,0,.25);
  backdrop-filter: blur(9px);
}
.game-mark { font-family: "Ma Shan Zheng", cursive; font-size: clamp(19px, 2.1vw, 31px); padding: 6px 15px; border-radius: 9px; }
.health { display: flex; gap: 5px; padding-left: 4px; }
.heart { position: relative; width: clamp(25px, 2.6vw, 40px); aspect-ratio: 1; filter: drop-shadow(0 4px 5px rgba(0,0,0,.35)); }
.heart::before { content: "♥"; color: #ff5b38; font-size: clamp(28px, 3vw, 45px); line-height: 1; -webkit-text-stroke: 2px #61261f; }
.heart.is-empty::before { color: rgba(18,20,27,.72); -webkit-text-stroke-color: #726555; }
.level-title { min-width: clamp(210px, 29vw, 400px); text-align: center; border-radius: 10px; padding: 9px 28px; }
.level-title span { color: #c9bda8; font-size: clamp(10px, 1vw, 13px); letter-spacing: .2em; }
.level-title strong { display: block; font-family: "Ma Shan Zheng", cursive; font-size: clamp(21px, 2.4vw, 35px); font-weight: 400; line-height: 1.05; }
.level-title em { display: block; margin-top: 4px; color: #dfb575; font-size: clamp(9px, .82vw, 12px); font-style: normal; letter-spacing: .06em; white-space: nowrap; }
.hud-right { justify-self: end; display: flex; gap: 8px; align-items: center; pointer-events: auto; }
.time { display: none; }
#pauseButton { color: var(--cream); border-radius: 8px; padding: 9px 13px; cursor: pointer; }

.toast { position: absolute; z-index: 7; top: 21%; left: 50%; max-width: 76%; transform: translate(-50%, -10px); opacity: 0; padding: 9px 18px; border: 1px solid rgba(255,210,122,.55); border-radius: 999px; color: #fff2d7; background: rgba(12,16,27,.88); box-shadow: 0 8px 24px rgba(0,0,0,.32); text-align: center; pointer-events: none; transition: .25s ease; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.game-frame.boss-active .toast { top: 31%; }

.boss-hud { position: absolute; z-index: 5; top: clamp(90px, 10vw, 120px); left: 50%; width: min(48%, 620px); transform: translateX(-50%); text-align: center; pointer-events: none; }
.boss-hud[hidden] { display: none; }
.boss-hud-copy { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 8px 5px; }
.boss-hud strong { display: block; color: var(--cream); font-family: "Ma Shan Zheng", cursive; font-size: clamp(20px, 2vw, 31px); font-weight: 400; line-height: 1; text-shadow: 0 3px 8px rgba(0,0,0,.8); }
.boss-hud-copy span { color: #dbcfbc; font-size: clamp(9px, .8vw, 12px); letter-spacing: .12em; }
.boss-health-track { height: 18px; padding: 3px; border: 1px solid rgba(255,215,156,.65); border-radius: 999px; background: rgba(8,11,19,.9); box-shadow: 0 6px 18px rgba(0,0,0,.36), inset 0 0 0 2px rgba(0,0,0,.45); }
.boss-health-track span { display: block; width: 100%; height: 100%; border-radius: inherit; background: linear-gradient(90deg,#a52f22,#ef6230 72%,#ffc05d); box-shadow: 0 0 12px rgba(238,86,40,.45); transition: width .18s ease; }
.boss-hud.is-eclipse .boss-health-track span { background: linear-gradient(90deg,#4030a8,#7e4de6 58%,#55d9ff); box-shadow: 0 0 16px rgba(107,93,255,.62); }
.boss-hud.is-eclipse strong { color: #d9d3ff; text-shadow: 0 0 14px rgba(104,84,255,.6),0 3px 8px rgba(0,0,0,.9); }
.boss-hud.is-enraged .boss-health-track { animation: boss-rage .7s ease-in-out infinite alternate; }
.boss-hud > em { display: block; min-height: 16px; margin-top: 4px; color: #ffd98d; font-size: clamp(9px, .9vw, 12px); font-style: normal; letter-spacing: .1em; text-shadow: 0 2px 8px #000; }
@keyframes boss-rage { to { border-color: #b49cff; box-shadow: 0 0 20px rgba(128,84,255,.58),inset 0 0 0 2px rgba(0,0,0,.45); } }

.tutorial-hud { position: absolute; z-index: 6; top: 22%; left: 50%; display: flex; align-items: center; gap: 9px; transform: translateX(-50%); padding: 8px 14px; border: 1px solid rgba(255,199,102,.58); border-radius: 999px; color: #fff1d3; background: rgba(12,16,27,.86); box-shadow: 0 8px 26px rgba(0,0,0,.3); pointer-events: none; }
.tutorial-hud[hidden], .buff-hud[hidden] { display: none; }
.tutorial-hud span { color: #ffb44f; font-size: 10px; font-weight: 900; }
.tutorial-hud strong { font-size: 12px; }
.buff-hud { position: absolute; z-index: 6; left: 24px; bottom: 23%; max-width: 220px; padding: 7px 11px; border: 1px solid rgba(255,210,122,.45); border-radius: 8px; color: #ffe6b2; background: rgba(11,15,25,.76); font-size: 11px; pointer-events: none; }

.skill-controls { position: absolute; z-index: 6; right: 24px; bottom: 24px; display: flex; gap: 10px; pointer-events: none; }
.skill-trigger { position: relative; width: 76px; height: 76px; padding: 8px 4px 6px; overflow: hidden; pointer-events: auto; border: 2px solid rgba(255,219,167,.72); border-radius: 14px; color: #fff0d7; background: linear-gradient(145deg,rgba(38,27,27,.94),rgba(15,18,29,.9)); box-shadow: inset 0 0 0 3px rgba(0,0,0,.2),0 8px 22px rgba(0,0,0,.35); touch-action: none; cursor: pointer; opacity: var(--touch-opacity); }
.skill-trigger::before { content: ""; position: absolute; inset: 5px; border-radius: 10px; background: radial-gradient(circle at 50% 65%,rgba(255,121,37,.32),transparent 68%); }
.skill-trigger span,.skill-trigger strong { position: relative; z-index: 1; display: block; }
.skill-trigger span { position: absolute; top: 5px; left: 7px; color: #d8c9b4; font-size: 10px; }
.skill-trigger strong { margin-top: 14px; font-size: 17px; }
.skill-trigger em { position: absolute; z-index: 2; inset: 0; display: grid; place-items: center; color: #fff; background: rgba(8,12,20,.72); font-size: 19px; font-style: normal; font-weight: 900; opacity: 0; }
.skill-trigger.is-cooling em { opacity: 1; }
.skill-trigger.is-ready { border-color: #ffb24e; box-shadow: 0 0 18px rgba(255,137,37,.34),inset 0 0 0 3px rgba(0,0,0,.2); }
.skill-trigger.is-pressed { transform: scale(.93); }
.ember-nova-control::before { background: radial-gradient(circle at 50% 65%,rgba(255,192,69,.38),rgba(172,61,28,.18) 42%,transparent 70%); }

.overlay { position: absolute; inset: 0; z-index: 8; display: grid; place-items: center; padding: 28px; background: rgba(7,10,17,.63); backdrop-filter: blur(8px); opacity: 0; visibility: hidden; transition: .25s ease; }
.overlay.is-visible { opacity: 1; visibility: visible; }
.start-panel, .pause-panel, .result-panel { width: min(92%, 590px); text-align: center; padding: clamp(25px, 5vw, 54px); border: 1px solid var(--line); border-radius: 14px; background: linear-gradient(155deg, rgba(28,32,45,.97), rgba(12,15,24,.98)); box-shadow: 0 26px 90px rgba(0,0,0,.55), inset 0 0 50px rgba(255,146,46,.04); }
.chapter, .pause-panel > p, .result-panel > p { color: var(--ember-light); letter-spacing: .3em; font-size: 12px; margin: 0 0 10px; }
.start-panel h1, .pause-panel h2, .result-panel h2 { font-family: "Ma Shan Zheng", cursive; font-weight: 400; font-size: clamp(44px, 8vw, 76px); margin: 0; line-height: 1; }
.pause-panel h2, .result-panel h2 { font-size: clamp(34px, 6vw, 56px); }
.story { color: #c8c2b7; line-height: 1.8; margin: 18px auto 24px; max-width: 440px; }
.control-guide { display: flex; justify-content: center; flex-wrap: wrap; gap: 9px 16px; margin-bottom: 28px; color: #aeb5c2; font-size: 12px; }
.control-guide span { display: flex; align-items: center; gap: 5px; }
.touch-guide { display: none; }
kbd { min-width: 27px; padding: 4px 7px; border: 1px solid #596174; border-bottom-width: 3px; border-radius: 5px; color: #f1e6d4; background: #242a38; font-family: inherit; }
.primary-action, .secondary-action { display: block; width: min(100%, 280px); margin: 10px auto 0; padding: 13px 24px; border-radius: 8px; cursor: pointer; font-weight: 700; }
.primary-action { color: #24170d; border: 1px solid #ffd98f; background: linear-gradient(#ffc766, #e47b25); box-shadow: 0 8px 24px rgba(236,119,30,.3); }
.primary-action:hover { filter: brightness(1.08); }
.secondary-action { color: #d3d6de; border: 1px solid #4d5567; background: #202635; }
.start-panel small { display: block; margin-top: 14px; color: #777f8d; }
.orientation-overlay { display: none; }
.orientation-panel { width: min(88%, 420px); padding: 30px 24px; border: 1px solid var(--line); border-radius: 16px; background: linear-gradient(155deg,rgba(28,32,45,.98),rgba(12,15,24,.99)); box-shadow: 0 24px 80px rgba(0,0,0,.65); text-align: center; }
.orientation-panel p, .upgrade-panel > p { margin: 0 0 9px; color: var(--ember-light); font-size: 11px; letter-spacing: .24em; }
.orientation-panel h2, .upgrade-panel h2 { margin: 0; font-family: "Ma Shan Zheng", cursive; font-size: clamp(32px, 8.5vw, 46px); font-weight: 400; line-height: 1.08; }
.orientation-panel span, .upgrade-panel > span { display: block; margin: 12px auto 18px; color: #bfc4ce; font-size: 13px; line-height: 1.7; }
.upgrade-panel { width: min(92%, 680px); padding: clamp(24px,4vw,42px); border: 1px solid var(--line); border-radius: 16px; background: linear-gradient(155deg,rgba(28,32,45,.98),rgba(12,15,24,.99)); box-shadow: 0 26px 90px rgba(0,0,0,.6); text-align: center; }
.upgrade-panel h2 { font-size: clamp(34px,6vw,52px); }
.upgrade-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.upgrade-choices button { min-height: 142px; padding: 18px 14px; border: 1px solid rgba(255,206,133,.48); border-radius: 12px; color: #f9e7ca; background: linear-gradient(150deg,rgba(94,45,26,.72),rgba(24,24,38,.94)); cursor: pointer; }
.upgrade-choices button:last-child { background: linear-gradient(150deg,rgba(80,53,116,.68),rgba(24,24,38,.94)); }
.upgrade-choices small, .upgrade-choices strong, .upgrade-choices em { display: block; }
.upgrade-choices small { color: #ffba5a; font-size: 11px; letter-spacing: .18em; }
.upgrade-choices strong { margin: 8px 0; font-size: 20px; }
.upgrade-choices em { color: #aeb5c2; font-size: 12px; font-style: normal; line-height: 1.55; }
.mobile-settings { display: none; margin: 16px auto 6px; gap: 8px; }
.mobile-settings button, .mobile-settings label { color: #d8dbe2; border: 1px solid rgba(255,255,255,.13); border-radius: 8px; background: rgba(255,255,255,.05); padding: 9px 11px; font-size: 12px; }
.mobile-settings label { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 12px; }
.mobile-settings input { width: 100%; accent-color: var(--ember); }
.result-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 25px 0; }
.result-stats div { padding: 15px; border: 1px solid rgba(255,255,255,.1); background: rgba(255,255,255,.04); border-radius: 9px; }
.result-stats span { display: block; color: #8f98a8; font-size: 12px; }
.result-stats strong { font-size: 25px; font-variant-numeric: tabular-nums; }
.secondary-link { display: inline-block; margin-top: 16px; color: #aeb5c2; }

.mobile-controls { position: absolute; z-index: 5; inset: auto 0 16px; display: none; justify-content: space-between; align-items: end; padding: 0 22px; pointer-events: none; opacity: var(--touch-opacity); }
.mobile-controls > div { display: flex; gap: 14px; align-items: end; }
.joystick { position: relative; pointer-events: auto; width: 132px; height: 132px; border-radius: 50%; border: 2px solid rgba(255,219,167,.62); background: radial-gradient(circle, rgba(36,42,56,.48) 0 42%, rgba(11,15,25,.74) 44% 100%); box-shadow: inset 0 0 0 8px rgba(0,0,0,.2), 0 8px 22px rgba(0,0,0,.3); touch-action: none; }
.joystick::before, .joystick::after { content: ""; position: absolute; inset: 50% 14px auto; height: 1px; background: rgba(255,230,192,.18); }
.joystick::after { inset: 14px auto; left: 50%; width: 1px; height: calc(100% - 28px); }
.joystick-knob { position: absolute; left: 50%; top: 50%; width: 64px; height: 64px; border-radius: 50%; transform: translate(-50%, -50%); background: linear-gradient(145deg, rgba(255,221,173,.96), rgba(206,122,54,.96)); border: 3px solid rgba(255,243,216,.72); box-shadow: 0 8px 18px rgba(0,0,0,.4), inset 0 0 0 3px rgba(87,39,17,.22); transition: transform .08s ease; }
.joystick small { position: absolute; left: 50%; bottom: 7px; transform: translateX(-50%); color: rgba(255,243,218,.7); font-size: 11px; font-weight: 700; letter-spacing: .15em; }
.mobile-controls button { pointer-events: auto; width: 82px; height: 82px; border-radius: 50%; border: 2px solid rgba(255,219,167,.68); color: #fff1da; background: rgba(13,17,29,.74); box-shadow: inset 0 0 0 4px rgba(0,0,0,.2), 0 8px 22px rgba(0,0,0,.28); font-size: 25px; font-weight: 900; touch-action: none; }
.mobile-controls button.is-pressed { transform: scale(.93); background: rgba(218,107,43,.8); }
.mobile-controls .attack-control { width: 106px; height: 106px; font-size: 31px; background: linear-gradient(145deg, rgba(224,91,30,.94), rgba(142,42,20,.9)); }
.mobile-controls .jump-control { width: 92px; height: 92px; background: rgba(39,49,68,.82); }
.mobile-controls .dash-control { width: 70px; height: 70px; font-size: 20px; }
.mobile-controls .dash-control.is-dodging { color: #fff; border-color: #fff0a5; background: linear-gradient(145deg,rgba(255,190,72,.96),rgba(189,78,30,.94)); box-shadow: 0 0 26px rgba(255,185,69,.82), inset 0 0 0 4px rgba(255,244,188,.24); }
.game-frame.controls-swapped .mobile-controls { flex-direction: row-reverse; }
.game-frame.controls-swapped .skill-controls { right: auto; left: 24px; }

.game-notes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: rgba(255,255,255,.08); border-top: 1px solid rgba(255,255,255,.08); }
.game-notes div { padding: 18px clamp(14px, 3vw, 28px); background: #0d1321; }
.game-notes span { display: block; color: #727c8e; font-size: 11px; letter-spacing: .18em; margin-bottom: 5px; }
.game-notes strong { color: #c7ccd5; font-size: 13px; font-weight: 500; }

@media (hover: none), (max-width: 900px) {
  .mobile-controls { display: flex; }
  .desktop-guide { display: none; }
  .touch-guide { display: flex; }
  .mobile-settings { display: grid; }
  .site-actions a { display: none; }
  #pauseButton span, .time { display: none; }
  .skill-controls { right: 14px; bottom: 114px; }
  .skill-trigger { width: 66px; height: 66px; }
  .skill-trigger strong { font-size: 15px; }
}

@media (orientation: portrait) and (max-width: 900px) {
  .orientation-overlay { position: fixed; z-index: 30; inset: 0; display: grid; place-items: center; padding: 22px; background: radial-gradient(circle at 50% 20%,rgba(139,72,35,.22),transparent 48%),#090e19; }
}

@media (max-width: 680px) {
  .site-bar { min-height: 56px; }
  .brand img { width: 34px; height: 34px; }
  .brand strong { font-size: 19px; }
  .site-actions button { padding: 7px 9px; font-size: 11px; }
  .game-frame { width: 100%; height: auto; aspect-ratio: 16 / 9; min-height: 0; }
  .hud { gap: 6px; padding: 9px; }
  .game-mark { display: none; }
  .level-title { min-width: 145px; padding: 7px 10px; }
  .health { gap: 2px; }
  .heart { width: 22px; }
  .heart::before { font-size: 25px; -webkit-text-stroke-width: 1px; }
  .mobile-controls { bottom: 12px; padding: 0 10px; }
  .joystick { width: 108px; height: 108px; }
  .joystick-knob { width: 54px; height: 54px; }
  .mobile-controls button { width: 68px; height: 68px; }
  .mobile-controls .attack-control { width: 88px; height: 88px; }
  .mobile-controls .jump-control { width: 76px; height: 76px; }
  .mobile-controls .dash-control { width: 58px; height: 58px; }
  .skill-controls { right: 8px; bottom: 104px; gap: 7px; }
  .skill-trigger { width: 58px; height: 58px; border-radius: 12px; }
  .skill-trigger strong { margin-top: 10px; font-size: 14px; }
  .upgrade-choices { grid-template-columns: 1fr; }
  .game-notes { grid-template-columns: 1fr; }
  .game-notes div:not(:first-child) { display: none; }
}

@media (orientation: landscape) and (max-height: 500px) {
  html.is-playing, body.is-playing { height: 100svh; overflow: hidden; }
  body.is-playing .game-page { height: 100svh; overflow: hidden; }
  body.is-playing .game-notes { display: none; }
  .site-bar { display: none; }
  .game-frame { width: min(100%, calc(100svh * 16 / 9)); }
  .game-mark { display: none; }
  .hud { padding: 8px 10px; }
  .level-title { min-width: 178px; padding: 6px 14px; }
  .level-title strong { font-size: 22px; }
  .level-title em { margin-top: 2px; font-size: 8px; }
  .heart { width: 22px; }
  .heart::before { font-size: 25px; -webkit-text-stroke-width: 1px; }
  .mobile-controls { bottom: 10px; padding: 0 12px; }
  .joystick { width: 118px; height: 118px; }
  .joystick-knob { width: 58px; height: 58px; }
  .mobile-controls button { width: 72px; height: 72px; font-size: 21px; }
  .mobile-controls .attack-control { width: 96px; height: 96px; font-size: 28px; }
  .mobile-controls .jump-control { width: 82px; height: 82px; }
  .mobile-controls .dash-control { width: 64px; height: 64px; font-size: 18px; }
  .boss-hud { top: 70px; width: 44%; }
  .boss-hud-copy { margin-bottom: 3px; }
  .boss-hud strong { font-size: 20px; }
  .boss-health-track { height: 13px; padding: 2px; }
  .boss-hud > em { min-height: 13px; margin-top: 2px; font-size: 9px; }
  .game-frame.boss-active .toast { top: 34%; }
  .tutorial-hud { top: 23%; padding: 6px 11px; }
  .buff-hud { left: 10px; bottom: 32%; }
  .skill-controls { right: 12px; bottom: 113px; gap: 8px; }
  .skill-trigger { width: 62px; height: 62px; }
  .skill-trigger strong { margin-top: 10px; font-size: 15px; }
  .game-frame.controls-swapped .skill-controls { left: 12px; }
  .start-panel { max-height: calc(100svh - 20px); overflow-y: auto; padding: 15px 22px; }
  .start-panel h1 { font-size: 44px; }
  .start-panel .chapter { margin-bottom: 5px; }
  .start-panel .story { margin: 8px auto 10px; line-height: 1.45; }
  .start-panel .control-guide { gap: 6px 12px; margin-bottom: 10px; }
  .start-panel .primary-action { margin-top: 5px; padding: 10px 20px; }
  .start-panel small { margin-top: 7px; }
  .upgrade-panel { max-height: calc(100svh - 16px); overflow-y: auto; padding: 15px 22px; }
  .upgrade-panel h2 { font-size: 34px; }
  .upgrade-panel > span { margin: 5px auto 9px; }
  .upgrade-choices button { min-height: 96px; padding: 10px; }
  .upgrade-choices strong { margin: 4px 0; font-size: 17px; }
}

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