:root {
  color-scheme: dark;
  --bg: #0d1118;
  --panel: rgba(14, 18, 26, 0.9);
  --glass: rgba(14, 18, 26, 0.78);
  --line: rgba(255, 255, 255, 0.09);
  --text: #e9eff7;
  --muted: #9aa6b8;
  --accent: #f2c14e;
  --friend: #5ab0ff;
  --foe: #ff6a3d;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

header {
  flex: none;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
}

.kicker {
  margin: 0;
  color: var(--accent);
  font-size: 11px;
  letter-spacing: 0.08em;
}

h1 {
  margin: 1px 0 0;
  font-size: 19px;
  font-weight: 650;
}

.head-btns { display: flex; gap: 8px; }

main {
  flex: 1;
  min-height: 0;
  position: relative;
}

body.prestart aside,
body.prestart #hud,
body.prestart #dock,
body.prestart #coach,
body.prestart #aim-hint,
body.prestart #wave-banner,
body.prestart #speed-toggle { display: none; }

#stage {
  position: relative;
  height: 100%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  background: #151b27;
}

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

aside {
  position: absolute;
  z-index: 4;
  top: 10px;
  right: 58px;
  width: auto;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: visible;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

button {
  font: inherit;
  font-size: 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: #222a3a;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s;
}

button:active:not(:disabled) { transform: scale(0.95); }

button.active {
  background: var(--accent);
  color: #1b1404;
  border-color: transparent;
  font-weight: 700;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

button em {
  font-style: normal;
  font-weight: 700;
  margin-left: 2px;
}

button.primary {
  background: var(--accent);
  color: #1b1404;
  font-weight: 700;
  font-size: 17px;
  padding: 12px 34px;
  border: 0;
}

/* HUD */
#hud {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 60px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.hp-card, .chip {
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 12px;
  backdrop-filter: blur(4px);
}

.hp-card { padding: 6px 12px 8px; min-width: 150px; }
.hp-label { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.hp-label b { font-size: 18px; color: var(--text); }
.hp-track { height: 8px; border-radius: 99px; background: rgba(255, 255, 255, 0.12); overflow: hidden; margin-top: 3px; }
#hp-bar { height: 100%; width: 100%; background: #3ddc97; border-radius: 99px; transition: width 0.2s, background 0.3s; }
.hp-card.hit { animation: hpHit 0.4s; }
@keyframes hpHit { 0%,100% { transform: none; } 25% { transform: translateX(-4px); } 60% { transform: translateX(4px); } }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 6px 11px; font-size: 12px; color: var(--muted); }
.chip b { color: var(--text); font-size: 17px; margin-left: 3px; font-variant-numeric: tabular-nums; }
.chip.pts b { color: var(--accent); }
.chip.dim b { font-size: 13px; }
.chip.bump { animation: bump 0.3s; }
@keyframes bump { 40% { transform: scale(1.18); background: rgba(242, 193, 78, 0.35); } }

.chip.wave { position: relative; overflow: hidden; padding-bottom: 9px; }
.chip.wave .sep { opacity: 0.4; }
.chip.wave b { font-size: 14px; }
.chip.wave .prog { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(255, 255, 255, 0.1); }
.chip.wave .prog i { display: block; height: 100%; width: 0; background: #ff6a7a; transition: width 0.4s linear; }
.chip.wave.imminent {
  border-color: rgba(255, 94, 116, 0.8);
  background: rgba(106, 17, 35, 0.86);
  animation: waveCountdown 0.72s cubic-bezier(0.2, 0, 0, 1) infinite;
}
.chip.wave.imminent .prog i { background: #fff0f2; }
.chip.wave.boss-next {
  border-color: rgba(114, 255, 120, 0.9);
  background: rgba(19, 77, 33, 0.92);
  box-shadow: 0 0 18px rgba(72, 255, 102, 0.28);
}
@keyframes waveCountdown {
  0%, 100% { transform: scale(1); }
  18% { transform: scale(1.035); }
}

#wave-impact {
  position: absolute;
  z-index: 5;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  background: radial-gradient(circle at center, transparent 30%, rgba(255, 46, 82, 0.34) 100%);
}
#wave-impact.show { animation: waveImpact 0.9s cubic-bezier(0.2, 0, 0, 1) both; }
#wave-impact.boss {
  background:
    radial-gradient(circle at center, transparent 22%, rgba(58, 255, 91, 0.28) 78%, rgba(7, 37, 14, 0.62) 100%);
}
@keyframes waveImpact {
  0% { opacity: 0; transform: scale(1.08); }
  18% { opacity: 1; }
  100% { opacity: 0; transform: scale(1); }
}

#wave-banner {
  position: absolute;
  z-index: 6;
  left: 50%;
  top: 40%;
  width: min(620px, calc(100% - 40px));
  transform: translate(-50%, -50%);
  opacity: 0;
  pointer-events: none;
  text-align: center;
  color: #fff;
  filter: drop-shadow(0 8px 22px rgba(0, 0, 0, 0.72));
}
#wave-banner::before,
#wave-banner::after {
  content: "";
  position: absolute;
  top: 50%;
  width: min(20vw, 150px);
  height: 2px;
  background: linear-gradient(90deg, transparent, #ff536f);
}
#wave-banner::before { right: calc(100% + 15px); }
#wave-banner::after { left: calc(100% + 15px); transform: scaleX(-1); }
#wave-banner-kicker,
#wave-banner-title,
#wave-banner-meta { display: block; }
#wave-banner-kicker {
  color: #ff8ca0;
  font: 800 13px/1.2 "Segoe UI", sans-serif;
  letter-spacing: 0.34em;
  margin: 0 0 5px 0.34em;
}
#wave-banner-title {
  font: 900 clamp(31px, 5vw, 54px)/1.04 Meiryo, "Yu Gothic UI", "Segoe UI", sans-serif;
  letter-spacing: 0.05em;
  text-shadow: 0 2px 2px #18050a, 0 0 24px rgba(255, 55, 88, 0.9);
}
#wave-banner-meta {
  margin-top: 10px;
  color: #ffe2e7;
  font-size: 13px;
  font-weight: 750;
  letter-spacing: 0.08em;
}
#wave-banner.show { animation: waveBannerIn 2.5s cubic-bezier(0.2, 0, 0, 1) both; }
#wave-banner.tough #wave-banner-title { color: #efd5ff; text-shadow: 0 2px 2px #15051d, 0 0 26px rgba(188, 91, 255, 0.92); }
#wave-banner.tough #wave-banner-kicker { color: #d9a5ff; }
#wave-banner.boss::before, #wave-banner.boss::after { background: linear-gradient(90deg, transparent, #72ff78); }
#wave-banner.boss #wave-banner-kicker { color: #9dffa2; }
#wave-banner.boss #wave-banner-title {
  color: #eaffdf;
  text-shadow: 0 2px 2px #071a09, 0 0 12px rgba(78, 255, 100, 0.95), 0 0 34px rgba(30, 255, 68, 0.72);
}
#wave-banner.boss #wave-banner-meta { color: #caffc8; }
#wave-banner.boss.show { animation-duration: 3s; }
@keyframes waveBannerIn {
  0% { opacity: 0; transform: translate(-50%, -42%) scale(1.22); letter-spacing: 0.11em; }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(0.97); }
  22%, 68% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -56%) scale(1.025); }
}

/* coach / toast */
#coach {
  position: absolute;
  left: 50%;
  top: var(--coach-top, 74px);
  transform: translateX(-50%);
  max-width: min(560px, calc(100% - 100px));
  display: flex;
  gap: 10px;
  align-items: center;
  background: rgba(242, 193, 78, 0.94);
  color: #1b1404;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.45;
  padding: 8px 16px;
  border-radius: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  transition: opacity 0.25s;
}
#coach.hidden { opacity: 0; }
#coach.warn { background: rgba(255, 90, 70, 0.95); color: #fff; }

#toast {
  z-index: 6;
  position: absolute;
  left: 50%;
  bottom: var(--dock-h, 130px);
  transform: translate(-50%, 8px);
  background: rgba(20, 24, 34, 0.95);
  border: 1px solid var(--line);
  padding: 8px 16px;
  border-radius: 12px;
  font-size: 13px;
  opacity: 0;
  max-width: calc(100% - 40px);
  text-align: center;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { border-color: #ff6a3d; }

/* zoom */
#zoom {
  position: absolute;
  right: 10px;
  top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#zoom button {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 12px;
  background: var(--glass);
  font-size: 20px;
}

/* dock */
#dock {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: max-content;
  max-width: calc(100% - 16px);
  z-index: 5;
}
#mode-base[hidden] { display: none; }
.dock-main, .dock-sub {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}
.dock-main button { padding: 11px 18px; font-size: 15px; background: var(--glass); backdrop-filter: blur(4px); }
.dock-main button.active { background: var(--accent); }
.dock-sub button { padding: 5px 12px; font-size: 12px; background: var(--glass); }
#dev { position: relative; overflow: hidden; min-width: 150px; }
#dev span { position: relative; }
#dev i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: rgba(110, 190, 255, 0.4); transition: width 0.3s linear; }
#dev.ready { border-color: #8fe3ff; box-shadow: inset 0 0 0 1px rgba(143, 227, 255, 0.45); }
.chip.rp b { color: #8fe3ff; }
.chip small { font-size: 11px; opacity: 0.8; }
.optional-stat { display: none; }
.hud-symbol { display: inline-grid; place-items: center; flex: none; font-style: normal; }
.hud-symbol.heart { color: #ff6576; font-size: 14px; }
.hud-symbol.coin { width: 12px; height: 12px; border: 2px solid #ffe18a; border-radius: 50%; background: #d99b18; box-shadow: inset 0 0 0 2px #f5c64f; }
.hud-symbol.research { color: #8fe3ff; font-size: 10px; }
.hud-symbol.sun { color: #ffd15a; font-size: 14px; }
.dawn-chip.dawn-soon {
  border-color: rgba(255, 209, 90, 0.65);
  animation: dawn-wait 1.8s ease-in-out infinite;
}
.dawn-chip.dawn-soon b { color: #ffe69a; }
@keyframes dawn-wait {
  50% { box-shadow: 0 0 11px rgba(255, 190, 75, 0.38); }
}

#stage-credit {
  position: absolute;
  right: 8px;
  bottom: 4px;
  margin: 0;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.6);
  pointer-events: none;
}

/* overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(8, 11, 17, 0.72);
  backdrop-filter: blur(3px);
  padding: 16px;
  visibility: visible;
  transition: opacity 0.2s ease-out, visibility 0s;
}
.overlay.hidden { opacity: 0; pointer-events: none; visibility: hidden; transition: opacity 0.2s ease-out, visibility 0s 0.2s; }
.overlay.hidden .card { transform: translateY(12px) scale(0.985); }
.card {
  background: #161c28;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 26px 30px;
  max-width: 460px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  transform: translateY(0) scale(1);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
.card h2 { margin: 4px 0 10px; font-size: 28px; }
.lead { color: var(--muted); line-height: 1.7; font-size: 14px; margin: 0 0 14px; }
.challenge-note {
  margin: 0 0 15px;
  border: 1px solid rgba(242, 193, 78, 0.42);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(242, 193, 78, 0.1);
  color: #ffe39a;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.5;
}
.steps { list-style: none; padding: 0; margin: 0 0 20px; text-align: left; }
.steps li { display: flex; gap: 12px; align-items: center; margin: 9px 0; font-size: 14px; }
.steps b {
  flex: none;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #1b1404;
}
#overlay-start {
  place-items: center;
  padding: clamp(18px, 4vw, 52px);
  background: linear-gradient(90deg, rgba(7, 11, 17, 0.82) 0%, rgba(7, 11, 17, 0.42) 36%, rgba(7, 11, 17, 0.05) 68%);
  backdrop-filter: none;
}
#overlay-start .start-card {
  --start-pad-x: 26px;
  --start-pad-top: 24px;
  width: min(420px, 100%);
  max-width: none;
  padding: 24px 26px 21px;
  overflow: hidden;
  text-align: left;
  background: rgba(13, 18, 27, 0.94);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.48);
}
#overlay-start .start-card.hidden { display: none; }
.return-hub {
  width: min(430px, 100%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 22px;
  background: rgba(13, 18, 27, 0.94);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.52);
}
.return-hub.hidden { display: none; }
.daily-mission { padding: 5px 4px 2px; }
.return-label {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}
.daily-mission h2 {
  margin: 0 0 14px;
  color: #fff;
  font-size: clamp(27px, 5vw, 36px);
  line-height: 1.15;
  letter-spacing: -0.025em;
  text-wrap: balance;
}
.daily-mission .primary { width: 100%; min-height: 50px; }
.previous-challenge-result {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0;
  padding: 9px 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  color: #aeb9c8;
  font-size: 12px;
}
.previous-challenge-result[hidden] { display: none; }
.previous-challenge-result b { overflow: hidden; color: #eef4fb; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.previous-challenge-result strong { margin-left: auto; color: var(--accent); font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.previous-mission {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 4px;
}
.previous-mission[hidden] { display: none; }
.previous-mission > div { min-width: 0; }
.previous-mission h3 {
  overflow: hidden;
  margin: 0;
  color: #f4f8fd;
  font-size: 19px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.previous-best { margin: 4px 0 0; color: #aeb9c8; font-size: 11px; }
.previous-best b { color: #fff; font-size: 15px; font-variant-numeric: tabular-nums; }
.previous-mission button { flex: none; margin-left: auto; border-color: rgba(242, 193, 78, 0.65); color: #ffe089; background: rgba(14, 18, 26, 0.88); font-weight: 800; }
.map-search {
  display: flex;
  min-height: 48px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  background: rgba(6, 9, 15, 0.72);
}
.map-search:focus-within { border-color: rgba(242, 193, 78, 0.8); box-shadow: 0 0 0 3px rgba(242, 193, 78, 0.14); }
.map-search input {
  min-width: 0;
  flex: 1;
  border: 0;
  outline: 0;
  padding: 0 8px 0 18px;
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 15px;
}
.map-search input::placeholder { color: #aeb9c8; opacity: 1; }
.map-search button { width: 52px; border: 0; border-radius: 0; padding: 0; color: transparent; background: transparent; position: relative; }
.map-search button::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 13px;
  width: 15px;
  height: 15px;
  border: 3px solid #fff;
  border-radius: 50%;
}
.map-search button::after {
  content: "";
  position: absolute;
  left: 31px;
  top: 29px;
  width: 10px;
  height: 3px;
  border-radius: 2px;
  background: #fff;
  transform: rotate(45deg);
  transform-origin: left center;
}
.map-search-status { min-height: 0; margin: -2px 8px 0; color: #bcc7d6; font-size: 11px; line-height: 1.4; }
.map-search-status:empty { display: none; }
.map-search-results { max-height: min(220px, 32vh); overflow-y: auto; border-top: 1px solid rgba(255, 255, 255, 0.1); }
.map-search-results[hidden] { display: none; }
.map-search-results button {
  width: 100%;
  display: block;
  overflow: hidden;
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0;
  padding: 11px 8px;
  background: transparent;
  color: #edf3fa;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.map-search-results button:hover, .map-search-results button:focus-visible { background: rgba(255, 255, 255, 0.07); outline: none; }
#overlay-start.revealing {
  padding: 0;
  background:
    radial-gradient(circle at center, rgba(7, 11, 17, 0) 30%, rgba(7, 11, 17, 0.22) 72%, rgba(7, 11, 17, 0.58) 100%);
}
.map-reveal {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  text-align: center;
}
.map-reveal.hidden { display: none; }
.map-reveal-skip {
  position: absolute;
  right: 20px;
  bottom: 20px;
  z-index: 1;
  min-width: 78px;
  padding: 9px 14px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 999px;
  color: #fff;
  background: rgba(7, 11, 17, 0.7);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  pointer-events: auto;
  cursor: pointer;
}
.map-reveal-skip:hover { background: rgba(7, 11, 17, 0.9); }
.start-illustration {
  position: relative;
  height: 156px;
  margin: calc(-1 * var(--start-pad-top)) calc(-1 * var(--start-pad-x)) 16px;
  overflow: hidden;
  border-bottom: 1px solid rgba(255, 193, 74, 0.38);
  background: #151b27;
}
.start-illustration::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(5, 8, 13, 0.02) 42%, rgba(5, 8, 13, 0.68) 100%);
  pointer-events: none;
}
.start-illustration img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: center;
}
.start-crisis {
  position: absolute;
  z-index: 1;
  left: 14px;
  bottom: 12px;
  margin: 0;
  padding: 7px 13px 8px;
  clip-path: polygon(3% 0, 100% 4%, 97% 100%, 0 94%);
  background: #c7352d;
  color: #fff;
  font-size: 17px;
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: 0.015em;
  text-shadow: 0 1px 0 #54100c;
  box-shadow: 0 5px 16px rgba(0, 0, 0, 0.42);
  transform: rotate(-1deg);
}
#overlay-start .start-card h2 { font-size: clamp(27px, 3vw, 38px); margin-bottom: 8px; }
#overlay-start .lead { max-width: 34em; margin-bottom: 18px; }
#overlay-start .primary { width: 100%; }
.map-load-status { margin: 10px 0 0; color: #d9e0e9; font-size: 13px; line-height: 1.4; text-align: center; }
.map-load-status:empty { display: none; }
.map-load-retry { display: block; width: 100%; margin-top: 10px; }
.map-load-retry.hidden { display: none; }
.brief-card .start-illustration { margin-bottom: 18px; }
.brief-card h2 {
  color: #fff4d6;
  text-transform: uppercase;
  letter-spacing: 0.01em;
}
.start-note {
  margin: 9px 0 0;
  color: #b6c1d0;
  font-size: 12px;
  line-height: 1.45;
  text-align: center;
}
#overlay-end {
  z-index: 30;
  place-items: center end;
  padding: clamp(18px, 4vw, 54px);
  background: rgba(5, 8, 13, 0.28);
  backdrop-filter: none;
  transition-duration: 0.2s;
}
body:is(.end-open, .victory-open) #hud,
body:is(.end-open, .victory-open) #coach,
body:is(.end-open, .victory-open) #aim-hint,
body:is(.end-open, .victory-open) #wave-banner,
body:is(.end-open, .victory-open) #toast,
body:is(.end-open, .victory-open) #zoom,
body:is(.end-open, .victory-open) #dock,
body:is(.end-open, .victory-open) #legend,
body:is(.end-open, .victory-open) #speed-toggle {
  visibility: hidden;
  pointer-events: none;
}
#overlay-end .end-card {
  width: min(400px, 100%);
  max-width: none;
  max-height: calc(100% - 12px);
  overflow-y: auto;
  padding: 24px 26px 20px;
  text-align: left;
  background: rgba(13, 18, 27, 0.97);
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.58);
  transition-duration: 0.2s;
}
#overlay-end[data-result="win"] .end-card {
  background: radial-gradient(circle at 95% 0%, rgba(242, 193, 78, 0.11), transparent 48%), #0d121c;
  border-color: rgba(242, 193, 78, 0.28);
}
#overlay-end[data-result="loss"] .end-card {
  background: radial-gradient(circle at 95% 0%, rgba(255, 106, 61, 0.08), transparent 48%), #0d121c;
  border-color: rgba(255, 178, 157, 0.22);
}
body.challenge-end #overlay-end { background: transparent; pointer-events: none; }
body.challenge-end #overlay-end .end-card { pointer-events: auto; }
body.challenge-end #overlay-end .end-compare,
body.challenge-end #overlay-end .end-details { display: none; }
.challenge-panel.hidden { display: none; }
.challenge-panel { border-top: 1px solid rgba(255,255,255,.13); padding: 12px 0 7px; }
.challenge-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: 14px; }
.challenge-heading span { color: #c4d0df; font-size: 12px; text-align: right; }
.challenge-status, .challenge-cell { margin: 7px 0; color: #e2eaf4; font-size: 13px; line-height: 1.45; }
.challenge-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; color: #eee4c9; font-size: 13px; line-height: 1.35; }
.challenge-legend span { display: inline-flex; align-items: center; gap: 5px; }
.challenge-legend span::before { content: ""; flex: none; width: 19px; height: 10px; border-radius: 3px; }
.challenge-legend span:first-child::before { background: linear-gradient(90deg, rgba(99, 208, 140, .18), rgba(99, 208, 140, .9)); }
.challenge-legend span:last-child::before { background: linear-gradient(90deg, #df7566, #d3b575, #6bcf8c); }
.challenge-ranking-details { margin-top: 8px; border-top: 1px solid rgba(255,255,255,.12); }
.challenge-ranking-details summary { min-height: 40px; padding: 10px 0; cursor: pointer; font-size: 14px; font-weight: 700; }
.challenge-ranking { display: grid; gap: 4px; margin: 0; padding: 0 0 4px; list-style: none; max-height: 180px; overflow: auto; }
.challenge-ranking li { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 8px; min-height: 44px; padding: 2px 6px; border-radius: 7px; background: rgba(255,255,255,.05); font-size: 13px; }
.challenge-ranking li button { min-height: 36px; border: 1px solid rgba(255,255,255,.35); border-radius: 6px; padding: 5px 10px; background: #263247; color: #fff; font-size: 13px; }
.challenge-ranking li.no-replay button { opacity: .45; }
.spectator-controls.hidden { display: none; }
.spectator-controls { position: absolute; z-index: 38; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 7px; width: min(96%, 620px); padding: 9px; border: 1px solid rgba(255,255,255,.2); border-radius: 12px; background: rgba(12,19,30,.94); color: #fff; box-shadow: 0 12px 30px #0008; font-size: 12px; }
.spectator-controls button { min-height: 36px; padding: 5px 9px; border: 1px solid #71809a; border-radius: 7px; background: #263247; color: #fff; font-size: 12px; }
.spectator-controls span { flex-basis: 100%; text-align: center; color: #dce7f3; }
body.spectator-open #hud, body.spectator-open #coach, body.spectator-open #aim-hint,
body.spectator-open #wave-banner, body.spectator-open #toast, body.spectator-open #dock,
body.spectator-open #legend, body.spectator-open #speed-toggle { visibility: hidden; pointer-events: none; }
@media (max-width: 700px) {
  body.challenge-end #overlay-end { place-items: end center; padding: 8px; }
  body.challenge-end #overlay-end .end-card { width: 100%; max-height: min(62vh, 520px); padding: 12px 16px; }
  body.challenge-end #overlay-end .end-card h2 { font-size: 27px; }
  body.challenge-end .end-score-block { padding: 5px 0; }
  body.challenge-end .end-score-block b { font-size: 34px; }
}
.end-place {
  display: flex;
  align-items: baseline;
  gap: 9px;
  margin: 0 0 7px;
  color: #c3cedd;
  font-size: 12px;
}
.end-place span { color: var(--muted); }
.end-place b { color: #f7fbff; font-size: 16px; font-weight: 720; }
#overlay-end .end-card h2 {
  margin: 0;
  color: #fff7dc;
  font-size: clamp(30px, 4vw, 42px);
  line-height: 1.1;
  text-wrap: balance;
}
#overlay-end[data-result="loss"] .end-card h2 { color: #ffb29d; }
.end-subtitle {
  min-height: 1.5em;
  margin: 8px 0 18px;
  color: #bac5d4;
  font-size: 13px;
  line-height: 1.5;
  text-wrap: pretty;
}
.end-score-block {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 12px 0 13px;
  border-top: 1px solid rgba(255, 255, 255, 0.11);
}
.end-score-block span { margin-right: auto; color: #bac5d4; font-size: 13px; }
.end-score-block b {
  color: var(--accent);
  font-size: clamp(42px, 7vw, 58px);
  font-weight: 780;
  line-height: 0.95;
  font-variant-numeric: tabular-nums;
}
.end-compare {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 3px 12px;
  padding: 9px 0 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.11);
}
.end-compare span { color: var(--muted); font-size: 12px; }
.end-compare b { color: #f7fbff; font-size: 18px; font-variant-numeric: tabular-nums; }
.end-compare em { grid-column: 1 / -1; color: #ffbd9e; font-size: 12px; font-style: normal; font-weight: 750; }
.end-compare em.good { color: #8ee0a9; }
.end-compare.first-record { display: flex; justify-content: flex-end; padding-top: 0; }
.end-compare.first-record span,
.end-compare.first-record b { display: none; }
.end-compare.first-record em {
  display: inline-flex;
  width: fit-content;
  padding: 4px 9px;
  border: 1px solid rgba(142, 224, 169, 0.4);
  border-radius: 999px;
  background: rgba(142, 224, 169, 0.1);
}
.end-details { margin: 5px 0 12px; }
.end-details summary {
  display: flex;
  align-items: center;
  min-height: 40px;
  color: #aeb9c8;
  font-size: 12px;
  cursor: pointer;
}
.end-details summary::after { content: "+"; margin-left: auto; color: #dbe5f2; font-size: 18px; }
.end-details[open] summary::after { content: "−"; }
.end-grid { display: grid; grid-template-columns: repeat(3, 1fr); margin: 0 0 8px; }
.end-grid div { min-width: 0; padding: 2px 10px; border-right: 1px solid rgba(255, 255, 255, 0.1); }
.end-grid div:first-child { padding-left: 0; }
.end-grid div:last-child { padding-right: 0; border-right: 0; }
.end-grid span { display: block; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.end-grid b { display: block; margin-top: 3px; font-size: 21px; font-variant-numeric: tabular-nums; }
.end-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.end-actions button { min-height: 46px; padding: 10px 14px; }
.end-actions button { font-size: 14px; font-weight: 650; }
.end-actions .primary { width: 100%; }
.end-city-btn {
  width: 100%;
  min-height: 42px;
  margin-top: 3px;
  padding: 8px;
  border: 0;
  background: transparent;
  color: #c3cedd;
  font-size: 12px;
}
.end-city-btn::after { content: " ›"; }
.end-city-btn:hover, .end-city-btn:focus-visible { color: #fff; background: rgba(255, 255, 255, 0.06); }
.share-status {
  min-height: 18px;
  margin: 7px 0 -5px;
  color: #b9e8c9;
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}
.share-status.bad { color: #ffb29d; }
.share-status:empty { display: none; }

.hint, .credit, .legend {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}
.legend { list-style: none; padding: 0; margin: 0; }
.legend li { display: flex; gap: 8px; align-items: center; margin: 0; padding: 3px 6px; border-radius: 6px; line-height: 1.3; cursor: help; white-space: nowrap; }
.legend li:hover, .legend li:focus { background: rgba(255, 255, 255, 0.07); outline: none; color: var(--text); }
.legend-box { width: 184px; margin: 0; border: 1px solid var(--line); border-radius: 10px; padding: 4px; background: rgba(14, 18, 26, 0.9); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28); backdrop-filter: blur(4px); }
.legend-head { display: flex; width: 100%; justify-content: space-between; align-items: center; border: 0; background: transparent; border-radius: 6px; padding: 4px 6px; font-size: 12px; font-weight: 700; color: var(--text); }
.legend-head .chev { width: 7px; height: 7px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform 0.15s; margin-right: 3px; }
.legend-box.collapsed .chev { transform: rotate(-45deg); }
.legend-box.collapsed .legend { display: none; }
.legend-box.collapsed { width: auto; }
.legend-box.collapsed .legend-head { width: 58px; }
#legend-tip { position: fixed; z-index: 50; max-width: 300px; padding: 8px 11px; border-radius: 8px; background: rgba(10, 14, 22, 0.97); border: 1px solid rgba(255, 255, 255, 0.18); color: var(--text); font-size: 12px; line-height: 1.55; pointer-events: none; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); }
#legend-tip[hidden] { display: none; }
.swatch { width: 18px; height: 8px; border-radius: 99px; display: inline-block; flex: none; }
.swatch.route { background: linear-gradient(90deg, #2ee6c5, #ffb02e, #ff3d5a); }
.swatch.next { background: #ffc14a; opacity: 0.55; height: 4px; }
.swatch.corr { background: #ff4d6d; height: 6px; }
.swatch.base { background: var(--friend); height: 12px; width: 12px; border-radius: 50%; }
.swatch.gun { background: transparent; border: 2px solid var(--friend); height: 12px; width: 12px; border-radius: 50%; }
.swatch.tough { background: #7a2fd0; border: 2px solid #f1d9ff; height: 13px; width: 13px; border-radius: 3px; }
.swatch.boss { background: #4fbf62; border: 2px solid #d9ffb8; height: 14px; width: 14px; border-radius: 50% 50% 35% 35%; box-shadow: 0 0 7px rgba(125, 255, 110, 0.7); }
.swatch.enemy { background: var(--foe); height: 9px; width: 9px; border-radius: 50%; }
.swatch.bonus { background: linear-gradient(90deg, rgba(242, 193, 78, 0.25), rgba(242, 193, 78, 0.95)); height: 6px; }
.swatch.slow { background: #b58cff; height: 4px; }
.swatch.store { background: #ffc94a; height: 9px; width: 9px; border-radius: 2px 2px 3px 3px; }
.swatch.school { background: #7eb6ff; height: 8px; width: 8px; border-radius: 2px; }
.swatch.abil { background: linear-gradient(90deg, #8fe3ff, #ffb02e); height: 6px; }
.swatch.park { background: rgba(80, 170, 110, 0.8); height: 10px; }

@media (max-width: 800px), (max-height: 500px) and (max-width: 1000px) {
  main { grid-template-columns: 1fr; }
  aside { display: none; }
  h1 { font-size: 16px; }
  header { padding: 6px 10px; }
  .head-btns { gap: 5px; }
  .head-btns button { min-height: 44px; padding: 8px 11px; }
  #hud { right: 56px; top: 8px; left: 8px; }
  .chip.dim, .chip.foes { display: none; }
  #wave-banner { top: 37%; width: calc(100% - 28px); }
  #wave-banner-title { font-size: clamp(27px, 9vw, 40px); }
  #wave-banner-meta { font-size: 12px; margin-top: 8px; }
  #wave-banner::before, #wave-banner::after { display: none; }
  .hp-card { min-width: 0; width: 100%; padding: 4px 10px 6px; }
  .chips { flex-wrap: wrap; gap: 4px; width: 100%; }
  .chip { padding: 4px 8px; font-size: 11px; white-space: nowrap; }
  .chip b { font-size: 15px; }
  .chip.wave { flex: 1 0 100%; text-align: center; }
  #coach { font-size: 13px; max-width: calc(100% - 20px); }
  #zoom { right: 8px; top: 8px; gap: 5px; }
  #zoom button { width: 46px; height: 46px; }
  .dock-main button { min-height: 44px; padding: 8px 13px; font-size: 14px; }
  #dock {
    width: calc(100% - 12px);
    bottom: max(8px, env(safe-area-inset-bottom));
    gap: 5px;
  }
  #dock .dock-kinds {
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    touch-action: pan-x;
    justify-content: flex-start;
    width: 100%;
    padding: 1px 0;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  #dock .dock-kinds::-webkit-scrollbar { display: none; }
  #dock .kind { min-height: 44px; padding: 8px 12px; font-size: 13px; scroll-snap-align: center; }
  #dev { min-width: 0; width: 100%; }
  .dock-sub { width: 100%; }
  .dock-sub button { width: 100%; min-height: 44px; padding: 8px 12px; font-size: 13px; }
  #tree-panel {
    top: 58px;
    width: calc(100% - 12px);
    overscroll-behavior: contain;
    touch-action: pan-x pan-y;
  }
  #tree-close { min-width: 44px; min-height: 44px; padding: 0; font-size: 24px; }
  .card { padding: 20px; }
  #overlay-start {
    place-items: center;
    padding: 12px;
    background: linear-gradient(180deg, rgba(7, 11, 17, 0.02) 0%, rgba(7, 11, 17, 0.12) 46%, rgba(7, 11, 17, 0.92) 76%, rgba(7, 11, 17, 0.98) 100%);
  }
  #overlay-start.revealing {
    padding: 0;
    background: radial-gradient(circle at center, rgba(7, 11, 17, 0) 25%, rgba(7, 11, 17, 0.25) 72%, rgba(7, 11, 17, 0.62) 100%);
  }
  .map-reveal-skip { right: 12px; bottom: 16px; }
  #overlay-start .start-card { --start-pad-x: 20px; --start-pad-top: 19px; padding: 19px 20px 17px; }
  .return-hub { align-self: end; padding: 14px; border-radius: 20px; }
  .daily-mission h2 { font-size: clamp(25px, 8vw, 32px); }
  .previous-challenge-result { padding-inline: 6px; }
  .previous-mission { padding-inline: 3px; }
  .start-illustration { height: 142px; margin-bottom: 14px; }
  .start-crisis { left: 12px; bottom: 10px; font-size: 15px; }
  #overlay-start .start-card h2 { font-size: clamp(27px, 8vw, 34px); }
  #overlay-end {
    place-items: end center;
    padding: 8px 8px max(8px, env(safe-area-inset-bottom));
    background: rgba(5, 8, 13, 0.18);
  }
  #overlay-end .end-card { width: 100%; padding: 17px 18px 13px; border-radius: 18px; }
  #overlay-end .end-card h2 { font-size: clamp(28px, 9vw, 38px); }
  .end-subtitle { margin: 6px 0 11px; }
  .end-score-block { padding: 10px 0 11px; }
  .end-score-block b { font-size: clamp(40px, 14vw, 54px); }
  .end-compare { padding: 7px 0 9px; }
  .end-details { margin-bottom: 8px; }
  .end-details summary { min-height: 36px; }
  .end-grid { grid-template-columns: repeat(3, 1fr); }
  .end-grid div { padding: 2px 7px; }
  .end-grid b { font-size: 18px; }
}

@media (max-height: 500px) and (min-width: 600px) {
  #overlay-end { place-items: center end; padding: 8px; }
  #overlay-end .end-card { width: min(390px, 48%); max-height: calc(100% - 4px); padding: 12px 14px 8px; border-radius: 16px; }
  .end-place { margin-bottom: 3px; }
  #overlay-end .end-card h2 { font-size: 26px; }
  .end-subtitle { margin: 4px 0 7px; font-size: 11px; }
  .end-score-block { padding: 7px 0; }
  .end-score-block b { font-size: 36px; }
  .end-compare { padding: 5px 0 6px; }
  .end-details { margin: 2px 0 5px; }
  .end-details summary { min-height: 30px; }
  .end-actions button { min-height: 42px; padding: 7px 9px; font-size: 11px; }
  .end-city-btn { min-height: 34px; padding: 5px; }
  .share-status { min-height: 12px; margin-top: 2px; }
}


@media (prefers-reduced-motion: reduce) {
  .overlay, .card { transition: none; }
  #dev.ready { animation: none; }
  .dawn-chip.dawn-soon { animation: none; }
  .chip.wave.imminent { animation: none; }
  #wave-impact.show { animation: none; }
  #wave-banner.show { animation: waveBannerReduced 2.2s ease both; }
}
@keyframes waveBannerReduced { 0%, 100% { opacity: 0; } 12%, 75% { opacity: 1; } }

#aim-hint {
  position: absolute;
  left: 50%;
  top: var(--aim-top, 112px);
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 99px;
  background: rgba(14, 21, 34, 0.9);
  border: 1px solid #8fe3ff;
  font-size: 13px;
  pointer-events: none;
  max-width: calc(100% - 20px);
  text-align: center;
}
#aim-hint.hidden { display: none; }

/* 武器の種類のボタン */
.dock-kinds { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.kind { flex: none; display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; padding: 4px 9px; font-size: 12px; background: var(--glass); backdrop-filter: blur(4px); border: 2px solid #888; }
.kind[hidden] { display: none; }
.tool-icon {
  position: relative;
  display: inline-block;
  width: 18px;
  height: 18px;
  color: var(--kc, var(--accent));
  font-style: normal;
  font-size: 15px;
  line-height: 1;
}
.tool-icon::before, .tool-icon::after { content: ""; position: absolute; display: block; box-sizing: border-box; }
/* 道具の用途を輪郭で判別できるCSSアイコン。画像・外部フォントは使わない。 */
.tool-barricade::before { left: 0.08em; top: 0.28em; width: 1.05em; height: 0.24em; border-radius: 0.05em; background: currentColor; box-shadow: 0 0.38em 0 currentColor; transform: rotate(-7deg); }
.tool-barricade::after { left: 0.3em; top: 0.12em; width: 0.12em; height: 1.02em; background: currentColor; box-shadow: 0.58em 0 0 currentColor; opacity: 0.8; }
.tool-gunner::before { left: 0.08em; bottom: 0.08em; width: 0.7em; height: 0.52em; border: 0.12em solid currentColor; border-radius: 50% 50% 0.16em 0.16em; }
.tool-gunner::after { left: 0.57em; top: 0.3em; width: 0.68em; height: 0.1em; border-radius: 0.1em; background: currentColor; box-shadow: 0 0.22em 0 currentColor; transform: rotate(-18deg); transform-origin: left center; }
.tool-cannon::before { left: 0.02em; bottom: 0.02em; width: 0.58em; height: 0.58em; border: 0.13em solid currentColor; border-radius: 50%; }
.tool-cannon::after { left: 0.43em; top: 0.31em; width: 0.88em; height: 0.24em; border-radius: 0.1em 0.24em 0.24em 0.1em; background: currentColor; transform: rotate(-24deg); transform-origin: left center; }
.tool-flamer::before { left: 0.28em; top: 0.02em; width: 0.72em; height: 1.05em; border-radius: 70% 25% 65% 55%; background: currentColor; transform: rotate(36deg); }
.tool-flamer::after { left: 0.48em; top: 0.45em; width: 0.28em; height: 0.46em; border-radius: 70% 30% 65% 55%; background: #0d1118; transform: rotate(28deg); opacity: 0.72; }
.tool-mortar::before { left: 0.27em; top: 0.05em; width: 0.38em; height: 0.92em; border: 0.12em solid currentColor; border-radius: 0.16em; transform: rotate(28deg); }
.tool-mortar::after { left: 0.12em; bottom: 0.02em; width: 1em; height: 0.18em; border-radius: 0.12em; background: currentColor; }
.tool-strafe::before { left: 0.42em; top: 0.43em; width: 0.38em; height: 0.38em; border: 0.1em solid currentColor; border-radius: 50%; }
.tool-strafe::after { left: 0.05em; top: 0.25em; width: 1.12em; height: 0.12em; border-radius: 0.1em; background: currentColor; box-shadow: 0 0.48em 0 currentColor; transform: rotate(-12deg); }
.tool-battery::before { left: 0.14em; top: 0.14em; width: 0.95em; height: 0.95em; border: 0.12em solid currentColor; border-radius: 50%; box-shadow: inset 0 0 0 0.16em #0d1118; }
.tool-battery::after { left: 0.55em; top: 0; width: 0.12em; height: 1.22em; background: currentColor; box-shadow: -0.55em 0.55em 0 -0.01em currentColor; transform: rotate(45deg); }
.tool-freeze::before { content: "❄"; inset: 0; color: currentColor; font-size: 1.16em; line-height: 1.05; text-align: center; }
.barricade-kind { --kc: #d7a05f; border-color: #d7a05f; }
.kind.active { background: var(--kc, var(--accent)); color: #0d1118; border-color: #fff; font-weight: 700; }
.kind.active .tool-icon { color: #0d1118; }
.kind.sel { box-shadow: inset 0 -3px 0 var(--kc, var(--accent)); }
.kind.locked { opacity: 0.5; }
#dev-compact { display: none; }

/* スマホは地図中央を戦場として空ける。上部は2段、下部は道具と開発の1段だけにする。 */
@media (max-width: 800px), (max-height: 500px) and (max-width: 1000px) {
  #hud {
    right: auto;
    width: min(322px, calc(100% - 68px));
    display: grid;
    grid-template-columns: minmax(118px, 1fr) auto auto;
    gap: 4px;
    align-items: stretch;
  }
  .hp-card {
    grid-column: 1;
    width: auto;
    min-width: 0;
    padding: 3px 9px 5px;
    border-radius: 11px;
  }
  .hp-label { align-items: center; line-height: 1; }
  .hp-label b { font-size: 16px; }
  .hp-track { height: 6px; margin-top: 2px; }
  #hud .chips { display: contents; }
  #hud .chip { display: none; align-content: center; padding: 3px 7px; border-radius: 11px; }
  #hud .chip.pts,
  #hud .dawn-chip,
  #hud .chip.wave { display: block; }
  #hud .chip.pts { grid-column: 2; }
  #hud .dawn-chip { grid-column: 3; }
  #hud .chip.wave {
    grid-column: 1 / -1;
    width: auto;
    min-height: 25px;
    padding: 3px 7px 7px;
    text-align: center;
  }
  #hud .chip.wave b { font-size: 12px; }

  /* ピンチ操作があるスマホでは +/- を畳み、全体表示だけを丸いボタンで残す。 */
  #zoom { right: 8px; top: 8px; }
  #zoom-in, #zoom-out { display: none; }
  #zoom #zoom-fit {
    display: block;
    width: 44px;
    height: 44px;
    min-height: 44px;
    border-radius: 50%;
    padding: 0;
    font-size: 21px;
  }

  #dock {
    flex-direction: row;
    align-items: flex-end;
    width: calc(100% - 12px);
    gap: 5px;
  }
  #dock .dock-main { flex: 0 0 auto; }
  #dock .dock-main button {
    width: 54px;
    height: 54px;
    min-height: 54px;
    padding: 0 5px;
    border-radius: 16px;
    font-size: 12px;
  }
  #dock .dock-kinds {
    flex: 1 1 auto;
    width: 0;
    min-width: 0;
    height: 58px;
    padding: 2px 0;
    align-items: flex-end;
  }
  #dock .kind {
    position: relative;
    display: grid;
    grid-template-rows: 27px 13px;
    place-items: center;
    width: 54px;
    height: 54px;
    min-height: 54px;
    padding: 4px 3px 3px;
    gap: 1px;
    border-radius: 16px;
    font-size: 10px;
  }
  #dock .kind[hidden] { display: none; }
  #dock .tool-icon {
    width: 27px;
    height: 27px;
    font-size: 23px;
  }
  #dock .tool-label { display: none; }
  #dock .kind em { margin: 0; font-size: 10px; line-height: 1; }
  #dock .dock-sub { flex: 0 0 106px; width: 106px; }
  #dev {
    width: 106px;
    min-width: 106px;
    height: 58px;
    min-height: 58px;
    padding: 5px 9px;
    border-radius: 18px;
  }
  #dev-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  #dev-compact { position: relative; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 5px 7px; line-height: 1; text-align: left; }
  #dev-compact .dev-action { grid-column: 1 / -1; color: #fff; font-size: 12px; white-space: nowrap; }
  #dev-compact .dev-rp-line { display: flex; align-items: baseline; gap: 5px; min-width: 0; font-variant-numeric: tabular-nums; }
  #dev-compact .dev-rp-line b { color: #8fe3ff; font-size: 11px; white-space: nowrap; }
  #dev-compact .dev-rp-line small { color: #b8c8dc; font-size: 9px; white-space: nowrap; }
  #dev-ready-compact { min-width: 19px; padding: 3px 5px; border-radius: 99px; background: #8fe3ff; color: #0b1119; font-size: 10px; font-style: normal; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; }
  #dev-ready-compact[hidden] { display: none; }
  #stage-credit { bottom: calc(var(--dock-h, 72px) - 3px); font-size: 9px; opacity: 0.72; }
}

/* 開発ツリー。枝ごとの列に節の箱を並べる */
#tree-panel {
  position: absolute;
  left: 50%;
  top: 56px;
  transform: translateX(-50%);
  width: min(1080px, calc(100% - 16px));
  max-height: calc(100% - var(--dock-h, 130px) - 70px);
  overflow: auto;
  padding: 10px;
  border-radius: 12px;
  background: rgba(10, 14, 22, 0.95);
  border: 1px solid #8fe3ff;
  z-index: 20;
}
#tree-panel.hidden { display: none; }
#tree-panel.victory-closing {
  pointer-events: none;
  animation: tree-victory-exit 240ms cubic-bezier(0.3, 0, 1, 1) both;
}
@keyframes tree-victory-exit {
  from { opacity: 1; transform: translateX(-50%) translateY(0); }
  to { opacity: 0; transform: translateX(-50%) translateY(-12px); }
}
.tree-head {
  position: sticky;
  top: -10px;
  left: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 44px;
  align-items: center;
  gap: 12px;
  min-width: min(100%, 320px);
  margin: -10px -10px 8px;
  padding: 10px;
  font-size: 14px;
  background: rgba(10, 14, 22, 0.98);
  border-bottom: 1px solid rgba(143, 227, 255, 0.28);
}
.tree-head > b { white-space: nowrap; }
.tree-head .tree-note { opacity: 0.7; font-size: 12px; flex: 1; }
#tree-overview {
  display: flex;
  min-width: 0;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}
#tree-overview::-webkit-scrollbar { display: none; }
.tree-branch-chip {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 4px;
  min-height: 24px;
  padding: 2px 6px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.045);
  color: #d7dfec;
  font-size: 10px;
  scroll-snap-align: start;
}
.tree-branch-chip i { width: 7px; height: 7px; border-radius: 50%; background: #8892a8; }
.tree-branch-chip b { font-size: 10px; white-space: nowrap; }
.tree-branch-chip small { color: #9faabc; font-size: 9px; }
.tree-branch-chip.has-ready { border-color: rgba(110, 229, 154, 0.65); background: rgba(110, 229, 154, 0.1); }
.tree-branch-chip.br1 i { background: #ffb347; }
.tree-branch-chip.br2 i { background: #7fe8ff; }
.tree-branch-chip.br3 i { background: #ff6a3d; }
.tree-branch-chip.br4 i { background: #b0b8c8; }
.tree-branch-chip.br5 i { background: #6ee59a; }
#tree-close {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  margin-left: auto;
  padding: 0;
  border-radius: 50%;
  font-size: 24px;
  line-height: 1;
}
#tree-cols { position: relative; }
.tree-lines { position: absolute; left: 0; top: 0; pointer-events: none; }
.tree-line { fill: none; stroke: #4a5570; stroke-width: 2; }
.tree-line.on { stroke: #8fe3ff; }
.tree-line.on.br1 { stroke: #ffb347; }
.tree-line.on.br2 { stroke: #7fe8ff; }
.tree-line.on.br3 { stroke: #ff6a3d; }
.tree-line.on.br4 { stroke: #b0b8c8; }
.tree-line.on.br5 { stroke: #6ee59a; }
.tree-line.cross { stroke-dasharray: 6 3; }
.tree-line.excl { stroke: #ff8a8a; stroke-dasharray: 3 3; stroke-width: 1.5; }
.tree-colhead { position: absolute; top: 0; text-align: center; font-size: 12px; color: #8fe3ff; }
.tree-node { position: absolute; display: flex; flex-direction: column; justify-content: flex-start; gap: 1px; text-align: left; font-size: 11px; line-height: 1.2; padding: 4px 34px 4px 10px; border-radius: 7px; border: 2px solid #556; background: #1a2030; color: #cfd8e8; overflow: hidden; }
.tree-node b { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.tree-node .tree-desc { overflow: hidden; color: #aeb9ca; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.tree-node .tree-cost { position: absolute; right: 5px; bottom: 4px; padding: 1px 4px; border-radius: 999px; background: rgba(0, 0, 0, 0.28); color: #dce5f3; font-size: 9px; line-height: 1.25; }
.tree-node em { font-style: normal; opacity: 0.85; }
.tree-node.ready { border-color: #6ee59a; background: #17301f; color: #fff; }
.tree-node.owned { border-color: #8fe3ff; background: #1b3a4a; color: #fff; }
.tree-node.locked, .tree-node.excluded { opacity: 0.45; border-style: dashed; }

@media (max-width: 800px), (max-height: 500px) and (max-width: 1000px) {
  #tree-panel {
    top: 8px;
    width: calc(100% - 12px);
    max-height: calc(100% - var(--dock-h, 70px) - 18px);
    padding: 8px;
    overscroll-behavior: contain;
    touch-action: pan-x pan-y;
  }
  .tree-head { top: -8px; margin: -8px -8px 8px; padding: 8px; }
}
.tree-node.poor { border-color: #ffb02e; }
.tree-node.cross { box-shadow: 0 0 0 2px rgba(255, 210, 74, 0.35); }
.chip.medal b { color: #ffd24a; }
.swatch.kinds { background: linear-gradient(90deg, #ffb347, #ff6a3d, #c9a8ff, #6ee59a); }
.swatch.medal { background: #ffd24a; }
.swatch.orc { background: #ffd21e; border-radius: 50%; }

/* 開発ツリーの枝の色（左の帯） */
.tree-node.br1 { box-shadow: inset 5px 0 0 #ffb347; }
.tree-node.br2 { box-shadow: inset 5px 0 0 #7fe8ff; }
.tree-node.br3 { box-shadow: inset 5px 0 0 #ff6a3d; }
.tree-node.br4 { box-shadow: inset 5px 0 0 #b0b8c8; }
.tree-node.br5 { box-shadow: inset 5px 0 0 #6ee59a; }
.tree-node.cross.br5 { box-shadow: inset 5px 0 0 #6ee59a, 0 0 0 2px rgba(255, 210, 74, 0.35); }
.tree-line.avail.on { stroke: #6ee59a; stroke-width: 3.5; }
.tree-node em { position: absolute; right: 6px; top: 2px; font-size: 14px; font-weight: 700; }
.tree-node.owned em { color: #8fe3ff; }
.tree-node.ready em { color: #6ee59a; }
.tree-node.excluded em { color: #ff8a8a; }
.change-town, #share-image { display: block; margin: 10px auto 0; min-height: 44px; padding: 8px 16px; background: transparent; border: 1px solid #596575; border-radius: 22px; color: #e1e7ee; font: inherit; cursor: pointer; }
#stage-credit a { color: inherit; text-underline-offset: 2px; }

#result-image-dialog { width: min(940px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 16px; border: 1px solid #596575; border-radius: 16px; background: #0d1118; color: #e9eff7; overflow: auto; }
#result-image-dialog::backdrop { background: rgba(0, 0, 0, .75); }
.result-image-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.result-image-head h2 { font-size: 18px; margin: 0; }
#result-image-close { min-width: 44px; min-height: 44px; border: 1px solid #596575; border-radius: 50%; background: transparent; color: inherit; font-size: 26px; cursor: pointer; }
#result-image-preview { display: block; width: 100%; height: auto; }
.result-image-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.result-image-actions a { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 10px 20px; border: 1px solid #596575; border-radius: 24px; color: #e9eff7; text-decoration: none; font-weight: 650; }
#result-image-download { background: #f2c14e; border-color: #f2c14e; color: #0d1118; }
#result-image-dialog p { margin: 12px 0 0; font-size: 13px; line-height: 1.6; color: #b7c2d1; }
#result-image-dialog :focus-visible { outline: 3px solid #5ab0ff; outline-offset: 3px; }
