* {
  box-sizing: border-box;
}

:root {
  --panel: rgba(9, 12, 15, 0.9);
  --panel-strong: rgba(15, 18, 21, 0.98);
  --line: rgba(179, 195, 205, 0.22);
  --text: #f0eee8;
  --muted: #aeb8bf;
  --accent: #d9bb72;
  --danger: #d88a83;
}

html {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  height: 100vh;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  background: #05070a;
  font-family: system-ui, "Yu Gothic", "Meiryo", sans-serif;
}

.trainBg,
.trainBg > div,
.trainBg > div::before,
.trainBg > div::after {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.trainBg {
  z-index: 0;
  overflow: hidden;
  perspective: 700px;
  background:
    radial-gradient(ellipse at 50% 32%, rgba(65, 74, 76, 0.2), transparent 23%),
    linear-gradient(180deg, #080b10 0%, #030405 100%);
}

.tunnelLayer::before,
.tunnelLayer::after {
  content: "";
  opacity: 0.7;
  background:
    repeating-linear-gradient(90deg, transparent 0 72px, rgba(144, 165, 172, 0.16) 84px 92px, transparent 106px 162px),
    linear-gradient(180deg, rgba(15, 20, 24, 0.28), rgba(0, 0, 0, 0.85));
}

.tunnelLayer::before {
  right: 50%;
  transform-origin: right center;
  transform: skewY(6deg) scaleX(1.15);
  animation: rushLeft 2.25s linear infinite;
}

.tunnelLayer::after {
  left: 50%;
  transform-origin: left center;
  transform: skewY(-6deg) scaleX(1.15);
  animation: rushRight 2.25s linear infinite;
}

.lightLayer::before,
.lightLayer::after {
  content: "";
  opacity: 0.55;
  background:
    repeating-linear-gradient(90deg, transparent 0 220px, rgba(231, 214, 156, 0.24) 238px 246px, transparent 270px 390px);
}

.lightLayer::before {
  right: 50%;
  animation: rushLeft 1.2s linear infinite;
}

.lightLayer::after {
  left: 50%;
  animation: rushRight 1.2s linear infinite;
}

.pillarLayer::before,
.pillarLayer::after {
  content: "";
  opacity: 0.55;
  background:
    repeating-linear-gradient(90deg, transparent 0 86px, rgba(0, 0, 0, 0.52) 92px 118px, transparent 126px 190px);
}

.pillarLayer::before {
  right: 50%;
  animation: rushLeft 0.65s linear infinite;
}

.pillarLayer::after {
  left: 50%;
  animation: rushRight 0.65s linear infinite;
}

.carLayer {
  background:
    radial-gradient(ellipse at 50% 44%, transparent 0 24%, rgba(0, 0, 0, 0.42) 61%, rgba(0, 0, 0, 0.72) 100%),
    linear-gradient(90deg, rgba(0, 0, 0, 0.78) 0 8%, transparent 13% 87%, rgba(0, 0, 0, 0.78) 92%),
    linear-gradient(180deg, rgba(235, 226, 190, 0.1) 0 7%, transparent 8% 62%, rgba(0, 0, 0, 0.58) 78%);
}

body[data-danger="2"] .lightLayer,
body[data-danger="3"] .lightLayer {
  opacity: 0.7;
}

body[data-danger="3"] .trainBg {
  filter: saturate(0.72);
}

@keyframes rushLeft {
  from { transform: translate3d(0, 0, 0) skewY(6deg) scaleX(1.15); }
  to { transform: translate3d(-420px, 0, 0) skewY(6deg) scaleX(1.15); }
}

@keyframes rushRight {
  from { transform: translate3d(0, 0, 0) skewY(-6deg) scaleX(1.15); }
  to { transform: translate3d(420px, 0, 0) skewY(-6deg) scaleX(1.15); }
}

.app {
  position: relative;
  z-index: 1;
  width: min(1060px, 100%);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 8px max(12px, env(safe-area-inset-bottom));
}

.playArea {
  display: grid;
  height: 100%;
  gap: 7px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 4px;
}

.visualStage,
.actionPanel,
.compactHud,
.drawerArea details {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(12px);
  box-shadow: 0 18px 64px rgba(0, 0, 0, 0.32);
}

.visualStage {
  position: relative;
  position: sticky;
  top: 0;
  z-index: 8;
  height: clamp(390px, 60dvh, 640px);
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(8, 11, 14, 0.22), rgba(0, 0, 0, 0.72)),
    radial-gradient(ellipse at 50% 25%, rgba(178, 157, 110, 0.12), transparent 42%),
    #07090c;
}

.sceneBackdrop,
.sceneAtmosphere,
.sceneSubject,
.stageVignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.sceneBackdrop {
  background-position: center;
  background-size: cover;
  opacity: 0.94;
}

.sceneBackdrop::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(18, 24, 27, 0.42) 0 13%, transparent 30%),
    linear-gradient(90deg, rgba(0, 0, 0, 0.5) 0 6%, transparent 17% 83%, rgba(0, 0, 0, 0.5) 94%);
}

.visualStage[data-tone="car-rear"] .sceneBackdrop {
  background-image:
    linear-gradient(180deg, rgba(56, 68, 72, 0.72), rgba(11, 14, 16, 0.96));
}

.visualStage[data-tone="rear-door"] .sceneBackdrop {
  background-image:
    radial-gradient(ellipse at 50% 45%, rgba(128, 30, 35, 0.2), transparent 24%),
    linear-gradient(90deg, rgba(17, 20, 23, 0.95) 0 30%, rgba(55, 63, 64, 0.8) 49% 51%, rgba(17, 20, 23, 0.95) 70%),
    linear-gradient(180deg, rgba(62, 75, 80, 0.82), rgba(8, 10, 12, 0.96));
}

.visualStage[data-tone="passenger"] .sceneBackdrop {
  background-image:
    radial-gradient(ellipse at 65% 44%, rgba(216, 193, 126, 0.12), transparent 26%),
    linear-gradient(180deg, rgba(61, 70, 72, 0.9), rgba(9, 11, 13, 0.98));
}

.visualStage[data-tone="front"] .sceneBackdrop {
  background-image:
    radial-gradient(ellipse at 50% 38%, rgba(220, 200, 142, 0.16), transparent 22%),
    linear-gradient(90deg, rgba(8, 10, 12, 0.95) 0 28%, rgba(50, 55, 56, 0.88) 41% 59%, rgba(8, 10, 12, 0.95) 72%),
    linear-gradient(180deg, rgba(42, 49, 51, 0.9), rgba(4, 5, 6, 0.98));
}

.visualStage[data-tone="morning"] .sceneBackdrop {
  background-image:
    radial-gradient(ellipse at 45% 20%, rgba(255, 230, 174, 0.35), transparent 28%),
    linear-gradient(180deg, rgba(102, 128, 132, 0.78), rgba(34, 43, 47, 0.92));
}

.visualStage[data-tone="terminal"] .sceneBackdrop,
.visualStage[data-tone="lost"] .sceneBackdrop {
  background-image:
    radial-gradient(ellipse at 50% 52%, rgba(80, 24, 33, 0.28), transparent 30%),
    linear-gradient(180deg, rgba(24, 24, 28, 0.92), rgba(0, 0, 0, 0.98));
}

.sceneAtmosphere {
  background:
    radial-gradient(ellipse at 28% 44%, rgba(218, 196, 130, 0.1), transparent 18%),
    radial-gradient(ellipse at 74% 40%, rgba(80, 20, 28, 0.12), transparent 21%),
    linear-gradient(180deg, transparent 42%, rgba(0, 0, 0, 0.54));
  mix-blend-mode: screen;
}

.sceneSubject {
  top: 6%;
  bottom: 22%;
  left: 50%;
  width: min(42vw, 300px);
  height: auto;
  transform: translateX(-50%);
  background-repeat: no-repeat;
  background-position: center center;
  background-size: contain;
  opacity: 0.98;
  filter: drop-shadow(0 20px 36px rgba(0, 0, 0, 0.55));
}

.sceneSubject[hidden] {
  display: none;
}

.subject-person {
  left: 58%;
  top: 9%;
  bottom: 27%;
  width: min(34vw, 260px);
}

.subject-white-girl {
  left: 48%;
  top: 10%;
  bottom: 18%;
  width: min(38vw, 320px);
  background-position: center top;
}

.subject-attendant {
  left: 53%;
  top: 5%;
  bottom: 24%;
  width: min(36vw, 300px);
  opacity: 0.95;
  filter: drop-shadow(0 0 30px rgba(210, 194, 122, 0.18)) drop-shadow(0 18px 32px rgba(0, 0, 0, 0.64));
}

.subject-rear-attendant {
  left: 52%;
  width: min(34vw, 280px);
}

.subject-front-attendant {
  left: 52%;
  top: 4%;
  bottom: 22%;
  width: min(38vw, 320px);
}

.subject-enemy {
  top: 7%;
  bottom: 25%;
  width: min(40vw, 330px);
  opacity: 0.9;
  filter: drop-shadow(0 0 34px rgba(95, 20, 35, 0.45));
}

.subject-moonbeast {
  left: 50%;
  top: 4%;
  bottom: 28%;
  width: min(50vw, 430px);
  opacity: 0.94;
  filter: drop-shadow(0 0 34px rgba(112, 28, 44, 0.48)) drop-shadow(0 20px 40px rgba(0, 0, 0, 0.68));
}

.subject-item {
  top: 22%;
  bottom: 36%;
  width: min(30vw, 220px);
}

.subject-passcase {
  top: 17%;
  bottom: 32%;
  width: min(36vw, 280px);
}

.subject-emergency-button {
  top: 16%;
  bottom: 32%;
  width: min(34vw, 250px);
}

.subject-red-note {
  top: 15%;
  bottom: 34%;
  width: min(36vw, 300px);
}

.subject-event {
  left: 50%;
  top: 5%;
  bottom: 24%;
  width: min(72vw, 780px);
  opacity: 0.94;
  filter: drop-shadow(0 22px 42px rgba(0, 0, 0, 0.62));
}

.subject-window-shadow {
  inset: 2% 5% 20%;
  width: auto;
  transform: none;
  background-size: cover;
  opacity: 0.78;
  mix-blend-mode: screen;
}

.subject-door-clue {
  top: 5%;
  bottom: 19%;
  width: min(46vw, 420px);
}

.subject-brother-scream {
  top: 5%;
  bottom: 20%;
  width: min(50vw, 430px);
}

.subject-moonbeast-attack {
  inset: 2% 2% 18%;
  width: auto;
  transform: none;
  background-size: contain;
  opacity: 0.96;
  filter: drop-shadow(0 0 36px rgba(120, 25, 32, 0.55)) drop-shadow(0 24px 44px rgba(0, 0, 0, 0.72));
}

.stageVignette {
  background:
    radial-gradient(ellipse at 50% 34%, transparent 0 45%, rgba(0, 0, 0, 0.55) 100%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.05), rgba(0, 0, 0, 0.72));
}

.restartButton {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 5;
  width: 42px;
  min-height: 42px;
  border: 1px solid rgba(240, 210, 140, 0.42);
  border-radius: 999px;
  background: rgba(9, 12, 15, 0.72);
  color: #fff4df;
  padding: 0;
  font-size: 20px;
  backdrop-filter: blur(8px);
}

.stageCaption {
  position: absolute;
  left: 14px;
  right: 68px;
  top: 12px;
  z-index: 2;
  display: grid;
  gap: 1px;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.85);
}

.stageCaption span {
  color: var(--accent);
  font-size: 12px;
}

.stageCaption strong {
  overflow: hidden;
  font-family: Georgia, "Yu Mincho", serif;
  font-size: clamp(22px, 4.4vw, 38px);
  font-weight: 700;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.storyPanel {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 4;
  max-height: min(32vh, 190px);
  overflow: auto;
  border: 1px solid rgba(226, 214, 178, 0.22);
  border-radius: 8px;
  background: rgba(8, 10, 12, 0.78);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.36);
  padding: 12px 14px;
  backdrop-filter: blur(10px);
}

.text {
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.72;
}

.notice {
  min-height: 1.2em;
  margin-top: 6px;
  color: #ffd18a;
  font-size: 13px;
}

.actionPanel {
  padding: 7px;
}

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

button {
  min-height: 36px;
  border: 1px solid #5f6b71;
  border-radius: 7px;
  background: rgba(28, 34, 38, 0.98);
  color: #f6f0e5;
  padding: 7px 8px;
  font-size: 13px;
  line-height: 1.35;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
  background: rgba(42, 49, 53, 0.98);
}

.choice {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: center;
  text-align: left;
}

.choiceIcon {
  color: var(--accent);
  font-family: Georgia, serif;
  font-weight: 700;
}

.freeForm {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 8px;
}

.freeForm[hidden] {
  display: none;
}

.freeForm input {
  min-width: 0;
  min-height: 42px;
  border: 1px solid rgba(179, 195, 205, 0.28);
  border-radius: 8px;
  background: rgba(4, 6, 8, 0.86);
  color: #fff7e8;
  padding: 0 12px;
  font-size: 14px;
}

.compactHud {
  display: grid;
  grid-template-columns: 1.25fr repeat(6, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
}

.compactHud div {
  min-width: 0;
  padding: 7px 8px;
  background: rgba(255, 255, 255, 0.035);
}

.compactHud span {
  display: block;
  color: var(--muted);
  font-size: 10px;
}

.compactHud strong {
  display: block;
  overflow: hidden;
  color: #fff7e8;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drawerArea {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.drawerArea details {
  min-width: 0;
  padding: 9px 10px;
}

.drawerArea summary {
  color: #dce4e5;
  cursor: pointer;
  font-size: 13px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  color: var(--muted);
}

.chip {
  border: 1px solid #52626a;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: #e4eaea;
  padding: 4px 8px;
  font-size: 12px;
}

.log {
  display: grid;
  gap: 8px;
  max-height: 180px;
  margin-top: 8px;
  overflow: auto;
}

.logItem {
  border-left: 2px solid #5b6971;
  color: #cbd1d4;
  padding-left: 8px;
  font-size: 12px;
  line-height: 1.5;
}

.log-san,
.log-danger {
  border-left-color: var(--danger);
}

.devnote {
  margin: 8px 0 0;
  color: #9ba8af;
  font-size: 12px;
  line-height: 1.5;
}

.eventPopup {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 20;
  width: min(520px, calc(100vw - 24px));
  transform: translate(-50%, 125%);
  border: 1px solid rgba(240, 210, 140, 0.42);
  border-radius: 8px;
  background: rgba(18, 14, 12, 0.96);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.48);
  opacity: 0;
  padding: 14px 16px;
  white-space: pre-wrap;
  transition: transform 180ms ease, opacity 180ms ease;
}

.eventPopup.visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

.eventPopupTitle {
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.eventPopupText {
  color: #fff4df;
  font-size: 14px;
  line-height: 1.55;
}

.seoInfo {
  color: rgba(235, 229, 210, 0.78);
  font-size: 13px;
  line-height: 1.8;
  padding: 4px 2px 12px;
}

.seoInfo h1 {
  margin: 6px 0 4px;
  color: rgba(255, 244, 222, 0.9);
  font-size: 18px;
  line-height: 1.35;
  letter-spacing: 0;
}

.seoInfo p {
  margin: 0 0 8px;
}

.seoInfo details {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding: 7px 0;
}

.seoInfo summary {
  color: rgba(243, 215, 151, 0.9);
  cursor: pointer;
}

@media (max-width: 720px) {
  .app {
    padding: max(8px, env(safe-area-inset-top)) 8px max(12px, env(safe-area-inset-bottom));
  }

  .playArea {
    gap: 8px;
  }

  .visualStage {
    height: min(56dvh, 500px);
    min-height: 360px;
    border-radius: 6px;
  }

  .stageCaption {
    left: 10px;
    right: 58px;
    top: 9px;
  }

  .stageCaption strong {
    font-size: 25px;
    line-height: 1.16;
    white-space: normal;
  }

  .restartButton {
    top: 8px;
    right: 8px;
    width: 38px;
    min-height: 38px;
  }

  .sceneSubject {
    top: 8%;
    bottom: 43%;
    width: min(64vw, 250px);
  }

  .subject-person {
    left: 58%;
    top: 10%;
    bottom: 44%;
    width: min(48vw, 220px);
  }

  .subject-white-girl {
    left: 50%;
    top: 10%;
    bottom: 42%;
    width: min(52vw, 230px);
  }

  .subject-attendant {
    left: 52%;
    top: 8%;
    bottom: 42%;
    width: min(56vw, 245px);
  }

  .subject-enemy {
    top: 9%;
    bottom: 43%;
    width: min(58vw, 270px);
  }

  .subject-moonbeast {
    left: 50%;
    top: 8%;
    bottom: 43%;
    width: min(76vw, 320px);
  }

  .subject-item {
    top: 22%;
    bottom: 48%;
    width: min(44vw, 190px);
  }

  .storyPanel {
    left: 8px;
    right: 8px;
    bottom: 8px;
    max-height: min(26dvh, 205px);
    padding: 9px 10px;
    background: rgba(5, 8, 10, 0.72);
    border-color: rgba(214, 229, 238, 0.28);
    backdrop-filter: blur(7px);
    overscroll-behavior: contain;
  }

  .text {
    font-size: 13px;
    line-height: 1.55;
  }

  .choices {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  button,
  .freeForm input {
    min-height: 38px;
    font-size: 13px;
    line-height: 1.35;
  }

  .freeForm input {
    font-size: 16px;
  }

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

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

  .compactHud div {
    padding: 7px 8px;
  }

  .compactHud span {
    font-size: 10px;
  }

  .compactHud strong {
    font-size: 13px;
  }

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

.drawerArea details {
  padding: 8px;
}

.seoInfo {
  color: rgba(235, 229, 210, 0.78);
  font-size: 13px;
  line-height: 1.8;
  padding: 4px 2px 12px;
}

.seoInfo h1 {
  margin: 6px 0 4px;
  color: rgba(255, 244, 222, 0.9);
  font-size: 18px;
  line-height: 1.35;
  letter-spacing: 0;
}

.seoInfo p {
  margin: 0 0 8px;
}

.seoInfo details {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding: 7px 0;
}

.seoInfo summary {
  color: rgba(243, 215, 151, 0.9);
  cursor: pointer;
}

  .eventPopup {
    bottom: max(10px, env(safe-area-inset-bottom));
    width: calc(100vw - 16px);
    max-height: min(52dvh, 360px);
    overflow: auto;
    padding: 9px 10px;
    overscroll-behavior: contain;
  }

  .eventPopupTitle {
    font-size: 14px;
  }

  .eventPopupText {
    font-size: 15px;
    line-height: 1.7;
  }
}

@media (max-width: 420px) {
  .visualStage {
    height: min(52dvh, 460px);
    min-height: 340px;
  }

  .storyPanel {
    max-height: min(22dvh, 165px);
    padding: 8px 9px;
    background: rgba(5, 8, 10, 0.68);
  }

  .text {
    font-size: 12.5px;
    line-height: 1.52;
  }

  .stageCaption strong {
    font-size: 23px;
  }

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

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

  .eventPopupText {
    font-size: 15px;
  }

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

@media (prefers-reduced-motion: reduce) {
  .tunnelLayer::before,
  .tunnelLayer::after,
  .lightLayer::before,
  .lightLayer::after,
  .pillarLayer::before,
  .pillarLayer::after {
    animation-duration: 90s;
  }

  .eventPopup {
    transition: none;
  }
}


.subject-true-girl {
  filter: drop-shadow(0 0 24px rgba(236, 205, 116, 0.16)) drop-shadow(0 20px 36px rgba(0, 0, 0, 0.55));
}


.statusChips {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.statusChips span {
  border: 1px solid rgba(179, 195, 205, 0.18);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  padding: 6px 7px;
}

.statusChips strong {
  color: #fff7e8;
}
