:root {
  color-scheme: light;
  --bg: #fdf7e7;
  --bg-soft: #f5edd8;
  --panel: #ffffff;
  --button: #f2ead6;
  --button-hover: #e7dec6;
  --rule: rgba(21, 132, 121, 0.14);
  --text: #164642;
  --muted: #5b7975;
  --coral: #f25252;
  --coral-hover: #df4141;
  --coral-soft: rgba(242, 82, 82, 0.12);
  --teal: #158479;
  --teal-hover: #106d64;
  --teal-light: #36b5a5;
  --teal-soft: rgba(54, 181, 165, 0.14);
  --hand: #ffa67a;
  --font-ui: "Hiragino Maru Gothic ProN", "Rounded Mplus 1c", -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
  font-family: var(--font-ui);
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
body {
  min-height: 100dvh;
  overflow: hidden;
}
body:has(dialog[open]) { overflow: hidden; }
h1, h2, h3, p { margin: 0; }
button {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:disabled { opacity: .4; cursor: default; }
button:focus-visible { outline: 2.5px solid var(--coral); outline-offset: 2px; }
button:active:not(:disabled) { transform: scale(.965); }
.hidden, [hidden] { display: none !important; }

.app {
  height: 100dvh;
  width: 100%;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}
.view {
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  animation: viewFadeIn .22s ease;
}
@keyframes viewFadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ========================================== */
/* Shared Topbar & Buttons                    */
/* ========================================== */
.topbar, .topbar-left, .brand, .topbar-actions, .icon-btn, .back-btn,
.stage-title, .counter, .ctrl-btn, .modal-header {
  display: flex;
  align-items: center;
}
.topbar {
  flex: none;
  justify-content: space-between;
  gap: 8px;
  min-height: calc(58px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
}
.topbar-left { gap: 10px; min-width: 0; }
.topbar-center-title {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: .04em;
  white-space: nowrap;
}
.topbar-actions { gap: 7px; flex: none; }

.brand { gap: 8px; }
.brand-icon-img {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--rule);
  flex: none;
}
.brand-btn {
  padding: 5px 8px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: .03em;
  white-space: nowrap;
}
.back-btn {
  gap: 3px;
  min-height: 40px;
  padding: 0 14px 0 9px;
  border-radius: 999px;
  background: var(--panel);
  border: 1.5px solid var(--rule);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(21, 132, 121, 0.05);
}
.icon-btn, .stage-nav button, .close-btn {
  min-width: 40px;
  height: 40px;
  border-radius: 999px;
  display: grid;
  place-items: center;
}
.icon-btn, .close-btn {
  background: var(--panel);
  border: 1.5px solid var(--rule);
  box-shadow: 0 2px 6px rgba(21, 132, 121, 0.05);
}
.text-pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 13px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.sound-toggle-btn[aria-pressed="false"] { color: var(--muted); }

/* ========================================== */
/* View 1: Home / Launch Screen (起動画面)     */
/* ========================================== */
.home-view {
  position: relative;
  background:
    radial-gradient(circle at 20% 18%, rgba(242, 82, 82, 0.07) 0%, transparent 45%),
    radial-gradient(circle at 82% 28%, rgba(54, 181, 165, 0.10) 0%, transparent 48%),
    var(--bg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.home-topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left));
}
.home-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  padding: clamp(8px, 3vh, 32px) max(22px, env(safe-area-inset-right)) max(26px, calc(16px + env(safe-area-inset-bottom))) max(22px, env(safe-area-inset-left));
}
.home-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.home-emblem {
  width: 224px;
  height: 176px;
  display: grid;
  place-items: center;
  margin-bottom: 4px;
}
.home-swipe-art {
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 8px 18px rgba(21, 132, 121, 0.08));
}
.hero-traced {
  stroke: var(--coral);
  stroke-width: 15;
  stroke-linecap: round;
}
.hero-dots {
  stroke: var(--teal-light);
  stroke-width: 11;
  stroke-linecap: round;
  stroke-dasharray: 0.1 22;
}
.hero-goal-ring {
  transform-origin: 196px 112px;
  animation: goalPulse 2.6s ease-in-out infinite;
}
@keyframes goalPulse {
  0%, 100% { transform: scale(1); }
  55% { transform: scale(1.08); }
}
.hero-hand-group {
  animation: heroHandSwipe 2.6s cubic-bezier(.42, 0, .28, 1) infinite;
}
@keyframes heroHandSwipe {
  0%, 14% { transform: translate(0px, 0px); }
  55%, 72% { transform: translate(74px, 60px); }
  88%, 100% { transform: translate(0px, 0px); }
}

.home-title {
  font-size: clamp(34px, 8.8vw, 44px);
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: .08em;
  text-indent: .08em;
  color: var(--text);
}
.home-tagline {
  margin-top: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .03em;
}
.home-stats {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.home-stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 1.5px solid var(--rule);
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  box-shadow: 0 2px 8px rgba(21, 132, 121, 0.05);
}
.home-stat-pill strong {
  color: var(--teal);
  font-variant-numeric: tabular-nums;
}
.home-stat-star {
  color: var(--coral);
  border-color: rgba(242, 82, 82, 0.22);
}
.home-stat-star strong {
  color: var(--coral);
}

.home-actions {
  width: 100%;
  display: grid;
  gap: 11px;
}
.home-btn {
  width: 100%;
  min-height: 58px;
  padding: 12px 18px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-weight: 800;
  font-size: 16px;
  transition: background-color .15s, transform .12s, box-shadow .15s;
}
.home-btn-main {
  display: inline-flex;
  align-items: center;
  gap: 11px;
}
.home-btn-primary {
  background: var(--coral);
  color: #ffffff;
  box-shadow: 0 8px 22px rgba(242, 82, 82, 0.28);
}
.home-btn-primary .home-btn-meta {
  padding: 4px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.home-btn-card {
  background: var(--panel);
  border: 1.5px solid var(--rule);
  color: var(--text);
  box-shadow: 0 4px 14px rgba(21, 132, 121, 0.06);
}
.home-btn-card .home-btn-main svg {
  color: var(--teal);
}
.home-btn-meta {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.home-btn-badge {
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--coral-soft);
  color: var(--coral);
  font-size: 11px;
  font-weight: 800;
}
.home-btn-badge.done {
  background: var(--teal-soft);
  color: var(--teal);
}

/* ========================================== */
/* View 2: Stage Select Screen (ステージ選択)  */
/* ========================================== */
.stages-view {
  background: var(--bg);
}
.stages-summary {
  flex: none;
  padding: 14px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  background: var(--bg-soft);
  border-bottom: 1px solid var(--rule);
}
.stages-progress-row {
  max-width: 820px;
  margin: 0 auto 8px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}
.stages-progress-text strong {
  color: var(--text);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.stages-star-text {
  color: var(--coral);
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.stages-progress-track {
  max-width: 820px;
  margin: 0 auto 12px;
  height: 8px;
  border-radius: 999px;
  background: rgba(21, 132, 121, 0.14);
  overflow: hidden;
}
.stages-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--teal-light), var(--coral));
  transition: width .25s ease;
}
.range-tabs {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.range-tabs::-webkit-scrollbar { display: none; }
.range-tab {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1.5px solid var(--rule);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.range-tab-count {
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
}
.range-tab[aria-selected="true"] {
  background: var(--teal);
  border-color: var(--teal);
  color: #ffffff;
}
.range-tab[aria-selected="true"] .range-tab-count {
  color: rgba(255, 255, 255, 0.85);
}
.range-tab.all-cleared .range-tab-count {
  color: var(--coral);
}
.range-tab[aria-selected="true"].all-cleared .range-tab-count {
  color: #ffe380;
}
.range-subtitle {
  max-width: 820px;
  margin: 8px auto 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.stages-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px max(16px, env(safe-area-inset-right)) max(28px, calc(16px + env(safe-area-inset-bottom))) max(16px, env(safe-area-inset-left));
}
.stage-select-grid {
  max-width: 820px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
}
@media (min-width: 540px) {
  .stage-select-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
}
@media (min-width: 780px) {
  .stage-select-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
}
.stage-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 13px 10px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--rule);
  background: var(--panel);
  color: var(--text);
  text-align: center;
  box-shadow: 0 4px 12px rgba(21, 132, 121, 0.05);
  transition: background-color .15s, border-color .15s, transform .12s;
}
.stage-card[aria-current="true"] {
  background: #edf9f7;
  border-color: var(--teal-light);
  box-shadow: 0 0 0 1.5px var(--teal-light);
}
.stage-card.is-cleared {
  background: #f1ece0;
  border-color: rgba(21, 132, 121, 0.12);
  box-shadow: none;
}
.stage-card.is-cleared .stage-card-canvas,
.stage-card.is-cleared .stage-card-num,
.stage-card.is-cleared .stage-card-meta {
  opacity: 0.42;
}
.stage-card.is-cleared[aria-current="true"] {
  background: #e9f2ee;
  border-color: var(--teal-light);
}
.stage-card-canvas {
  width: 62px;
  height: 62px;
  display: block;
}
.stage-card-num {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stage-card-meta {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  min-height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.stage-card-tag {
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--teal-soft);
  color: var(--teal);
  font-size: 10px;
  font-weight: 800;
}
.stage-card-clear-mask {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(253, 247, 231, 0.32);
  display: grid;
  place-items: center;
  pointer-events: none;
}
.stage-card-clear-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  border: 1.5px solid rgba(21, 132, 121, 0.28);
  color: var(--teal);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .06em;
  box-shadow: 0 4px 12px rgba(22, 70, 66, 0.10);
}
.stage-card-clear-pill.is-hintless {
  border-color: rgba(242, 82, 82, 0.34);
  color: var(--coral);
}
.stage-card-next-dot {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--teal);
  color: #ffffff;
  font-size: 10px;
  font-weight: 800;
}

/* ========================================== */
/* View 3: Gameplay / Tutorial Screen         */
/* ========================================== */
.play-area {
  flex: 1;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
}
.scene {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background-color: var(--bg);
  background-image: radial-gradient(rgba(21, 132, 121, 0.11) 1.3px, transparent 1.3px);
  background-size: 24px 24px;
  min-width: 0;
  min-height: 0;
}
.stage-header {
  display: grid;
  grid-template-columns: 44px minmax(120px, auto) 44px;
  justify-content: center;
  align-items: center;
  gap: 14px;
  text-align: center;
  padding: clamp(10px, 2.2vh, 22px) 16px 0;
}
.stage-title {
  grid-column: 2;
  grid-row: 1;
  flex-direction: column;
  justify-content: center;
  position: relative;
}
.stage-title h2 {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 7px;
  font-weight: 900;
}
.stage-prefix {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .12em;
  color: var(--teal);
}
#stageNum {
  font-size: clamp(34px, 4.6vh, 48px);
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.stage-sub-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 3px;
  min-height: 18px;
}
.stage-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
.cleared-badge {
  font-size: 10px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--coral-soft);
  color: var(--coral);
}
.stage-nav { display: contents; }
.stage-nav button {
  grid-row: 1;
  border: 1.5px solid var(--rule);
  background: var(--panel);
  color: var(--teal);
  box-shadow: 0 2px 6px rgba(21, 132, 121, 0.06);
}
#prevStageBtn { grid-column: 1; }
#nextStageBtn { grid-column: 3; }
.stage-nav svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.4;
}

/* Interactive Tutorial Banner */
.tutorial-banner {
  margin: clamp(8px, 1.8vh, 14px) max(14px, env(safe-area-inset-right)) 4px max(14px, env(safe-area-inset-left));
  max-width: 520px;
  width: calc(100% - 28px);
  justify-self: center;
  padding: 13px 16px;
  border-radius: 20px;
  background: var(--panel);
  border: 1.5px solid rgba(54, 181, 165, 0.28);
  box-shadow: 0 6px 18px rgba(21, 132, 121, 0.08);
}
.tutorial-banner-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 5px;
}
.tutorial-step-badge {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .05em;
  color: var(--coral);
}
.tutorial-dots {
  display: flex;
  gap: 6px;
}
.tutorial-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: rgba(21, 132, 121, 0.18);
  transition: background-color .2s, width .2s;
}
.tutorial-dot.active {
  width: 22px;
  background: var(--coral);
}
.tutorial-dot.done {
  background: var(--teal-light);
}
.tutorial-step-title {
  font-size: 16px;
  font-weight: 800;
  line-height: 1.3;
  color: var(--text);
}
.tutorial-step-desc {
  margin-top: 4px;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.55;
  color: var(--muted);
}

.print-frame {
  position: relative;
  container-type: size;
  min-height: 0;
  margin: 0 max(4px, env(safe-area-inset-right)) clamp(18px, 4.5vh, 52px) max(4px, env(safe-area-inset-left));
}
.board-wrap {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(100cqw, 100cqh, 600px);
  height: min(100cqw, 100cqh, 600px);
  isolation: isolate;
  user-select: none;
  -webkit-user-select: none;
}

/* Friendly animated hand cursor on the board (matches app icon) */
.guide-hand {
  position: absolute;
  top: 0;
  left: 0;
  width: 54px;
  height: 80px;
  margin-left: -22px;
  margin-top: -6px;
  pointer-events: none;
  z-index: 4;
  will-change: transform, opacity;
  filter: drop-shadow(0 6px 10px rgba(22, 70, 66, 0.18));
}

.console {
  display: grid;
  grid-template-areas: "counter controls" "instructions controls";
  grid-template-columns: minmax(210px, 1fr) minmax(264px, .8fr);
  gap: 5px 28px;
  align-items: center;
  padding: 15px max(24px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  background: var(--panel);
  border-top: 1.5px solid var(--rule);
  box-shadow: 0 -4px 16px rgba(21, 132, 121, 0.04);
}
.counter {
  grid-area: counter;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.counter strong {
  color: var(--coral);
  font-size: 20px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.line-meter { flex: 1; display: flex; gap: 4px; }
.line-meter i {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: var(--teal-light);
  transition: background .18s;
}
.line-meter i.traced { background: var(--coral); }
#gameCanvas {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: pointer;
}
.board-wrap.shake { animation: boardShake .28s ease; }
@keyframes boardShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
.status-toast {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  width: max-content;
  max-width: 94%;
  text-align: center;
  border-radius: 999px;
  padding: 9px 16px;
  background: rgba(22, 70, 66, 0.94);
  color: #fdf7e7;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
  pointer-events: none;
  z-index: 5;
  animation: toastIn .2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 7px); } }
.instructions {
  grid-area: instructions;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.55;
}
.legend { display: flex; gap: 4px 12px; flex-wrap: wrap; margin-top: 2px; }
.legend-item { display: flex; align-items: center; gap: 6px; color: var(--teal); font-weight: 700; }
.legend-item i { width: 18px; text-align: center; font: 700 16px/1 system-ui; }
.swatch-double { height: 5px; border-block: 1.8px solid var(--teal-light); }
.controls {
  grid-area: controls;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.ctrl-btn, .btn-primary, .btn-secondary {
  min-height: 48px;
  border-radius: 16px;
  font-weight: 800;
}
.ctrl-btn {
  justify-content: center;
  gap: 6px;
  font-size: 13px;
  background: var(--bg);
  border: 1.5px solid var(--rule);
  color: var(--text);
}
.ctrl-btn svg { width: 18px; height: 18px; }
.ctrl-hint {
  background: var(--teal);
  border-color: var(--teal);
  color: #ffffff;
}
.btn-primary {
  background: var(--coral);
  color: #ffffff;
  box-shadow: 0 6px 16px rgba(242, 82, 82, 0.25);
}
@media (hover: hover) {
  .stage-card:hover, .icon-btn:hover, .back-btn:hover, .brand-btn:hover,
  .stage-nav button:not(:disabled):hover, .ctrl-btn:not(.ctrl-hint):not(:disabled):hover,
  .btn-secondary:hover, .range-tab:not([aria-selected="true"]):hover,
  .home-btn-card:hover {
    background: #eef7f5;
    border-color: rgba(21, 132, 121, 0.28);
  }
  .ctrl-hint:not(:disabled):hover { background: var(--teal-hover); }
  .btn-primary:hover, .home-btn-primary:hover { background: var(--coral-hover); }
}

/* ========================================== */
/* Modals                                     */
/* ========================================== */
.modal {
  color: var(--text);
  width: min(400px, calc(100% - 32px));
  max-height: 88dvh;
  padding: 0;
  border: 1.5px solid var(--rule);
  border-radius: 28px;
  background: var(--bg);
  box-shadow: 0 24px 72px rgba(22, 70, 66, 0.22);
  overscroll-behavior: contain;
}
.modal[open] { animation: popUp .23s cubic-bezier(.2, .9, .3, 1); }
.modal::backdrop { background: rgba(22, 70, 66, 0.45); backdrop-filter: blur(6px); }
.modal-card { padding: 24px; }
.modal-card h3 { font-size: 21px; font-weight: 900; }
.stage-dialog { width: min(478px, calc(100% - 32px)); }
.modal-header { justify-content: space-between; margin-bottom: 16px; }
.close-btn { font-size: 15px; font-weight: 800; }
.clear-card { text-align: center; padding-top: 30px; }
.clear-badge-circle {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  margin: 0 auto 18px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--coral), #ff7a6b);
  color: #ffffff;
  font-size: 28px;
  font-weight: 900;
  box-shadow: 0 10px 24px rgba(242, 82, 82, 0.30);
  animation: stampDrop .35s cubic-bezier(.2, 1.25, .4, 1);
}
.clear-stage-info { margin: 8px 0; color: var(--teal); font-weight: 800; }
.clear-badge-note { color: var(--muted); font-size: 13px; font-weight: 600; line-height: 1.65; }
.modal-actions { display: grid; gap: 9px; margin-top: 22px; }
.modal-sub-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.btn-secondary {
  background: var(--panel);
  border: 1.5px solid var(--rule);
  font-size: 13px;
}
@keyframes popUp { from { opacity: 0; transform: scale(.95) translateY(8px); } }
@keyframes stampDrop { from { opacity: 0; transform: scale(1.5); } }
@keyframes slideUp { from { transform: translateY(100%); } }

.trivia-list details { border-top: 1px solid var(--rule); }
.trivia-list summary { padding: 14px 2px; min-height: 44px; cursor: pointer; font-weight: 700; }
.trivia-list details[open] summary { color: var(--coral); }
.trivia-list p { padding: 0 4px 14px; font-size: 14px; line-height: 1.8; color: var(--muted); }
.trivia-list a { color: var(--teal); font-weight: 700; text-underline-offset: 3px; }

/* ========================================== */
/* Responsive Breakpoints                     */
/* ========================================== */
@media (max-width: 900px) and (min-height: 501px) {
  .console {
    grid-template-areas: "counter" "instructions" "controls";
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;
    padding-inline: max(18px, calc((100% - 560px) / 2));
  }
  .controls { margin-top: 6px; }
  .ctrl-btn { font-size: 14px; }
}
@media (max-width: 680px) {
  .stage-dialog {
    margin: auto auto 0;
    width: 100%;
    max-width: 100%;
    max-height: calc(95dvh - env(safe-area-inset-top));
    border-radius: 26px 26px 0 0;
    border-bottom: 0;
  }
  .stage-dialog[open] { animation: slideUp .26s cubic-bezier(.2, .8, .2, 1); }
  .stage-select-card {
    padding: 20px max(16px, env(safe-area-inset-right)) max(22px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }
}
@media (max-width: 430px) {
  .topbar {
    padding-inline: max(10px, env(safe-area-inset-left)) max(10px, env(safe-area-inset-right));
  }
  .topbar-left { gap: 6px; }
  .topbar-actions { gap: 5px; }
  .brand-btn span { display: none; }
  .brand-btn { padding: 4px; }
  .text-pill-btn { padding: 0 11px; font-size: 12px; }
  .back-btn { padding: 0 11px 0 7px; font-size: 12px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .topbar { min-height: calc(46px + env(safe-area-inset-top)); }
  .home-body {
    flex-direction: row;
    max-width: 720px;
    justify-content: center;
    align-items: center;
    gap: 28px;
    padding-block: 10px max(14px, env(safe-area-inset-bottom));
  }
  .home-emblem { width: 168px; height: 132px; margin-bottom: 0; }
  .home-actions { max-width: 300px; gap: 8px; }
  .home-btn { min-height: 48px; font-size: 14px; }
  .play-area {
    grid-template-rows: 1fr;
    grid-template-columns: 1fr clamp(160px, 24vw, 224px);
  }
  .scene { position: relative; grid-template-rows: 1fr; }
  .stage-header {
    position: absolute;
    z-index: 1;
    top: 8px;
    left: max(6px, env(safe-area-inset-left));
    display: flex;
    flex-direction: column;
    padding: 0;
    gap: 6px;
  }
  .stage-prefix { font-size: 10px; }
  #stageNum { font-size: 24px; }
  .stage-nav { display: flex; flex-direction: column; gap: 3px; }
  .tutorial-banner {
    position: absolute;
    z-index: 2;
    top: 8px;
    left: max(8px, env(safe-area-inset-left));
    width: 196px;
    margin: 0;
    padding: 9px 10px;
  }
  .tutorial-step-title { font-size: 13px; }
  .tutorial-step-desc { font-size: 11px; }
  .print-frame {
    margin: 0 0 max(14px, env(safe-area-inset-bottom)) max(66px, env(safe-area-inset-left));
  }
  .play-view.is-tutorial .print-frame {
    margin-left: max(206px, env(safe-area-inset-left));
  }
  .console {
    grid-template-columns: 1fr;
    grid-template-areas: "counter" "instructions" "controls";
    gap: 8px;
    align-content: center;
    border-top: 0;
    border-left: 1.5px solid var(--rule);
    padding: 8px max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) 10px;
  }
  .controls { grid-template-columns: 1fr; gap: 4px; }
  .ctrl-btn { min-height: 42px; }
  .instructions { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) {
  .view, .modal[open], .board-wrap.shake, .status-toast, .clear-badge-circle,
  .hero-hand-group, .hero-goal-ring {
    animation: none;
  }
  .line-meter i, .stages-progress-fill, .tutorial-dot { transition: none; }
}
