:root {
  color-scheme: dark;
  --ink: #e9fbff;
  --muted: #8aa9b7;
  --panel: rgba(7, 25, 39, .82);
  --line: rgba(139, 227, 237, .14);
  --aqua: #73e7df;
  --violet: #b69cff;
  --shadow: 0 28px 80px rgba(0, 4, 10, .52);
  font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% -15%, #174b58 0, transparent 36rem),
    linear-gradient(155deg, #071724 0%, #06121f 45%, #050d18 100%);
  overflow-x: hidden;
}

button, input { font: inherit; }
button { color: inherit; }

.ambient { position: fixed; border-radius: 50%; filter: blur(80px); pointer-events: none; opacity: .22; }
.ambient-one { width: 32rem; height: 32rem; background: #27cfbd; top: 5%; left: -18rem; }
.ambient-two { width: 28rem; height: 28rem; background: #8a63ed; right: -15rem; bottom: -8rem; }

.app-shell { width: min(1110px, calc(100% - 32px)); margin: 0 auto; padding: 24px 0 44px; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.eyebrow { margin: 0 0 5px; color: #78adba; font-size: 10px; font-weight: 800; letter-spacing: .19em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(26px, 4vw, 40px); line-height: 1; letter-spacing: -.05em; }
h1 span { color: var(--aqua); }
h2 { margin: 0; font-size: 22px; letter-spacing: -.035em; }
h3 { margin: 18px 0 8px; font-size: 11px; text-transform: uppercase; color: #8cb2bc; letter-spacing: .13em; }

.ghost-button, .icon-button {
  border: 1px solid var(--line); background: rgba(11, 32, 47, .74); border-radius: 13px; cursor: pointer;
}
.ghost-button { padding: 10px 15px; font-weight: 750; }
.ghost-button:hover { background: rgba(18, 55, 67, .8); }
.tune-icon { display: inline-block; margin-right: 7px; color: var(--aqua); transform: rotate(90deg); }

.play-layout { display: grid; grid-template-columns: minmax(340px, 520px) minmax(330px, 1fr); align-items: start; gap: 24px; }
.game-column { min-width: 0; }
.mission-panel {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 74px;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
  padding: 14px 15px 16px;
  overflow: hidden;
  border: 1px solid rgba(115, 231, 223, .18);
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(10, 42, 53, .92), rgba(8, 25, 41, .94));
  box-shadow: 0 12px 30px rgba(0, 6, 13, .22);
}
.mission-copy { min-width: 0; }
.mission-copy span, .mission-copy strong, .mission-copy small { display: block; }
.mission-copy span { color: var(--aqua); font-size: 8px; font-weight: 900; letter-spacing: .16em; }
.mission-copy strong { margin-top: 3px; font-size: 15px; letter-spacing: -.02em; }
.mission-copy small { margin-top: 3px; overflow: hidden; color: #82a7b1; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.mission-target, .drop-budget { padding-left: 14px; border-left: 1px solid rgba(139, 227, 237, .11); }
.mission-target small, .mission-target strong, .mission-target span, .drop-budget small, .drop-budget strong { display: block; }
.mission-target small, .drop-budget small { color: #6e939f; font-size: 7px; font-weight: 850; letter-spacing: .1em; }
.mission-target strong { margin-top: 4px; color: #c8fff8; font-size: 10px; letter-spacing: .04em; white-space: nowrap; }
.mission-target span { margin-top: 2px; color: #66dcd5; font-size: 9px; font-weight: 800; }
.drop-budget { text-align: center; }
.drop-budget strong { margin-top: 2px; color: #f3ffff; font-size: 25px; line-height: 1; font-variant-numeric: tabular-nums; }
.mission-meter { position: absolute; right: 0; bottom: 0; left: 0; height: 3px; background: rgba(103, 219, 214, .08); }
.mission-meter i { display: block; width: 0; height: 100%; background: linear-gradient(90deg, #55d7cf, #d4fff8); box-shadow: 0 0 14px #62e1d8; transition: width .35s ease; }
.mission-panel.resolving { border-color: rgba(255, 210, 104, .34); }
.mission-panel.resolving .drop-budget strong { color: #ffd978; }
.game-toolbar { display: grid; grid-template-columns: 84px 1fr 92px; align-items: center; gap: 12px; margin-bottom: 10px; }
.next-card { display: flex; align-items: center; height: 54px; border: 1px solid var(--line); border-radius: 16px; background: rgba(5, 21, 33, .78); overflow: hidden; }
.next-card span { writing-mode: vertical-rl; transform: rotate(180deg); margin-left: 9px; color: #6e98a6; font-size: 8px; letter-spacing: .16em; font-weight: 850; }
#next-canvas { width: 52px; height: 52px; }
.mode-pill { justify-self: center; display: flex; align-items: center; gap: 8px; padding: 9px 13px; border-radius: 999px; background: rgba(9, 30, 44, .72); border: 1px solid var(--line); color: #afd0d9; font-size: 11px; font-weight: 700; }
.mode-pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--aqua); box-shadow: 0 0 12px var(--aqua); }
.drop-button { height: 44px; border: 0; border-radius: 13px; background: linear-gradient(135deg, #57daca, #3db6cc); box-shadow: 0 10px 25px rgba(50, 202, 197, .18); color: #06202a; font-size: 11px; font-weight: 900; letter-spacing: .11em; cursor: pointer; }
.drop-button:disabled { filter: grayscale(.6); opacity: .4; cursor: default; }

.tank-frame { position: relative; width: 100%; aspect-ratio: 35 / 51; border: 1px solid rgba(137, 228, 237, .23); border-radius: 28px; overflow: hidden; box-shadow: var(--shadow), inset 0 0 50px rgba(85, 214, 222, .07); background: #071b2d; isolation: isolate; }
#game-canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.tank-glass { position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: 2; box-shadow: inset 18px 0 28px rgba(111, 230, 236, .035), inset -16px 0 30px rgba(3, 8, 20, .34); }
.tank-glass::before { content: ""; position: absolute; top: 4%; bottom: 12%; left: 3%; width: 2px; border-radius: 50%; background: linear-gradient(transparent, rgba(213, 255, 255, .23), transparent); }
.instruction { position: absolute; z-index: 3; left: 50%; top: 14%; transform: translateX(-50%); padding: 9px 15px; text-align: center; border-radius: 12px; background: rgba(3, 18, 29, .67); border: 1px solid rgba(139, 227, 237, .12); pointer-events: none; transition: opacity .5s, transform .5s; white-space: nowrap; }
.instruction strong, .instruction span { display: block; }
.instruction strong { font-size: 11px; letter-spacing: .04em; }
.instruction span { margin-top: 3px; color: #87aeb8; font-size: 9px; }
.instruction.hidden { opacity: 0; transform: translate(-50%, -7px); }

.stage-result {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(2, 13, 24, .66);
  backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity .28s ease;
}
.stage-result[hidden] { display: none; }
.stage-result.visible { opacity: 1; }
.result-card {
  width: min(310px, 92%);
  padding: 28px 24px 23px;
  border: 1px solid rgba(145, 244, 238, .24);
  border-radius: 22px;
  background: linear-gradient(160deg, rgba(15, 57, 67, .97), rgba(6, 24, 40, .98));
  box-shadow: 0 28px 70px rgba(0, 4, 12, .56), inset 0 1px rgba(255,255,255,.06);
  text-align: center;
  transform: translateY(12px) scale(.97);
  transition: transform .3s ease;
}
.stage-result.visible .result-card { transform: translateY(0) scale(1); }
.result-card > span:first-child { color: var(--aqua); font-size: 8px; font-weight: 900; letter-spacing: .2em; }
.result-stars { margin: 13px 0 7px; color: #ffd56f; font-size: 25px; letter-spacing: .12em; text-shadow: 0 0 18px rgba(255, 205, 99, .38); }
.result-card h2 { font-size: 24px; }
.result-card p { min-height: 34px; margin: 9px 0 18px; color: #91b1ba; font-size: 11px; line-height: 1.55; }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.result-actions button { padding: 11px 8px; border-radius: 11px; font-size: 10px; font-weight: 850; cursor: pointer; }
.result-primary { border: 0; color: #06232b; background: linear-gradient(135deg, #76e8dc, #4bc4d1); }
.result-retry { border: 1px solid rgba(139, 227, 237, .17); color: #b9d6dc; background: rgba(16, 45, 58, .7); }
.result-retry[hidden] { display: none; }

.stats-grid { display: grid; grid-template-columns: repeat(6, 1fr); margin-top: 10px; padding: 12px 4px; background: rgba(5, 18, 29, .5); border: 1px solid rgba(139, 227, 237, .08); border-radius: 17px; }
.stats-grid div { min-width: 0; padding: 1px 6px; text-align: center; border-right: 1px solid rgba(139, 227, 237, .08); }
.stats-grid div:last-child { border: 0; }
.stats-grid small, .stats-grid strong { display: block; }
.stats-grid small { overflow: hidden; color: #678995; font-size: 7px; font-weight: 800; letter-spacing: .08em; white-space: nowrap; }
.stats-grid strong { margin-top: 5px; font-size: 14px; }

.debug-drawer { position: sticky; top: 18px; max-height: calc(100vh - 36px); padding: 21px; overflow-y: auto; border: 1px solid var(--line); border-radius: 24px; background: var(--panel); box-shadow: 0 20px 60px rgba(0, 5, 12, .36); backdrop-filter: blur(18px); scrollbar-width: thin; scrollbar-color: #235265 transparent; }
.drawer-heading { display: flex; justify-content: space-between; align-items: center; }
.icon-button { display: none; width: 36px; height: 36px; font-size: 22px; }
.panel-copy { margin: 13px 0 17px; color: var(--muted); font-size: 11px; line-height: 1.55; }
.mode-switch { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; border-radius: 13px; background: rgba(2, 13, 22, .5); }
.mode-switch button { padding: 9px; border: 0; border-radius: 10px; background: transparent; color: #799aa5; font-size: 11px; font-weight: 800; cursor: pointer; }
.mode-switch button.active { color: #09242c; background: var(--aqua); box-shadow: 0 5px 16px rgba(85, 225, 210, .18); }
.debug-controls { margin-top: 12px; }
.debug-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 5px 12px; margin: 10px 0; color: #abc5cb; font-size: 10px; }
.debug-row output { color: #75e4dd; font-variant-numeric: tabular-nums; }
.debug-row input { grid-column: 1 / -1; width: 100%; }
input[type="range"] { height: 4px; accent-color: #64ded5; cursor: pointer; }
.depth-grid { display: grid; gap: 7px; }
.depth-grid label { display: grid; grid-template-columns: 24px 1fr 30px; align-items: center; gap: 7px; color: #8fb0b9; font-size: 9px; }
.depth-grid input { width: 100%; }
.depth-grid output { text-align: right; color: #74ddd8; }
.toggle-row { display: flex; gap: 9px; align-items: center; margin: 16px 0 12px; color: #a9c5cc; font-size: 10px; }
.debug-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.debug-actions button { padding: 9px 5px; border: 1px solid rgba(139, 227, 237, .12); border-radius: 10px; background: rgba(18, 46, 59, .68); color: #b5d1d7; font-size: 9px; font-weight: 750; cursor: pointer; }
.debug-actions button:hover { border-color: rgba(112, 226, 220, .35); color: white; }

.toast { position: fixed; left: 50%; bottom: 25px; z-index: 20; transform: translate(-50%, 18px); padding: 10px 16px; border-radius: 12px; color: #05222b; background: #83ebe2; box-shadow: 0 12px 35px rgba(0,0,0,.35); font-size: 11px; font-weight: 800; opacity: 0; pointer-events: none; transition: .24s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 850px) {
  .app-shell { width: min(540px, calc(100% - 24px)); padding-top: 17px; }
  .play-layout { display: block; }
  .debug-drawer { position: fixed; inset: auto 0 0; z-index: 10; max-height: min(78vh, 730px); border-radius: 24px 24px 0 0; transform: translateY(103%); transition: transform .3s ease; }
  .debug-drawer.open { transform: translateY(0); }
  .icon-button { display: block; }
  .stats-grid { grid-template-columns: repeat(3, 1fr); row-gap: 12px; }
  .stats-grid div:nth-child(3) { border-right: 0; }
}

@media (max-width: 420px) {
  .app-shell { width: calc(100% - 16px); padding-top: 12px; }
  .topbar { margin-bottom: 13px; }
  .game-toolbar { grid-template-columns: 72px 1fr 78px; gap: 7px; }
  .mission-panel { grid-template-columns: minmax(0, 1fr) 62px; gap: 9px; padding: 12px 12px 14px; }
  .mission-target { grid-row: 2; grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; padding: 8px 0 0; border-top: 1px solid rgba(139, 227, 237, .1); border-left: 0; }
  .mission-target strong, .mission-target span { margin: 0; }
  .mission-copy small { white-space: normal; line-height: 1.35; }
  .drop-budget { grid-column: 2; grid-row: 1; }
  .mode-pill { padding: 8px 9px; font-size: 9px; }
  .tank-frame { border-radius: 21px; }
}

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