:root {
  color-scheme: dark;
  --bg: #171513;
  --bg-soft: #211e1a;
  --panel: rgba(31, 29, 26, 0.92);
  --panel-strong: rgba(18, 18, 16, 0.96);
  --line: rgba(234, 216, 174, 0.18);
  --text: #f6efe1;
  --muted: #bfb3a0;
  --gold: #e5bb55;
  --red: #b8463c;
  --green: #3f8a69;
  --blue: #4f89a8;
  --violet: #7a638f;
  --shadow: #11100e;
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Yu Gothic UI", "Noto Sans JP", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background:
    linear-gradient(130deg, rgba(184, 70, 60, 0.18) 0 18%, transparent 18% 100%),
    linear-gradient(228deg, rgba(63, 138, 105, 0.2) 0 22%, transparent 22% 100%),
    linear-gradient(160deg, #171513 0%, #242018 46%, #101312 100%);
  color: var(--text);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

button {
  color: inherit;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.app {
  position: relative;
  width: min(100%, 480px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 10px) 12px calc(env(safe-area-inset-bottom) + 12px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 44px;
}

.eyebrow,
.panelLabel {
  margin: 0;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  margin-top: 2px;
  font-size: 1.42rem;
  line-height: 1.1;
  font-weight: 850;
}

.primaryButton:active,
.continueButton:active,
.choiceButton:active,
.resetButton:active {
  transform: translateY(1px);
}

.stagePanel {
  position: relative;
  min-height: 156px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #171513;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.28);
}

.sceneArt {
  position: relative;
  width: 100%;
  height: 156px;
  min-height: 156px;
  overflow: hidden;
  background: #171513;
}

.sceneArt svg,
.sceneImage {
  display: block;
  width: 100%;
  height: 100%;
}

.sceneImage {
  object-fit: cover;
  object-position: 50% 50%;
  transform: scale(1.015);
  filter: saturate(0.98) contrast(1.06) brightness(0.82);
}

.sceneVignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(9, 9, 8, 0.72), rgba(9, 9, 8, 0.18) 47%, rgba(9, 9, 8, 0.36)),
    linear-gradient(180deg, rgba(9, 9, 8, 0.06), rgba(9, 9, 8, 0.54));
  box-shadow:
    inset 0 0 0 1px rgba(246, 239, 225, 0.06),
    inset 0 -42px 58px rgba(0, 0, 0, 0.45);
}

.sceneCharacters {
  position: absolute;
  left: 10px;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: flex-end;
  gap: 0;
  pointer-events: none;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.52));
}

.stageCharacter {
  position: relative;
  display: inline-flex;
  align-items: flex-end;
}

.stagePortrait {
  width: 84px;
  height: 112px;
  object-fit: cover;
  object-position: 50% 0%;
  border: 1px solid rgba(234, 216, 174, 0.34);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  background: #11100e;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.stagePortrait.support {
  width: 68px;
  height: 94px;
  margin-left: -18px;
  opacity: 0.9;
  transform: translateY(7px);
}

.stageYouPill {
  position: absolute;
  left: 7px;
  bottom: 7px;
  z-index: 3;
  padding: 2px 6px;
  border: 1px solid rgba(229, 187, 85, 0.42);
  border-radius: 5px;
  background: rgba(14, 14, 12, 0.78);
  color: #f8dda0;
  font-size: 0.62rem;
  font-weight: 900;
  line-height: 1;
}

.perspectiveBadge {
  position: absolute;
  z-index: 5;
  right: 10px;
  bottom: 10px;
  max-width: min(52%, 230px);
  padding: 6px 8px;
  border: 1px solid rgba(229, 187, 85, 0.34);
  border-radius: var(--radius);
  background: rgba(14, 14, 12, 0.72);
  color: #f8dda0;
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1.2;
}

.chapterBadge {
  position: absolute;
  z-index: 4;
  left: auto;
  right: 10px;
  top: 10px;
  bottom: auto;
  width: min(44%, 190px);
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 9px;
  border: 1px solid rgba(246, 239, 225, 0.14);
  border-radius: var(--radius);
  background: rgba(12, 12, 10, 0.72);
  backdrop-filter: blur(12px);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 700;
}

#chapterName {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#chapterStep {
  flex: 0 0 auto;
}

.routePanel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 32px;
  padding: 6px 8px;
  border: 1px solid rgba(234, 216, 174, 0.16);
  border-radius: var(--radius);
  background: rgba(18, 18, 16, 0.62);
}

#goalText {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.25;
}

.chapterFocus {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 7px;
  padding-left: 8px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.66rem;
  line-height: 1.2;
}

.chapterFocus strong {
  color: var(--gold);
  font-size: 0.72rem;
}

.resetButton {
  flex: 0 0 auto;
  min-height: 28px;
  padding: 0 8px;
  border: 1px solid rgba(234, 216, 174, 0.16);
  border-radius: var(--radius);
  background: rgba(246, 239, 225, 0.05);
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 850;
  line-height: 1;
}

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

.stat {
  min-width: 0;
  padding: 6px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(24, 23, 21, 0.82);
}

.stat.danger {
  border-color: rgba(184, 70, 60, 0.55);
}

.stat.warning {
  border-color: rgba(229, 187, 85, 0.48);
}

.statTop {
  display: flex;
  justify-content: space-between;
  gap: 4px;
  align-items: baseline;
  font-size: 0.66rem;
  color: var(--muted);
}

.statValue {
  color: var(--text);
  font-weight: 800;
}

.statMeaning {
  display: none;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.3;
}

.bar {
  position: relative;
  height: 5px;
  margin-top: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(246, 239, 225, 0.12);
}

.barFill {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--value);
  border-radius: inherit;
  background: var(--stat-color);
}

.eventPanel {
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  transition: border-color 120ms ease, background 120ms ease, transform 90ms ease;
}

.eventPanel.resultReady {
  border-color: rgba(229, 187, 85, 0.34);
  background: rgba(31, 29, 26, 0.96);
  cursor: pointer;
}

.eventPanel.resultReady:active {
  transform: translateY(1px);
}

.eventTopline {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

#sourceNote {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
}

#eventTitle {
  margin-top: 6px;
  color: var(--gold);
  font-size: 1.12rem;
  line-height: 1.28;
}

.decisionFrame {
  display: grid;
  gap: 5px;
  margin-top: 8px;
  padding: 8px 9px;
  border: 1px solid rgba(234, 216, 174, 0.2);
  border-radius: var(--radius);
  background: rgba(14, 14, 12, 0.42);
}

#roleText,
#questionText,
#stakesText {
  margin: 0;
  line-height: 1.45;
}

#roleText {
  color: #f8dda0;
  font-size: 0.79rem;
  font-weight: 850;
}

#questionText {
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 800;
}

#stakesText {
  color: var(--muted);
  font-size: 0.74rem;
}

#eventText {
  margin-top: 6px;
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.62;
}

.castLine {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.castChip {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 7px 4px 4px;
  border: 1px solid rgba(234, 216, 174, 0.18);
  border-radius: var(--radius);
  background: rgba(14, 14, 12, 0.42);
}

.castChip.perspectiveCast {
  border-color: rgba(229, 187, 85, 0.38);
  background: rgba(229, 187, 85, 0.09);
}

.castThumb {
  width: 29px;
  height: 36px;
  flex: 0 0 auto;
  border-radius: 5px;
  object-fit: cover;
  object-position: 50% 0%;
  background: #11100e;
}

.castName,
.castRole {
  display: block;
  line-height: 1.1;
}

.castName {
  color: var(--text);
  font-size: 0.74rem;
  font-weight: 850;
}

.youTag {
  display: inline-block;
  margin-left: 5px;
  padding: 1px 4px;
  border-radius: 5px;
  background: rgba(229, 187, 85, 0.2);
  color: #f8dda0;
  font-size: 0.58rem;
  font-weight: 900;
  vertical-align: 1px;
}

.castRole {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 700;
}

.resultBox,
.canonBox {
  margin-top: 8px;
  padding: 7px 9px;
  border-radius: var(--radius);
}

.resultBox {
  border: 1px solid rgba(229, 187, 85, 0.28);
  background: rgba(229, 187, 85, 0.08);
}

.canonBox {
  border: 1px solid rgba(79, 137, 168, 0.28);
  background: rgba(79, 137, 168, 0.09);
}

#resultText,
#canonText {
  margin-top: 4px;
  font-size: 0.8rem;
  line-height: 1.52;
  white-space: pre-line;
}

#resultText {
  color: #f3ddaa;
}

#canonText {
  color: #d9e6e8;
}

.choices {
  display: grid;
  gap: 8px;
}

.choices.resultChoices {
  margin-bottom: calc(env(safe-area-inset-bottom) + 8px);
}

.choiceButton {
  width: 100%;
  min-height: 56px;
  padding: 8px 10px;
  border: 1px solid rgba(234, 216, 174, 0.2);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(229, 187, 85, 0.11), rgba(79, 137, 168, 0.08)),
    rgba(24, 23, 21, 0.94);
  text-align: left;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
}

.choiceHead {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
}

.choiceTitle {
  min-width: 0;
  font-size: 0.92rem;
  font-weight: 850;
  line-height: 1.25;
}

.choiceCost {
  flex: 0 0 auto;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 800;
}

.choiceText {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.35;
}

.continueButton {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid rgba(229, 187, 85, 0.36);
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(229, 187, 85, 0.2), rgba(217, 133, 67, 0.14));
  color: var(--text);
  font-weight: 900;
  text-align: center;
}

.deltaRow {
  display: none;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 7px;
}

.delta {
  padding: 3px 6px;
  border-radius: 999px;
  background: rgba(246, 239, 225, 0.08);
  color: var(--text);
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1;
}

.delta.good {
  color: #8fe0b4;
}

.delta.bad {
  color: #f18c82;
}

.lowerPanel {
  display: none;
  grid-template-columns: 1fr 1.25fr;
  gap: 8px;
  min-height: 88px;
}

.lowerPanel > div {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(18, 18, 16, 0.74);
}

.relics {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}

.runLog {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.35;
}

.relic {
  max-width: 100%;
  padding: 5px 7px;
  border-radius: 999px;
  background: rgba(229, 187, 85, 0.15);
  color: #f8dda0;
  font-size: 0.7rem;
  font-weight: 800;
  line-height: 1.1;
}

.chronicle {
  display: grid;
  gap: 5px;
  max-height: 72px;
  margin: 7px 0 0;
  padding-left: 18px;
  overflow: auto;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.35;
}

.endOverlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(8, 8, 7, 0.72);
  backdrop-filter: blur(14px);
}

.endOverlay.gameOverOverlay {
  background: rgba(24, 4, 3, 0.84);
}

.hidden {
  display: none;
}

.endCard {
  width: min(100%, 420px);
  padding: 20px;
  border: 1px solid rgba(234, 216, 174, 0.24);
  border-radius: var(--radius);
  background: var(--panel-strong);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.44);
}

.gameOverOverlay .endCard {
  border-color: rgba(184, 70, 60, 0.72);
  background: linear-gradient(180deg, rgba(58, 17, 13, 0.96), rgba(17, 14, 11, 0.98));
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.58), 0 0 0 1px rgba(255, 130, 98, 0.12);
}

.endCard h2 {
  margin-top: 6px;
  color: var(--gold);
  font-size: 1.45rem;
  line-height: 1.25;
}

.gameOverOverlay .eyebrow {
  color: #ff8d78;
  letter-spacing: 0.08em;
}

.gameOverOverlay .endCard h2 {
  color: #ffb29f;
  font-size: 1.9rem;
}

.endCard p {
  margin-top: 10px;
  color: var(--text);
  line-height: 1.65;
  white-space: pre-line;
}

.endScore {
  display: grid;
  gap: 6px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.84rem;
}

.sharePreview {
  margin-top: 12px;
  padding: 10px;
  border: 1px solid rgba(229, 187, 85, 0.28);
  border-radius: var(--radius);
  background: rgba(229, 187, 85, 0.08);
  color: #f3ddaa;
  font-size: 0.86rem;
  font-weight: 750;
  line-height: 1.45;
  white-space: pre-line;
}

.gameOverBadge {
  padding: 8px 9px;
  border: 1px solid rgba(255, 141, 120, 0.36);
  border-radius: var(--radius);
  background: rgba(184, 70, 60, 0.16);
  color: #ffd1c7;
}

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

.primaryButton,
.secondaryButton {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: var(--radius);
  font-weight: 900;
}

.primaryButton {
  background: linear-gradient(135deg, var(--gold), #d98543);
  color: #1b1309;
}

.secondaryButton {
  border: 1px solid rgba(234, 216, 174, 0.24);
  background: rgba(246, 239, 225, 0.08);
  color: var(--text);
}

@media (max-height: 760px) {
  .app {
    gap: 8px;
  }

  .stagePanel,
  .sceneArt {
    height: 146px;
    min-height: 146px;
  }

  .stagePortrait {
    width: 78px;
    height: 104px;
  }

  .stagePortrait.support {
    width: 64px;
    height: 88px;
  }

  .stageYouPill {
    left: 6px;
    bottom: 6px;
    font-size: 0.58rem;
  }

  .choiceButton {
    min-height: 66px;
  }

  .lowerPanel {
    display: none;
  }
}

@media (max-width: 360px) {
  .stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .stat {
    padding: 6px;
  }
}
