/* Channel Dodge — a bullet-hell survival game. Theme colors come from
   style.css variables so light/dark mode track the rest of the site. */
.cd-app {
  max-width: 560px; margin: 0 auto; padding: 8px 16px 24px;
  display: flex; flex-direction: column; gap: 12px;
  /* Allow vertical scroll (so the legend/joystick stay reachable on short
     phones); the stage and joystick opt out of scroll themselves. */
  touch-action: pan-y;
}
.cd-scores {
  display: flex; gap: 10px; justify-content: center;
}
.cd-score {
  flex: 1; min-width: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  text-align: center;
}
.cd-score-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--fg-muted);
}
.cd-score-value {
  font-family: var(--font-mono);
  font-size: 22px; font-weight: 700; color: var(--fg);
  line-height: 1.1; margin-top: 2px;
}
.cd-actions {
  display: flex; gap: 10px; justify-content: center;
}
/* Pause is inert outside a running round; .btn:disabled (shared in style.css)
   dims it and blocks pointer events so it reads as disabled, not clickable. */
/* The autopilot button label carries the SkyZero wordmark. Drop the flex gap
   so the wordmark + " 接管" keep their original single-space spacing. Once
   engaged (.primary → neutral ink fill) only "Sky" follows the button's text
   colour (else it'd vanish into the fill); "Zero" keeps its rainbow. */
#ai_btn { gap: 0; }
#ai_btn.primary .bw-sky {
  color: currentColor; -webkit-text-fill-color: currentColor;
}
/* The arena: a portrait play field that scales to the viewport. */
.cd-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: calc(100vh - 220px);
  max-height: calc(100dvh - 220px);   /* dvh tracks the mobile URL bar; vh is the fallback */
  margin: 0 auto;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
  user-select: none; -webkit-user-select: none;
  touch-action: none;
}
.cd-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
}
/* HP bar overlaid at the top of the arena. */
.cd-hp {
  position: absolute; left: 12px; right: 12px; top: 10px;
  height: 12px;
  background: color-mix(in srgb, var(--fg-subtle) 26%, transparent);
  border-radius: 999px;
  overflow: hidden;
  pointer-events: none; z-index: 2;
}
.cd-hp-fill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, #2ecc71, #27ae60);
  border-radius: 999px;
  transition: width 80ms linear, background-color 120ms linear;
}
.cd-hp-fill.low  { background: linear-gradient(90deg, #f39c12, #e67e22); }
.cd-hp-fill.crit { background: linear-gradient(90deg, #e74c3c, #c0392b); }
/* Floating "time survived" readout, top-right inside the arena. */
.cd-time {
  position: absolute; right: 12px; top: 28px;
  font-family: var(--font-mono); font-size: 12px; font-weight: 700;
  color: var(--fg-muted);
  pointer-events: none; z-index: 2;
  text-shadow: 0 1px 2px var(--surface-sunken);
}
/* Start / pause / game-over overlay. */
.cd-overlay {
  position: absolute; inset: 0;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px; text-align: center;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(2px);
  border-radius: var(--radius-lg);
  z-index: 4;
}
.cd-overlay.show { display: flex; }
.cd-overlay-title { font-size: 26px; font-weight: 700; color: var(--fg); }
.cd-overlay-sub {
  font-size: 13px; color: var(--fg-muted); line-height: 1.6; max-width: 360px;
}
.cd-overlay-stats {
  font-family: var(--font-mono); font-size: 14px; color: var(--fg);
  line-height: 1.7;
}
.cd-overlay-stats b { color: var(--accent); font-size: 20px; }
.cd-overlay-stats .ai-note {
  font-family: inherit; font-size: 12px; color: var(--fg-muted);
}
/* Legend of bullet types and their point values. */
.cd-legend {
  display: flex; flex-direction: column; gap: 6px;
  padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface-2);
}
.cd-legend-title {
  font-size: 11px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--fg-muted); margin-bottom: 2px;
}
.cd-legend-row {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; color: var(--fg);
}
.cd-legend-swatch {
  width: 18px; height: 18px; flex: none; border-radius: 50%;
}
.cd-legend-swatch.laser { border-radius: 3px; }
.cd-legend-name { flex: 1; }
.cd-legend-pts {
  font-family: var(--font-mono); font-weight: 700; color: var(--accent);
}
.cd-hint {
  font-size: 12px; color: var(--fg-muted); text-align: center; line-height: 1.6;
}

/* ---------- Touch joystick (below the arena, touch devices only) ---------- */
.cd-joystick { display: none; }
body.cd-touch .cd-joystick {
  display: block;
  position: relative;
  width: 100%;
  height: 160px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  touch-action: none;
  user-select: none; -webkit-user-select: none;
  overflow: hidden;
}
/* On touch screens the arena should leave room for the joystick below. */
body.cd-touch .cd-stage {
  max-height: calc(100vh - 360px);
  max-height: calc(100dvh - 360px);
}
.cd-joystick-base {
  position: absolute;
  left: 50%; top: 50%;
  width: 116px; height: 116px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: color-mix(in srgb, var(--fg-subtle) 16%, transparent);
  border: 2px solid var(--border-strong);
  transition: opacity 120ms ease;
}
.cd-joystick.dragging .cd-joystick-base { transition: none; }
.cd-joystick-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 56px; height: 56px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 10px rgba(0,0,0,0.25);
}
.cd-joystick-tip {
  position: absolute; left: 0; right: 0; bottom: 8px;
  text-align: center; pointer-events: none;
  font-size: 11px; font-weight: 600; color: var(--fg-subtle);
}
.cd-joystick.dragging .cd-joystick-tip { opacity: 0; }

/* ---------- Avatar roster (collapsible) ---------- */
.cd-roster { display: flex; flex-direction: column; gap: 10px; }
.cd-roster-toggle {
  align-self: stretch; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  background: none; border: none;
  font-family: var(--font-sans);
  font-size: 13px; font-weight: 600; color: var(--fg-muted);
  padding: 4px 4px; border-radius: var(--radius-sm);
}
.cd-roster-toggle:hover { color: var(--fg); }
.cd-roster-toggle .cd-roster-current { margin-left: auto; color: var(--fg); font-weight: 700; }
.cd-roster-toggle .chev { transition: transform 0.2s ease; }
.cd-roster-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }
.cd-roster-body {
  display: flex; flex-direction: column; gap: 12px;
  padding: 12px;
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface-2);
}
.cd-roster-body[hidden] { display: none; }
.cd-avatar-grid {
  display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
}
.cd-avatar-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 6px 4px; cursor: pointer;
  background: var(--surface); border: 2px solid var(--border);
  border-radius: var(--radius-md); color: var(--fg-muted);
  font-size: 11px; font-weight: 600;
  transition: border-color .12s ease, color .12s ease;
}
.cd-avatar-btn:hover { border-color: var(--border-strong); color: var(--fg); }
.cd-avatar-btn:active { transform: scale(0.97); }
.cd-avatar-btn[aria-pressed="true"] { border-color: var(--accent); color: var(--fg); }
.cd-avatar-btn canvas { width: 48px; height: 48px; display: block; }

/* ---------- Draw-your-own modal ---------- */
.cd-draw {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(3px);
}
.cd-draw[hidden] { display: none; }
.cd-draw-panel {
  width: 100%; max-width: 340px;
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 40px rgba(0,0,0,0.3);
}
.cd-draw-title { font-size: 16px; font-weight: 700; color: var(--fg); text-align: center; }
.cd-draw-stage {
  display: flex; gap: 12px; align-items: flex-start; justify-content: center;
}
.cd-draw-canvas {
  width: 232px; height: 232px; flex: none;
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface-sunken);
  touch-action: none; cursor: crosshair;
}
.cd-draw-side { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.cd-draw-preview {
  width: 56px; height: 56px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background:
    conic-gradient(#0000 90deg, color-mix(in srgb, var(--fg-subtle) 14%, transparent) 0 180deg, #0000 0 270deg, color-mix(in srgb, var(--fg-subtle) 14%, transparent) 0) 0 0 / 12px 12px;
}
.cd-draw-preview-label { font-size: 10px; color: var(--fg-muted); text-align: center; line-height: 1.3; }
.cd-draw-palette { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.cd-swatch {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--border); cursor: pointer; padding: 0;
}
.cd-swatch:not([aria-pressed="true"]):hover { border-color: var(--border-strong); }
.cd-swatch:active { transform: scale(0.96); }
.cd-swatch[aria-pressed="true"] { border-color: var(--fg); transform: scale(1.12); }
.cd-swatch.eraser {
  display: grid; place-items: center;
  background: var(--surface); color: var(--fg-muted);
}
.cd-draw-sizes { display: flex; gap: 6px; justify-content: center; align-items: center; }
.cd-size-btn {
  width: 30px; height: 26px; display: grid; place-items: center;
  background: var(--surface); border: 2px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer; color: var(--fg);
}
.cd-size-btn:not([aria-pressed="true"]):hover { border-color: var(--border-strong); }
.cd-size-btn:active { background: var(--surface-2); }
.cd-size-btn[aria-pressed="true"] { border-color: var(--accent); }
.cd-size-btn .dot { background: currentColor; border-radius: 50%; }
.cd-draw-actions { display: flex; gap: 8px; justify-content: center; }

/* Honor the OS "reduce motion" setting for the decorative UI transitions
   (the game canvas animations are inherent to play and stay as-is). */
@media (prefers-reduced-motion: reduce) {
  .cd-roster-toggle .chev,
  .cd-hp-fill,
  .cd-avatar-btn { transition: none; }
}

