:root {
  --ink: #10243f;
  --paper: #f5edcf;
  --night: #071526;
  --blue: #4fc4d6;
  --yellow: #ffd34e;
  --coral: #f36d5f;
  --violet: #a48cff;
  --green: #66d27d;
  --shadow: #05101d;
}

* { box-sizing: border-box; }
html { background: var(--night); color-scheme: dark; }
body {
  margin: 0;
  min-width: 280px;
  overflow-x: hidden;
  background: var(--night);
  color: var(--paper);
  font-family: ui-monospace, "Yu Gothic", "Hiragino Kaku Gothic ProN", monospace;
  line-height: 1.65;
}
button { font: inherit; }
button:focus-visible { outline: 4px solid #fff; outline-offset: 3px; }
[hidden] { display: none !important; }

.masthead {
  width: min(1100px, calc(100% - 24px));
  margin: 12px auto 0;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  border: 4px solid var(--paper);
  border-bottom-color: var(--yellow);
  padding: 10px 14px;
  box-shadow: 7px 7px 0 var(--shadow);
}
.brand-mark { color: var(--yellow); font-size: 2.5rem; line-height: 1; }
.eyebrow, .chapter { margin: 0; color: var(--yellow); font-weight: 900; letter-spacing: .12em; font-size: .76rem; }
h1 { margin: 0; font-size: clamp(1.2rem, 4vw, 2.25rem); line-height: 1.2; }
.sound-button, .secondary-button {
  min-height: 46px;
  border: 3px solid var(--paper);
  background: var(--ink);
  color: var(--paper);
  padding: 8px 14px;
  box-shadow: 4px 4px 0 #000;
  cursor: pointer;
}

.game-shell { width: min(1100px, calc(100% - 24px)); margin: 16px auto 30px; }
.screen { border: 4px solid var(--paper); box-shadow: 8px 8px 0 #000; }
.start-screen { display: grid; grid-template-columns: minmax(280px, 1.1fr) minmax(280px, .9fr); background: #123456; }
.start-world { min-height: 470px; position: relative; overflow: hidden; background: #173e63; border-right: 4px solid var(--paper); }
.start-world::before {
  content: ""; position: absolute; inset: auto 0 0; height: 45%; background: #10243f;
  clip-path: polygon(0 38%, 8% 38%, 8% 14%, 14% 14%, 14% 45%, 22% 45%, 22% 24%, 30% 24%, 30% 52%, 38% 52%, 38% 7%, 46% 7%, 46% 47%, 57% 47%, 57% 19%, 65% 19%, 65% 50%, 76% 50%, 76% 29%, 84% 29%, 84% 42%, 100% 42%, 100% 100%, 0 100%);
}
.start-world::after { content: ""; position: absolute; left: 0; right: 0; bottom: 31px; height: 8px; background: var(--yellow); box-shadow: 0 16px 0 var(--coral); }
.pixel-sun { position: absolute; width: 90px; height: 90px; right: 45px; top: 40px; background: var(--yellow); box-shadow: 12px 0 0 #f09b3c, 0 12px 0 #f09b3c; }
.diet-building, .cabinet-building, .court-building {
  position: absolute; bottom: 78px; padding: 10px 12px; color: var(--night); font-weight: 900; border: 4px solid var(--night); box-shadow: 7px 7px 0 #000; z-index: 2;
}
.diet-building { left: 6%; background: var(--blue); }
.cabinet-building { left: 39%; bottom: 130px; background: var(--yellow); }
.court-building { right: 6%; background: var(--violet); }
.civic-ship { position: absolute; z-index: 3; left: 19%; top: 32%; color: var(--paper); font-size: 4rem; transform: rotate(45deg); text-shadow: 9px 0 var(--coral), -9px 0 var(--blue); }
.start-copy { padding: clamp(20px, 4vw, 42px); align-self: center; }
.start-copy h2, .quiz-screen h2, .result-screen h2, .setback-panel h2 { margin: 6px 0 12px; line-height: 1.35; font-size: clamp(1.45rem, 4vw, 2.4rem); }
.role-legend { display: grid; gap: 8px; margin: 18px 0; }
.role-legend span { display: flex; align-items: center; gap: 10px; }
.role-legend b { width: 18px; height: 18px; display: inline-block; border: 3px solid var(--paper); }
.diet-dot { background: var(--blue); }.cabinet-dot { background: var(--yellow); }.court-dot { background: var(--violet); }
.start-note { color: #c4e9ee; font-size: .9rem; }
.primary-button {
  min-height: 54px; border: 4px solid var(--night); background: var(--yellow); color: var(--night); padding: 10px 22px; font-weight: 900; box-shadow: 6px 6px 0 var(--coral); cursor: pointer;
}
.primary-button:active, .secondary-button:active, .sound-button:active { transform: translate(3px, 3px); box-shadow: 2px 2px 0 #000; }

.play-screen { background: #0c2139; }
.hud { display: grid; grid-template-columns: .7fr 1fr .7fr 2fr; border-bottom: 4px solid var(--paper); background: #071526; }
.hud > div { min-height: 66px; padding: 8px 12px; border-right: 2px solid #496078; display: flex; flex-direction: column; justify-content: center; }
.hud > div:last-child { border-right: 0; }
.hud small { color: #9ec4d1; font-size: .72rem; letter-spacing: .08em; }
.hud strong { color: #fff; font-size: 1.2rem; }
.shield-track { margin-top: 6px; display: block; height: 12px; background: #020913; border: 2px solid var(--paper); }
#shieldFill { display: block; width: 100%; height: 100%; background: var(--green); transition: width .2s linear; }
.mission-strip { min-height: 50px; display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 7px 12px; background: var(--paper); color: var(--ink); border-bottom: 4px solid var(--ink); }
.mission-strip > span:first-child { background: var(--ink); color: var(--paper); padding: 2px 8px; font-weight: 900; }
.world-frame { position: relative; background: #0a1c30; }
.civic-world { display: block; width: 100%; height: auto; max-height: 66vh; min-height: 300px; object-fit: contain; touch-action: pan-y; cursor: crosshair; }
.release-banner { position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%); width: min(560px, 86%); padding: 14px; background: var(--yellow); color: var(--night); border: 5px solid #fff; box-shadow: 10px 10px 0 var(--coral); text-align: center; pointer-events: none; }
.release-banner strong { display: block; font-size: clamp(1.6rem, 5vw, 3.3rem); line-height: 1.1; }
.warning-text { min-height: 48px; margin: 0; padding: 8px 12px; background: #08101c; color: #fff1ad; border-top: 3px solid #314860; border-bottom: 3px solid #314860; text-align: center; font-weight: 800; }
.role-controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; border-bottom: 4px solid var(--paper); }
.role-button { min-height: 74px; border: 0; border-right: 3px solid var(--paper); background: #172b43; color: #b9c4d0; padding: 7px; cursor: pointer; }
.role-button:last-child { border-right: 0; }
.role-button span { display: inline-grid; place-items: center; width: 25px; height: 25px; border: 2px solid currentColor; margin-right: 6px; }
.role-button b { font-size: 1rem; }.role-button small { display: block; }
.role-button.active { color: var(--night); box-shadow: inset 0 -7px 0 var(--night); }
.role-button.diet.active { background: var(--blue); }.role-button.cabinet.active { background: var(--yellow); }.role-button.court.active { background: var(--violet); }
.role-button:disabled { opacity: .45; cursor: not-allowed; }
.control-dock { display: grid; grid-template-columns: 230px 1fr 230px; gap: 12px; align-items: center; padding: 12px; background: #10243f; }
.move-pad { display: grid; grid-template-columns: repeat(3, 58px); grid-template-rows: repeat(2, 52px); gap: 5px; justify-content: center; }
.move-pad button { min-width: 52px; min-height: 48px; border: 3px solid var(--paper); background: #193754; color: #fff; box-shadow: 3px 3px 0 #000; touch-action: manipulation; }
#upButton { grid-column: 2; }.move-pad #leftButton { grid-column: 1; grid-row: 2; }.pad-core { grid-column: 2; grid-row: 2; display: grid; place-items: center; color: #8eabba; font-size: .7rem; }.move-pad #rightButton { grid-column: 3; grid-row: 2; }#downButton { grid-column: 2; grid-row: 3; }
.aim-readout { text-align: center; }.aim-readout span, .aim-readout small { display: block; color: #9ec4d1; }.aim-readout strong { color: var(--yellow); }
.fire-button { min-height: 94px; border: 4px solid var(--paper); background: var(--coral); color: #fff; padding: 8px; box-shadow: 6px 6px 0 #000; touch-action: manipulation; cursor: pointer; }
.fire-button span { display: block; font-size: .74rem; }.fire-button strong { display: block; font-size: 1.05rem; }
.charge-track { display: block; height: 9px; margin-top: 5px; background: #5b1b24; border: 2px solid #fff; }.charge-track i { display: block; height: 100%; width: 0; background: var(--yellow); }
.setback-panel { margin: 14px; padding: 20px; border: 5px solid var(--coral); background: #1b2535; }

.quiz-screen, .result-screen { padding: clamp(20px, 5vw, 52px); background: #10243f; }
.quiz-count { color: var(--blue); font-weight: 900; }
.quiz-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 24px 0; }
.quiz-choices button { min-height: 62px; border: 4px solid var(--paper); background: #173e63; color: #fff; padding: 10px; text-align: left; overflow-wrap: anywhere; cursor: pointer; }
.quiz-choices button.correct { background: #155c3a; border-style: double; }.quiz-choices button.wrong { background: #6e2730; text-decoration: line-through; }
.quiz-feedback { border-left: 8px solid var(--yellow); padding: 14px 18px; background: #071526; }
.quiz-feedback strong { color: var(--yellow); font-size: 1.2rem; }
.final-score { display: flex; flex-wrap: wrap; align-items: baseline; gap: 14px; padding: 14px; border: 5px solid var(--yellow); background: #071526; }
.final-score strong { font-size: clamp(2.6rem, 9vw, 5rem); color: var(--yellow); line-height: 1; }
.result-grid { display: grid; grid-template-columns: repeat(4, 1fr); margin: 16px 0; border: 3px solid var(--paper); }
.result-grid div { padding: 12px; border-right: 2px solid #5a7186; }.result-grid div:last-child { border: 0; }.result-grid span, .result-grid strong { display: block; }.result-grid span { color: #9ec4d1; font-size: .8rem; }.result-grid strong { font-size: 1.3rem; }
.result-learning { border-left: 7px solid var(--blue); padding: 12px; background: #071526; }
.result-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 18px; }
.ranking-panel { width: 100%; max-width: 760px; margin: 20px auto 0; padding: 14px; background: #f7f0d7; color: #14233b; border: 5px solid var(--yellow); overflow-wrap: anywhere; }
.ranking-panel button, .ranking-panel [role="tab"] { color: #14233b !important; background: #fff4b5 !important; border-color: #14233b !important; }
.ranking-panel [aria-selected="true"], .ranking-panel .active { background: #14233b !important; color: #fff !important; }
footer { padding: 18px 12px 34px; text-align: center; color: #91a9bb; font-size: .78rem; }

@media (max-width: 760px) {
  .masthead { grid-template-columns: auto 1fr; }.sound-button { grid-column: 1 / -1; width: 100%; }
  .game-shell, .masthead { width: min(100% - 12px, 1100px); }
  .start-screen { grid-template-columns: 1fr; }.start-world { min-height: 300px; border-right: 0; border-bottom: 4px solid var(--paper); }
  .hud { grid-template-columns: repeat(3, 1fr); }.rights-cell { grid-column: 1 / -1; }.hud > div:nth-child(3) { border-right: 0; }
  .mission-strip { grid-template-columns: 1fr auto; }.mission-strip strong { grid-column: 1 / -1; grid-row: 2; }
  .civic-world { min-height: 260px; max-height: none; }
  .role-button { min-height: 86px; }.role-button b { display: block; }
  .control-dock { grid-template-columns: 1fr 1fr; }.aim-readout { grid-column: 1 / -1; grid-row: 1; }.move-pad { grid-row: 2; }.fire-button { grid-row: 2; }
  .quiz-choices { grid-template-columns: 1fr; }
  .result-grid { grid-template-columns: repeat(2, 1fr); }.result-grid div:nth-child(2) { border-right: 0; }.result-grid div:nth-child(-n+2) { border-bottom: 2px solid #5a7186; }
  .ranking-panel { max-width: calc(100vw - 36px); }
}
@media (max-width: 430px) {
  .game-shell, .masthead { width: 100%; margin-left: 0; margin-right: 0; border-left-width: 0; border-right-width: 0; box-shadow: none; }
  .start-copy, .quiz-screen, .result-screen { padding: 18px 12px; }
  .role-controls { grid-template-columns: 1fr; }.role-button { min-height: 56px; border-right: 0; border-bottom: 2px solid var(--paper); }.role-button small { display: inline; margin-left: 6px; }
  .control-dock { padding: 9px 5px; gap: 4px; }.move-pad { transform: scale(.9); transform-origin: center; }
  .fire-button { min-width: 0; padding: 5px; }.fire-button strong { font-size: .88rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
