:root {
  color-scheme: light;
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-strong: #f0f7f5;
  --ink: #171918;
  --muted: #68706d;
  --line: #d9ddd7;
  --line-strong: #b8c5bf;
  --teal: #0f766e;
  --teal-dark: #0b4f49;
  --red: #b42318;
  --amber: #a15c00;
  --green: #247a3c;
  --blue: #315f9b;
  --shadow: 0 18px 45px rgba(27, 31, 35, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

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

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: 20px;
}

.topbar {
  align-items: center;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  margin: 0 auto 18px;
  max-width: 1480px;
}

.eyebrow,
.section-kicker,
.scenario-overline,
.input-label,
.toolbar-caption {
  margin: 0;
}

.eyebrow,
.section-kicker,
.scenario-overline {
  color: var(--teal-dark);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar h1 {
  font-size: 1.85rem;
  line-height: 1.15;
  margin: 4px 0 0;
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

.topbar-button {
  min-height: 42px;
}

.icon-button {
  align-items: center;
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 8px;
  color: #fff;
  display: inline-flex;
  font-size: 1.2rem;
  font-weight: 800;
  height: 42px;
  justify-content: center;
  width: 42px;
}

.workspace {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(230px, 290px) minmax(420px, 1fr) minmax(250px, 320px);
  margin: 0 auto;
  max-width: 1480px;
}

.scenario-select {
  margin: 0 auto;
  max-width: 980px;
}

.scenario-select-heading {
  margin: 34px 0 18px;
}

.scenario-select-heading h2 {
  font-size: 1.8rem;
  line-height: 1.15;
  margin: 5px 0 8px;
}

.scenario-select-heading p:last-child {
  color: var(--muted);
  line-height: 1.55;
  margin: 0;
}

.scenario-cards {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.scenario-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--ink);
  display: grid;
  gap: 8px;
  min-height: 170px;
  padding: 18px;
  text-align: left;
  transition:
    border-color 140ms ease,
    box-shadow 140ms ease,
    transform 140ms ease;
}

.scenario-card:hover {
  border-color: var(--teal);
  box-shadow: 0 16px 34px rgba(15, 118, 110, 0.12);
  transform: translateY(-2px);
}

.scenario-card.cleared {
  border-color: #8fbea3;
}

.scenario-card-header {
  align-items: start;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.scenario-card-title {
  color: var(--teal-dark);
  font-size: 1.3rem;
  font-weight: 900;
  line-height: 1.15;
}

.scenario-card-badge {
  background: #e7f5ec;
  border: 1px solid #b7d8c4;
  border-radius: 999px;
  color: var(--green);
  flex: 0 0 auto;
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1;
  padding: 6px 8px;
}

.scenario-card-meta {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
}

.scenario-card-score {
  background: #f5f8f7;
  border: 1px solid #d7e3df;
  border-radius: 8px;
  color: #27302d;
  font-size: 0.78rem;
  font-weight: 850;
  line-height: 1.35;
  padding: 7px 9px;
}

.scenario-card-summary {
  color: #303936;
  font-size: 0.95rem;
  line-height: 1.55;
}

.dossier-panel,
.play-panel,
.status-panel {
  min-width: 0;
}

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

.dossier-panel,
.status-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel-block {
  padding: 16px;
}

.section-heading {
  display: grid;
  gap: 3px;
}

.section-heading h2 {
  font-size: 1.3rem;
  line-height: 1.15;
  margin: 0;
}

.section-heading.compact h2 {
  font-size: 1rem;
}

.route-map {
  background: #edf4f2;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: block;
  margin: 14px 0;
  max-width: 100%;
  width: 100%;
}

.facts-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.facts-list div {
  align-items: baseline;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding-top: 8px;
}

.facts-list dt {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.facts-list dd {
  font-weight: 800;
  margin: 0;
  text-align: right;
}

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

.evidence-list li {
  align-items: start;
  background: var(--surface-strong);
  border-left: 4px solid var(--teal);
  border-radius: 6px;
  color: #1d3d39;
  display: grid;
  font-size: 0.9rem;
  line-height: 1.4;
  min-height: 36px;
  padding: 8px 10px;
}

.evidence-list li.empty {
  background: #f7f7f4;
  border-left-color: var(--line-strong);
  color: var(--muted);
}

.play-panel {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.mission-meta {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: max-content minmax(130px, 1fr) max-content;
}

#phaseLabel,
#progressText {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.progress-track {
  background: #ecece7;
  border-radius: 999px;
  height: 9px;
  overflow: hidden;
}

.progress-track span {
  background: var(--teal);
  display: block;
  height: 100%;
  transition: width 180ms ease;
  width: 12%;
}

.mobile-hud {
  display: none;
}

.scenario-surface {
  background: #fbfbf8;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 250px;
  padding: 18px;
}

.scenario-surface h2 {
  font-size: 1.55rem;
  line-height: 1.2;
  margin: 6px 0 10px;
}

#nodeText {
  color: #2f3734;
  font-size: 1rem;
  line-height: 1.72;
  margin: 0;
  white-space: pre-line;
}

.branch-context {
  background: #fffaf1;
  border: 1px solid #ead8b5;
  border-left: 4px solid var(--amber);
  border-radius: 8px;
  margin-top: 16px;
  padding: 13px 14px;
}

.branch-context-label {
  color: var(--amber);
  font-size: 0.74rem;
  font-weight: 900;
  margin: 0 0 5px;
  text-transform: uppercase;
}

.branch-context h3 {
  font-size: 1rem;
  line-height: 1.35;
  margin: 0 0 7px;
}

.branch-context p {
  color: #3e3320;
  font-size: 0.92rem;
  line-height: 1.58;
  margin: 0;
  white-space: pre-line;
}

.branch-context-terminal {
  background: #2a241b;
  border-radius: 6px;
  color: #f5e8c8;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.8rem;
  line-height: 1.48;
  margin: 10px 0 0;
  overflow-x: auto;
  padding: 10px;
  white-space: pre-wrap;
}

.terminal-output {
  background: #161a19;
  border-radius: 8px;
  color: #d7f3e8;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.84rem;
  line-height: 1.55;
  margin: 16px 0 0;
  min-height: 118px;
  overflow-x: auto;
  padding: 14px;
  white-space: pre-wrap;
}

.input-label {
  color: #27302d;
  font-size: 0.9rem;
  font-weight: 800;
  margin-bottom: 7px;
}

button:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.22);
  outline-offset: 2px;
}

.primary-action,
.secondary-action,
.choice-button {
  border-radius: 8px;
  font-weight: 800;
}

.primary-action {
  background: var(--teal);
  border: 1px solid var(--teal);
  color: #fff;
  min-height: 48px;
  padding: 0 18px;
  white-space: nowrap;
}

.secondary-action {
  background: #fff;
  border: 1px solid var(--line-strong);
  color: var(--teal-dark);
  min-height: 40px;
  padding: 0 14px;
}

.choices-region {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.clear-banner {
  align-items: center;
  background: var(--surface-strong, #effaf3);
  border: 1px solid #b7d8c4;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 16px;
  padding: 24px 18px;
  text-align: center;
}

.clear-banner-emoji {
  font-size: 2.4rem;
  line-height: 1;
}

.clear-banner-title {
  color: var(--teal-dark);
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.clear-banner-text {
  color: var(--ink, #1b1f23);
  font-size: 0.98rem;
}

.clear-banner-score {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.clear-banner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 10px;
}

.choice-toolbar {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 12px;
}

.toolbar-caption {
  color: var(--muted);
  font-size: 0.86rem;
}

.choice-tree-root {
  align-items: center;
  background: var(--surface-strong);
  border: 1px solid #c7d8d2;
  border-radius: 8px;
  color: var(--teal-dark);
  display: inline-flex;
  font-size: 0.92rem;
  font-weight: 900;
  line-height: 1.3;
  margin-bottom: 0;
  min-height: 38px;
  padding: 8px 12px;
}

.choice-tree-root::before {
  color: var(--teal);
  content: "●";
  font-size: 0.72rem;
  margin-right: 8px;
}

.choice-grid {
  border-left: 2px solid var(--line-strong);
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr;
  margin-left: 18px;
  padding-left: 18px;
  padding-top: 10px;
}

.choice-button {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  display: grid;
  gap: 10px;
  grid-template-columns: 28px minmax(0, 1fr);
  min-height: 58px;
  padding: 10px 12px;
  position: relative;
  text-align: left;
  transition:
    border-color 140ms ease,
    transform 140ms ease,
    box-shadow 140ms ease;
}

.choice-button::before {
  background: var(--line-strong);
  content: "";
  height: 2px;
  left: -19px;
  position: absolute;
  top: 50%;
  width: 18px;
}

.choice-button:hover {
  border-color: var(--teal);
  box-shadow: 0 10px 24px rgba(15, 118, 110, 0.12);
  transform: translateX(2px);
}

.choice-button:disabled {
  background: #f2f2ee;
  border-color: var(--line);
  box-shadow: none;
  color: var(--muted);
  cursor: not-allowed;
  transform: none;
}

.choice-number {
  align-items: center;
  background: #edf4f2;
  border: 1px solid #c7d8d2;
  border-radius: 999px;
  color: var(--teal-dark);
  display: inline-flex;
  font-size: 0.8rem;
  height: 24px;
  justify-content: center;
  width: 24px;
}

.choice-title {
  font-size: 0.98rem;
  line-height: 1.35;
  min-width: 0;
  overflow-wrap: anywhere;
}

.score-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 12px;
}

.score-tile {
  background: #f8f8f5;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  min-height: 70px;
  padding: 10px;
}

.score-tile span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.score-tile strong {
  font-size: 1.35rem;
  line-height: 1;
}

.feedback-box {
  background: #fffaf1;
  border: 1px solid #ead8b5;
  border-radius: 8px;
  color: #3e3320;
  font-size: 0.92rem;
  line-height: 1.55;
  margin-top: 12px;
  min-height: 145px;
  padding: 12px;
}

.feedback-box p {
  margin: 0 0 10px;
}

.feedback-box p:last-child {
  margin-bottom: 0;
}

.decision-tree {
  background: #fbfbf8;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 12px;
  max-height: 330px;
  overflow: auto;
  padding: 10px;
}

.tree-node {
  min-width: 0;
}

.tree-row {
  align-items: center;
  border-radius: 6px;
  color: #323936;
  display: grid;
  gap: 7px;
  grid-template-columns: 18px minmax(0, 1fr) max-content;
  min-height: 32px;
  padding: 5px 7px;
}

.tree-row.state {
  font-weight: 850;
}

.tree-row.branch {
  color: #4d5652;
  font-size: 0.86rem;
}

.tree-row.current {
  background: var(--surface-strong);
  color: var(--teal-dark);
}

.tree-marker {
  color: var(--line-strong);
  font-size: 0.78rem;
}

.tree-label {
  line-height: 1.3;
  min-width: 0;
  overflow-wrap: anywhere;
}

.tree-children {
  border-left: 1px solid var(--line-strong);
  margin-left: 16px;
  padding-left: 9px;
}

.tree-outcome {
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 900;
  padding: 3px 6px;
  white-space: nowrap;
}

.tree-outcome.good {
  background: #e7f4e8;
  color: var(--green);
}

.tree-outcome.okay {
  background: #eef3fb;
  color: var(--blue);
}

.tree-outcome.bad {
  background: #fae9e6;
  color: var(--red);
}

.feedback-tag {
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.76rem;
  font-weight: 900;
  margin-bottom: 8px;
  padding: 4px 8px;
}

.feedback-tag.good {
  background: #e7f4e8;
  color: var(--green);
}

.feedback-tag.okay {
  background: #eef3fb;
  color: var(--blue);
}

.feedback-tag.bad {
  background: #fae9e6;
  color: var(--red);
}

.action-log {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  max-height: 310px;
  overflow: auto;
  padding-left: 20px;
}

.action-log li {
  color: #333a37;
  font-size: 0.86rem;
  line-height: 1.4;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(220px, 280px) minmax(420px, 1fr);
  }

  .status-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 960px) {
  .workspace {
    grid-template-columns: minmax(210px, 260px) minmax(0, 1fr);
  }

  .status-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

  .topbar {
    align-items: start;
    gap: 12px;
    margin-bottom: 12px;
  }

  .topbar h1 {
    font-size: 1.25rem;
  }

  .workspace,
  .status-panel,
  .scenario-cards {
    grid-template-columns: 1fr;
  }

  .workspace {
    gap: 12px;
  }

  .play-panel {
    order: 1;
  }

  .dossier-panel {
    order: 2;
  }

  .status-panel {
    order: 3;
  }

  .panel-block,
  .play-panel {
    border-radius: 8px;
    box-shadow: 0 10px 24px rgba(27, 31, 35, 0.06);
  }

  .panel-block,
  .play-panel,
  .scenario-surface {
    padding: 12px;
  }

  .scenario-surface {
    min-height: auto;
  }

  .scenario-surface h2 {
    font-size: 1.22rem;
  }

  #nodeText {
    font-size: 0.95rem;
    line-height: 1.62;
  }

  .mission-meta {
    grid-template-columns: minmax(0, 1fr) max-content;
    gap: 7px 10px;
  }

  .progress-track {
    grid-column: 1 / -1;
  }

  .route-map {
    max-height: 140px;
    object-fit: cover;
  }

  .terminal-output,
  .branch-context-terminal {
    font-size: 0.74rem;
    line-height: 1.48;
    max-height: 230px;
    padding: 10px;
  }

  .branch-context {
    margin-top: 12px;
    padding: 11px 12px;
  }

  .branch-context h3 {
    font-size: 0.96rem;
  }

  .branch-context p {
    font-size: 0.88rem;
  }

  .choice-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .secondary-action {
    align-self: start;
  }

  .choice-tree-root {
    display: flex;
    font-size: 0.88rem;
    width: 100%;
  }

  .choice-grid {
    margin-left: 12px;
    padding-left: 12px;
  }

  .choice-button {
    gap: 8px;
    grid-template-columns: 26px minmax(0, 1fr);
    min-height: 54px;
    padding: 10px;
  }

  .choice-button::before {
    left: -13px;
    width: 12px;
  }

  .choice-title {
    font-size: 0.94rem;
  }

  .feedback-box {
    min-height: auto;
  }

  .decision-tree,
  .action-log {
    max-height: 260px;
  }

  .tree-row {
    grid-template-columns: 15px minmax(0, 1fr);
  }

  .tree-outcome {
    grid-column: 2;
    justify-self: start;
    margin-top: 2px;
  }

  .tree-children {
    margin-left: 11px;
    padding-left: 8px;
  }

  .choice-grid {
    grid-template-columns: 1fr;
  }
}

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

  .topbar {
    align-items: center;
  }

  .topbar h1 {
    font-size: 1.08rem;
    line-height: 1.25;
  }

  .eyebrow,
  .section-kicker,
  .scenario-overline {
    font-size: 0.68rem;
  }

  .icon-button {
    flex: 0 0 auto;
    height: 38px;
    width: 38px;
  }

  .facts-list div {
    align-items: start;
    flex-direction: column;
    gap: 3px;
  }

  .facts-list dd {
    text-align: left;
  }

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

  .score-tile {
    min-height: 62px;
    padding: 9px;
  }

  .score-tile strong {
    font-size: 1.18rem;
  }

  .scenario-select-heading {
    margin-top: 18px;
  }

  .scenario-select-heading h2 {
    font-size: 1.28rem;
  }

  .scenario-card {
    min-height: 150px;
    padding: 14px;
  }

  .choice-toolbar .secondary-action {
    width: 100%;
  }
}

@media (max-width: 640px) {
  /* スマホ: 1画面固定をやめ、全情報を縦スクロールで表示する */
  .app-shell {
    min-height: 100dvh;
    padding: 10px;
  }

  .topbar {
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
  }

  .topbar .eyebrow {
    display: none;
  }

  .topbar h1 {
    font-size: 1.05rem;
    line-height: 1.25;
    margin: 0;
  }

  .topbar-actions {
    gap: 6px;
  }

  .topbar-button {
    font-size: 0.78rem;
    min-height: 36px;
    padding: 0 10px;
    white-space: nowrap;
  }

  .icon-button {
    flex: 0 0 auto;
    font-size: 1rem;
    height: 36px;
    width: 36px;
  }

  .play-panel {
    gap: 12px;
    padding: 12px;
  }

  .mission-meta {
    gap: 6px 10px;
    grid-template-columns: minmax(0, 1fr) max-content;
  }

  #phaseLabel,
  #progressText {
    font-size: 0.78rem;
  }

  .progress-track {
    grid-column: 1 / -1;
  }

  /* 簡易スコアはスクロールせず一目で見えるよう上部に残す */
  .mobile-hud {
    display: grid;
    gap: 6px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .mobile-hud span {
    align-items: center;
    background: #f5f8f7;
    border: 1px solid #d7e3df;
    border-radius: 8px;
    color: var(--muted);
    display: flex;
    font-size: 0.72rem;
    font-weight: 900;
    gap: 4px;
    justify-content: center;
    min-height: 32px;
  }

  .mobile-hud strong {
    color: var(--ink);
    font-size: 0.82rem;
    line-height: 1;
  }

  .scenario-surface {
    min-height: auto;
    padding: 14px;
  }

  .scenario-surface h2 {
    font-size: 1.18rem;
  }

  #nodeText {
    font-size: 0.92rem;
    line-height: 1.62;
  }

  .terminal-output {
    font-size: 0.74rem;
    line-height: 1.5;
    padding: 11px;
  }

  .branch-context-terminal {
    font-size: 0.72rem;
  }

  .choices-region {
    border-top: 1px solid var(--line);
    padding-top: 12px;
  }

  .choice-button {
    gap: 8px;
    grid-template-columns: 26px minmax(0, 1fr);
    min-height: 52px;
    padding: 10px;
  }

  .choice-number {
    font-size: 0.76rem;
    height: 24px;
    width: 24px;
  }

  .choice-title {
    font-size: 0.92rem;
    line-height: 1.3;
  }
}
