:root {
  color-scheme: dark;
  --ink: #f2f0e8;
  --muted: #aeb6ad;
  --soft: #d7ded6;
  --line: rgba(223, 232, 224, 0.2);
  --line-strong: rgba(223, 232, 224, 0.38);
  --panel: rgba(16, 19, 18, 0.82);
  --panel-strong: rgba(8, 10, 10, 0.94);
  --green: #83b19c;
  --blue: #9caec7;
  --gold: #ceb36e;
  --black: #070807;
  font-family: "Yu Gothic", "Hiragino Sans", "Meiryo", system-ui, sans-serif;
  background: var(--black);
  color: var(--ink);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: var(--black);
}

button,
select {
  font: inherit;
}

[hidden] {
  display: none !important;
}

a {
  color: inherit;
}

h1,
h2,
h3,
p,
button,
select {
  margin-top: 0;
  overflow-wrap: anywhere;
}

.vn-shell {
  min-height: 100vh;
}

.stage {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(circle at 72% 18%, rgba(156, 174, 199, 0.16), transparent 32%),
    linear-gradient(90deg, rgba(7, 8, 7, 0.97), rgba(21, 25, 23, 0.84) 58%, rgba(7, 8, 7, 0.96)),
    linear-gradient(180deg, #151816, #070807 72%);
}

.stage.has-scene-bg {
  background:
    linear-gradient(90deg, rgba(7, 8, 7, 0.9), rgba(7, 8, 7, 0.46), rgba(7, 8, 7, 0.94)),
    var(--scene-bg) center / cover,
    linear-gradient(180deg, #151816, #070807 72%);
}

.signal-grid {
  position: absolute;
  inset: 0;
  z-index: -2;
  background-image:
    linear-gradient(rgba(180, 206, 193, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(180, 206, 193, 0.055) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(90deg, rgba(0, 0, 0, 0.95), transparent 80%);
}

.scanline {
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    repeating-linear-gradient(180deg, rgba(255, 255, 255, 0.03) 0, rgba(255, 255, 255, 0.03) 1px, transparent 1px, transparent 8px),
    linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.42));
}

.topbar {
  width: min(1240px, calc(100% - 44px));
  max-width: 100%;
  min-width: 0;
  min-height: 72px;
  position: relative;
  z-index: 3;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 16px;
  padding: 18px 0;
}

.brand {
  width: fit-content;
  color: #fffdf5;
  font-weight: 800;
  text-decoration: none;
}

.story-picker {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.story-picker label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.story-picker select,
.topbar button,
.backlog button,
.portal-links a {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: rgba(9, 11, 11, 0.76);
  color: var(--ink);
}

.story-picker select {
  max-width: min(38vw, 420px);
  padding: 0 12px;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.topbar button,
.backlog button {
  min-width: 64px;
  padding: 0 11px;
  cursor: pointer;
}

.topbar button:hover,
.topbar button:focus-visible,
.portal-links a:hover,
.portal-links a:focus-visible,
.choice-button:hover,
.choice-button:focus-visible {
  border-color: var(--green);
  outline: none;
}

.reader,
.empty-state {
  width: min(1120px, calc(100% - 44px));
  min-height: calc(100vh - 112px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(250px, 360px) minmax(0, 1fr);
  gap: clamp(20px, 4vw, 42px);
  align-items: end;
  padding: 34px 0 58px;
}

.empty-state {
  align-items: center;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 360px);
}

.scene-meta {
  align-self: center;
}

.eyebrow,
.panel-title {
  margin: 0 0 10px;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.scene-meta h1,
.empty-state h1 {
  max-width: 11em;
  margin: 0;
  color: #fffdf5;
  font-size: clamp(2rem, 5.4vw, 4.9rem);
  line-height: 1.04;
  letter-spacing: 0;
}

.meta-note,
.empty-state p {
  max-width: 42rem;
  margin: 18px 0 0;
  color: var(--muted);
  line-height: 1.85;
}

.textbox {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(14px);
}

.portal-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 22px;
}

.portal-links a {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.textbox {
  min-height: 292px;
  max-height: min(58vh, 560px);
  overflow: auto;
  padding: clamp(22px, 3vw, 34px);
  cursor: pointer;
}

.speaker {
  min-height: 1.35em;
  margin: 0 0 14px;
  color: var(--gold);
  font-weight: 850;
}

.line {
  max-width: 54rem;
  margin: 0;
  white-space: pre-wrap;
  color: rgba(255, 255, 252, 0.96);
  font-size: clamp(1.02rem, 1rem + 0.16vw, 1.15rem);
  line-height: 2.05;
}

.choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.choice-button {
  min-height: 54px;
  padding: 12px 14px;
  border: 1px solid rgba(180, 205, 196, 0.28);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  cursor: pointer;
  text-align: left;
}

.choice-button:hover,
.choice-button:focus-visible {
  background: rgba(131, 177, 156, 0.12);
}

.backlog {
  position: fixed;
  z-index: 5;
  inset: 0 0 0 auto;
  width: min(520px, 100vw);
  padding: 22px;
  background: var(--panel-strong);
  border-left: 1px solid var(--line);
  overflow: auto;
  box-shadow: -20px 0 60px rgba(0, 0, 0, 0.42);
}

.backlog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.backlog h2 {
  margin: 0;
  font-size: 1.2rem;
}

.backlog-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.backlog-entry,
.backlog-empty {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--soft);
  background: rgba(255, 255, 255, 0.04);
}

body.has-empty-library {
  background: #f5f3ec;
}

.stage.has-empty-library {
  min-height: 0;
  color: #252821;
  background: #f5f3ec;
}

.stage.has-empty-library .signal-grid,
.stage.has-empty-library .scanline,
.stage.has-empty-library .story-picker,
.stage.has-empty-library .topbar-actions {
  display: none;
}

.stage.has-empty-library .brand {
  color: #252821;
}

.stage.has-empty-library .empty-state {
  width: min(900px, calc(100% - 44px));
  min-height: 0;
  display: block;
  padding: clamp(3rem, 8vw, 5rem) 0 3rem;
}

.stage.has-empty-library .empty-state h1 {
  max-width: none;
  color: #252821;
  font-size: clamp(2rem, 5vw, 3.6rem);
  line-height: 1.2;
}

.stage.has-empty-library .empty-state p {
  color: #55584f;
}

.stage.has-empty-library .portal-links a {
  border-radius: 0;
  border-color: #8f9388;
  background: transparent;
  color: #31583d;
}

.stage.has-empty-library .portal-links a:focus-visible {
  outline: 3px solid #31583d;
  outline-offset: 3px;
}

.archive-page {
  color-scheme: light;
  color: #252821;
  background: #f5f3ec;
}

.archive-shell {
  width: min(760px, calc(100% - 40px));
  min-height: 100vh;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding-block: clamp(56px, 12vh, 120px);
}

.archive-shell h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.6rem);
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: -0.035em;
}

.archive-status {
  max-width: 32rem;
  margin: 1.5rem 0 0;
  padding-top: 1.25rem;
  border-top: 1px solid #aaa99b;
  color: #55584f;
  line-height: 1.8;
}

.archive-list {
  width: min(100%, 42rem);
  margin: 1.5rem 0 0;
  padding: 0;
  list-style: none;
}

.archive-list li {
  border-bottom: 1px solid #c9c8bc;
}

.archive-list a {
  width: 100%;
  margin-top: 0;
  padding-block: 0.55rem;
  text-decoration: none;
}

.archive-list a:hover {
  text-decoration: underline;
}

.archive-shell a {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  margin-top: 2rem;
  color: #31583d;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

.archive-shell a:focus-visible {
  outline: 3px solid #31583d;
  outline-offset: 3px;
}

@media (max-width: 820px) {
  .topbar {
    width: min(100% - 28px, 1240px);
    grid-template-columns: 1fr;
    align-items: start;
    gap: 12px;
  }

  .story-picker {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .story-picker select {
    max-width: none;
    width: 100%;
  }

  .reader,
  .empty-state {
    width: min(100% - 28px, 1120px);
    min-height: auto;
    grid-template-columns: 1fr;
    align-items: start;
    padding-top: 42px;
  }

  .scene-meta h1,
  .empty-state h1 {
    max-width: 10em;
    font-size: clamp(1.75rem, 9.5vw, 2.35rem);
  }

  .topbar-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
  }

  .topbar-actions button {
    min-width: 0;
    padding-inline: 8px;
  }

  .portal-links {
    display: grid;
    grid-template-columns: 1fr;
  }

  .stage.has-empty-library .empty-state h1 {
    font-size: clamp(1.75rem, 8vw, 2.35rem);
  }

  .textbox {
    max-height: none;
  }
}
