:root {
  color-scheme: dark;
  --bg: #0a0812;
  --panel: #15111f;
  --text: #f8effa;
  --muted: #c0b4ca;
  --line: #342840;
  --pink: #f5a6d4;
  --violet: #c5a8ff;
  --cyan: #8af3ef;
  --screen: 100vh;
  --screen-small: 100vh;
  --mono: "IBM Plex Mono", "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}

@supports (height: 100dvh) {
  :root { --screen: 100dvh; --screen-small: 100svh; }
}

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

body {
  margin: 0;
  min-height: var(--screen-small);
  background: radial-gradient(ellipse at 68% 5%, #21132d 0, transparent 57%), var(--bg);
}

button {
  font: inherit;
  cursor: pointer;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button:focus-visible, a:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 4px;
}

button:disabled { cursor: default; }

.shell {
  width: min(100%, 1512px);
  margin-inline: auto;
  padding: max(18px, env(safe-area-inset-top)) max(clamp(16px, 3.2vw, 52px), env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(clamp(16px, 3.2vw, 52px), env(safe-area-inset-left));
}

.topbar, .top-actions, .brand, .best-score {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  min-height: 48px;
  margin-bottom: 15px;
  gap: 12px;
}

.brand {
  gap: 12px;
  color: #f3e4f8;
  font: 800 1rem var(--mono);
  letter-spacing: .17em;
  white-space: nowrap;
}

.brand-mark {
  position: relative;
  width: 28px;
  height: 28px;
  border: 2px solid #edb5f5;
  border-radius: 50%;
  transform: rotate(-42deg) scaleY(.56);
  box-shadow: 0 0 14px #d179fd5e;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 4px;
  background: linear-gradient(145deg, #fff4ff 20%, #e296ed 70%);
  clip-path: polygon(50% 0, 61% 37%, 100% 50%, 61% 62%, 50% 100%, 39% 62%, 0 50%, 39% 37%);
  transform: scaleY(1.68) rotate(42deg);
}

.top-actions { gap: 18px; }
.best-score { gap: 9px; white-space: nowrap; }
.best-score span { color: var(--muted); font-size: .875rem; }
.best-score strong {
  color: var(--pink);
  font: 700 1.0625rem var(--mono);
  letter-spacing: .035em;
}

.utility, .primary, .pulse, .guard-fire {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  gap: 8px;
  border-radius: 7px;
  font-size: .9375rem;
  line-height: 1.25;
  font-weight: 650;
}

.utility {
  border: 1px solid var(--line);
  background: #171123;
  padding-inline: 13px;
}

.utility:hover { border-color: #8c6c9c; background: #241932; }

.sound { min-width: 44px; font-size: .875rem; }
.sound-icon { width: 18px; height: 16px; position: relative; flex: none; }

.sound-icon::before {
  content: "";
  position: absolute;
  inset: 1px 6px 1px 0;
  background: currentColor;
  clip-path: polygon(0 31%, 31% 31%, 72% 0, 72% 100%, 31% 69%, 0 69%);
}

.sound-icon::after {
  content: "";
  position: absolute;
  inset: 2px 1px 2px 7px;
  border-radius: 50%;
  border-right: 1.5px solid currentColor;
  box-shadow: inset -4px 0 0 -3px currentColor;
}

.sound[aria-pressed="false"] .sound-icon::after {
  inset: 1px 4px 0 auto;
  width: 1.5px;
  background: currentColor;
  border: none;
  border-radius: 0;
  box-shadow: none;
  transform: rotate(38deg);
}

.hero {
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: center;
  overflow: hidden;
  min-height: clamp(460px, calc(var(--screen-small) - 174px), 795px);
  padding: clamp(32px, 6.2vw, 96px);
  border: 1px solid #72527782;
  border-radius: 15px;
  background: #130d20;
  box-shadow: 0 22px 60px #0005;
}

.hero::before, .hero::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: -1;
}

.hero::before {
  background: #140c23 url("ringfall-cover.webp") right 52% / cover no-repeat;
}

.hero::after {
  background: linear-gradient(90deg, #0d0919d9, #0c081870 33%, transparent 60%),
              linear-gradient(0deg, #10092063, transparent 42%);
}

.hero-content { position: relative; z-index: 1; }
.genre {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #f1b7ed;
  font-size: .9375rem;
  font-weight: 750;
  letter-spacing: .17em;
}

.genre span {
  width: 16px;
  height: 1px;
  background: #ed92d8;
  box-shadow: 5px 0 10px #f4a5def5;
}

h1 {
  margin: 12px 0 0;
  color: #fff2fb;
  font-size: clamp(3.8rem, 7.0vw, 7.2rem);
  font-weight: 950;
  letter-spacing: -.055em;
  line-height: 1.1;
  text-shadow: 0 6px 32px #0c051d, 0 0 28px #d286db4a;
}

.mission-line {
  margin: 17px 0 21px;
  color: #ead8ef;
  font-size: clamp(1rem, 1.45vw, 1.2rem);
  line-height: 1.55;
}

.mode-choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: min(100%, 283px);
  gap: 7px;
  margin-bottom: 12px;
}

.mode-choices button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  min-height: 47px;
  padding: 7px 11px;
  border: 1px solid #725479;
  border-radius: 7px;
  background: #1c102bda;
}

.mode-choices button strong { font-size: 1rem; white-space: nowrap; }
.mode-choices button span { color: #c8b6d1; font-size: .8125rem; white-space: nowrap; }
.mode-choices button[aria-pressed="true"] {
  border-color: #db9cde;
  background: #43284fe8;
  box-shadow: inset 0 0 20px #b973d21c;
}
.mode-choices button:hover { border-color: #efb8ef; }

.difficulty {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
  color: #d0bfd7;
  font-size: .875rem;
}

.difficulty > span { flex: none; }
.difficulty-hint {
  margin: 0 0 12px;
  color: #d9c5e1;
  font-size: .875rem;
  line-height: 1.5;
}

.mode-picker {
  display: inline-flex;
  gap: 3px;
  border: 1px solid #b484cb5e;
  border-radius: 7px;
  padding: 3px;
  background: #110c1b9e;
}

.mode-picker button {
  min-width: clamp(46px, 6vw, 65px);
  min-height: 36px;
  padding: 0 10px;
  color: #d7bfdc;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  font-weight: 650;
}

.mode-picker button[aria-pressed="true"] {
  color: #fff2ff;
  border-color: #a579c1b2;
  background: #4c315f;
}

.mode-picker button:hover { color: #fff; }
.mode-picker button[data-difficulty="hard"][aria-pressed="true"] { background: #593c49; border-color: #e3a384; }
.mode-picker button[data-difficulty="hell"][aria-pressed="true"] { background: #582a41; border-color: #f797aa; }

.primary {
  padding: 0 19px;
  border: 1px solid #ffcbef;
  color: #29122e;
  background: linear-gradient(104deg, #fac0dc 5%, #e3b4ff 98%);
  font-weight: 850;
  box-shadow: 0 6px 24px #dda0ec39;
}

.primary:hover { background: linear-gradient(104deg, #ffd2e7, #f2cbff); }
.primary:active, .pulse:active, .utility:active { transform: translateY(1px); }

.start {
  min-height: 54px;
  min-width: 230px;
  justify-content: flex-start;
  gap: 12px;
  font-size: 1.0625rem;
}

.start-icon {
  width: 14px;
  height: 17px;
  background: currentColor;
  clip-path: polygon(12% 0, 100% 50%, 12% 100%);
}

.start kbd { margin-left: auto; border-color: #674c71a3; background: #714a7a1c; color: #46264d; }

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 4px;
  border: 1px solid #5e496f;
  border-radius: 4px;
  color: #e7d6ed;
  background: #20182d;
  font: 650 .8125rem var(--mono);
  white-space: nowrap;
}

.guide {
  margin-top: 13px;
  border: 1px solid #3b2d47;
  border-radius: 9px;
  background: #130e1bde;
}

.guide.keyboard-only { display: grid; grid-template-columns: 1.35fr 1fr 1fr 1fr; }
.guide.touch-only { grid-template-columns: 1fr 1fr 1.23fr; }

.guide > div {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 57px;
  padding: 8px 4px;
  color: #e4d5eb;
  font-size: .875rem;
  white-space: nowrap;
}

.guide > div + div { border-left: 1px solid #3b2d47; }

.burst-icon, .pulse-icon, .drag-icon, .energy-icon, .graze-icon {
  display: inline-block;
  flex: none;
  width: 17px;
  height: 17px;
  color: var(--violet);
  background: currentColor;
}

.burst-icon { clip-path: polygon(54% 0, 13% 57%, 43% 57%, 39% 100%, 91% 39%, 61% 39%); }

.pulse-icon {
  clip-path: polygon(0 54%, 25% 54%, 42% 15%, 68% 77%, 79% 53%, 100% 53%, 100% 67%, 88% 67%, 67% 100%, 42% 46%, 34% 67%, 0 67%);
}

.drag-icon {
  clip-path: polygon(46% 0, 62% 15%, 55% 15%, 55% 43%, 85% 43%, 85% 35%, 100% 50%, 85% 65%, 85% 57%, 55% 57%, 55% 85%, 62% 85%, 46% 100%, 31% 85%, 39% 85%, 39% 57%, 15% 57%, 15% 65%, 0 50%, 15% 35%, 15% 43%, 39% 43%, 39% 15%, 31% 15%);
}

.energy-icon { color: var(--cyan); clip-path: polygon(50% 1%, 85% 50%, 50% 98%, 15% 50%); }
.graze-icon { color: var(--pink); clip-path: polygon(50% 0, 64% 36%, 100% 50%, 64% 64%, 50% 100%, 36% 64%, 0 50%, 36% 36%); }

.touch-only { display: none; }

/* Combat uses the available viewport; the arena alone preserves its ratio. */
body.in-combat .shell {
  height: var(--screen);
  display: flex;
  flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.in-combat .topbar { flex: none; min-height: 44px; margin-bottom: 12px; }
.in-combat main { flex: 1; min-height: 0; }
.mission {
  display: grid;
  grid-template-columns: minmax(170px, 210px) minmax(0, 1fr) minmax(240px, 292px);
  grid-template-rows: auto 1fr;
  grid-template-areas: "progress play deck" "guide play deck";
  gap: 14px 22px;
  height: 100%;
  min-height: 0;
  padding: 16px;
  border: 1px solid #382a48;
  border-radius: 14px;
  background: radial-gradient(ellipse at 50% 38%, #35234c4d, transparent 74%), #100c18b3;
}
.side { min-width: 0; }
.left-side { grid-area: progress; }
.right-side { display: contents; }
.side-panel, .flight-deck {
  padding: 16px;
  border: 1px solid #3c2e4b;
  border-radius: 10px;
  background: #171020e8;
}
.side h2, .deck-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 15px;
  font-size: .875rem;
  font-weight: 750;
  color: #e1c8f2;
  line-height: 1.4;
}
.difficulty-badge { padding: 2px 7px; border: 1px solid #735589; border-radius: 4px; background: #33223e; color: #eacdf7; font-size: .75rem; font-weight: 600; }
.stages { list-style: none; padding: 0; margin: 0; }
.stages li { display: flex; align-items: center; gap: 10px; min-height: 42px; color: #ad9ab9; font-size: .875rem; }
.stage-marker { flex: none; width: 8px; height: 8px; margin: 3px; border: 1px solid #806c8e; transform: rotate(45deg); }
.stages li[aria-current="step"] { color: #ffe6fb; font-weight: 750; }
.stages li[aria-current="step"] .stage-marker { background: #fac1ea; border-color: #ffd0f3; box-shadow: 0 0 12px #ed9fea80; }
.stages li.complete .stage-marker { background: #6ba5ac; border-color: #9ed5d9; }
.right-side > .side-panel { grid-area: guide; align-self: start; }
.quick-guide { margin: 0 0 14px; }
.quick-guide div { display: flex; justify-content: space-between; gap: 8px; line-height: 1.6; margin: 7px 0; }
.quick-guide .touch-only { display: none; }
.quick-guide dt { color: #e7d5ed; font-size: .875rem; }
.quick-guide dd { margin: 0; color: #c1b0ce; font-size: .875rem; }
.tip { display: flex; align-items: center; gap: 7px; margin: 9px 0 0; color: #cdbbd9; font-size: .875rem; line-height: 1.5; }
.tip .energy-icon, .tip .graze-icon { width: 12px; height: 12px; flex: none; }
.play-column { grid-area: play; min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.flight-top { display: grid; grid-template-columns: .8fr 1fr 1.25fr; gap: 1px; border: 1px solid #483457; border-radius: 8px; background: #3d2d4c; }
.metric { min-width: 0; display: flex; flex-direction: column; justify-content: center; min-height: 60px; padding: 6px 10px; background: #181122; }
.metric:first-child { border-radius: 7px 0 0 7px; }
.metric:last-child { border-radius: 0 7px 7px 0; }
.metric > span:first-child { color: var(--muted); font-size: .875rem; line-height: 1.5; }
.metric strong { font: 700 1.125rem var(--mono); letter-spacing: .02em; }
.shield-bays { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; min-height: 22px; }
.shield-pips { display: flex; gap: 3px; align-items: center; }
.shield-pips span { width: 7px; height: 9px; border: 1px solid #6b536e; border-radius: 2px; background: #32243e; transform: skewX(-12deg); }
.shield-pips .filled { background: #f5a6d4; border-color: #f6bfdc; box-shadow: 0 0 7px #fc90c840; }
.barrier-indicator { padding: 1px 4px; border: 1px solid #75dcc5a3; border-radius: 3px; background: #21434b; color: #b9fff1; font-size: .75rem; }
.experience { display: flex; align-items: center; gap: 9px; min-height: 24px; padding-inline: 2px; color: #cfbada; font: 600 .8125rem var(--mono); }
.experience strong { color: #bafdfa; font-size: .875rem; white-space: nowrap; }
.experience progress { flex: 1; min-width: 20px; height: 5px; margin: 0; }
.experience > span { white-space: nowrap; }
.experience progress::-webkit-progress-bar { background: #322941; }
.experience progress::-webkit-progress-value { background: #86eadb; }
.experience progress::-moz-progress-bar { background: #86eadb; }
.boss-band { flex: none; height: 44px; }
.boss-meter { display: grid; gap: 5px; padding: 5px 8px; border: 1px solid #89587980; border-radius: 6px; background: #251629; }
.boss-caption { display: flex; justify-content: space-between; gap: 8px; color: #ffd1e5; font-size: .875rem; line-height: 1.25; }
.boss-caption span:last-child { flex: none; }
.boss-tracks { display: grid; grid-template-columns: minmax(0, 1fr); align-items: center; gap: 8px; min-height: 10px; }
.boss-meter[data-armored] .boss-tracks { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.boss-meter progress { height: 5px; margin: 0; }
.boss-armor { display: flex; align-items: center; gap: 4px; min-width: 0; color: #b2fff0; font-size: .75rem; }
.boss-armor progress { min-width: 0; }
.boss-armor progress::-webkit-progress-bar { background: #263a53; }
.boss-armor progress::-webkit-progress-value { background: #92f3d9; }
.boss-armor progress::-moz-progress-bar { background: #92f3d9; }
.sector-status { display: flex; align-items: center; justify-content: center; height: 100%; margin: 0; border: 1px solid #372c46; border-radius: 6px; color: #baa5cd; background: #150f20; font-size: .875rem; letter-spacing: .04em; }
.arena-bay { flex: 1; min-width: 0; min-height: 0; container-type: size; display: grid; place-items: center; }
.playfield { position: relative; isolation: isolate; width: min(100cqw, calc(100cqh * 12 / 19)); aspect-ratio: 12 / 19; overflow: hidden; border: 1px solid #ac82c6; border-radius: 9px; background: #100b1f; box-shadow: 0 0 45px #a264f31c, 0 16px 40px #0005; }
canvas { display: block; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; outline: none; }
.arena-frame { position: absolute; inset: 8px; border: 1px solid #c6a0e51c; border-radius: 3px; pointer-events: none; }
progress { display: block; width: 100%; height: 6px; margin-top: 5px; appearance: none; border: 0; border-radius: 2px; background: #493049; color: #f58aba; overflow: hidden; }
progress::-webkit-progress-bar { background: #493049; }
progress::-webkit-progress-value { background: linear-gradient(90deg, #ec6a9a, #ffc1dc); }
progress::-moz-progress-bar { background: linear-gradient(90deg, #ec6a9a, #ffc1dc); }
.announcement { position: absolute; top: 35%; width: 100%; display: grid; justify-items: center; gap: 3px; padding: 12px 4px 16px; color: #fef0fa; background: linear-gradient(90deg, transparent, #120917ec 25% 75%, transparent); pointer-events: none; text-shadow: 0 2px 14px #000; }
.announcement span { color: #ffc1df; font-size: .8125rem; letter-spacing: .16em; font-weight: 750; }
.announcement strong { font-size: clamp(1.125rem, 4cqw, 1.875rem); letter-spacing: .08em; }
.announcement[data-kind="warning"] { top: 29%; padding: 12px 5px 15px; border-block: 1px solid #e2a87175; background: linear-gradient(90deg, #28142bc9, #461f32f2 50%, #28142bc9); color: #ffdfb4; }
.announcement[data-kind="warning"] span { color: #ffbc85; }
.loot-toast { position: absolute; z-index: 2; top: 9px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 12px); padding: 5px 9px; border: 1px solid #75c9cb9c; border-radius: 5px; background: #101f31f0; color: #c4fff8; text-align: center; font-size: .8125rem; font-weight: 720; pointer-events: none; overflow-wrap: anywhere; }
.flight-deck { grid-area: deck; align-self: start; min-width: 0; }
.flight-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.flight-actions button { min-width: 0; font-size: .875rem; gap: 6px; }
.flight-actions #guard-fire { grid-column: 1 / -1; order: 3; }
.flight-actions kbd { margin-left: auto; }
.guard-fire { padding-inline: 10px; border: 1px solid #4e9c90; background: #192e38; color: #c7fff5; }
.guard-fire:not(:disabled):hover { background: #22464b; }
.guard-fire:disabled { border-color: #41404e; background: #191721; color: #b2a6bd; }
.guard-fire strong { font: 600 .8125rem var(--mono); }
.equipment-note { margin: 18px 0 8px; font-size: .8125rem; color: #c0acca; line-height: 1.5; }
.equipment { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.weapon-slot { display: grid; align-content: center; gap: 5px; min-width: 0; min-height: 70px; padding: 9px 6px; border: 1px solid #463253; border-radius: 7px; background: #21162c; text-align: center; overflow-wrap: anywhere; }
.weapon-slot:disabled { cursor: default; }
.weapon-slot:not(:disabled):hover { border-color: #dbaceb; background: #34233f; }
.weapon-slot[aria-pressed="true"] { border-color: #d8adeb; background: #38254d; box-shadow: inset 0 0 11px #ab73cc3a; }
.weapon-slot span { color: #e3cfed; font-size: .875rem; line-height: 1.3; }
.weapon-slot strong { font: 600 .8125rem/1.35 var(--mono); color: #b4a0c0; }
.weapon-slot[data-equipped] { border-color: #b28369; }
.weapon-slot[data-equipped] strong { color: #ffc090; }
.weapon-slot[data-weapon="laser"][data-equipped] strong { color: #a0f9ed; }
.weapon-slot[data-weapon="column"][data-equipped] strong { color: #fff1a9; }
.weapon-slot[data-weapon="guard"][data-equipped] strong { color: #dcc1ff; }
.pulse { padding-inline: 10px; border: 1px solid #956aac; background: #38234b; color: #f9e7ff; }
.pulse strong { color: #e5c3fa; font: 700 .8125rem var(--mono); }
.pulse:hover:not(:disabled) { background: #412959; border-color: #d59ff0; }
.pulse:disabled { border-color: #494050; background: #221a2a; color: #b9a9c5; }
.pause-icon { width: 10px; height: 12px; border-inline: 3px solid currentColor; flex: none; }

dialog {
  width: min(430px, calc(100% - 28px));
  max-height: calc(100% - 24px);
  padding: 0;
  border: 1px solid #a37db7;
  border-radius: 15px;
  background: radial-gradient(ellipse at 80% 0, #382043, transparent 65%), #191021;
  color: var(--text);
  box-shadow: 0 20px 95px #0009, inset 0 1px #fcc4eb20;
}

dialog::backdrop { background: #070510c4; backdrop-filter: blur(3px); }
.dialog-interior { padding: clamp(18px, 5.7vw, 33px); }
.dialog-kicker { font-size: .875rem; color: var(--pink); letter-spacing: .14em; font-weight: 750; }
dialog h2 { margin: 5px 0 0; font-size: clamp(1.7rem, 7vw, 2.3rem); line-height: 1.3; }
dialog p { color: #d1bed9; margin: 8px 0 17px; font-size: 1rem; line-height: 1.5; }

.result-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin: 0 0 17px;
}

.result-metrics div { padding: 8px 12px; border: 1px solid #493958; border-radius: 5px; background: #150d1e; }
.result-metrics span { display: block; color: #cdb7d6; font-size: .8125rem; }
.result-metrics strong { display: block; margin-top: 2px; font: 750 1.3rem var(--mono); color: #ffd0eb; }
.dialog-actions { display: flex; gap: 9px; }
.dialog-actions button { flex: 1; }

.noscript { position: fixed; bottom: 0; inset-inline: 0; margin: 0; padding: 12px; text-align: center; background: #1d1427; }


@media (pointer: coarse) {
  .keyboard-only, .guide.keyboard-only, .quick-guide .keyboard-only { display: none !important; }
  .guide.touch-only { display: grid; }
  .quick-guide .touch-only { display: flex; }
}

@media (max-width: 600px) {
  .shell {
    padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }
  .topbar { margin-bottom: 8px; }
  .brand { gap: 7px; font-size: .875rem; letter-spacing: .105em; }
  .brand-mark { width: 22px; height: 22px; }
  .brand-mark::after { inset: 2px; }
  .top-actions { gap: 8px; }
  .best-score { gap: 5px; }
  .best-score span { font-size: .75rem; }
  .best-score strong { font-size: .9375rem; }
  .sound { padding-inline: 7px; }
  .sound span:nth-child(2) { display: none; }
  .hero {
    min-height: max(475px, calc(var(--screen-small) - 135px));
    align-items: end;
    padding: 21px 22px 25px;
    border-radius: 11px;
  }
  .hero::before {
    bottom: 37%;
    background-position: 88% 30%;
    -webkit-mask-image: linear-gradient(#000 76%, transparent);
    mask-image: linear-gradient(#000 76%, transparent);
  }
  .hero::after {
    background: linear-gradient(0deg, #100a1fec 0%, #100a1ff5 26%, #100a1f9e 45%, transparent 71%),
                linear-gradient(90deg, #100a1f32, transparent);
  }
  .genre { font-size: .875rem; }
  h1 { font-size: clamp(3rem, 13vw, 4.9rem); margin-top: 10px; }
  .mission-line { margin: 10px 0 13px; }
  .start { width: 100%; min-width: 0; justify-content: center; }
  .start kbd { margin-left: 3px; }
  .hero-content { width: 100%; }
  .mode-picker button { min-height: 44px; }
  .guide { margin-top: 8px; }
  .guide > div { gap: 5px; min-height: 48px; font-size: .8125rem; }
  .guide.keyboard-only { grid-template-columns: 1.4fr 1fr .9fr; }
  .guide.keyboard-only > div:first-child { flex-direction: column; }
  .guide.keyboard-only > div:last-child { display: none; }
  .guide .drag-icon, .guide .burst-icon, .guide .pulse-icon { width: 14px; height: 14px; }
}

@media (orientation: landscape) and (max-height: 513px) {
  .hero { min-height: 280px; padding-block: 20px; }
  h1 { font-size: clamp(3rem, 8vw, 4.4rem); }
  .mission-line { margin: 10px 0 12px; }
}

@media (max-width: 359px) {
  .difficulty { gap: 7px; }
  .mode-picker button { min-width: 40px; padding-inline: 6px; }
  .guide > div { font-size: .75rem; }
  .guide > div span:first-child:not(:last-child) { gap: 2px; }
  .top-actions { gap: 6px; }
  .best-score span { font-size: .6875rem; }
  .flight-actions kbd { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .primary:active, .pulse:active, .utility:active { transform: none; }
}

/* Compact screens keep every panel in normal grid flow. */
@media (min-width: 701px) and (max-width: 1100px) {
  .mission { grid-template-columns: 160px minmax(0, 1fr) 244px; gap: 12px; padding: 12px; }
  .side-panel, .flight-deck { padding: 12px; }
  .quick-guide div { flex-wrap: wrap; gap: 0 6px; }
  .flight-actions kbd { display: none; }
  .metric { padding-inline: 7px; }
  .shield-pips { gap: 2px; }
  .shield-pips span { width: 5px; }
}
@media (max-width: 700px) and (orientation: portrait), (max-width: 600px) and (min-height: 514px) {
  body.in-combat .shell { padding: max(6px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
  .in-combat .topbar { min-height: 44px; margin-bottom: 6px; }
  .mission { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto auto minmax(100px, 1fr) auto auto; grid-template-areas: "progress" "hud" "xp" "boss" "arena" "deck" "guide"; gap: 5px; padding: 8px; border-radius: 10px; }
  .play-column, .right-side { display: contents; }
  .left-side .side-panel { padding: 6px 8px; }
  .left-side h2 { margin: 0 0 4px; line-height: 1.25; font-size: .8125rem; }
  .difficulty-badge { font-size: .75rem; padding-block: 0; }
  .stages { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px; }
  .stages li { justify-content: center; gap: 3px; min-height: 20px; font-size: .8125rem; white-space: nowrap; }
  .stage-marker { width: 5px; height: 5px; margin: 1px; }
  .flight-top { grid-area: hud; }
  .metric { min-height: 48px; padding: 3px 8px; }
  .metric strong { font-size: 1rem; }
  .metric > span:first-child { font-size: .8125rem; }
  .shield-pips { gap: 2px; }
  .shield-pips span { width: 5px; height: 8px; }
  .experience { grid-area: xp; min-height: 20px; font-size: .75rem; gap: 6px; }
  .experience strong { font-size: .8125rem; }
  .boss-band { grid-area: boss; height: 36px; }
  .sector-status { font-size: .8125rem; }
  .boss-meter { padding: 3px 7px; gap: 3px; }
  .boss-caption { font-size: .8125rem; }
  .arena-bay { grid-area: arena; }
  .flight-deck { padding: 7px; }
  .side .deck-title { display: none; }
  .flight-actions { grid-template-columns: 1fr 1.25fr 1fr; gap: 5px; }
  .flight-actions #guard-fire { grid-column: auto; order: 0; display: grid; justify-items: center; align-content: center; gap: 1px; }
  .flight-actions button { min-height: 44px; gap: 4px; padding-inline: 4px; }
  .flight-actions .guard-word-tail { display: inline; }
  .flight-actions kbd { display: none; }
  .guard-fire strong, .pulse strong { font-size: .75rem; }
  .equipment-note { margin: 5px 0; font-size: .75rem; line-height: 1.25; }
  .equipment { gap: 5px; }
  .weapon-slot { min-height: 44px; gap: 2px; padding: 4px 5px; }
  .weapon-slot span { font-size: .875rem; }
  .weapon-slot strong { font-size: .75rem; }
  .right-side > .side-panel { padding: 5px 8px; }
  .right-side > .side-panel h2 { display: none; }
  .quick-guide { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 8px; margin: 0; }
  .quick-guide div { margin: 0; gap: 5px; }
  .quick-guide dt, .quick-guide dd { font-size: .75rem; line-height: 1.6; }
  .tip { display: inline-flex; gap: 4px; margin: 1px 8px 0 0; font-size: .75rem; line-height: 1.5; }
  .tip .energy-icon, .tip .graze-icon { width: 9px; height: 9px; }
}
@media (min-width: 430px) and (max-width: 700px) and (orientation: portrait) {
  .equipment { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .weapon-slot { min-height: 53px; }
}
@media (orientation: landscape) and (max-height: 600px) {
  body.in-combat .shell { padding: max(5px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(5px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
  .in-combat .topbar { min-height: 36px; margin-bottom: 5px; }
  .in-combat .sound { min-height: 36px; }
  .mission { grid-template-columns: minmax(145px, .8fr) minmax(120px, 1fr) minmax(220px, 1.05fr); grid-template-rows: auto 1fr; grid-template-areas: "progress play deck" "guide play deck"; gap: 8px; padding: 8px; }
  .side-panel, .flight-deck { padding: 8px; }
  .side h2, .deck-title { margin-bottom: 6px; }
  .stages li { min-height: 26px; }
  .quick-guide { margin-bottom: 4px; }
  .quick-guide div { margin: 2px 0; flex-wrap: wrap; gap: 0 5px; }
  .quick-guide dt, .quick-guide dd, .tip { font-size: .8125rem; }
  .tip { margin-top: 4px; }
  .play-column { gap: 5px; }
  .metric { min-height: 44px; padding: 3px 5px; }
  .metric > span:first-child { font-size: .8125rem; }
  .metric strong { font-size: .9375rem; }
  .shield-pips { gap: 2px; }
  .shield-pips span { width: 4px; height: 6px; }
  .experience { font-size: .75rem; min-height: 20px; gap: 5px; }
  .experience strong { font-size: .8125rem; }
  .boss-band { height: 36px; }
  .boss-caption, .sector-status { font-size: .8125rem; }
  .boss-meter { padding: 3px 5px; gap: 3px; }
  .flight-actions { gap: 5px; }
  .flight-actions kbd { display: none; }
  .flight-actions button { min-height: 44px; padding-inline: 6px; }
  .equipment-note { margin: 8px 0 5px; font-size: .75rem; }
  .equipment { gap: 5px; }
  .weapon-slot { min-height: 53px; gap: 3px; padding: 4px; }
  .weapon-slot span { font-size: .875rem; }
  .weapon-slot strong { font-size: .75rem; }
}
@media (max-width: 374px) and (orientation: portrait) {
  .shield-bays { gap: 3px; }
  .shield-pips { flex-wrap: wrap; max-width: 22px; }
  .stages li { font-size: .75rem; }
}

/* Short portrait displays place controls beside the arena to preserve play space. */
@media (min-width: 320px) and (max-width: 700px) and (max-height: 740px) and (orientation: portrait) {
  .mission {
    grid-template-columns: minmax(0, 1fr) minmax(130px, 40%);
    grid-template-rows: auto auto auto auto minmax(150px, 1fr) auto;
    grid-template-areas: "progress progress" "hud hud" "xp xp" "boss deck" "arena deck" "guide guide";
    gap: 5px 8px;
  }
  .boss-band { height: 56px; }
  .boss-caption { flex-wrap: wrap; gap: 0 6px; }
  .sector-status { text-align: center; font-size: .75rem; letter-spacing: 0; }
  .flight-actions { grid-template-columns: 1fr 1fr; }
  .flight-actions #guard-fire { grid-column: 1 / -1; order: 3; }
  .flight-actions #pulse { flex-wrap: wrap; gap: 1px 4px; }
  .flight-actions #pulse .pulse-icon { display: none; }
  .equipment-note { min-height: 30px; display: flex; align-items: center; }
  .equipment { grid-template-columns: 1fr 1fr; }
  .weapon-slot { min-height: 64px; padding-inline: 3px; }
  .weapon-slot span { font-size: .8125rem; }
  .announcement strong { font-size: clamp(1rem, 8cqw, 1.5rem); }
}

@media (max-width: 359px) and (max-height: 740px) and (orientation: portrait) {
  .flight-deck { padding: 5px; }
  .equipment-note { min-height: 0; margin-block: 4px; }
  .weapon-slot { min-height: 58px; padding: 2px; }
  .weapon-slot span { font-size: .75rem; }
}

@media (orientation: landscape) and (max-height: 600px) {
  .mission {
    grid-template-columns: minmax(200px, 1fr) minmax(120px, 1fr) minmax(220px, 1fr);
    grid-template-rows: auto auto auto auto minmax(0, 1fr);
    grid-template-areas: "hud arena deck" "xp arena deck" "boss arena deck" "progress arena deck" "guide arena deck";
    gap: 5px 10px;
  }
  .play-column { display: contents; }
  .flight-top { grid-area: hud; }
  .experience { grid-area: xp; }
  .boss-band { grid-area: boss; }
  .arena-bay { grid-area: arena; }
  .left-side .side-panel { padding: 5px 8px; }
  .left-side h2 { margin-bottom: 3px; }
  .stages { display: grid; grid-template-columns: 1fr 1fr; gap: 0 5px; }
  .stages li { min-height: 22px; gap: 6px; font-size: .8125rem; }
  .right-side > .side-panel { padding: 5px 8px; }
  .right-side > .side-panel h2 { display: none; }
  .quick-guide { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 8px; margin: 0; }
  .quick-guide div { margin: 0; gap: 5px; }
  .quick-guide dt, .quick-guide dd, .tip { font-size: .75rem; }
  .tip { margin-top: 2px; line-height: 1.4; }
}
