:root {
  --bg: #f7faf8;
  --ink: #223044;
  --muted: #5e6a7c;
  --panel: #ffffff;
  --line: #d8e1e8;
  --orange: #f28d35;
  --green: #3fa66b;
  --blue: #4386d9;
  --yellow: #ffd866;
  --red: #e85d62;
  --shadow: 0 12px 28px rgba(31, 45, 61, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans",
    "Yu Gothic", sans-serif;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(247, 250, 248, 0.96)),
    repeating-linear-gradient(90deg, #e6f0ea 0 2px, transparent 2px 96px);
}

button {
  font: inherit;
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 36px;
}

.top-panel,
.mission-panel,
.game-board,
.result-panel {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.top-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 20px 24px;
}

.eyebrow,
.clock-label,
#levelLabel,
#stepCount,
#resultBadge {
  display: block;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 6vw, 3.4rem);
  line-height: 1.05;
}

.score-box {
  min-width: 112px;
  padding: 12px 16px;
  text-align: center;
  background: #edf6ff;
  border: 2px solid #bdd8f4;
  border-radius: 8px;
}

.score-box span {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
}

.score-box strong {
  display: block;
  font-size: 1.35rem;
}

.control-band {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 16px 0;
}

.level-button,
.ghost-button,
.primary-button {
  min-height: 48px;
  border: 2px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

.level-button {
  font-weight: 800;
}

.level-button.is-active {
  background: var(--yellow);
  border-color: #d5a91c;
}

.mission-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: center;
  padding: 22px 24px;
}

.mission-copy h2 {
  margin-top: 6px;
  font-size: clamp(1.45rem, 4vw, 2.5rem);
}

.mission-copy p {
  margin-top: 10px;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.6;
}

.route-plan {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 14px;
}

.route-chip {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 7px 12px;
  border-radius: 8px;
  color: #fff;
  font-weight: 800;
}

.route-chip.orange {
  background: var(--orange);
}

.route-chip.green {
  background: var(--green);
}

.route-chip.blue {
  background: var(--blue);
}

.route-arrow {
  color: var(--muted);
  font-weight: 900;
}

.clock-pair {
  display: flex;
  gap: 14px;
}

.clock-pair > div {
  width: 132px;
  padding: 8px 6px 10px;
  text-align: center;
  background: #f8fbfd;
  border: 2px solid #d7e5ef;
  border-radius: 8px;
}

.clock-pair canvas {
  display: block;
  width: 104px;
  height: 104px;
  margin: 4px auto;
}

.clock-pair strong {
  font-size: 1.25rem;
}

.route-map {
  display: grid;
  gap: 12px;
  margin: 16px 0;
  padding: 18px 20px;
  background: #eef6f3;
  border: 2px solid #cfe1d8;
  border-radius: 8px;
}

.line {
  display: grid;
  grid-template-columns: 118px repeat(3, minmax(0, 1fr));
  align-items: center;
  gap: 10px;
  position: relative;
}

.line::before {
  content: "";
  position: absolute;
  left: calc(118px + 9%);
  right: 9%;
  top: 50%;
  height: 8px;
  border-radius: 999px;
  transform: translateY(-50%);
}

.line-orange::before {
  background: var(--orange);
}

.line-green::before {
  background: var(--green);
}

.line-blue::before {
  background: var(--blue);
}

.line.is-muted {
  opacity: 0.36;
}

.line-name,
.line span {
  position: relative;
  min-height: 42px;
  display: grid;
  place-items: center;
  padding: 7px 8px;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 8px;
  font-weight: 800;
  text-align: center;
}

.line-name {
  color: #fff;
  border-color: transparent;
}

.line-orange .line-name {
  background: var(--orange);
}

.line-green .line-name {
  background: var(--green);
}

.line-blue .line-name {
  background: var(--blue);
}

.game-board {
  padding: 20px 22px 24px;
}

.step-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
}

.step-header h3 {
  margin-top: 4px;
  font-size: 1.55rem;
}

.ghost-button {
  min-width: 100px;
  padding: 0 16px;
  font-weight: 800;
}

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

.choice-card {
  min-height: 164px;
  padding: 16px;
  text-align: left;
  background: #fff;
  border: 3px solid #d7e1e9;
  border-radius: 8px;
  box-shadow: 0 7px 16px rgba(31, 45, 61, 0.08);
  cursor: pointer;
}

.choice-card:hover,
.choice-card:focus-visible {
  border-color: #2f7bd3;
  outline: 3px solid rgba(67, 134, 217, 0.25);
}

.choice-card.is-selected {
  background: #edf7ff;
  border-color: #2f7bd3;
}

.choice-line {
  display: inline-block;
  margin-bottom: 12px;
  padding: 5px 9px;
  color: #fff;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 800;
}

.choice-line.orange {
  background: var(--orange);
}

.choice-line.green {
  background: var(--green);
}

.choice-line.blue {
  background: var(--blue);
}

.choice-main {
  display: grid;
  gap: 8px;
  font-size: 1.2rem;
  font-weight: 800;
}

.choice-note {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.result-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
  padding: 20px 22px;
}

.result-panel h3 {
  margin-top: 4px;
  font-size: 1.5rem;
}

.result-panel p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.55;
}

.result-panel.good {
  border-color: #83c79c;
  background: #f1fbf4;
}

.result-panel.close,
.result-panel.miss {
  border-color: #f2b565;
  background: #fff8eb;
}

.primary-button {
  min-width: 130px;
  padding: 0 18px;
  background: #223044;
  color: #fff;
  border-color: #223044;
  font-weight: 800;
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 20px, 680px);
    padding-top: 12px;
  }

  .top-panel,
  .mission-panel,
  .result-panel {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: stretch;
  }

  .clock-pair {
    justify-content: center;
  }

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

@media (max-width: 560px) {
  .control-band {
    grid-template-columns: 1fr;
  }

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

  .clock-pair > div {
    width: auto;
  }

  .line span {
    font-size: 0.82rem;
    min-height: 50px;
  }

  .line {
    grid-template-columns: 86px repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .line::before {
    left: calc(86px + 7%);
    right: 7%;
    top: 50%;
  }
}

/* iPad layout */
.ipad-page {
  min-height: 100svh;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.ipad-page .app-shell {
  width: min(100% - 40px, 1180px);
  padding: max(20px, env(safe-area-inset-top)) 0 max(32px, env(safe-area-inset-bottom));
}

.ipad-page button {
  min-height: 58px;
}

.ipad-page .top-panel,
.ipad-page .mission-panel,
.ipad-page .game-board,
.ipad-page .result-panel {
  border-width: 3px;
}

.ipad-page .level-button,
.ipad-page .ghost-button,
.ipad-page .primary-button,
.ipad-page .choice-card {
  font-size: 1.08rem;
}

.ipad-page .choice-grid {
  gap: 16px;
}

.ipad-page .choice-card {
  min-height: 184px;
  padding: 18px;
}

.ipad-page .clock-pair canvas {
  width: 112px;
  height: 112px;
}

@media (orientation: portrait) and (min-width: 700px) {
  .ipad-page .top-panel,
  .ipad-page .mission-panel,
  .ipad-page .step-header,
  .ipad-page .result-panel {
    display: grid;
    grid-template-columns: 1fr;
  }

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

  .ipad-page .clock-pair {
    justify-content: center;
  }
}

@media (orientation: landscape) and (min-width: 900px) {
  .ipad-page .choice-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* LiNest v3: 路線色・時計・判定色はそのままに外枠を統一 */
body.linest-themed {
  --bg: var(--linest-bg);
  --ink: var(--linest-text);
  --muted: var(--linest-muted);
  --panel: var(--linest-surface);
  --line: var(--linest-border);
  --shadow: var(--linest-shadow);
}

body.linest-themed .app-shell,
body.linest-themed :where(.top-panel, .mission-panel, .game-board, .result-panel) > * {
  min-width: 0;
}

body.linest-themed .top-panel,
body.linest-themed .mission-panel,
body.linest-themed .game-board,
body.linest-themed .result-panel {
  border-color: var(--linest-border);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--linest-shadow);
}

body.linest-themed .top-panel {
  border-left: 6px solid var(--linest-green-bright);
}

body.linest-themed .score-box {
  border-color: var(--linest-border);
  background: var(--linest-green-soft);
}

body.linest-themed .level-button {
  border-color: var(--linest-border);
  color: var(--linest-text);
  background: #fff;
}

body.linest-themed .level-button.is-active {
  border-color: var(--linest-green);
  color: var(--linest-green-dark);
  background: var(--linest-green-soft);
  box-shadow: inset 0 -4px 0 rgba(47, 158, 68, 0.15);
}

body.linest-themed .route-map {
  border-color: var(--linest-border);
  background: #f6faf1;
}

body.linest-themed .clock-pair > div,
body.linest-themed .choice-card {
  border-color: var(--linest-border);
  background: #fff;
  box-shadow: 0 6px 16px rgba(74, 55, 40, 0.07);
}

body.linest-themed .choice-card:hover,
body.linest-themed .choice-card:focus-visible,
body.linest-themed .choice-card.is-selected {
  border-color: var(--linest-green);
  background: var(--linest-green-soft);
  outline-color: rgba(47, 158, 68, 0.25);
}

body.linest-themed .ghost-button {
  border-color: var(--linest-terracotta);
  color: var(--linest-terracotta-dark);
  background: #fffaf6;
}

body.linest-themed :where(.level-button, .ghost-button, .primary-button, .choice-card, .line-name, .line span) {
  min-width: 0;
  line-height: 1.35;
  white-space: normal;
}

@media (max-width: 560px) {
  body.linest-themed .route-map {
    padding-inline: 10px;
  }

  body.linest-themed .line {
    grid-template-columns: 82px repeat(3, minmax(0, 1fr));
  }

  body.linest-themed .line::before {
    left: calc(82px + 7%);
  }

  body.linest-themed .step-header {
    align-items: stretch;
    flex-direction: column;
  }

  body.linest-themed .ghost-button {
    width: 100%;
  }
}
