:root {
  color-scheme: light;
  --ink: #25313b;
  --muted: #66727c;
  --paper: #f8f7f3;
  --panel: #ffffff;
  --line: #d8ddd9;
  --accent: #315f68;
  --accent-dark: #23474e;
  --player-accent: #795548;
  --chat: #e9f2ee;
  --narration: #f0eee7;
  --warning: #7e2f27;
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: linear-gradient(145deg, #e8ece9, #f6f4ed 55%, #e2e8e5);
  transition:
    background-color 500ms ease,
    color 500ms ease;
}

body.is-dark {
  color: #edf1ef;
  background: #101616;
}

button {
  font: inherit;
}
button:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 3px solid #d29c45;
  outline-offset: 3px;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font: inherit;
  text-decoration: none;
}

.sound-toggle-button {
  position: fixed;
  z-index: 30;
  top: max(12px, env(safe-area-inset-top));

  /* ブラウザ右端ではなく、幅760pxのゲーム領域の右端に合わせる */
  right: max(
    12px,
    env(safe-area-inset-right),
    calc((100vw - 760px) / 2 + 12px)
  );

  min-width: 78px;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid rgba(49, 95, 104, 0.45);
  border-radius: 999px;
  color: var(--accent-dark);
  background: rgba(248, 247, 243, 0.86);
  box-shadow: 0 6px 18px rgba(35, 54, 55, 0.14);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.sound-toggle-button:hover {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.96);
}

.sound-toggle-button[aria-pressed="true"] {
  color: #fff;
  border-color: var(--accent);
  background: rgba(49, 95, 104, 0.94);
}

body.is-dark .sound-toggle-button {
  color: #dce9e6;
  border-color: rgba(220, 233, 230, 0.35);
  background: rgba(23, 32, 32, 0.88);
}

body.is-dark .sound-toggle-button[aria-pressed="true"] {
  color: #172020;
  border-color: #b9d3d1;
  background: #b9d3d1;
}

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

.screen {
  min-height: 560px;
  padding: clamp(28px, 6vw, 58px);
  border: 1px solid rgba(49, 95, 104, 0.16);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 22px 65px rgba(35, 54, 55, 0.14);
}

body.is-dark .screen {
  background: #172020;
  border-color: #354343;
  box-shadow: none;
}
[hidden] {
  display: none !important;
}

.title-screen,
.ending-screen,
.same-name-screen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}
.name-description,
.name-help,
.same-name-message {
  color: var(--muted);
  line-height: 1.8;
}
.name-field {
  margin-top: 34px;
}
.name-field label {
  display: block;
  margin-bottom: 8px;
  font-weight: 700;
}
.name-field input {
  width: 100%;
  min-height: 52px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  font: inherit;
  font-size: 1.1rem;
}
.name-help {
  margin-top: 12px;
  font-size: 0.9rem;
}
.same-name-message span {
  color: var(--ink);
  font-weight: 700;
}
.eyebrow {
  margin: 0 0 12px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}
h1,
h2,
h3 {
  margin-top: 0;
}
h1 {
  margin-bottom: 18px;
  font-size: clamp(2rem, 7vw, 3.7rem);
  line-height: 1.22;
}
h2 {
  margin-bottom: 20px;
  font-size: clamp(1.5rem, 5vw, 2.25rem);
}
.subtitle,
.intro-copy {
  color: var(--muted);
  line-height: 1.9;
}
.intro-copy {
  margin: 48px 0;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 32px;
}
.primary-button,
.secondary-button,
.choice-button {
  min-height: 48px;
  padding: 12px 22px;
  border-radius: 8px;
  cursor: pointer;
}
.primary-button {
  border: 1px solid var(--accent);
  color: #fff;
  background: var(--accent);
}
.primary-button:hover {
  background: var(--accent-dark);
}
.secondary-button {
  border: 1px solid var(--accent);
  color: var(--accent);
  background: transparent;
}
button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.scene-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
}
.id-label {
  padding: 5px 8px;
  border-radius: 4px;
  color: var(--muted);
  background: #eef0ed;
  font:
    0.75rem ui-monospace,
    monospace;
}
.story-content {
  min-height: 270px;
  margin: 28px 0;
  line-height: 1.9;
}
.story-item {
  margin: 0 0 19px;
  animation: story-item-enter 220ms ease-out both;
  animation-delay: var(--item-delay, 0ms);
}
.story-item p {
  margin: 0;
  white-space: pre-line;
}
.speaker {
  display: block;
  margin-bottom: 2px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
}
.story-dialogue {
  padding-left: 14px;
  border-left: 3px solid #a8babc;
}
.story-dialogue-player {
  border-left-color: var(--player-accent);
}
.story-dialogue-player .speaker {
  color: var(--player-accent);
  font-weight: 800;
}
.story-narration {
  padding: 17px 19px;
  border-radius: 8px;
  color: var(--ink);
  background: var(--narration);
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
}
.story-chat {
  max-width: 88%;
  margin-left: auto;
  padding: 15px 18px;
  border-radius: 14px 14px 3px 14px;
  color: var(--ink);
  background: var(--chat);
}
.story-file {
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: #fafafa;
  font-family: ui-monospace, monospace;
}
.story-file::before {
  content: "添付ファイル";
  display: block;
  color: var(--muted);
  font:
    0.72rem system-ui,
    sans-serif;
}
.story-episode-title {
  padding: 28px;
  border-bottom: 1px solid var(--line);
  text-align: center;
  font-family: "Yu Mincho", serif;
  font-size: 1.35rem;
}
.story-label {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.78rem;
}

.choice-list {
  display: grid;
  gap: 11px;
  margin-top: 28px;
}
.choice-list.is-revealing .choice-button {
  animation: choice-enter 190ms ease-out both;
  animation-delay: var(--choice-delay, 0ms);
}
.choice-button {
  width: 100%;
  border: 1px solid var(--line);
  color: var(--ink);
  background: #fff;
  text-align: left;
}
.choice-button::after {
  content: attr(data-choice-id);
  float: right;
  color: #889197;
  font:
    0.7rem ui-monospace,
    monospace;
}
.choice-button:hover {
  border-color: var(--accent);
  background: #f2f7f5;
}

.save-warning {
  position: sticky;
  z-index: 5;
  top: 0;
  padding: 12px 20px;
  color: #fff;
  background: var(--warning);
  text-align: center;
}
.debug-panel {
  margin-top: 18px;
  padding: 12px 16px;
  border: 1px dashed #9aa6a1;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}
.debug-panel summary {
  cursor: pointer;
  color: var(--muted);
}
.debug-panel pre {
  overflow: auto;
  max-height: 360px;
  font-size: 0.75rem;
  white-space: pre-wrap;
}
.remains {
  margin: 36px 0;
  padding: 24px;
  border-block: 1px solid var(--line);
  text-align: left;
}
#endingTitle {
  white-space: pre-line;
}
.remains li {
  margin: 10px 0;
  line-height: 1.65;
}
.coming-soon {
  font-weight: 700;
  letter-spacing: 0.08em;
}

@keyframes story-item-enter {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes choice-enter {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 560px) {
  .sound-toggle-button {
    top: max(8px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
    min-width: 72px;
    min-height: 38px;
    padding: 7px 10px;
  }

  .app-shell {
    width: min(100% - 18px, 760px);
    padding-top: 56px;
  }
  .screen {
    min-height: calc(100vh - 48px);
    padding: 25px 20px;
    border-radius: 12px;
  }
  .scene-header {
    display: block;
  }
  .id-label {
    display: inline-block;
    margin-bottom: 14px;
  }
  .actions {
    align-items: stretch;
    flex-direction: column;
  }
  .story-chat {
    max-width: 96%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}

#titleScreen,
#introScreen,
#gameScreen,
#endingScreen {
  position: relative;
  min-height: 100svh;
  isolation: isolate;

  background-color: #d9d7d2;
  background-image: var(--screen-background);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

#titleScreen::before,
#introScreen::before,
#gameScreen::before,
#endingScreen::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;

  background: linear-gradient(
    to bottom,
    rgba(28, 31, 35, 0.12) 0%,
    rgba(28, 31, 35, 0.02) 35%,
    rgba(28, 31, 35, 0.18) 60%,
    rgba(28, 31, 35, 0.55) 100%
  );
}

.title-copy {
  padding: 26px 18px;

  background: radial-gradient(
    ellipse at center,
    rgba(250, 249, 246, 0.78) 0%,
    rgba(250, 249, 246, 0.52) 55%,
    rgba(250, 249, 246, 0) 100%
  );
}

/*
.title-kicker {
  color: #365c67;
  font-weight: 600;
}

.title-heading {
  color: #172b32;
  font-weight: 700;
  text-shadow:
    0 1px 1px rgba(255, 255, 255, 0.9),
    0 0 10px rgba(255, 255, 255, 0.65);
}

.title-description {
  color: #526166;
  font-weight: 500;
  text-shadow: 0 1px 4px rgba(255, 255, 255, 0.9);
}
.continue-button:disabled {
  color: rgba(35, 72, 82, 0.65);
  border-color: rgba(35, 72, 82, 0.38);
  background: rgba(245, 246, 244, 0.22);
  opacity: 1;
  cursor: default;
}
*/

#titleScreen .eyebrow {
  color: #365c67;
  font-weight: 700;
  text-shadow: 0 1px 5px rgba(255, 255, 255, 0.95);
}

#gameTitle {
  color: #172b32;
  font-weight: 700;
  text-shadow:
    0 1px 1px rgba(255, 255, 255, 0.95),
    0 0 10px rgba(255, 255, 255, 0.75);
}

#titleScreen .subtitle {
  color: #526166;
  font-weight: 500;
  text-shadow:
    0 1px 3px rgba(255, 255, 255, 1),
    0 0 8px rgba(255, 255, 255, 0.8);
}

#continueButton:disabled {
  color: rgba(35, 72, 82, 0.65);
  border-color: rgba(35, 72, 82, 0.42);
  background: rgba(245, 246, 244, 0.32);
  opacity: 1;
  cursor: default;
}

/* ========================================
   ゲーム本編：背景画像上の可読性
   ======================================== */

#gameScreen .scene-header {
  padding: 12px 14px 14px;
  border-bottom: 0;
  border-radius: 12px;

  background: linear-gradient(
    90deg,
    rgba(248, 247, 243, 0.9) 0%,
    rgba(248, 247, 243, 0.7) 72%,
    rgba(248, 247, 243, 0) 100%
  );

  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

#gameScreen .story-content {
  min-height: 270px;
  margin: 18px 0 22px;
  padding: 20px 18px;

  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 14px;

  color: #29373c;
  background: rgba(248, 247, 243, 0.86);

  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);

  box-shadow:
    0 12px 30px rgba(35, 49, 53, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.72);

  line-height: 1.9;
}

#gameScreen .story-dialogue p {
  color: #29373c;
}

#gameScreen .speaker {
  color: #315f68;
  font-weight: 800;
}

#gameScreen .story-dialogue {
  border-left-color: rgba(73, 111, 117, 0.7);
}

#gameScreen .story-dialogue-player {
  border-left-color: rgba(121, 85, 72, 0.75);
}

#gameScreen .id-label {
  color: #49666d;
  background: rgba(238, 240, 237, 0.9);
  border: 1px solid rgba(49, 95, 104, 0.14);
}

#gameScreen::before {
  background: linear-gradient(
    to bottom,
    rgba(248, 247, 243, 0.03) 0%,
    rgba(248, 247, 243, 0) 42%,
    rgba(28, 31, 35, 0.08) 70%,
    rgba(28, 31, 35, 0.22) 100%
  );
}

/* debug */

#debugPanel {
  display: none;
}

@media (max-width: 560px) {
  #gameScreen .scene-header {
    padding: 10px 12px 12px;
  }

  #gameScreen .story-content {
    min-height: 250px;
    margin: 14px 0 18px;
    padding: 16px 14px;
    background: rgba(248, 247, 243, 0.89);
  }
}

/* ========================================
   本文内の情報種別を見分けやすくする
   ======================================== */

/* 地の文・ナレーション */
#gameScreen .story-narration {
  padding: 17px 19px;

  border: 1px solid rgba(116, 98, 70, 0.16);
  border-left: 4px solid rgba(116, 98, 70, 0.32);
  border-radius: 9px;

  color: #384044;
  background: var(--narration);

  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    0 3px 10px rgba(50, 45, 38, 0.04);
}

/* チャット・メッセージ */
#gameScreen .story-chat {
  max-width: 84%;
  margin-left: auto;
  padding: 15px 18px;

  border: 1px solid rgba(49, 95, 104, 0.22);
  border-radius: 16px 16px 4px 16px;

  color: #2d3c40;
  background: var(--chat);

  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    0 5px 14px rgba(49, 95, 104, 0.09);
}

#gameScreen .story-narration p,
#gameScreen .story-chat p {
  color: inherit;
}

@media (max-width: 560px) {
  #gameScreen .story-chat {
    max-width: 90%;
  }
}

/* ========================================
   エピソード開始画面
   ======================================== */

#introScreen::before {
  background: linear-gradient(
    to bottom,
    rgba(248, 247, 243, 0.34) 0%,
    rgba(248, 247, 243, 0.08) 48%,
    rgba(28, 31, 35, 0.24) 100%
  );
}

#introScreen .eyebrow {
  color: #315f68;
  text-shadow:
    0 1px 2px rgba(255, 255, 255, 1),
    0 0 10px rgba(255, 255, 255, 0.9);
}

#introScreen #introTitle {
  color: #1d3139;
  text-shadow:
    0 1px 2px rgba(255, 255, 255, 1),
    0 0 12px rgba(255, 255, 255, 0.9);
}

#introScreen .intro-copy {
  margin: 34px 0;
  padding: 16px 18px;

  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: 12px;

  color: #3c494e;
  background: rgba(248, 247, 243, 0.8);

  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);

  box-shadow:
    0 8px 24px rgba(35, 49, 53, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

/* ========================================
   暗転シーン
   ======================================== */

/*
  通常時の #gameScreen::before より後へ書くことで、
  is-dark時だけ暗いオーバーレイへ置き換える。
*/
body.is-dark #gameScreen::before {
  background: linear-gradient(
    to bottom,
    rgba(9, 14, 15, 0.62) 0%,
    rgba(9, 14, 15, 0.7) 52%,
    rgba(9, 14, 15, 0.78) 100%
  );
}

/* 暗転時の見出しは、白系の半透明パネルへしない */
body.is-dark #gameScreen .scene-header {
  border: 1px solid rgba(255, 255, 255, 0.12);

  background: linear-gradient(
    90deg,
    rgba(18, 27, 29, 0.9) 0%,
    rgba(18, 27, 29, 0.78) 72%,
    rgba(18, 27, 29, 0.28) 100%
  );

  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
}

body.is-dark #gameScreen .scene-header .eyebrow {
  color: #b9d3d1;
  text-shadow: none;
}

body.is-dark #gameScreen #sceneHeading {
  color: #f0f4f2;
  text-shadow: none;
}

body.is-dark #gameScreen .id-label {
  color: #d6e2df;
  border-color: rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
}

/*
  本文カードは明るいまま残す。
  暗い背景とのコントラストで、場面転換を表現する。
*/
body.is-dark #gameScreen .story-content {
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow:
    0 16px 36px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

/* ========================================
   エピソード終了画面
   ======================================== */

#endingScreen::before {
  background: linear-gradient(
    to bottom,
    rgba(248, 247, 243, 0.18) 0%,
    rgba(248, 247, 243, 0.02) 36%,
    rgba(28, 31, 35, 0.3) 100%
  );
}

#endingScreen .eyebrow {
  color: #315f68;
  text-shadow:
    0 1px 2px rgba(255, 255, 255, 1),
    0 0 10px rgba(255, 255, 255, 0.9);
}

#endingScreen #endingTitle {
  color: #1d3139;
  text-shadow:
    0 1px 2px rgba(255, 255, 255, 1),
    0 0 12px rgba(255, 255, 255, 0.9);
}

#endingScreen .remains {
  margin: 30px 0 24px;
  padding: 22px 20px;

  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 14px;

  color: #29373c;
  background: rgba(248, 247, 243, 0.87);

  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);

  box-shadow:
    0 12px 30px rgba(35, 49, 53, 0.13),
    inset 0 1px 0 rgba(255, 255, 255, 0.74);

  text-align: left;
}

#endingScreen .remains h3 {
  margin-bottom: 16px;
  color: #24373d;
}

#endingScreen .remains li {
  color: #354349;
}

#endingScreen .coming-soon {
  color: #31464c;
  text-shadow:
    0 1px 2px rgba(255, 255, 255, 1),
    0 0 8px rgba(255, 255, 255, 0.8);
}

/* ========================================
   スマホ調整
   ======================================== */

@media (max-width: 560px) {
  #introScreen .intro-copy {
    margin: 28px 0;
    padding: 15px 16px;
    background: rgba(248, 247, 243, 0.85);
  }

  #endingScreen .remains {
    margin: 24px 0 20px;
    padding: 20px 17px;
    background: rgba(248, 247, 243, 0.9);
  }
}
