:root {
  color-scheme: light;
  --bg: #eef6f2;
  --panel: #ffffff;
  --ink: #1e2a26;
  --muted: #66756f;
  --line: #d9e5df;
  --primary: #2b7a68;
  --primary-dark: #1f5f50;
  --coral: #d9785f;
  --yellow: #f2c45b;
  --sky: #dcecf7;
  --mint: #e4f4e8;
  --soft: #f8fbf5;
  --shadow: 0 18px 44px rgba(30, 51, 45, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(140deg, rgba(43, 122, 104, 0.12), transparent 34%),
    linear-gradient(320deg, rgba(217, 120, 95, 0.14), transparent 36%),
    var(--bg);
  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "Hiragino Sans",
    "Yu Gothic",
    "Meiryo",
    sans-serif;
  line-height: 1.65;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1440px, calc(100% - 28px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px 0;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 340px;
  gap: 16px;
}

.scene-panel,
.comic-panel,
.reflection-panel {
  min-width: 0;
  max-height: calc(100vh - 44px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.scene-panel,
.reflection-panel {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.comic-panel {
  padding: 20px;
}

.app-header {
  display: grid;
  gap: 4px;
}

.eyebrow,
.field-label,
.mini-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
  line-height: 1.16;
}

h1 {
  font-size: clamp(1.6rem, 3vw, 2.25rem);
}

h2 {
  font-size: clamp(1.55rem, 2.4vw, 2.35rem);
}

.control-stack,
.field-group,
.reflection-section {
  display: grid;
  gap: 9px;
}

.search-input,
.category-select,
.supporter-memo {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.search-input,
.category-select {
  min-height: 48px;
  padding: 0 12px;
}

.supporter-memo {
  min-height: 122px;
  resize: vertical;
  padding: 12px;
}

.search-input:focus,
.category-select:focus,
.supporter-memo:focus {
  outline: 3px solid rgba(43, 122, 104, 0.2);
  border-color: var(--primary);
}

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

.level-button,
.tool-button,
.nav-button,
.choice-button,
.scene-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.level-button {
  min-height: 42px;
  font-weight: 800;
}

.level-button.is-active,
.tool-button.primary,
.choice-button.is-selected {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tool-button,
.nav-button {
  min-height: 46px;
  padding: 0 13px;
  font-weight: 800;
}

.tool-button.wide {
  width: 100%;
}

.scene-count {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.scene-list {
  min-height: 0;
  flex: 1;
  overflow: auto;
  display: grid;
  grid-auto-rows: max-content;
  align-content: start;
  gap: 8px;
  padding-right: 2px;
}

.scene-button {
  width: 100%;
  min-height: 84px;
  height: auto;
  padding: 12px 14px;
  display: grid;
  align-content: center;
  gap: 6px;
  text-align: left;
  transition:
    border-color 160ms ease,
    transform 160ms ease,
    background 160ms ease;
}

.scene-button:hover,
.scene-button:focus-visible {
  outline: none;
  transform: translateY(-1px);
  border-color: rgba(43, 122, 104, 0.55);
}

.scene-button.is-active {
  border-color: var(--primary);
  background: var(--mint);
}

.scene-button-title {
  display: block;
  font-weight: 900;
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: normal;
}

.scene-button-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px 8px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

.scene-button-level {
  flex: 0 0 auto;
  padding: 2px 8px;
  border: 1px solid rgba(43, 122, 104, 0.28);
  border-radius: 999px;
  background: var(--mint);
  color: var(--primary-dark);
  font-size: 0.8rem;
  font-weight: 900;
}

.scene-button-category {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: normal;
}

.loading-state {
  min-height: calc(100vh - 44px);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 800;
}

.scene-view {
  display: grid;
  gap: 16px;
}

.scene-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
}

.scene-meta {
  margin: 0 0 6px;
  color: var(--primary-dark);
  font-weight: 900;
}

.scene-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

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

.comic-frame {
  min-height: 220px;
  border: 2px solid #25332f;
  border-radius: 8px;
  background: #fffefb;
  display: grid;
  grid-template-rows: 96px minmax(0, 1fr);
  overflow: hidden;
}

.comic-frame.is-illustrated {
  min-height: 0;
  grid-template-rows: auto auto;
}

.comic-visual {
  position: relative;
  min-height: 96px;
  background:
    linear-gradient(180deg, rgba(220, 236, 247, 0.9), rgba(248, 251, 245, 0.7));
  border-bottom: 2px solid #25332f;
}

.comic-visual::before {
  content: "";
  position: absolute;
  left: 24px;
  bottom: 17px;
  width: 38px;
  height: 38px;
  border: 3px solid #25332f;
  border-radius: 50%;
  background: #fff;
  box-shadow:
    0 38px 0 -9px #fff,
    0 38px 0 -6px #25332f;
}

.panel-number {
  position: absolute;
  left: 9px;
  top: 8px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--yellow);
  color: #25332f;
  display: grid;
  place-items: center;
  font-weight: 900;
}

.panel-mark {
  position: absolute;
  right: 34px;
  bottom: 14px;
  width: 38px;
  height: 30px;
  border: 3px solid #25332f;
  border-radius: 8px;
  background: var(--coral);
  opacity: 0.82;
}

.comic-frame.is-illustrated .comic-visual {
  min-height: 0;
  aspect-ratio: 2 / 1;
  background: #fffdf7;
}

.comic-frame.is-illustrated .comic-visual::before {
  content: none;
}

.comic-art {
  display: block;
  width: 100%;
  height: 100%;
}

.comic-art-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fffdf7;
}

.art-line {
  stroke: #25332f;
  stroke-width: 5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.art-thin {
  stroke: #25332f;
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.art-bg {
  fill: #eef8ff;
}

.art-ground {
  fill: #eaf5e5;
}

.art-skin {
  fill: #fff6df;
}

.art-shirt {
  fill: #8fd3c4;
}

.art-shirt-friend {
  fill: #f5b78f;
}

.art-hair {
  fill: #31433d;
}

.art-hat {
  fill: #f2c45b;
}

.art-hat-band {
  fill: #d9785f;
}

.art-sfx {
  fill: #25332f;
  font-size: 20px;
  font-weight: 900;
}

.art-number-fill {
  fill: var(--yellow);
}

.art-number-text {
  fill: #25332f;
  font-size: 18px;
  font-weight: 900;
  text-anchor: middle;
  dominant-baseline: middle;
}

.art-eye,
.art-dot {
  fill: #25332f;
}

.art-cheek {
  fill: #f6a996;
  opacity: 0.55;
}

.comic-text {
  margin: 0;
  padding: 15px;
  font-size: clamp(1.02rem, 2vw, 1.28rem);
  font-weight: 800;
  line-height: 1.55;
}

.comic-frame.is-illustrated .comic-text {
  padding: 12px 14px 14px;
  font-size: clamp(0.98rem, 1.35vw, 1.08rem);
}

body.captions-hidden .comic-text,
body.captions-hidden .prompt-band {
  display: none;
}

body.captions-hidden .comic-frame {
  min-height: 0;
  grid-template-rows: auto;
}

body.captions-hidden .comic-frame:not(.is-illustrated) .comic-visual {
  min-height: 150px;
}

.prompt-band,
.selected-box,
.cue-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  padding: 14px;
}

.supporter-prompt,
.selected-summary,
.image-note {
  margin: 4px 0 0;
  font-weight: 800;
}

.choice-grid {
  display: grid;
  gap: 8px;
}

.choice-button {
  min-height: 52px;
  padding: 10px 12px;
  text-align: left;
  font-weight: 900;
}

.choice-button:hover,
.choice-button:focus-visible,
.tool-button:hover,
.tool-button:focus-visible,
.nav-button:hover,
.nav-button:focus-visible {
  outline: none;
  border-color: rgba(43, 122, 104, 0.55);
  box-shadow: 0 0 0 3px rgba(43, 122, 104, 0.14);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 280px minmax(0, 1fr);
  }

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

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 18px, 680px);
    grid-template-columns: 1fr;
    padding: 10px 0;
  }

  .scene-panel,
  .comic-panel,
  .reflection-panel {
    max-height: none;
  }

  .comic-grid,
  .reflection-panel {
    grid-template-columns: 1fr;
  }

  .scene-header {
    grid-template-columns: 1fr;
  }

  .scene-nav {
    width: 100%;
  }

  .nav-button {
    flex: 1;
  }
}

/* LiNest v3: 4コマ画像と「正解を決めない」選択体験を保持 */
body.linest-themed {
  --bg: var(--linest-bg);
  --panel: var(--linest-surface);
  --ink: var(--linest-text);
  --muted: var(--linest-muted);
  --line: var(--linest-border);
  --primary: var(--linest-green);
  --primary-dark: var(--linest-green-dark);
  --coral: var(--linest-warm);
  --mint: var(--linest-green-soft);
  --soft: #f9fcf6;
  --shadow: var(--linest-shadow);
}

body.linest-themed .app-shell,
body.linest-themed .app-shell > *,
body.linest-themed .scene-header > *,
body.linest-themed .reflection-panel > * {
  min-width: 0;
}

body.linest-themed .scene-panel,
body.linest-themed .comic-panel,
body.linest-themed .reflection-panel {
  border-color: var(--linest-border);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: var(--linest-shadow);
}

body.linest-themed .app-header {
  padding: 14px 16px;
  border-left: 6px solid var(--linest-green-bright);
  border-radius: 8px;
  background: var(--linest-green-soft);
}

body.linest-themed .app-header h1 {
  font-size: clamp(1.4rem, 2.2vw, 1.75rem);
  line-height: 1.45;
  text-wrap: pretty;
  word-break: normal;
}

body.linest-themed :where(
  .search-input,
  .category-select,
  .supporter-memo,
  .level-button,
  .tool-button,
  .nav-button,
  .choice-button,
  .scene-button
) {
  min-width: 0;
  border-color: var(--linest-border);
  line-height: 1.4;
  white-space: normal;
}

body.linest-themed :where(.level-button.is-active, .tool-button.primary, .choice-button.is-selected) {
  border-color: var(--linest-green);
  color: #fff;
  background: var(--linest-green);
}

body.linest-themed .scene-button.is-active {
  border-color: var(--linest-green);
  background: var(--linest-green-soft);
}

/* 共通テーマの44px指定より優先し、題名とレベルを必ずカード内に収める */
body.linest-themed button.scene-button {
  min-height: 84px;
  height: auto;
  padding: 12px 14px;
}

body.linest-themed .scene-button-level {
  border-color: rgba(37, 120, 54, 0.28);
  background: var(--linest-green-soft);
  color: var(--linest-green-dark);
}

body.linest-themed .scene-button.is-active .scene-button-level {
  background: #ffffff;
}

body.linest-themed :where(.prompt-band, .selected-box, .cue-box) {
  border-color: var(--linest-border);
  background: #f9fcf6;
}

@media (max-width: 760px) {
  body.linest-themed .app-header {
    padding: 12px;
  }

  body.linest-themed :where(.level-button, .tool-button, .nav-button, .choice-button, .scene-button) {
    font-size: 0.94rem;
  }
}
