:root {
  color-scheme: light;
  --bg: #f4f7f6;
  --surface: #ffffff;
  --ink: #132321;
  --muted: #60716d;
  --line: #d9e2df;
  --primary: #0c5a52;
  --primary-soft: #e5f2ef;
  --warn: #a84e08;
  --danger: #a52222;
  --accent: #234b8c;
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "YuGothic", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body.large-text {
  font-size: 125%;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  max-width: 1180px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 16px;
}

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

.eyebrow {
  margin: 0 0 2px;
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  line-height: 1.15;
}

h2 {
  margin: 0 0 14px;
  font-size: 1.15rem;
}

h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.size-toggle,
.icon-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--primary);
  border-radius: var(--radius);
  padding: 8px 11px;
  font-weight: 700;
}

.tabbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 6px;
  padding: 8px 0 14px;
  background: var(--bg);
}

.tabbar a {
  min-height: 42px;
  display: grid;
  place-items: center;
  text-decoration: none;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-weight: 700;
}

.tabbar a.active {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 14px;
}

.status-band {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  background: #163c38;
  color: #fff;
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.status-label {
  display: block;
  color: #b7d4ce;
  font-size: 0.8rem;
  font-weight: 700;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(150px, 220px) minmax(0, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.toolbar label span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.toolbar input,
.toolbar select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 10px 12px;
}

.layout-two {
  display: grid;
  grid-template-columns: minmax(300px, 0.8fr) minmax(0, 1.2fr);
  gap: 14px;
  align-items: start;
}

.task-list,
.topic-list,
.inventory-list,
.source-list,
.role-list,
.map-place-list {
  display: grid;
  gap: 10px;
}

.task-card,
.topic-card,
.inventory-card,
.source-card,
.report-card {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: inherit;
  padding: 12px;
}

button.task-card,
button.topic-card {
  cursor: pointer;
}

.task-card.active,
.topic-card.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 8px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 700;
}

.badge.danger {
  background: #fde8e8;
  color: var(--danger);
}

.muted {
  color: var(--muted);
}

.danger-box {
  border-left: 5px solid var(--danger);
  background: #fff1f1;
  padding: 10px 12px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  color: #681717;
  font-weight: 700;
}

.check-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}

.check-list li {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 8px;
  align-items: start;
}

.check-list input {
  width: 22px;
  height: 22px;
  margin: 3px 0 0;
}

.pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.pill-list li {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  background: #fbfcfc;
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.role-intro h2 {
  margin-bottom: 6px;
}

.role-overview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.role-summary {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 10px;
  align-items: start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

.role-summary p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.role-mark,
.role-select-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #173f3a;
  color: #fff;
  font-weight: 800;
}

.role-select {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 10px;
  align-items: center;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  padding: 10px;
  text-align: left;
  cursor: pointer;
}

.role-select.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.role-select strong,
.role-select small {
  display: block;
}

.role-select small {
  color: var(--muted);
}

.role-mission {
  font-weight: 700;
  color: var(--primary);
}

.role-sections {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.role-section {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.role-section ul {
  margin: 0;
  padding-left: 1.2em;
}

.role-section li {
  margin-bottom: 0.4em;
}

.map-layout {
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr);
}

.map-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.map-toolbar button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--primary);
  min-height: 38px;
  padding: 7px 12px;
  font-weight: 800;
}

.map-scroller {
  overflow: auto;
  max-height: min(72vh, 820px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8faf9;
}

.school-map {
  display: block;
  height: auto;
  max-width: none;
}

.school-map.fit {
  width: 100%;
}

.school-map.wide {
  width: 145%;
}

.school-map.full {
  width: 1820px;
}

.map-place-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 12px;
}

.map-place-card p {
  margin: 0;
  color: var(--muted);
}

.quest-layout {
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr);
}

.quest-stage {
  display: grid;
  gap: 12px;
}

#questCanvas {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  image-rendering: pixelated;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #9fcf8c;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  gap: 8px;
  justify-content: center;
}

.dpad button {
  width: 56px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--primary);
  font-weight: 800;
}

.quest-status {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 16px;
  background: #fbfcfc;
}

.quest-location {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.quest-reference {
  margin: 0 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #f8faf9;
}

.quest-reference img {
  display: block;
  width: 100%;
  height: auto;
}

.quest-reference figcaption {
  padding: 8px 10px;
  color: var(--muted);
  font-size: 0.82rem;
  border-top: 1px solid var(--line);
}

.quest-legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.legend-row {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 8px;
  align-items: center;
  min-height: 30px;
}

.legend-row span {
  width: 22px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.source-card a {
  color: var(--primary);
  font-weight: 800;
}

.source-document {
  background: #fff;
}

.source-header,
.source-main {
  width: min(980px, calc(100% - 28px));
  margin: 0 auto;
}

.source-header {
  padding: 24px 0 14px;
  border-bottom: 1px solid var(--line);
}

.source-header a {
  color: var(--primary);
  font-weight: 800;
}

.source-path,
.source-note {
  color: var(--muted);
  margin: 8px 0 0;
}

.source-page {
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.source-page p {
  margin: 0 0 0.85em;
}

.source-page .empty {
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
  margin: 12px 0;
}

table {
  border-collapse: collapse;
  width: 100%;
}

td,
th {
  border: 1px solid var(--line);
  padding: 8px;
  vertical-align: top;
}

.raw-part {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  margin: 8px 0;
}

pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #f8faf9;
  padding: 10px;
  border-radius: var(--radius);
}

@media (max-width: 760px) {
  .app-shell {
    padding: 10px;
  }

  .app-header,
  .status-band {
    grid-template-columns: 1fr;
  }

  .app-header {
    display: grid;
  }

  .tabbar {
    grid-template-columns: repeat(8, minmax(58px, 1fr));
    overflow-x: auto;
  }

  .tabbar a {
    min-width: 58px;
    font-size: 0.85rem;
  }

  .toolbar,
  .layout-two,
  .report-grid,
  .role-overview,
  .role-sections {
    grid-template-columns: 1fr;
  }

  .quest-legend {
    grid-template-columns: 1fr;
  }

  .map-scroller {
    max-height: 68vh;
  }

  .school-map.wide {
    width: 180%;
  }
}
