/* Last Salvo.
   Cartoon casual: bright flat colours, thick dark outlines, chunky buttons with
   a hard drop shadow. One screen, nothing scrolls. Palette mirrors js/render.js. */
:root {
  --outline: #0b1730;
  --bg: #17326b;
  --bg-dot: rgba(255, 255, 255, 0.1);
  --tab: #2b4f8f;
  --panel: #fff8ea;
  --chip: #e4ecfa;
  --ink: #0b1730;
  --ink-soft: #4b5a78;
  --white: #ffffff;
  --yellow: #ffd23f;
  --yellow-soft: #ffe78f;
  --red: #ff5340;
  --green: #7bdc4a;
  --blue: #35c4f0;
  --idle: #cdd6e6;
  --lip: rgba(11, 23, 48, 0.2);
  --scrim: rgba(11, 23, 48, 0.72);
  --line: 3px;
  --radius: 16px;
  --radius-sm: 12px;
  --font: "Arial Rounded MT Bold", "Baloo 2", "Nunito", "Trebuchet MS", "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --ease: cubic-bezier(0.2, 0.9, 0.3, 1.3);
  --z-report: 10;
  --z-scrim: 20;
  --z-manual: 21;
  --z-toast: 30;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  background-color: var(--bg);
  background-image: radial-gradient(circle, var(--bg-dot) 1.5px, transparent 2px);
  background-size: 44px 44px;
  color: var(--white);
  font-family: var(--font); font-size: 16px; font-weight: 700; line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--white); outline-offset: 2px; }
canvas { display: block; }
.hidden { display: none !important; }

/* ---------- one screen: bar on top, board left, panel right ---------- */
#app {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(290px, 31vw, 400px);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "top top" "stage side";
}

/* ---------- buttons ---------- */
.btn, .tool, .tab, .unit {
  border: var(--line) solid var(--outline);
  box-shadow: inset 0 -4px 0 var(--lip), 0 4px 0 var(--outline);
  transition: transform 0.08s, box-shadow 0.08s, background-color 0.15s;
}
.btn:active:not(:disabled), .tool:active, .tab:active, .unit:active {
  transform: translateY(3px);
  box-shadow: inset 0 -1px 0 var(--lip), 0 1px 0 var(--outline);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 50px; padding: 0 18px 3px; border-radius: 14px;
  background: var(--white); color: var(--ink);
  font-size: 17px; font-weight: 900; text-align: center;
}
.btn:hover:not(:disabled) { background: var(--yellow-soft); }
.btn:disabled { opacity: 0.5; }
.btn-primary { background: var(--yellow); }
.btn-fire { background: var(--idle); font-size: 21px; letter-spacing: 0.02em; }
.btn-fire.armed { background: var(--red); color: var(--white); }
.btn-fire.armed:hover:not(:disabled) { background: var(--red); }
.btn-fire.ready { animation: bounce 0.9s var(--ease) infinite; }
@keyframes bounce { 0%, 55%, 100% { transform: scale(1); } 25% { transform: scale(1.06); } }

/* ---------- top bar ---------- */
.topbar {
  grid-area: top; display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px;
  padding: max(10px, env(safe-area-inset-top)) 14px 6px;
}
.logo {
  margin-right: 6px; color: var(--yellow);
  font-size: clamp(22px, 2.6vw, 30px); font-weight: 900; line-height: 1; white-space: nowrap;
  -webkit-text-stroke: 6px var(--outline); paint-order: stroke fill;
  text-shadow: 0 3px 0 var(--outline);
}
.tabs { display: flex; gap: 8px; }
.tab {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  min-height: 46px; padding: 2px 14px 5px; border-radius: 14px;
  background: var(--tab); color: var(--white); line-height: 1.15;
}
.tab-label { font-size: 16px; font-weight: 900; }
.tab-sub { font-size: 11.5px; opacity: 0.85; font-variant-numeric: tabular-nums; }
.tab.active { background: var(--yellow); color: var(--ink); }
.streak {
  padding: 4px 10px; border: 2px solid var(--outline); border-radius: 999px;
  background: var(--green); color: var(--ink); font-size: 13px; font-weight: 900; white-space: nowrap;
}
.tools { margin-left: auto; display: flex; gap: 8px; }
.tool {
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 42px; padding: 0 12px 3px; border-radius: var(--radius-sm);
  background: var(--white); color: var(--ink); font-size: 14px; font-weight: 900; white-space: nowrap;
}
.tool:hover { background: var(--yellow-soft); }
.tool-help { background: var(--blue); }
.q {
  display: inline-grid; place-items: center; width: 22px; height: 22px;
  border: 2px solid var(--outline); border-radius: 50%; background: var(--white); font-size: 14px; line-height: 1;
}

/* ---------- board ---------- */
.stage { grid-area: stage; position: relative; min-width: 0; min-height: 0; }
#board { position: absolute; top: 0; left: 0; touch-action: none; cursor: pointer; }

/* ---------- side panel ---------- */
.side {
  grid-area: side; position: relative; min-height: 0; padding: 6px 14px 16px 2px;
  display: grid; grid-template-rows: minmax(0, 1fr);
}
.panel, .report {
  overflow: hidden; padding: 14px;
  background: var(--panel); color: var(--ink);
  border: var(--line) solid var(--outline); border-radius: var(--radius);
  box-shadow: 0 6px 0 var(--outline);
}
.panel {
  display: grid; gap: 10px; margin-bottom: 6px;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
}
.pill {
  display: inline-block; padding: 3px 11px 4px; border-radius: 999px;
  background: var(--outline); color: var(--white); font-size: 13px; font-weight: 900; line-height: 1.3;
}
#hud-goal { margin-top: 7px; font-size: 21px; font-weight: 900; line-height: 1.2; text-wrap: balance; }
#hud-goal-sub, #hud-left, .label { font-size: 13px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.rockets { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.label { font-weight: 900; }
#hud-fuses { display: flex; gap: 5px; }
.rocket {
  width: 16px; height: 28px; border: var(--line) solid var(--outline);
  border-radius: 8px 8px 3px 3px; background: var(--idle); opacity: 0.55;
}
.rocket.on { background: var(--red); opacity: 1; box-shadow: inset 0 7px 0 var(--white); }

.bubble {
  min-height: 70px; padding: 9px 12px 11px;
  background: var(--yellow-soft); border: var(--line) solid var(--outline); border-radius: 14px;
}
#step { display: inline-block; margin-bottom: 3px; padding: 1px 8px 2px; border-radius: 999px; background: var(--outline); color: var(--yellow); font-size: 12px; font-weight: 900; }
#step:empty { display: none; }
#prompt { font-size: 16px; font-weight: 900; line-height: 1.3; font-variant-numeric: tabular-nums; }
#inspect { min-height: 2.7em; font-size: 13px; color: var(--ink-soft); }

#legend { display: grid; grid-template-columns: 1fr 1fr; gap: 9px 8px; align-content: start; min-height: 0; overflow: hidden; padding-bottom: 5px; }
.unit {
  display: flex; align-items: center; gap: 7px; min-width: 0;
  padding: 4px 8px 6px 5px; border-width: 2px; border-radius: var(--radius-sm);
  background: var(--chip); color: var(--ink); box-shadow: inset 0 -3px 0 var(--lip), 0 3px 0 var(--outline);
}
.unit:hover, .unit.active { background: var(--yellow); }
.unit-art { flex: none; width: 69px; height: 30px; }
.unit-name { min-width: 0; font-size: 13px; font-weight: 900; line-height: 1.15; text-align: left; overflow: hidden; text-overflow: ellipsis; }

.controls { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; padding-bottom: 4px; }
.controls .btn { min-height: 56px; }

/* ---------- result card: covers the panel, the board stays visible ---------- */
.report {
  position: absolute; top: 6px; right: 14px; bottom: 22px; left: 2px; z-index: var(--z-report);
  display: flex; flex-direction: column; align-items: flex-start;
  animation: pop-in 0.28s var(--ease);
}
@keyframes pop-in { from { opacity: 0; transform: scale(0.92); } }
.report-title { margin-top: 10px; font-size: 30px; font-weight: 900; line-height: 1.1; }
.report-score { margin-top: 8px; display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px 10px; }
.report-big {
  color: var(--green); font-size: 84px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums;
  -webkit-text-stroke: 8px var(--outline); paint-order: stroke fill; text-shadow: 0 4px 0 var(--outline);
}
.report-lose .report-big { color: var(--red); }
.report-big-sub { font-size: 15px; color: var(--ink-soft); }
.report-rows { align-self: stretch; margin-top: 12px; display: grid; grid-template-columns: minmax(0, 1fr) auto; font-size: 14px; }
.report-rows dt, .report-rows dd { padding: 7px 0; border-top: 2px solid var(--chip); }
.report-rows dt { color: var(--ink-soft); }
.report-rows dd { display: flex; align-items: center; justify-content: flex-end; gap: 8px; font-weight: 900; font-variant-numeric: tabular-nums; }
.rating { display: inline-flex; gap: 4px; }
.rating-pip { width: 14px; height: 14px; border: 2px solid var(--outline); border-radius: 50%; background: var(--idle); }
.rating-pip.on { background: var(--yellow); }
.report-note { margin-top: 10px; font-size: 14px; line-height: 1.4; text-wrap: pretty; }
.report-count { margin-top: 8px; font-size: 13px; color: var(--ink-soft); }
.report-count b { color: var(--ink); font-variant-numeric: tabular-nums; }
.report-actions { align-self: stretch; margin-top: auto; padding: 12px 0 4px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.report-actions .btn { padding-left: 8px; padding-right: 8px; font-size: 15px; line-height: 1.15; }
.report-actions .btn-primary { grid-column: 1 / -1; min-height: 56px; font-size: 19px; }
.report-actions .btn-primary + .btn:last-child { grid-column: 1 / -1; }

/* ---------- help card ---------- */
.scrim { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: var(--z-scrim); background: var(--scrim); }
.manual {
  position: fixed; top: 50%; left: 50%; z-index: var(--z-manual);
  width: min(700px, calc(100% - 24px)); max-height: calc(100% - 24px); overflow: hidden;
  transform: translate(-50%, -50%);
  padding: 16px 18px 18px; background: var(--panel); color: var(--ink);
  border: var(--line) solid var(--outline); border-radius: 20px; box-shadow: 0 8px 0 var(--outline);
}
.manual-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.manual-head h2 { font-size: 26px; font-weight: 900; }
.manual-lede { margin-top: 2px; font-size: 15px; color: var(--ink-soft); }
.steps { list-style: none; counter-reset: step; margin-top: 12px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.steps li { counter-increment: step; }
.steps canvas { width: 100%; height: auto; }
.steps h3 { margin-top: 8px; font-size: 18px; font-weight: 900; }
.steps h3::before {
  content: counter(step); display: inline-grid; place-items: center; width: 24px; height: 24px; margin-right: 7px;
  border-radius: 50%; background: var(--outline); color: var(--yellow); font-size: 14px;
}
.steps p { margin-top: 2px; font-size: 14px; line-height: 1.35; color: var(--ink-soft); }
.manual-tip { margin-top: 14px; padding: 9px 12px 10px; background: var(--yellow-soft); border: 2px solid var(--outline); border-radius: var(--radius-sm); font-size: 14px; line-height: 1.4; }
.manual-foot { margin-top: 14px; padding-bottom: 4px; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.manual-keys { font-size: 12.5px; color: var(--ink-soft); }
.manual-foot .btn { flex: none; min-width: 140px; }

/* ---------- toast, clipboard helper ---------- */
#toast {
  position: fixed; left: 16px; bottom: 16px; z-index: var(--z-toast);
  max-width: min(420px, calc(100vw - 32px)); padding: 9px 14px 10px;
  background: var(--white); color: var(--ink);
  border: var(--line) solid var(--outline); border-radius: var(--radius-sm); box-shadow: 0 4px 0 var(--outline);
  font-size: 14px; font-weight: 900;
  opacity: 0; transform: translateY(10px); pointer-events: none;
  transition: opacity 0.18s, transform 0.18s var(--ease);
}
#toast.show { opacity: 1; transform: translateY(0); }
.clip-buffer { position: fixed; top: 0; left: 0; opacity: 0; pointer-events: none; }

/* ---------- short landscape windows: tighten the panel so it still fits ---------- */
@media (max-height: 640px) {
  .panel { gap: 7px; padding: 10px 12px; }
  #hud-goal { font-size: 18px; margin-top: 5px; }
  #inspect { display: none; }
  .panel { grid-template-rows: auto auto minmax(0, 1fr) auto; }
  .bubble { min-height: 0; }
  .report { padding: 10px 12px; }
  .report-title { font-size: 24px; margin-top: 6px; }
  .report-big { font-size: 60px; }
  .report-rows dt, .report-rows dd { padding: 4px 0; }
}
@media (max-height: 480px) {
  .topbar { padding-top: 6px; padding-bottom: 2px; }
  .tab { min-height: 38px; }
  .tab-sub, #hud-goal-sub, .unit-name, .manual-tip { display: none; }
  .tool { min-height: 36px; }
  #legend { display: flex; flex-wrap: wrap; gap: 6px; }
  .rockets { margin-top: 4px; }
  .controls .btn, .report-actions .btn, .report-actions .btn-primary { min-height: 44px; }
  .report-note { display: none; }
}

/* ---------- portrait and narrow windows: stack, board in the middle ---------- */
@media (max-width: 760px), (orientation: portrait) {
  #app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto minmax(0, 1fr) auto auto;
    grid-template-areas: "top" "brief" "bubble" "stage" "legend" "controls";
  }
  .side, .panel { display: contents; }
  .logo, .tool-lang, .tab-sub { display: none; }
  .topbar { gap: 8px; padding-left: 10px; padding-right: 10px; }
  .tab { min-height: 42px; padding: 0 12px 3px; }

  .brief { grid-area: brief; padding: 4px 12px 0; color: var(--white); }
  .brief .pill { background: var(--white); color: var(--ink); }
  #hud-goal { margin-top: 5px; font-size: 17px; }
  #hud-goal-sub { display: none; }
  #hud-left, .label { color: var(--white); opacity: 0.85; }
  .rockets { margin-top: 5px; }
  .rocket { width: 14px; height: 22px; }
  .bubble { grid-area: bubble; min-height: 0; margin: 8px 12px 0; padding: 7px 11px 8px; color: var(--ink); }
  #prompt { font-size: 15px; }
  #inspect { display: none; }
  #legend { grid-area: legend; display: flex; flex-wrap: wrap; justify-content: center; gap: 7px 6px; padding: 0 10px 4px; }
  .unit { padding: 3px 5px 5px; }
  .unit-art { width: 55px; height: 24px; }
  .unit-name { display: none; }
  .controls { grid-area: controls; padding: 8px 12px max(14px, env(safe-area-inset-bottom)); }

  .report {
    position: fixed; top: auto; right: 8px; bottom: max(12px, env(safe-area-inset-bottom)); left: 8px;
    max-height: calc(100% - 24px); padding: 14px;
  }
  .report-title { font-size: 26px; }
  .report-big { font-size: 64px; }
  .report-actions { margin-top: 12px; }

  .manual { padding: 14px; }
  .steps { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .steps li { display: grid; grid-template-columns: 118px minmax(0, 1fr); column-gap: 12px; align-items: center; }
  .steps canvas { grid-row: span 2; }
  .steps h3 { margin-top: 0; font-size: 16px; }
  .steps p { font-size: 13px; }
  .manual-keys { display: none; }
  .manual-foot { justify-content: flex-end; margin-top: 10px; }
  #toast { left: 10px; right: 10px; bottom: 92px; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
