:root {
  color-scheme: light;
  --bg: #eef4ed;
  --panel: #ffffff;
  --panel-soft: #f7faf5;
  --text: #20302a;
  --muted: #5f7069;
  --line: #d7e2d8;
  --primary: #2f7d62;
  --primary-dark: #225d4a;
  --accent: #c86f3d;
  --amber: #d9a427;
  --blue: #2f78b7;
  --danger: #b84b3f;
  --shadow: 0 14px 36px rgba(29, 50, 42, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(47, 125, 98, 0.12), transparent 36%),
    repeating-linear-gradient(
      90deg,
      rgba(47, 125, 98, 0.05) 0,
      rgba(47, 125, 98, 0.05) 1px,
      transparent 1px,
      transparent 24px
    ),
    var(--bg);
  color: var(--text);
  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "Hiragino Sans",
    "Yu Gothic",
    "Meiryo",
    sans-serif;
  letter-spacing: 0;
}

button {
  color: inherit;
  font: inherit;
}

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

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

.eyebrow,
.section-kicker {
  margin: 0 0 4px;
  color: var(--primary-dark);
  font-size: 0.88rem;
  font-weight: 800;
}

h1,
h2 {
  margin: 0;
  line-height: 1.18;
}

h1 {
  font-size: clamp(2rem, 4.2vw, 3.8rem);
}

h2 {
  font-size: 1.25rem;
}

.session-meter {
  min-width: 128px;
  padding: 10px 16px;
  border: 2px solid rgba(47, 125, 98, 0.2);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 22px rgba(29, 50, 42, 0.08);
  text-align: center;
}

.meter-label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.session-meter strong {
  display: block;
  color: var(--primary-dark);
  font-size: 1.9rem;
  line-height: 1;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(420px, 1.2fr) minmax(230px, 0.58fr);
  gap: 14px;
  align-items: start;
}

.mission-panel,
.build-panel,
.support-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.mission-panel,
.build-panel {
  padding: 14px;
}

.support-panel {
  padding: 16px;
}

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

.primary-action,
.mission-tab,
.prompt-button,
.tool-button,
.difficulty-button,
.wide-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  cursor: pointer;
  font-weight: 800;
  touch-action: manipulation;
  transition:
    transform 120ms ease,
    background 120ms ease,
    border-color 120ms ease;
}

.primary-action {
  min-width: 110px;
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.primary-action:active,
.mission-tab:active,
.prompt-button:active,
.tool-button:active,
.difficulty-button:active,
.wide-button:active,
.block-cell:active,
.inventory-button:active {
  transform: scale(0.98);
}

.mission-tabs,
.prompt-tabs,
.tool-row,
.difficulty-buttons {
  display: grid;
  gap: 8px;
}

.mission-tabs {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 12px;
}

.mission-tab.is-active,
.prompt-button.is-active,
.tool-button.is-active,
.difficulty-button.is-active {
  border-color: rgba(47, 125, 98, 0.72);
  background: #dff0e4;
  color: var(--primary-dark);
}

.mission-surface {
  min-height: 390px;
  padding: 12px;
  border: 2px solid #dce7d7;
  border-radius: 8px;
  background: #fbfcf8;
}

.mission-status {
  min-height: 48px;
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #f2f6ef;
  color: var(--muted);
  font-weight: 800;
}

.mission-status.is-clear {
  background: #dff0e4;
  color: var(--primary-dark);
}

.mission-status.is-error {
  background: #ffe7df;
  color: var(--danger);
}

.mini-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.mini-title strong {
  font-size: 1.18rem;
}

.mini-badge {
  padding: 6px 10px;
  border-radius: 8px;
  background: #e8f0fb;
  color: #245981;
  font-weight: 900;
}

.symbol-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 7px;
}

.symbol-button {
  aspect-ratio: 1;
  min-height: 44px;
  border: 2px solid #d6dfd4;
  border-radius: 8px;
  background: #fff;
  color: #21312b;
  font-size: 1.45rem;
  font-weight: 900;
}

.symbol-button.is-found {
  border-color: var(--primary);
  background: #dff0e4;
  color: var(--primary-dark);
}

.symbol-button.is-wrong {
  border-color: var(--danger);
  background: #ffe7df;
}

.math-card {
  display: grid;
  gap: 16px;
  justify-items: center;
  padding: 18px 0;
}

.math-problem {
  width: min(100%, 380px);
  padding: 24px 16px;
  border: 2px solid #dbe4d8;
  border-radius: 8px;
  background: #fffdf2;
  color: #26342f;
  text-align: center;
  font-size: clamp(2.4rem, 7vw, 4.8rem);
  font-weight: 900;
}

.answer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: min(100%, 380px);
}

.answer-button {
  min-height: 62px;
  border: 2px solid #d8e0d6;
  border-radius: 8px;
  background: #fff;
  font-size: 1.6rem;
  font-weight: 900;
}

.pattern-card {
  display: grid;
  gap: 16px;
  padding: 12px 0;
}

.pattern-row,
.blueprint-answer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  min-height: 58px;
  padding: 10px;
  border: 2px solid #dbe4d8;
  border-radius: 8px;
  background: #fffdf2;
}

.blueprint-answer {
  background: #f4f8ef;
}

.pattern-slot,
.choice-swatch {
  width: 48px;
  height: 48px;
  border: 2px solid rgba(32, 48, 42, 0.18);
  border-radius: 7px;
  box-shadow: inset 0 4px 0 rgba(255, 255, 255, 0.28);
}

.empty-slot {
  display: grid;
  place-items: center;
  background: #eef4ed;
  color: var(--muted);
  font-weight: 900;
}

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

.block-choice {
  display: grid;
  justify-items: center;
  gap: 6px;
  min-height: 82px;
  padding: 8px 4px;
  border: 2px solid #d8e0d6;
  border-radius: 8px;
  background: #fff;
  font-weight: 900;
}

.sequence-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  width: min(100%, 420px);
}

.sequence-tile {
  display: grid;
  place-items: center;
  min-height: 72px;
  border: 2px solid #dbe4d8;
  border-radius: 8px;
  background: #fff;
  font-size: 2rem;
  font-weight: 900;
}

.sequence-tile.is-blank {
  background: #fff5d9;
  color: #76530f;
}

.word-card {
  display: grid;
  gap: 16px;
  justify-items: center;
  padding: 18px 0;
}

.word-clue {
  color: var(--muted);
  font-size: 1.05rem;
  font-weight: 900;
}

.word-problem {
  width: min(100%, 380px);
  padding: 24px 16px;
  border: 2px solid #dbe4d8;
  border-radius: 8px;
  background: #fffdf2;
  text-align: center;
  font-size: clamp(2.6rem, 7vw, 4.8rem);
  font-weight: 900;
}

.story-card {
  display: grid;
  gap: 16px;
  justify-items: center;
  padding: 14px 0;
}

.story-text {
  width: min(100%, 420px);
  min-height: 150px;
  padding: 20px;
  border: 2px solid #dbe4d8;
  border-radius: 8px;
  background: #fffdf2;
  font-size: 1.45rem;
  font-weight: 900;
  line-height: 1.55;
}

.story-hint {
  color: var(--muted);
  font-weight: 900;
}

.canvas-wrap {
  display: grid;
  gap: 10px;
}

.mini-canvas {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 2px solid #d5dfd2;
  border-radius: 8px;
  background: #fff;
  touch-action: none;
}

.build-prompt {
  min-width: 102px;
  padding: 8px 12px;
  border-radius: 8px;
  background: #fff5d9;
  color: #76530f;
  font-weight: 900;
  text-align: center;
}

.prompt-tabs {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 10px;
}

.inventory {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.inventory-button {
  display: grid;
  grid-template-rows: 36px auto auto;
  gap: 4px;
  min-height: 88px;
  padding: 8px 6px;
  border: 2px solid #d8e1d6;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.inventory-button.is-active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px rgba(200, 111, 61, 0.22);
}

.block-swatch {
  width: 36px;
  height: 36px;
  margin: 0 auto;
  border: 2px solid rgba(32, 48, 42, 0.18);
  border-radius: 6px;
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.32);
}

.inventory-name,
.inventory-count {
  display: block;
  text-align: center;
  line-height: 1.1;
}

.inventory-name {
  font-size: 0.82rem;
  font-weight: 900;
}

.inventory-count {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.tool-row {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 10px;
}

.build-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 4px;
  padding: 8px;
  border: 2px solid #cfdccf;
  border-radius: 8px;
  background:
    linear-gradient(#eaf2e6 0 0) padding-box,
    #cfdccf;
}

.block-cell {
  aspect-ratio: 1;
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(69, 91, 80, 0.2);
  border-radius: 5px;
  background: #f6fbf3;
  cursor: pointer;
}

.block-cell.is-filled {
  box-shadow:
    inset 0 4px 0 rgba(255, 255, 255, 0.28),
    inset 0 -5px 0 rgba(0, 0, 0, 0.12);
}

.support-group {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.support-label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 900;
}

.difficulty-buttons {
  grid-template-columns: 1fr;
}

.wide-button {
  width: 100%;
  background: #fff;
}

.wide-button.danger {
  border-color: rgba(184, 75, 63, 0.35);
  color: var(--danger);
}

.reward-log {
  min-height: 78px;
  margin-top: 18px;
  padding: 12px;
  border-radius: 8px;
  background: #f4f7f2;
  color: var(--muted);
  font-weight: 800;
  line-height: 1.5;
}

.reward-log.is-pop {
  background: #fff5d9;
  color: #76530f;
}

.swatch-grass,
.cell-grass {
  background:
    linear-gradient(180deg, #76b85f 0 45%, #5d9c4e 45% 100%),
    #76b85f;
}

.swatch-wood,
.cell-wood {
  background:
    repeating-linear-gradient(90deg, rgba(68, 36, 15, 0.22) 0 3px, transparent 3px 9px),
    #b8783e;
}

.swatch-stone,
.cell-stone {
  background:
    linear-gradient(135deg, #8d9694 0 45%, #737d7c 45% 100%);
}

.swatch-glass,
.cell-glass {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.7), rgba(85, 154, 196, 0.55)),
    #82bed6;
}

.swatch-gold,
.cell-gold {
  background:
    linear-gradient(135deg, #f5d35e 0 44%, #c99022 44% 100%);
}

.swatch-water,
.cell-water {
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.28) 0 5px, transparent 5px 12px),
    #3c8bc2;
}

@media (max-width: 1120px) {
  .game-layout {
    grid-template-columns: 1fr 1fr;
  }

  .support-panel {
    grid-column: 1 / -1;
  }

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

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 18px, 1440px);
  }

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

  .game-layout {
    grid-template-columns: 1fr;
  }

  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .primary-action {
    width: 100%;
  }

  .prompt-tabs,
  .inventory,
  .choice-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .mission-surface {
    min-height: 330px;
  }
}

/* LiNest v3: ブロックの材質色とCanvas描画色を保持する */
body.linest-themed {
  --bg: var(--linest-bg);
  --panel: var(--linest-surface);
  --panel-soft: var(--linest-green-soft);
  --text: var(--linest-text);
  --muted: var(--linest-muted);
  --line: var(--linest-border);
  --primary: var(--linest-green);
  --primary-dark: var(--linest-green-dark);
  --accent: var(--linest-terracotta);
  --shadow: var(--linest-shadow);
}

body.linest-themed .app-shell,
body.linest-themed .topbar > *,
body.linest-themed .game-layout > *,
body.linest-themed .panel-heading > * {
  min-width: 0;
}

body.linest-themed .topbar {
  padding: 18px 20px;
  border: 1px solid var(--linest-border);
  border-left: 6px solid var(--linest-green-bright);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--linest-shadow);
}

body.linest-themed .mission-panel,
body.linest-themed .build-panel,
body.linest-themed .support-panel,
body.linest-themed .session-meter {
  border-color: var(--linest-border);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: var(--linest-shadow);
}

body.linest-themed .support-panel {
  background: #f9fcf6;
}

body.linest-themed :where(
  .mission-tab,
  .prompt-button,
  .tool-button,
  .difficulty-button,
  .wide-button
) {
  min-width: 0;
  border-color: var(--linest-border);
  background: var(--linest-green-soft);
  line-height: 1.35;
  white-space: normal;
}

body.linest-themed :where(
  .mission-tab.is-active,
  .prompt-button.is-active,
  .tool-button.is-active,
  .difficulty-button.is-active
) {
  border-color: var(--linest-green);
  color: var(--linest-green-dark);
  background: #e8f4e4;
}

body.linest-themed .mission-surface,
body.linest-themed .build-grid,
body.linest-themed .reward-log {
  border-color: var(--linest-border);
  background-color: #fffefb;
}

@media (max-width: 1120px) {
  body.linest-themed .math-problem {
    font-size: clamp(2.4rem, 5vw, 3.4rem);
  }
}

@media (max-width: 760px) {
  body.linest-themed .topbar {
    padding: 16px;
  }

  body.linest-themed :where(.mission-tab, .prompt-button, .tool-button, .difficulty-button, .wide-button) {
    padding-inline: 6px;
    font-size: 0.94rem;
  }
}
