:root {
  --ink: #18314b;
  --paper: #fff7dc;
  --court: #d9f1ed;
  --aqua: #33b7c7;
  --warm: #f28b4b;
  --crystal: #9b7bd8;
  --lime: #cddd55;
  --danger: #c8433b;
  --line: #285d68;
  --shadow: #102737;
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; min-width: 280px; min-height: 100%; background: var(--ink); }
body {
  color: var(--ink);
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.42;
  overflow: hidden;
}
button { min-width: 44px; min-height: 44px; font: inherit; font-size: 14px; font-weight: 800; cursor: pointer; }
button:focus-visible { outline: 4px solid #fff; outline-offset: 2px; }
[hidden] { display: none !important; }
.app-shell {
  height: 100svh;
  height: 100dvh;
  min-height: 568px;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--ink);
}
.topbar {
  min-height: 58px;
  padding: 5px max(8px, calc((100vw - 1100px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--paper);
  border-bottom: 4px solid var(--lime);
  background: var(--ink);
}
.identity { display: flex; align-items: center; gap: 8px; min-width: 0; }
.identity small, .hud small, .shot-types small { display: block; font-size: 14px; font-weight: 800; }
.identity small { color: #aee4e5; letter-spacing: .04em; white-space: nowrap; }
.identity h1 { margin: 0; max-width: 48vw; overflow-wrap: anywhere; font-size: clamp(16px, 3.4vw, 23px); line-height: 1.1; }
.crest { display: grid; place-items: center; width: 40px; height: 40px; flex: 0 0 40px; color: var(--ink); background: var(--lime); border: 3px solid var(--paper); transform: rotate(45deg); font-weight: 900; }
.top-actions { display: flex; flex-shrink: 0; gap: 5px; }
.top-actions button, #pauseButton, #rankingButton { padding: 5px 9px; color: var(--paper); border: 2px solid var(--paper); background: #244963; box-shadow: 3px 3px 0 #091b29; }
.screen-stack { position: relative; min-height: 0; width: min(1100px, 100%); height: 100%; margin: 0 auto; }
.screen { width: 100%; height: 100%; min-height: 0; background: var(--paper); }

.start-screen { display: grid; grid-template-columns: minmax(0, 1.16fr) minmax(300px, .84fr); overflow: hidden; }
.start-court { position: relative; min-height: 0; overflow: hidden; background: var(--court); border-right: 5px solid var(--ink); }
.start-court::before { content: ""; position: absolute; inset: 7% 7%; border: 5px solid var(--line); border-radius: 50% 50% 10% 10%; }
.court-lines { position: absolute; inset: 0; background: repeating-linear-gradient(90deg, transparent 0 74px, rgba(40,93,104,.13) 74px 78px); }
.court-lines::after { content: ""; position: absolute; left: 8%; right: 8%; top: 52%; height: 5px; background: var(--line); box-shadow: 0 80px 0 rgba(40,93,104,.45); }
.sample { position: absolute; width: 96px; height: 130px; top: 12%; border: 7px solid var(--ink); border-top: 0; border-radius: 8px 8px 28px 28px; background: rgba(255,255,255,.68); transform: rotate(-5deg); }
.sample::before { content: ""; position: absolute; left: -9px; right: -9px; top: -9px; height: 17px; border: 6px solid var(--ink); border-radius: 50%; background: var(--paper); }
.sample b { position: absolute; left: 8px; top: 15px; font-size: 16px; }
.sample span { position: absolute; left: 6px; right: 6px; bottom: 7px; height: 58%; border-radius: 4px 4px 18px 18px; background: var(--aqua); opacity: .78; }
.sample-cold { right: 28%; }.sample-warm { right: 8%; top: 25%; transform: rotate(7deg); }
.sample-warm span { height: 78%; background: var(--warm); }
.pitcher { position: absolute; left: 12%; bottom: 9%; width: 112px; height: 112px; border: 7px solid var(--ink); border-radius: 50% 50% 42% 42%; background: var(--lime); box-shadow: 11px 11px 0 var(--shadow); display: grid; place-items: center; font-size: 38px; }
.pitcher::before, .pitcher::after { content: ""; position: absolute; bottom: -40px; width: 34px; height: 46px; border: 6px solid var(--ink); background: var(--paper); }
.pitcher::before { left: 12px; transform: rotate(7deg); }.pitcher::after { right: 12px; transform: rotate(-7deg); }
.pitcher i { position: absolute; width: 67px; height: 22px; top: -18px; border: 6px solid var(--ink); background: var(--crystal); transform: rotate(-10deg); }
.crystal-ball { position: absolute; width: 34px; height: 34px; background: var(--crystal); border: 5px solid var(--ink); transform: rotate(45deg); }
.crystal-one { left: 36%; top: 25%; }.crystal-two { left: 50%; top: 15%; width: 24px; height: 24px; }
.start-copy { align-self: center; padding: clamp(18px, 3vw, 38px); }
.kicker { margin: 0 0 4px; color: #276a73; font-size: 14px; font-weight: 900; letter-spacing: .05em; }
.start-copy h2, .quiz-screen h2, .result-screen h2, .setback-panel h2, .help-card h2 { margin: 4px 0 9px; font-size: clamp(22px, 4vw, 38px); line-height: 1.17; }
.start-copy p { margin: 7px 0; }
.start-copy ul { margin: 10px 0 14px; padding-left: 1.3em; }
.primary-button { min-height: 48px; padding: 8px 20px; color: var(--ink); border: 4px solid var(--ink); background: var(--lime); box-shadow: 6px 6px 0 var(--crystal); }

.game-screen { display: grid; grid-template-rows: auto auto minmax(160px, 1fr) auto auto; overflow: hidden; background: #b9dfd9; }
.hud { min-height: 52px; display: grid; grid-template-columns: .62fr .9fr .68fr 1.6fr auto; color: var(--paper); background: var(--ink); border-bottom: 3px solid var(--line); }
.hud > div { min-width: 0; padding: 4px 8px; border-right: 2px solid #3d6076; display: flex; flex-direction: column; justify-content: center; }
.hud strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 18px; }
.power-track { display: block; width: 100%; height: 11px; margin-top: 3px; border: 2px solid var(--paper); background: #0b1f2e; }
.power-track i { display: block; height: 100%; width: 100%; background: var(--lime); transition: width .18s linear; }
#pauseButton { min-width: 78px; border-width: 0 0 0 3px; box-shadow: none; }
.mission-ribbon { min-height: 38px; padding: 4px 9px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; color: var(--ink); background: var(--paper); border-bottom: 4px solid var(--ink); }
.mission-ribbon strong { padding: 2px 7px; color: var(--paper); background: var(--line); white-space: nowrap; }
.mission-ribbon span { min-width: 0; overflow-wrap: anywhere; }
.field-wrap { position: relative; min-height: 160px; overflow: hidden; display: grid; place-items: center; background: #afd9d4; }
#gameField { display: block; width: 100%; height: 100%; min-width: 160px; min-height: 160px; object-fit: contain; touch-action: pan-y; cursor: crosshair; }
.release-banner { position: absolute; left: 50%; top: 44%; transform: translate(-50%, -50%) rotate(-2deg); min-width: min(80%, 420px); padding: 10px 14px; text-align: center; color: var(--ink); background: var(--lime); border: 5px solid var(--ink); box-shadow: 8px 8px 0 var(--crystal); pointer-events: none; }
.release-banner strong, .release-banner span { display: block; }.release-banner strong { font-size: clamp(24px, 5vw, 42px); }
.pause-panel { position: absolute; inset: 0; z-index: 4; display: grid; place-content: center; gap: 12px; text-align: center; color: var(--paper); background: rgba(24,49,75,.9); }
.pause-panel strong { font-size: 25px; }.pause-panel button { border: 3px solid var(--paper); background: var(--lime); color: var(--ink); }
.status-line { min-height: 31px; margin: 0; padding: 4px 9px; overflow-wrap: anywhere; text-align: center; font-weight: 800; color: var(--paper); background: #244963; border-top: 3px solid var(--ink); }
.control-bench { min-height: 78px; padding: 5px 7px; display: grid; grid-template-columns: auto minmax(0, 1fr) minmax(92px, .55fr); gap: 7px; align-items: stretch; color: var(--ink); background: var(--paper); border-top: 4px solid var(--ink); }
.move-controls { display: grid; grid-template-columns: repeat(2, 54px); gap: 5px; }
.move-controls button { color: var(--paper); border: 3px solid var(--ink); background: var(--line); box-shadow: 3px 3px 0 var(--shadow); touch-action: manipulation; }
.shot-types { min-width: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.shot-types button { min-width: 0; padding: 3px; color: var(--ink); border: 3px solid var(--ink); background: #e6e0c9; }
.shot-types button.active { background: var(--aqua); box-shadow: inset 0 -7px 0 rgba(24,49,75,.25); }
.shot-types b, .shot-types small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fire-button { min-width: 92px; padding: 3px 6px; color: var(--paper); border: 4px solid var(--ink); background: var(--danger); box-shadow: 4px 4px 0 var(--shadow); touch-action: manipulation; }
.fire-button span, .fire-button strong { display: block; }.fire-button > i { display: block; height: 9px; margin-top: 3px; border: 2px solid var(--paper); background: #612c2b; }.fire-button > i > i { display: block; height: 100%; width: 0; background: var(--lime); }
.setback-panel { position: absolute; inset: 7% 6%; z-index: 5; padding: 20px; display: grid; place-content: center; text-align: center; color: var(--paper); background: #27354a; border: 6px solid var(--danger); box-shadow: 10px 10px 0 var(--shadow); }

.quiz-screen { padding: clamp(12px, 3vw, 32px); overflow: hidden; }
.quiz-head { display: flex; justify-content: space-between; gap: 10px; }.quiz-head strong { font-size: 18px; }
.quiz-screen h2 { max-width: 900px; font-size: clamp(20px, 4vw, 32px); }
.quiz-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin: 10px 0; }
.quiz-choices button { min-height: 58px; padding: 7px 10px; overflow-wrap: anywhere; text-align: left; color: var(--ink); border: 4px solid var(--ink); background: #d7eee9; }
.quiz-choices button.correct { background: var(--lime); border-style: double; }.quiz-choices button.wrong { background: #f3aaa4; text-decoration: line-through; }
.quiz-feedback { padding: 10px 13px; border-left: 8px solid var(--crystal); background: #eee7cf; }
.quiz-feedback p { margin: 5px 0 8px; }

.result-screen { padding: clamp(12px, 3vw, 30px); overflow: hidden; display: grid; grid-template-columns: minmax(0, 1fr); align-content: center; }
.final-score { display: flex; align-items: baseline; gap: 12px; padding: 7px 12px; color: var(--paper); background: var(--ink); border: 5px solid var(--lime); }
.final-score strong { font-size: clamp(34px, 8vw, 68px); line-height: 1; color: var(--lime); }
.result-stats { display: grid; grid-template-columns: repeat(4, 1fr); margin: 10px 0; border: 3px solid var(--ink); }
.result-stats div { padding: 6px; text-align: center; border-right: 2px solid var(--ink); }.result-stats div:last-child { border: 0; }
.result-stats span, .result-stats b { display: block; }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ranking-panel { position: absolute; inset: 8px; z-index: 8; padding: 12px; overflow: auto; color: var(--ink); background: var(--paper); border: 6px solid var(--crystal); }
.ranking-panel button, .ranking-panel [role="tab"] { color: var(--ink) !important; background: #e7f4ef !important; border-color: var(--ink) !important; }
.ranking-panel [aria-selected="true"], .ranking-panel .active { color: var(--paper) !important; background: var(--ink) !important; }

.help-panel { position: absolute; inset: 0; z-index: 20; padding: 10px; overflow: auto; background: rgba(10,27,41,.92); }
.help-card { width: min(760px, 100%); margin: 0 auto; padding: 16px; color: var(--ink); background: var(--paper); border: 5px solid var(--lime); }
.help-card > div:first-child { display: inline-block; }.help-card > button { float: right; color: var(--paper); border: 3px solid var(--ink); background: var(--danger); }
.help-card li { margin-bottom: 7px; }.model-note { padding: 10px; border-left: 7px solid var(--aqua); background: #d7eee9; }

@media (max-width: 640px) {
  body { font-size: 14px; }
  .app-shell { min-height: 568px; }
  .topbar { min-height: 58px; padding: 4px 5px; }
  .identity small { display: none; }.crest { width: 35px; height: 35px; flex-basis: 35px; }.identity h1 { max-width: 42vw; }
  .top-actions button { padding: 3px 6px; }
  .start-screen { grid-template-columns: 1fr; grid-template-rows: minmax(165px, 38%) minmax(0, 1fr); }
  .start-court { border-right: 0; border-bottom: 4px solid var(--ink); }
  .sample { width: 60px; height: 86px; border-width: 5px; }.sample::before { border-width: 4px; height: 12px; }.sample b { font-size: 14px; top: 10px; }.sample-cold { right: 27%; }.sample-warm { right: 8%; top: 20%; }
  .pitcher { width: 72px; height: 72px; left: 9%; bottom: 10%; border-width: 5px; box-shadow: 7px 7px 0 var(--shadow); font-size: 25px; }.pitcher::before, .pitcher::after { bottom: -28px; width: 23px; height: 33px; border-width: 4px; }.pitcher i { width: 44px; height: 15px; top: -13px; border-width: 4px; }
  .start-copy { padding: 8px 12px 10px; }.start-copy h2 { font-size: 21px; }.start-copy p { margin: 4px 0; }.start-copy ul { margin: 5px 0 7px; }.start-copy .primary-button { width: 100%; min-height: 46px; }
  .hud { grid-template-columns: .58fr .9fr .62fr 1.5fr auto; min-height: 50px; }.hud > div { padding: 3px 4px; }.hud strong { font-size: 16px; }.power-cell small { white-space: normal; }#powerValue { display: block; }#pauseButton { min-width: 52px; padding: 2px; }
  .mission-ribbon { min-height: 36px; padding: 2px 5px; gap: 2px 5px; grid-template-columns: minmax(0, 1fr) auto; }.mission-ribbon span { grid-column: 1 / -1; grid-row: 2; }.mission-ribbon strong { justify-self: start; }#progressValue { grid-column: 2; grid-row: 1; }
  .status-line { min-height: 30px; padding: 4px 6px; }
  .control-bench { min-height: 76px; padding: 4px; gap: 4px; grid-template-columns: auto minmax(0, 1fr) minmax(72px, .52fr); }
  .move-controls { grid-template-columns: repeat(2, 46px); gap: 3px; }.move-controls button { padding: 0; }
  .shot-types { gap: 2px; }.shot-types button { padding: 1px; border-width: 2px; }.shot-types small { font-size: 14px; }
  .fire-button { min-width: 72px; padding: 1px 3px; }.fire-button span { display: none; }
  .quiz-screen { padding: 9px 8px; }.quiz-screen h2 { margin: 4px 0 7px; font-size: 19px; }.quiz-choices { gap: 6px; margin: 6px 0; }.quiz-choices button { min-height: 54px; padding: 5px; }
  .quiz-feedback { padding: 7px 9px; }.quiz-feedback p { margin: 3px 0 5px; }
  .result-screen { padding: 9px 8px; }.result-screen h2 { font-size: 21px; }.result-screen p { margin: 7px 0; }.final-score { padding: 5px 8px; }.final-score strong { font-size: 38px; }.result-stats { margin: 7px 0; }.result-stats div { padding: 4px 2px; }
}

@media (max-height: 620px) and (max-width: 640px) {
  .topbar { min-height: 54px; }.start-screen { grid-template-rows: 165px minmax(0, 1fr); }.start-copy h2 { margin: 2px 0 4px; }.start-copy ul { display: none; }
  .hud { min-height: 46px; }.mission-ribbon { min-height: 34px; }.control-bench { min-height: 72px; }
}

@media (max-height: 567px), (max-width: 279px) {
  body { overflow: auto; }.app-shell { height: auto; min-height: 568px; }.screen-stack { min-height: 510px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
