:root {
  --paper-bg: #f6f2e9;
  --card-bg: #fffdf8;
  --ink: #252a30;
  --ink-soft: #59626e;
  --accent-blue: #3b9eff;
  --accent-pink: #ff6b9d;
  --accent-gold: #ffcf40;
  --accent-green: #42c97a;
  --border-w: 3px;
  --target-size: 24px;
}

@media (pointer: coarse) {
  :root {
    --target-size: 44px;
  }
}

* {
  box-sizing: border-box;
}

h1, h2 {
  text-wrap: balance;
}

p, li {
  text-wrap: pretty;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100dvh;
  overscroll-behavior: none;
  background-color: var(--paper-bg);
  background-image:
    linear-gradient(to right, rgba(60, 90, 130, 0.06) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(60, 90, 130, 0.06) 1px, transparent 1px);
  background-size: 28px 28px;
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

.cabinet-shell {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 1.25rem;
  min-height: 100dvh;
  padding: 0.75rem 1rem max(0.75rem, env(safe-area-inset-bottom, 0px));
}

.side-panel {
  width: 268px;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding-top: 0.35rem;
}

.sketch-card {
  background: var(--card-bg);
  border: var(--border-w) solid var(--ink);
  border-radius: 16px;
  box-shadow: 4px 5px 0 rgba(37, 42, 48, 0.16);
  padding: 0.9rem 1rem;
}

.brand-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  background: var(--accent-gold);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  margin-bottom: 0.45rem;
}

.panel-title {
  margin: 0 0 0.4rem;
  font-size: 1.05rem;
  font-weight: 800;
}

.panel-note {
  margin: 0 0 0.65rem;
  font-size: 0.84rem;
  line-height: 1.35;
  color: var(--ink-soft);
}

.bell-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.38rem;
  font-size: 0.84rem;
}

.bell-list li {
  display: grid;
  grid-template-columns: 14px 56px 1fr;
  align-items: center;
  gap: 0.45rem;
}

.dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid var(--ink);
}
.dot-yellow { background: #ffe042; }
.dot-blue { background: #4bb5ff; }
.dot-white { background: #ffffff; }
.dot-green { background: #5be87d; }
.dot-purple { background: #c56bff; }
.dot-red { background: #ff5c84; }
.dot-bee { background: #ff9c24; }

.key-grid {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.32rem 0.75rem;
  font-size: 0.82rem;
}
.key-grid dt {
  font-weight: 700;
}
.key-grid dd {
  margin: 0;
  text-align: right;
  color: var(--ink-soft);
  font-weight: 600;
}

.stage-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(100%, 500px);
  gap: 0.45rem;
}

.hud-bar {
  width: 100%;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  background: var(--card-bg);
  border: var(--border-w) solid var(--ink);
  border-radius: 12px;
  padding: 0.35rem 0.6rem;
  box-shadow: 3px 3px 0 rgba(37, 42, 48, 0.14);
}

.status-bar {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
  background: var(--card-bg);
  border: var(--border-w) solid var(--ink);
  border-radius: 12px;
  padding: 0.4rem 0.7rem;
  box-shadow: 3px 3px 0 rgba(37, 42, 48, 0.14);
}

.hud-stat {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.hud-label,
.status-label {
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
}

.hud-value {
  font-size: clamp(0.88rem, 0.7rem + 0.5vw, 1.05rem);
  font-variant-numeric: tabular-nums;
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.icon-gear-btn {
  min-inline-size: max(36px, var(--target-size));
  min-block-size: max(36px, var(--target-size));
  display: inline-grid;
  place-items: center;
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  background: #eef4fb;
  color: var(--ink);
  padding: 0.25rem;
  cursor: pointer;
}
.icon-gear-btn:hover {
  background: var(--accent-gold);
}
@media (prefers-reduced-motion: no-preference) {
  .icon-gear-btn svg {
    transition: transform 0.2s ease;
  }
  .icon-gear-btn:hover svg {
    transform: rotate(30deg);
  }
}

.stage-frame {
  position: relative;
  width: 100%;
  max-height: calc(100dvh - 150px);
  aspect-ratio: 3 / 4;
  border: 4px solid var(--ink);
  border-radius: 16px;
  overflow: hidden;
  background: #6bc7f5;
  box-shadow: 6px 8px 0 rgba(37, 42, 48, 0.2);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.stage-frame.hover-nav-active #game-canvas {
  cursor: crosshair;
}

.stage-banner {
  position: absolute;
  top: 42px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 253, 248, 0.94);
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  padding: 0.3rem 0.95rem;
  font-size: 0.85rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 2px 3px 0 rgba(37, 42, 48, 0.2);
}

@media (prefers-reduced-motion: no-preference) {
  .stage-banner {
    animation: popBanner 0.2s ease-out;
  }
  @keyframes popBanner {
    from { opacity: 0; transform: translateX(-50%) scale(0.9); }
    to { opacity: 1; transform: translateX(-50%) scale(1); }
  }
}

.stage-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(37, 42, 48, 0.28);
  backdrop-filter: blur(2px);
}
.stage-overlay[hidden] {
  display: none;
}

.overlay-card {
  width: min(100%, 390px);
  text-align: center;
}

.eyebrow {
  margin: 0 0 0.25rem;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--accent-blue);
}

.game-title {
  margin: 0;
  font-size: clamp(1.5rem, 1.1rem + 1.5vw, 2.1rem);
  font-weight: 900;
}

.subtitle {
  margin: 0.35rem 0 0.9rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.pilot-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.pilot-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.5rem 0.3rem;
  background: #f3f6fa;
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  cursor: pointer;
  color: var(--ink);
  transition: transform 0.12s ease, background-color 0.12s ease;
}
.pilot-btn img {
  width: 48px;
  height: 48px;
  object-fit: contain;
}
.pilot-btn.is-selected {
  background: #fff3b8;
  box-shadow: 0 0 0 2px var(--accent-blue) inset;
}
@media (prefers-reduced-motion: no-preference) {
  .pilot-btn:hover {
    transform: translateY(-2px);
  }
}

.pilot-name {
  font-size: 0.82rem;
  font-weight: 800;
}
.pilot-role {
  font-size: 0.7rem;
  color: var(--ink-soft);
}

.overlay-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.primary-btn,
.secondary-btn {
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  padding: 0.65rem 1rem;
  font-size: 0.95rem;
  font-weight: 900;
  cursor: pointer;
  color: var(--ink);
  box-shadow: 2px 3px 0 var(--ink);
}

.primary-btn {
  background: var(--accent-gold);
}
.primary-btn:hover {
  background: #ffd966;
}
.secondary-btn {
  background: #eef4fb;
}
.secondary-btn:hover {
  background: #dde9f8;
}

.end-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.45rem;
  margin-bottom: 1rem;
  background: #f5f7fa;
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 0.55rem 0.4rem;
}
.end-stats span {
  display: block;
  font-size: 0.7rem;
  color: var(--ink-soft);
}
.end-stats strong {
  font-size: 1rem;
}

.status-bar {
  font-size: 0.82rem;
}

.status-group {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.heart-row {
  display: flex;
  gap: 2px;
  font-size: 0.9rem;
}

.touch-controls {
  --dial-size: clamp(128px, 40.5vw, 158px);
  display: none;
  width: 100%;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding-top: 0.15rem;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.dial-pad {
  position: relative;
  width: var(--dial-size);
  height: var(--dial-size);
  flex: 0 0 auto;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: radial-gradient(circle at 38% 34%, #ffffff 0%, #eaf1fa 72%, #d5e2f2 100%);
  box-shadow: 3px 4px 0 rgba(37, 42, 48, 0.18);
  display: grid;
  place-items: center;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  cursor: grab;
}
.dial-pad.is-active {
  cursor: grabbing;
}
.dial-ring {
  position: absolute;
  inset: 22px;
  border-radius: 50%;
  border: 2px dashed rgba(37, 42, 48, 0.22);
  pointer-events: none;
}
.dial-dir {
  position: absolute;
  font-size: 0.78rem;
  font-weight: 900;
  color: var(--ink-soft);
  pointer-events: none;
  line-height: 1;
}
.dial-up { top: 7px; left: 50%; transform: translateX(-50%); }
.dial-right { right: 8px; top: 50%; transform: translateY(-50%); }
.dial-down { bottom: 7px; left: 50%; transform: translateX(-50%); }
.dial-left { left: 8px; top: 50%; transform: translateY(-50%); }
.dial-knob {
  width: clamp(48px, 14.5vw, 56px);
  height: clamp(48px, 14.5vw, 56px);
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: var(--accent-blue);
  box-shadow: 0 3px 0 var(--ink);
  pointer-events: none;
  will-change: transform;
  transition: background-color 0.1s ease;
}
.dial-pad.is-active .dial-knob {
  background: var(--accent-gold);
}
.act-btn {
  min-block-size: var(--target-size);
  min-inline-size: var(--target-size);
  height: 100%;
  display: grid;
  place-items: center;
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  background: var(--card-bg);
  color: var(--ink);
  font-weight: 900;
  padding: 0.25rem 0.3rem;
  font-size: 0.74rem;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
.act-btn.is-pressed {
  transform: translateY(1px) scale(0.97);
  filter: brightness(0.94);
}
.action-pads {
  flex: 1;
  height: var(--dial-size);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  grid-template-areas:
    "punch shoot"
    "chibi shoot"
    "formation bomb";
  gap: 6px;
}
.act-shoot { grid-area: shoot; background: #bfe3ff; font-size: 0.85rem; }
.act-bomb { grid-area: bomb; background: #ffe49c; }
.act-punch { grid-area: punch; background: #ffc8dd; }
.act-chibi { grid-area: chibi; background: #c5f5d5; }
.act-formation { grid-area: formation; background: #e6d8ff; }

/* Native <dialog> styling per modern-web-guidance */
dialog[open] {
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: var(--card-bg);
  color: var(--ink);
  padding: 0;
  width: min(92vw, 460px);
  box-shadow: 6px 8px 0 rgba(37, 42, 48, 0.25);
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: rgba(37, 42, 48, 0.45);
  overflow: hidden;
  overscroll-behavior: contain;
}

.modal-inner {
  padding: 1.25rem 1.35rem;
}
.modal-inner h1 {
  margin: 0 0 0.65rem;
  font-size: 1.35rem;
}
.modal-inner p {
  margin: 0.45rem 0;
  font-size: 0.9rem;
  line-height: 1.45;
}
.modal-list {
  margin: 0.4rem 0 0.7rem;
  padding-left: 1.2rem;
  font-size: 0.86rem;
  line-height: 1.45;
}
.credit-note {
  color: var(--ink-soft);
  font-size: 0.82rem;
}
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}
.settings-status {
  margin: 0 0 0.75rem;
  padding: 0.45rem 0.65rem;
  border-radius: 10px;
  background: #fff3b8;
  border: 2px solid var(--ink);
  font-weight: 800;
  font-size: 0.85rem;
}
.settings-toggles {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.45rem 0.65rem;
  border-radius: 10px;
  background: #f5f7fa;
  border: 2px solid var(--ink);
  font-weight: 800;
  font-size: 0.9rem;
}
.toggle-pill {
  min-block-size: var(--target-size);
  min-inline-size: 64px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: #e2e8f0;
  color: var(--ink);
  font-weight: 900;
  font-size: 0.8rem;
  cursor: pointer;
}
.toggle-pill.is-on {
  background: var(--accent-green);
}
.full-btn {
  width: 100%;
}

@media (max-width: 880px), (pointer: coarse), (hover: none) {
  .side-panel {
    display: none;
  }
  .status-bar {
    gap: 0.35rem;
    padding: 0.35rem 0.55rem;
    font-size: 0.78rem;
  }
  .touch-controls {
    display: flex;
  }
  .stage-frame {
    max-height: calc(100dvh - 282px);
  }
}
