/* ==========================================================
   ROOT / RESET — one theme, one variable system
   ========================================================== */
:root {
  --bg: #F6F8FB;
  --card: #FFFFFF;
  --panel: #FFFFFF;
  --panel-2: #E8EEF5;
  --border: #CBD5E1;
  --text: #14233B;
  --muted: #4A5D78;
  --sage: #9BD8B0;
  --cyan: #7FC8C4;
  --amber: #E8C47A;
  --coral: #E89A8C;
  --lavender: #B9A4E8;
  --navy: #14233B;
  --ink: #10182a;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 28px rgba(20, 35, 59, .08);
  --shadow-sm: 0 4px 14px rgba(20, 35, 59, .06);
  --shadow-hover: 0 14px 32px rgba(20, 35, 59, .12);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { background: var(--bg); }
[hidden] { display: none !important; }

/* ==========================================================
   GLOBAL
   ========================================================== */
body {
  min-height: 100vh;
  background:
    radial-gradient(900px 420px at 12% -8%, rgba(127, 200, 196, .22), transparent 58%),
    radial-gradient(720px 380px at 92% 4%, rgba(155, 216, 176, .18), transparent 52%),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  line-height: 1.55;
  overflow-x: hidden;
}
body.modal-open { overflow: hidden; }
button, input { font: inherit; }
button {
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: transform .12s ease, filter .12s ease, box-shadow .12s ease, background .12s ease, border-color .12s ease;
}
button:hover:not(:disabled) { transform: translateY(-1px); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { cursor: not-allowed; opacity: .55; transform: none; }
h1, h2, h3, .brand, .small-label, .pixel-badge, .mode-badge, .mission-number {
  font-family: "Segoe UI", system-ui, Arial, sans-serif;
}
h1 { font-size: clamp(25px, 3vw, 38px); line-height: 1.2; margin: 12px 0; letter-spacing: -.04em; }
h2 { font-size: 22px; margin: 10px 0; }
#app { max-width: 1240px; margin: auto; padding: 20px 28px; }
.screen { margin: 28px auto; }
.intro { color: var(--muted); font-size: 16px; max-width: 780px; }
.fine-print { color: var(--muted); font-size: 12px; margin-top: 14px; }
.small-label, .panel-title, .control-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.4px;
  text-transform: uppercase;
}
.error { color: #b85a4e; min-height: 22px; margin: 8px 0; font-size: 14px; }
.error:empty { min-height: 0; }
.notice {
  padding: 12px 14px;
  border: 1px solid var(--amber);
  background: #FFF8EA;
  color: var(--navy);
  margin-top: 12px;
  border-radius: var(--radius-sm);
}
.pixel-badge {
  display: inline-block;
  background: var(--cyan);
  color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--cyan) 60%, var(--border));
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  border-radius: 999px;
}
.mode-badge { display: inline-block; font-size: 12px; font-weight: 800; color: #b5893a; }
.main-btn, .secondary-btn, .launch-btn {
  width: 100%;
  min-height: 48px;
  padding: 13px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .8px;
  margin-top: 12px;
}
.main-btn {
  background: var(--sage);
  color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--sage) 55%, var(--border));
  box-shadow: var(--shadow-sm);
}
.launch-btn {
  background: var(--sage);
  color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--sage) 55%, var(--border));
  box-shadow: var(--shadow-sm);
}
.secondary-btn {
  background: var(--card);
  color: var(--navy);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.main-btn:hover:not(:disabled), .launch-btn:hover:not(:disabled) {
  filter: brightness(1.04);
  box-shadow: var(--shadow);
}
.secondary-btn:hover:not(:disabled) { background: var(--panel-2); }
.compact-btn, .icon-btn {
  background: var(--card);
  color: var(--navy);
  border: 1px solid var(--border);
  min-height: 44px;
  font-weight: 700;
  font-size: 12px;
  box-shadow: var(--shadow-sm);
}
.compact-btn { padding: 10px 14px; }
.icon-btn { min-width: 44px; font-size: 20px; }
.button-row { display: flex; gap: 12px; flex-wrap: wrap; margin: 18px 0; }
.button-row button { flex: 1; min-width: 150px; margin: 0; }
.input-group { margin-top: 18px; }
.input-group label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
}
.input-group input, .control-input {
  width: 100%;
  min-height: 48px;
  padding: 12px;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 18px;
  box-shadow: inset 0 1px 2px rgba(20, 35, 59, .04);
}
:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }
input:focus-visible { outline-offset: 0; }

/* ==========================================================
   HEADER
   ========================================================== */
.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; font-size: 20px; color: var(--navy); letter-spacing: -.02em; }
.brand::after {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 8px;
  border-radius: 50%;
  background: var(--sage);
  vertical-align: 1px;
}

/* ==========================================================
   HERO
   ========================================================== */
#loginScreen { margin-top: 18px; }
.hero { display: flex; flex-direction: column; align-items: center; gap: 22px; text-align: center; animation: rise .5s ease both; }
.hero-title {
  font-size: clamp(54px, 9vw, 108px);
  font-weight: 800;
  letter-spacing: -.06em;
  line-height: 1;
  margin: 6px 0 0;
  color: var(--navy);
}
.hero-title span { color: #3d8f78; }
.hero-stage {
  width: 100%;
  max-width: 1000px;
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  background: var(--card);
  overflow: hidden;
}
#heroCanvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 960 / 420;
  object-fit: contain;
  object-position: center bottom;
}
.hero-actions { display: flex; gap: 14px; width: 100%; max-width: 560px; }
.hero-actions button { margin: 0; flex: 1; }

/* ==========================================================
   CHECK-IN
   ========================================================== */
.checkin { max-width: 500px; margin: 40px auto; animation: rise .4s ease both; }
.title-card, .briefing-card {
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 32px;
  border-radius: 20px;
}
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

/* ==========================================================
   MISSION CONTROL
   ========================================================== */
.screen-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.screen-header p { overflow-wrap: anywhere; color: var(--muted); }
.total-score-box {
  min-width: 145px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  text-align: center;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.total-score-box span { display: block; color: var(--muted); font-size: 11px; font-weight: 800; }
.total-score-box strong { color: var(--navy); font-size: 30px; }
.total-score-box small { color: var(--muted); }
.progress-panel {
  display: flex;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 18px;
  margin: 22px 0;
  border-radius: var(--radius);
}
.progress-panel progress { flex: 1; min-width: 100px; height: 12px; accent-color: var(--sage); }
.mission-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin: 24px 0; }
.mission-card {
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 8px;
  min-height: 128px;
  padding: 20px;
  text-align: left;
  align-items: center;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.mission-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  background: var(--cyan);
}
.mission-card[data-mission="1"]::before { background: var(--cyan); }
.mission-card[data-mission="2"]::before { background: var(--sage); }
.mission-card[data-mission="3"]::before { background: var(--amber); }
.mission-card[data-mission="4"]::before { background: #6aa8c9; }
.mission-card[data-mission="5"]::before { background: var(--coral); }
.mission-card[data-mission="6"]::before { background: #8fb07a; }
.mission-card:hover:not(:disabled) {
  border-color: var(--cyan);
  box-shadow: var(--shadow-hover);
  background: #fbfeff;
}
.mission-card.completed { border-color: color-mix(in srgb, var(--sage) 70%, var(--border)); background: #f4fbf6; }
.mission-card.completed::before { background: var(--sage); }
.mission-number { grid-row: 1 / 3; color: var(--navy); font-size: 27px; font-weight: 800; }
.mission-content h3 { font-size: 17px; letter-spacing: -.02em; }
.mission-content p { margin-top: 4px; color: var(--muted); font-size: 12px; }
.mission-status { grid-column: 2; color: #3d8f78; font-size: 11px; font-weight: 800; letter-spacing: 1px; }

/* ==========================================================
   BRIEFING
   ========================================================== */
.briefing-card { max-width: 800px; margin: 30px auto; padding: 40px; }
.situation { font-size: 17px; line-height: 1.75; }
.briefing-card .mode-badge { margin-top: 22px; }

/* ==========================================================
   GAME
   ========================================================== */
.game-header { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 12px; }
.header-mission span { display: block; color: #3d8f78; font-size: 11px; font-weight: 800; letter-spacing: 1px; }
.header-mission h1 { font-size: 24px; margin: 4px 0; }
.header-score { text-align: right; }
.header-score span { display: block; color: var(--muted); font-size: 10px; font-weight: 800; }
.header-score strong { color: var(--navy); font-size: 24px; }
.session-strip {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 14px 12px;
  margin-bottom: 12px;
  font-size: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
#timerDisplay { font-variant-numeric: tabular-nums; color: #2f7a62; margin-left: 10px; font-size: 18px; }
.game-layout { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(320px, 1fr); gap: 24px; align-items: start; }
#gameScreen[data-mode="practice"] .session-strip { border-left: 4px solid var(--amber); background: #FFF8EA; }
#gameScreen[data-mode="bonus"] .session-strip { border-left: 4px solid var(--lavender); background: #F4EFFC; }
#gameScreen[data-mode="bonus"] .mode-badge { color: #6d57a8; }

/* ==========================================================
   CANVAS
   ========================================================== */
.canvas-container {
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
#gameCanvas { display: block; width: 100%; height: auto; aspect-ratio: 2 / 1; }
.canvas-container figcaption {
  padding: 14px 16px;
  font-size: 14px;
  border-top: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
}
.readout {
  font: 12px/1.6 Consolas, "Courier New", monospace;
  min-height: 40px;
  padding: 0 16px 14px;
  color: #2f6f6c;
  background: var(--card);
}

/* ==========================================================
   CONTROL PANEL
   ========================================================== */
.mission-info, .control-panel {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 20px;
  margin-bottom: 12px;
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
}
.mission-info .situation { font-size: 16px; line-height: 1.7; }
.answer-row { display: flex; align-items: center; gap: 12px; margin-top: 6px; }
.answer-row input { min-width: 0; }
.answer-row span { min-width: 35px; font-weight: 700; }
.hint-panel {
  padding: 16px;
  border-left: 3px solid var(--amber);
  background: #FFF8EA;
  font-size: 14px;
  line-height: 1.7;
  margin: 12px 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* ==========================================================
   RESULT MODAL
   ========================================================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 35, 59, .28);
  backdrop-filter: blur(8px);
  overflow-y: auto;
}
.modal-card {
  width: 100%;
  max-width: 560px;
  max-height: 100%;
  overflow-y: auto;
  padding: 26px;
  background: var(--card);
  border: 1px solid var(--coral);
  box-shadow: var(--shadow-hover);
  border-radius: 18px;
  animation: rise .3s ease both;
}
.modal.success .modal-card { border-color: var(--sage); }
.modal.warning .modal-card { border-color: var(--amber); }
.modal.fail .modal-card { border-color: var(--coral); }
.modal.bonus .modal-card { border-color: var(--lavender); }
.modal.success .result-stats div { background: #f3faf5; }
.modal.warning .result-stats div { background: #FFF8EA; }
.modal.fail .result-stats div { background: #fdf3f1; }
.modal.bonus .result-stats div { background: #f6f2fc; }
.modal-card h2 { font-size: 23px; }
.modal-card p { font-size: 16px; line-height: 1.7; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.result-stats div {
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 12px;
  border-radius: var(--radius-sm);
}
.result-stats span { display: block; color: var(--muted); font-size: 10px; font-weight: 800; }
.result-stats strong { display: block; margin-top: 4px; font-size: 17px; }

/* ==========================================================
   SUMMARY / LEADERBOARD
   ========================================================== */
.table-wrap {
  overflow-x: auto;
  margin: 24px 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--shadow-sm);
}
table { width: 100%; border-collapse: collapse; background: var(--card); font-size: 14px; }
th, td { text-align: left; padding: 16px 14px; border-bottom: 1px solid var(--border); }
th { background: var(--panel-2); font-size: 11px; letter-spacing: 1px; color: var(--muted); }
td small { display: block; color: var(--muted); }
#leaderboardRows td:nth-child(2) { max-width: 260px; overflow-wrap: anywhere; }

/* ==========================================================
   BONUS
   ========================================================== */
.bonus-bar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  background: #F4EFFC;
  color: #6d57a8;
  border: 1px solid var(--lavender);
  padding: 16px 20px;
  font: 800 12px "Segoe UI", system-ui, sans-serif;
  margin: 24px 0;
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
}
dialog {
  margin: auto;
  max-width: 540px;
  width: calc(100% - 32px);
  padding: 30px;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--lavender);
  box-shadow: var(--shadow-hover);
  border-radius: 18px;
}
dialog::backdrop { background: rgba(20, 35, 59, .32); backdrop-filter: blur(8px); }
dialog h2 { font-size: 26px; margin: 22px 0; color: #6d57a8; }
.site-footer {
  margin-top: 30px;
  padding: 18px 0;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 1px;
}

/* ==========================================================
   RESPONSIVE
   ========================================================== */
@media (max-width: 1440px) {
  #app { max-width: 1180px; }
}
@media (max-width: 1024px) {
  #app { padding: 18px 22px; }
  .game-layout { grid-template-columns: minmax(0, 1.1fr) minmax(280px, 1fr); gap: 18px; }
}
@media (max-width: 900px) {
  #app { padding: 16px 20px; }
  .game-layout { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .hero-title { font-size: clamp(44px, 12vw, 72px); }
  .hero-actions { max-width: 100%; }
}
@media (max-width: 600px) {
  #app { padding: 12px 14px; }
  .screen { margin: 18px auto; }
  .hero-title { letter-spacing: -.05em; }
  #heroCanvas {
    aspect-ratio: 960 / 420;
    object-fit: contain;
    object-position: center bottom;
  }
  .hero-actions { flex-direction: column; }
  .title-card, .briefing-card { padding: 22px 16px; }
  .mission-list { grid-template-columns: 1fr; gap: 12px; }
  .mission-card { grid-template-columns: 40px 1fr; padding: 16px; }
  .game-header { grid-template-columns: 44px 1fr; }
  .header-score { grid-column: 2; text-align: left; display: flex; gap: 10px; align-items: center; }
  .header-mission h1 { font-size: 20px; }
  .result-stats { grid-template-columns: 1fr; }
  .button-row { flex-direction: column; }
  .bonus-bar { flex-direction: column; }
  th, td { padding: 12px 10px; font-size: 12px; }
  .modal { align-items: flex-end; padding: 8px; }
}
@media (max-width: 430px) {
  #app { padding: 10px 12px; }
  .hero-stage { border-radius: 16px; }
}
@media (max-width: 390px), (max-width: 360px) {
  .brand { font-size: 18px; }
  .hero-title { font-size: clamp(40px, 14vw, 56px); }
}

/* ==========================================================
   ACCESSIBILITY
   ========================================================== */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
