:root {
  color-scheme: light;
  --bg: #eef4f8;
  --surface: #ffffff;
  --ink: #101827;
  --muted: #4b5f7a;
  --line: #d4dfec;
  --accent: #0f766e;
  --accent-2: #7c3aed;
  --shadow: 0 16px 36px rgba(15, 23, 42, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
}

body.game-control { --bg: #e8f3f1; --surface: #fbfffe; background: linear-gradient(135deg, #dff3ef 0%, #f7fbff 48%, #ece7ff 100%); }
body.game-packet { --bg: #eef5ff; --surface: #fbfdff; background: linear-gradient(135deg, #e4efff 0%, #f8fbff 52%, #fff3d8 100%); }
body.game-islands { --bg: #e8f7f2; --surface: #fcfffd; background: linear-gradient(135deg, #d9f6ea 0%, #e9fbff 48%, #fff8df 100%); }
body.game-detective { --bg: #f7efe6; --surface: #fffdf8; background: linear-gradient(135deg, #f9ead6 0%, #fffaf1 52%, #f2e3d0 100%); }
body.game-court { --bg: #f4ede8; --surface: #fffdfb; background: linear-gradient(135deg, #f1e2d8 0%, #fff9f2 52%, #e8eeff 100%); }
body.game-debug { --bg: #eef0ff; --surface: #fcfcff; background: linear-gradient(135deg, #e7e9ff 0%, #f9fbff 52%, #e5faed 100%); }

button, input { font: inherit; }

button {
  border: 0;
  border-radius: 8px;
  padding: 12px 15px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 850;
  cursor: pointer;
}

button:hover { filter: brightness(1.05); }
button:focus, input:focus { outline: 3px solid color-mix(in srgb, var(--accent) 28%, transparent); outline-offset: 2px; }

.app-header, footer {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 28px 0 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  min-width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-weight: 950;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: clamp(1.8rem, 4vw, 3.35rem); line-height: 1; }
h2 { font-size: 1.24rem; margin-bottom: 12px; }
h3 { font-size: 1rem; margin-bottom: 6px; }
p, small, summary, li { color: var(--muted); }
strong { color: var(--ink); }
.fantasy-line { max-width: 760px; margin: 5px 0 0; font-size: 0.98rem; }
.verb-line { margin-bottom: 0; }

nav { display: flex; flex-wrap: wrap; gap: 12px; }
nav a { color: var(--muted); text-decoration: none; font-weight: 850; }
nav a:hover { color: var(--accent); }

.layout {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
}

.stage, .panel, .cards-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stage {
  padding: 18px;
  min-width: 0;
}

.stage-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 14px;
}

.status-pill {
  display: inline-flex;
  border-radius: 999px;
  padding: 7px 11px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 13%, white);
  font-weight: 950;
  margin-bottom: 10px;
}

.timer {
  text-align: right;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  min-width: 128px;
}

#timerValue {
  display: block;
  font-size: 2rem;
  line-height: 1;
  font-weight: 950;
}

canvas {
  width: 100%;
  aspect-ratio: 16 / 9;
  display: block;
  border-radius: 12px;
  background: #0f172a;
  border: 3px solid color-mix(in srgb, var(--accent) 28%, #ffffff);
}

.arena-frame {
  position: relative;
  overflow: hidden;
  border-radius: 14px;
  background: #0f172a;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12);
}

.hud-strip {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  pointer-events: none;
}

.hud-strip span, .phase-rail span, .mechanic-panel span {
  border: 1px solid color-mix(in srgb, var(--accent) 38%, #ffffff);
  border-radius: 999px;
  background: rgba(255,255,255,0.9);
  color: var(--ink);
  padding: 7px 10px;
  font-weight: 900;
  font-size: 0.86rem;
}

.phase-rail {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  pointer-events: none;
}

.phase-rail span {
  opacity: 0.72;
}

.phase-rail span.active {
  opacity: 1;
  background: var(--accent-2);
  color: #fff;
}

.mechanic-panel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin: 12px 0 14px;
  padding: 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 26%, var(--line));
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 7%, #ffffff);
}

.mechanic-panel p {
  margin: 0;
}

.mission-card {
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: 8px;
  padding: 16px;
  margin: 14px 0;
  background: #fbfdff;
}

.game-control .stage { border-radius: 10px; background: linear-gradient(180deg, #ffffff 0%, #f2fffb 100%); }
.game-control .arena-frame { border: 4px solid #0f766e; }
.game-control .brand-mark { border-radius: 14px; }
.game-control .mission-card { border-left-color: #7c3aed; }

.game-packet .stage { background: linear-gradient(180deg, #ffffff 0%, #f3f8ff 100%); }
.game-packet .arena-frame { border: 4px solid #2563eb; }
.game-packet .brand-mark { border-radius: 999px; background: #1d4ed8; }
.game-packet .mission-card { border-left-color: #f59e0b; }

.game-islands .stage { border-radius: 26px 10px 26px 10px; background: linear-gradient(180deg, #ffffff 0%, #effdf8 100%); }
.game-islands .arena-frame { border: 4px solid #047857; border-radius: 28px; }
.game-islands .brand-mark { border-radius: 18px 999px 999px 18px; background: #047857; }
.game-islands .mission-card { border-left-color: #0891b2; }

.game-detective .stage { background: linear-gradient(180deg, #fffdf7 0%, #fbf0df 100%); }
.game-detective .arena-frame { border: 4px solid #9a3412; border-radius: 10px; }
.game-detective .brand-mark { border-radius: 6px; background: #7f1d1d; }
.game-detective .mission-card { border-left-color: #be123c; background: #fffaf1; }

.game-court .stage { background: linear-gradient(180deg, #fffdfb 0%, #f7eee7 100%); }
.game-court .arena-frame { border: 4px double #7c2d12; }
.game-court .brand-mark { border-radius: 50% 50% 8px 8px; background: #7c2d12; }
.game-court .mission-card { border-left-color: #1d4ed8; }

.game-debug .stage { background: linear-gradient(180deg, #ffffff 0%, #f2f4ff 100%); }
.game-debug .arena-frame { border: 4px solid #4f46e5; box-shadow: 0 0 0 4px rgba(79,70,229,0.12); }
.game-debug .brand-mark { border-radius: 10px; background: #312e81; }
.game-debug .mission-card { border-left-color: #16a34a; }

.deliverable, .criterion { margin-bottom: 6px; color: var(--ink); }

.teacher-panel {
  display: grid;
  gap: 18px;
  align-content: start;
}

.panel, .cards-section { padding: 18px; }
.teacher-guide ul { padding-left: 18px; margin: 0; }
.teacher-guide li + li { margin-top: 8px; }

.team-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.controls.compact { margin: 10px 0; }
.controls button:nth-child(2n) { background: var(--accent-2); }
.controls button:nth-child(3n) { background: var(--ink); }

.scoreboard, .rubric, .print-grid {
  display: grid;
  gap: 10px;
}

.team-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.team-score {
  font-size: 1.45rem;
  font-weight: 950;
}

.score-actions {
  display: flex;
  gap: 6px;
}

.score-actions button {
  padding: 8px 10px;
  background: var(--ink);
}

.rubric-item, .mission-print-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdff;
}

.print-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.cards-section {
  grid-column: 1 / -1;
  margin-bottom: 28px;
}

footer { padding: 0 0 32px; }

.projector {
  --bg: #e9f1f6;
  --ink: #07111f;
}

.projector .layout { grid-template-columns: 1fr; }
.projector .teacher-panel { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.projector button { padding: 14px 18px; font-size: 1.06rem; }
.projector .stage { border-width: 2px; }
.projector .status-pill, .projector h2 { font-size: 1.35rem; }
.projector #timerValue { font-size: 2.45rem; }
.projector .arena-frame canvas { min-height: 62vh; object-fit: cover; }
.projector .mechanic-panel { grid-template-columns: 1fr; }

@media (max-width: 920px) {
  .app-header, .layout { width: min(100% - 20px, 1240px); }
  .app-header, .stage-toolbar { align-items: stretch; flex-direction: column; }
  .layout, .projector .teacher-panel, .print-grid { grid-template-columns: 1fr; }
  .timer { text-align: left; }
  .team-form { grid-template-columns: 1fr; }
  .mechanic-panel { grid-template-columns: 1fr; }
  .hud-strip, .phase-rail { position: static; padding: 10px; background: #101827; }
  .hud-strip span, .phase-rail span { font-size: 0.78rem; }
}

@media print {
  .app-header, .stage, .teacher-panel, footer { display: none; }
  body { background: #fff; }
  .layout, .cards-section, .print-grid { display: block; width: 100%; box-shadow: none; border: 0; }
  .mission-print-card { break-inside: avoid; margin-bottom: 12px; }
}
