/*
  Robot Code Adventure
  File: css/style.css
  Version: v0.7.0
  History:
  - v0.1.0 (2026-04-14): 初期版のスマホ縦画面向けスタイルを追加
  - v0.2.0 (2026-04-14): 会話画面、章表示、黒背景メッセージウィンドウ、進行UIを追加
  - v0.3.0 (2026-04-14): タイトル、プロローグ、ステージ選択、Python風コードUIへ再設計
  - v0.3.1 (2026-04-14): 結果モーダルが残留しないよう hidden 時の表示と操作を明確化
  - v0.3.2 (2026-04-14): 会話オーバーレイの hidden 時の消去を明示し、残留防止を補強
  - v0.4.1 (2026-04-14): ストーリー一覧画面と再読画面のスタイルを追加
  - v0.4.2 (2026-04-14): スマホ向けに作戦マップの sticky 表示と縮小レイアウトを追加
  - v0.4.4 (2026-04-14): ストーリー再読用の全文一覧表示スタイルを追加
  - v0.5.1 (2026-04-14): ストーリー画面を章ごとの読み物レイアウトへ再設計
  - v0.7.0 (2026-04-15): build / read / fix の学習ステージ表示と固定コード表示スタイルを追加
*/
:root {
  --bg-top: #102030;
  --bg-bottom: #24364d;
  --panel: rgba(247, 243, 231, 0.95);
  --panel-border: rgba(230, 219, 194, 0.35);
  --text-main: #18242e;
  --text-soft: #5a6773;
  --accent: #d9b562;
  --accent-strong: #9d7330;
  --accent-soft: #f3e7c5;
  --subtle: #dde7ed;
  --danger: #d15a54;
  --grid-line: rgba(53, 73, 92, 0.22);
  --tile-floor: #f8f2e8;
  --tile-wall: #6b7a84;
  --tile-hole: #24303b;
  --tile-goal: #f0c85f;
  --tile-enemy: #cc6859;
  --robot: #4a95d9;
  --message-bg: #090909;
  --message-text: #f8f8f8;
  --message-sub: rgba(255, 255, 255, 0.72);
  --code-bg: #19242f;
  --code-line: #d7f0e2;
  --code-faint: #8ea0af;
  --shadow: 0 20px 44px rgba(0, 0, 0, 0.22);
  --radius-panel: 20px;
  --radius-button: 16px;
  --font-main: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  --font-code: "SFMono-Regular", "Menlo", "Consolas", monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-main);
  color: var(--text-main);
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.12), transparent 22%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
}

button {
  font: inherit;
}

.app-shell {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: 18px 14px 28px;
}

.screen.hidden,
.hidden {
  display: none;
}

.screen-kicker,
.panel-kicker,
.message-kicker,
.speaker-subtitle,
.stage-number {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.screen-kicker,
.panel-kicker,
.stage-number {
  color: #dbe7ef;
}

.title-screen,
.story-screen,
.panel,
.menu-header {
  color: #fff;
}

.title-screen {
  min-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
}

.title-screen h1 {
  margin: 6px 0;
  font-size: 2.2rem;
  line-height: 1.08;
  color: #fff6df;
}

.title-copy,
.menu-copy {
  margin: 0;
  line-height: 1.6;
  color: #d9e4ed;
}

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

.cast-card {
  padding: 14px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
}

.cast-kakeru {
  background: linear-gradient(180deg, rgba(236, 191, 88, 0.25), rgba(255, 255, 255, 0.06));
}

.cast-roca {
  background: linear-gradient(180deg, rgba(100, 168, 226, 0.25), rgba(255, 255, 255, 0.06));
}

.cast-name {
  margin: 0;
  font-weight: 800;
  color: #fff;
}

.cast-copy {
  margin: 6px 0 0;
  color: #d8e5ec;
}

.title-actions,
.story-actions {
  display: grid;
  gap: 10px;
}

.menu-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.menu-header h2 {
  margin: 6px 0 0;
  color: #fff6df;
}

.story-screen {
  min-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.story-reader-header {
  margin-bottom: 18px;
}

.story-speaker-card {
  margin-bottom: 12px;
}

.story-window {
  display: grid;
  gap: 14px;
}

.story-transcript {
  display: grid;
  gap: 14px;
}

.story-archive {
  display: grid;
  gap: 26px;
  margin-top: 18px;
}

.story-article {
  padding: 18px 18px 20px;
  border-radius: 20px;
  background: rgba(10, 18, 28, 0.48);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.story-article-title {
  margin: 0 0 14px;
  color: #fff4d1;
  font-size: 1.24rem;
}

.story-article-body {
  margin: 0 0 12px;
  color: #e4edf4;
  line-height: 1.8;
}

.story-article-body:last-child {
  margin-bottom: 0;
}

.story-transcript-item {
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.story-transcript-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.story-transcript-speaker {
  margin: 0 0 6px;
  color: #ffe4a1;
  font-weight: 800;
}

.story-transcript-text {
  margin: 0;
  color: var(--message-text);
  line-height: 1.65;
}

.panel {
  margin-top: 12px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow);
  color: var(--text-main);
}

.sticky-map-shell {
  position: relative;
  z-index: 1;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-header.compact {
  align-items: center;
}

.panel-header h2,
.result-block h3,
.play-header h2 {
  margin: 4px 0 0;
  color: var(--text-main);
  font-size: 1.08rem;
}

.play-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.stage-story-panel {
  padding: 12px 16px;
}

.story-text {
  margin: 0;
  color: var(--text-soft);
}

.wide-story {
  max-width: 100%;
  text-align: left;
}

.message-window-panel {
  margin-top: 12px;
}

.message-window {
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--message-bg);
  border: 2px solid rgba(255, 255, 255, 0.84);
  box-shadow: 0 14px 26px rgba(0, 0, 0, 0.26);
}

.message-kicker,
.speaker-subtitle {
  color: var(--message-sub);
}

.message-text {
  margin: 6px 0 0;
  min-height: 2.8em;
  line-height: 1.55;
  color: var(--message-text);
  font-weight: 700;
}

.speaker-card {
  display: flex;
  align-items: center;
  gap: 12px;
}

.speaker-portrait {
  width: 66px;
  height: 66px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  font-weight: 900;
  font-size: 0.92rem;
  border: 2px solid rgba(255, 255, 255, 0.82);
  color: #17242d;
  background: #d4dde3;
}

.speaker-kakeru {
  background: #f3cb72;
  color: #65480d;
}

.speaker-roca2009 {
  background: #9dc8ec;
  color: #1a4a71;
}

.speaker-roca2020 {
  background: #c9cfe2;
  color: #2b3554;
}

.speaker-system {
  background: #dcdcdc;
  color: #2b2b2b;
}

.speaker-label {
  margin: 0;
  color: #fff;
  font-size: 1rem;
  font-weight: 800;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  aspect-ratio: 1 / 1;
}

.grid-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  border-radius: 14px;
  border: 1px solid var(--grid-line);
  background: var(--tile-floor);
}

.grid-cell.wall {
  background: var(--tile-wall);
}

.grid-cell.goal {
  background: var(--tile-goal);
}

.grid-cell.hole {
  background: var(--tile-hole);
}

.grid-cell.enemy {
  background: var(--tile-enemy);
}

.cell-mark {
  font-size: 1.52rem;
  line-height: 1;
}

.grid-cell.wall .cell-mark,
.grid-cell.hole .cell-mark,
.grid-cell.enemy .cell-mark {
  color: #fff8f5;
}

.grid-cell.goal .cell-mark {
  color: #6c5015;
}

.robot-token {
  position: absolute;
  inset: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: var(--robot);
  color: #fff;
  font-size: 1.35rem;
  font-weight: 800;
}

.code-queue {
  padding: 12px;
  min-height: 170px;
  border-radius: 16px;
  background: var(--code-bg);
  color: var(--code-line);
  font-family: var(--font-code);
}

.reference-code {
  margin: 0 0 12px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(16, 27, 39, 0.88);
  color: #e8f2f8;
  font-family: var(--font-code);
  line-height: 1.55;
  white-space: pre-wrap;
}

.code-line {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.code-line:last-child {
  border-bottom: none;
}

.code-line.active {
  color: #fff6ca;
}

.code-index {
  color: var(--code-faint);
  text-align: right;
}

.code-line.empty {
  display: block;
  color: var(--code-faint);
}

.code-text,
.command-code {
  white-space: pre-wrap;
  word-break: break-word;
}

.queue-count,
.panel-kicker {
  color: var(--text-soft);
}

.queue-actions,
.result-actions,
.command-buttons {
  display: grid;
  gap: 10px;
}

.queue-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 14px;
}

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

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

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

.wide-button {
  grid-column: span 3;
}

.primary-button,
.secondary-button,
.command-button,
.stage-card {
  min-height: 52px;
  border: none;
  border-radius: var(--radius-button);
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease;
  font-weight: 800;
}

.primary-button {
  background: var(--accent);
  color: #35260c;
}

.secondary-button {
  background: var(--subtle);
  color: var(--text-main);
}

.small-button {
  min-height: 42px;
  padding: 0 14px;
}

.command-button {
  padding: 14px 12px;
  border: 1px solid rgba(24, 36, 46, 0.12);
  background: #fffdf7;
  color: var(--text-main);
  text-align: left;
  font-family: var(--font-code);
}

.command-button code {
  font-size: 1rem;
  font-weight: 800;
}

.choice-button.selected {
  border: 2px solid rgba(217, 181, 98, 0.92);
  background: #fff5d8;
}

.command-button small {
  display: block;
  margin-top: 5px;
  color: var(--text-soft);
  font-family: var(--font-main);
  font-size: 0.78rem;
}

.primary-button:disabled,
.secondary-button:disabled,
.command-button:disabled,
.stage-card.locked {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}

.stage-select-list {
  display: grid;
  gap: 16px;
  margin-top: 14px;
}

.chapter-block {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.chapter-title {
  margin: 0 0 12px;
  color: #fff7e4;
}

.stage-cards {
  display: grid;
  gap: 10px;
}

.stage-card {
  width: 100%;
  padding: 14px;
  text-align: left;
  background: #f6efe0;
  color: var(--text-main);
}

.stage-card.locked {
  background: rgba(255, 255, 255, 0.08);
  color: #dbe5ee;
  border: 1px dashed rgba(255, 255, 255, 0.3);
}

.stage-card.current {
  outline: 3px solid rgba(217, 181, 98, 0.72);
}

.stage-card p {
  margin: 0;
}

.stage-card-meta {
  margin-top: 6px;
  color: var(--text-soft);
  font-size: 0.86rem;
}

.stage-card.locked .stage-card-meta {
  color: rgba(255, 255, 255, 0.74);
}

.dialogue-overlay,
.result-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 18px 14px;
  background: rgba(10, 14, 19, 0.68);
  z-index: 20;
}

.dialogue-overlay.hidden,
.result-modal.hidden {
  display: none;
  pointer-events: none;
}

.dialogue-stage,
.result-card {
  width: min(100%, 560px);
}

.dialogue-window {
  display: grid;
  gap: 14px;
}

.result-card {
  padding: 20px;
  border-radius: 24px 24px 16px 16px;
  background: #fffdf7;
  box-shadow: var(--shadow);
}

.result-message {
  margin: 0;
  color: var(--text-soft);
}

.result-block {
  margin-top: 16px;
}

.result-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.result-chip {
  padding: 8px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  font-family: var(--font-code);
  font-weight: 800;
  white-space: pre-wrap;
}

.python-output {
  margin: 10px 0 0;
  padding: 12px;
  min-height: 92px;
  border-radius: 16px;
  background: var(--code-bg);
  color: var(--code-line);
  font-family: var(--font-code);
  line-height: 1.55;
  white-space: pre-wrap;
}

@media (hover: hover) {
  .primary-button:hover,
  .secondary-button:hover,
  .command-button:hover,
  .stage-card:hover {
    transform: translateY(-1px);
  }
}

@media (min-width: 720px) {
  .command-buttons {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 768px) {
  .sticky-map-shell {
    position: sticky;
    top: 8px;
    z-index: 14;
  }

  .sticky-map-shell .game-panel {
    margin-top: 10px;
    padding: 12px;
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.24);
  }

  .sticky-map-shell .panel-header {
    margin-bottom: 8px;
  }

  .sticky-map-shell .panel-header h2 {
    font-size: 1rem;
  }

  .sticky-map-shell .game-grid {
    gap: 4px;
    max-height: 200px;
  }

  .sticky-map-shell .grid-cell {
    min-height: 38px;
    border-radius: 10px;
  }

  .sticky-map-shell .cell-mark {
    font-size: 1.15rem;
  }

  .sticky-map-shell .robot-token {
    inset: 5px;
    border-radius: 9px;
    font-size: 1rem;
  }
}
