:root {
  color-scheme: dark;
  --bg: #070b12;
  --panel: rgba(13, 23, 36, .92);
  --panel-2: #111d2b;
  --line: rgba(126, 221, 234, .24);
  --line-strong: rgba(126, 221, 234, .58);
  --cyan: #70e8f3;
  --cyan-strong: #09cadc;
  --text: #edf8fa;
  --muted: #9db4bb;
  --danger: #ff8d98;
  --shadow: 0 24px 80px rgba(0, 0, 0, .42);
  --base-font-size: 16px;
}

:root[data-font-size="large"] { --base-font-size: 19px; }
:root[data-font-size="xlarge"] { --base-font-size: 22px; }

* { box-sizing: border-box; }

html { min-height: 100%; max-width: 100%; overflow-x: hidden; background: var(--bg); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 8%, rgba(0, 185, 214, .13), transparent 36rem),
    linear-gradient(145deg, #08111d 0%, #070b12 50%, #0a111b 100%);
  font-family: "Segoe UI", "Microsoft JhengHei", system-ui, sans-serif;
  font-size: var(--base-font-size);
}

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

.scanline {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .16;
  background: repeating-linear-gradient(180deg, transparent 0 3px, rgba(116, 232, 242, .08) 4px);
}

.shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 30px 0 64px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 34px;
}

.topbar-tools { display: flex; min-width: 0; align-items: center; justify-content: flex-end; gap: 16px; }
.language-control { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .86rem; }
.language-control select { width: auto; min-width: 8rem; padding: 7px 28px 7px 10px; }
.font-size-control {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  background: rgba(4, 10, 17, .58);
}
.font-size-control > span { padding: 0 7px; color: var(--muted); font-size: .78rem; }
.font-size-control button {
  min-width: 38px;
  min-height: 38px;
  padding: 0 8px;
  border: 1px solid transparent;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}
.font-size-control button:hover { color: var(--text); border-color: var(--line-strong); }
.font-size-control button[aria-pressed="true"] { color: #031014; border-color: var(--cyan); background: var(--cyan); font-weight: 800; }

.brand { display: flex; min-width: 0; align-items: center; gap: 14px; }
.brand > div:last-child { min-width: 0; }
.brand strong { overflow-wrap: anywhere; }
.mark {
  display: grid;
  place-items: center;
  width: 42px;
  aspect-ratio: 1;
  border: 1px solid var(--line-strong);
  clip-path: polygon(12% 0, 100% 0, 100% 72%, 72% 100%, 0 100%, 0 12%);
  color: var(--cyan);
  font-weight: 800;
  letter-spacing: -.08em;
}
.brand strong { display: block; letter-spacing: .09em; }
.brand small { display: block; margin-top: 3px; color: var(--muted); }

.status {
  color: var(--cyan);
  font-size: .9rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.status::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--cyan-strong);
  box-shadow: 0 0 14px var(--cyan-strong);
}

.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.home-grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 24px; }
.home-copy, .new-save { padding: clamp(24px, 4vw, 44px); }

.eyebrow {
  color: var(--cyan);
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .18em;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }
h1 { max-width: 12ch; margin-bottom: 18px; font-size: clamp(2.4rem, 7vw, 5.2rem); line-height: .96; letter-spacing: -.055em; }
h2 { margin-bottom: 8px; font-size: clamp(1.65rem, 4vw, 2.6rem); letter-spacing: -.025em; }
h3 { font-size: 1.05rem; }
.lede { max-width: 52ch; color: var(--muted); font-size: 1.06rem; line-height: 1.75; }
.protagonists { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 24px; }
.protagonist-card { position: relative; min-width: 0; overflow: hidden; border: 1px solid var(--line); background: #09111b; }
.protagonist-card::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(180deg, transparent 40%, rgba(3, 8, 14, .18) 58%, rgba(3, 8, 14, .96) 100%); }
.protagonist-card img { display: block; width: 100%; height: auto; aspect-ratio: 4 / 5; object-fit: cover; }
.protagonist-card div { position: absolute; z-index: 1; right: 10px; bottom: 10px; left: 10px; }
.protagonist-card strong, .protagonist-card span { display: block; }
.protagonist-card strong { color: #fff; font-size: 1rem; letter-spacing: .08em; }
.protagonist-card span { margin-top: 3px; color: #b9d0d6; font-size: .75rem; line-height: 1.35; }
.rule { width: 82px; height: 3px; margin: 30px 0; background: var(--cyan-strong); box-shadow: 0 0 18px rgba(9, 202, 220, .55); }
.ending-progress { margin-top: 26px; padding: 18px; border: 1px solid var(--line); background: rgba(4, 10, 17, .5); }
.progress-heading { display: flex; justify-content: space-between; gap: 18px; color: var(--cyan); }
.progress-heading span { color: var(--text); font-variant-numeric: tabular-nums; }
.progress-track { height: 10px; margin-top: 13px; overflow: hidden; border: 1px solid var(--line-strong); background: rgba(112, 232, 243, .07); }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--cyan-strong), var(--cyan)); box-shadow: 0 0 16px rgba(9, 202, 220, .65); transition: width .35s ease; }
.ending-progress p { margin: 11px 0 0; color: var(--muted); font-size: .88rem; line-height: 1.55; }

label { display: block; margin-bottom: 9px; color: var(--muted); font-size: .9rem; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0;
  outline: none;
  color: var(--text);
  background: rgba(4, 10, 17, .72);
}
input, select { min-height: 48px; padding: 0 14px; }
textarea { min-height: 106px; padding: 13px 14px; line-height: 1.55; resize: vertical; }
textarea { max-width: 100%; overflow-wrap: anywhere; white-space: pre-wrap; }
input:focus, select:focus, textarea:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(112, 232, 243, .12); }
.field + .field { margin-top: 18px; }
.import-field { margin-top: 32px; padding-top: 24px; border-top: 1px solid var(--line); }

.button {
  min-height: 48px;
  padding: 0 20px;
  border: 1px solid var(--line-strong);
  background: transparent;
  cursor: pointer;
  transition: transform .16s ease, background .16s ease, border-color .16s ease;
  line-height: 1.35;
  white-space: normal;
}
.button:hover { transform: translateY(-1px); border-color: var(--cyan); background: rgba(112, 232, 243, .08); }
.button.primary { color: #031014; background: var(--cyan); border-color: var(--cyan); font-weight: 750; }
.button.primary:hover { background: #a5f6fc; }
.button:disabled { opacity: .42; cursor: not-allowed; transform: none; }
.button.wide { width: 100%; margin-top: 22px; }
.button.ghost { border-color: transparent; color: var(--muted); }
.button.danger { border-color: rgba(255, 141, 152, .5); color: var(--danger); }
.button.danger:hover { border-color: var(--danger); background: rgba(255, 141, 152, .1); }
.download-button { display: flex; align-items: center; justify-content: center; text-align: center; text-decoration: none; }
.offline-download { margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--line); }
.offline-download .tiny { margin: 10px 0 0; line-height: 1.55; }
.fan-disclaimer { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); color: #8099a2; font-size: .76rem; line-height: 1.6; }

.save-list { margin-top: 26px; }
.save-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-top: 10px;
  padding: 17px 18px;
  border: 1px solid var(--line);
  background: rgba(9, 18, 28, .62);
}
.save-card strong { display: block; }
.save-card span { display: block; margin-top: 5px; color: var(--muted); font-size: .88rem; }
.save-summary { min-width: min(100%, 310px); flex: 1; }
.save-ending-progress { max-width: 390px; margin-top: 13px; }
.save-ending-progress > div:first-child { display: flex; justify-content: space-between; gap: 14px; }
.save-ending-progress > div:first-child span { margin: 0; color: var(--cyan); }
.save-ending-progress b { color: var(--text); font-size: .82rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.progress-track.compact { height: 7px; margin-top: 7px; }
.save-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.save-actions .button { min-height: 42px; padding: 0 14px; }

.game-layout { display: grid; min-width: 0; grid-template-columns: minmax(0, 1fr) 310px; gap: 22px; }
.scene { padding: clamp(24px, 5vw, 54px); }
.scene, .sidebar, .answer-box { min-width: 0; max-width: 100%; }
.chapter-line { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 34px; color: var(--muted); font-size: .9rem; }
.scene-text { max-width: 780px; margin: 28px 0 36px; font-size: clamp(1.12rem, 2vw, 1.34rem); line-height: 1.9; white-space: pre-wrap; }
:root[data-font-size="large"] .scene-text { font-size: 1.5rem; line-height: 1.82; }
:root[data-font-size="xlarge"] .scene-text { font-size: 1.78rem; line-height: 1.72; }
.active-context { max-width: 780px; margin: 24px 0 30px; padding: 17px 18px; border: 1px solid rgba(7, 213, 232, .28); border-left: 3px solid var(--cyan); background: rgba(7, 213, 232, .055); }
.active-context-title { color: var(--cyan); font-size: .92rem; font-weight: 800; letter-spacing: .08em; }
.active-context p { margin: 7px 0 12px; color: var(--muted); font-size: .82rem; line-height: 1.6; }
.active-context ul { display: grid; gap: 9px; margin: 0; padding: 0; list-style: none; }
.active-context li { display: grid; grid-template-columns: 5.2rem 1fr; gap: 10px; align-items: start; line-height: 1.55; }
.active-context li span { color: var(--muted); font-size: .78rem; letter-spacing: .05em; }
:root[data-font-size="large"] .active-context-title { font-size: 1.08rem; }
:root[data-font-size="large"] .active-context p { font-size: 1rem; }
:root[data-font-size="large"] .active-context li { grid-template-columns: 6.4rem 1fr; font-size: 1.12rem; }
:root[data-font-size="large"] .active-context li span { font-size: .96rem; }
:root[data-font-size="xlarge"] .active-context-title { font-size: 1.25rem; }
:root[data-font-size="xlarge"] .active-context p { font-size: 1.12rem; line-height: 1.7; }
:root[data-font-size="xlarge"] .active-context li { grid-template-columns: 7.2rem 1fr; gap: 14px; font-size: 1.28rem; line-height: 1.6; }
:root[data-font-size="xlarge"] .active-context li span { font-size: 1.06rem; line-height: 1.65; }

.choices { display: grid; gap: 12px; }
.choice {
  display: grid;
  grid-template-columns: 44px 1fr;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 66px;
  padding: 10px 18px 10px 10px;
  border: 1px solid var(--line);
  text-align: left;
  background: rgba(6, 13, 22, .64);
  cursor: pointer;
}
.choice:hover, .choice.selected { border-color: var(--cyan); background: rgba(31, 105, 118, .2); }
:root[data-font-size="large"] .choice { font-size: 1.14rem; line-height: 1.55; }
:root[data-font-size="xlarge"] .choice { font-size: 1.3rem; line-height: 1.5; }
.choice-key { display: grid; place-items: center; height: 44px; border: 1px solid var(--line-strong); color: var(--cyan); font-weight: 800; }

.sidebar { align-self: start; position: sticky; top: 22px; padding: 22px; }
.sidebar section + section { margin-top: 26px; padding-top: 24px; border-top: 1px solid var(--line); }
.sidebar p { color: var(--muted); line-height: 1.65; }
.sidebar .button { width: 100%; margin-top: 9px; }
.tiny { font-size: .82rem; color: var(--muted); }
.usage-note { margin: 18px 0; padding: 14px 16px; border: 1px solid var(--line); background: rgba(7, 213, 232, .04); }
.usage-note summary { cursor: pointer; color: var(--cyan); font-weight: 700; }
.usage-note p:last-child { margin-bottom: 0; }
.cloud-save-note { margin: 14px 0 4px; padding: 14px 16px; border: 1px solid rgba(7, 213, 232, .35); border-radius: 10px; background: rgba(7, 213, 232, .07); }
.cloud-save-note strong { color: var(--cyan); }
.cloud-save-note p { margin: 8px 0 0; color: var(--muted); font-size: .82rem; line-height: 1.6; }
.answer-box { margin-top: 28px; padding: 20px; border: 1px solid var(--line); background: rgba(4, 10, 17, .5); }
.answer-box.hidden { display: none; }
.answer-actions { display: flex; gap: 10px; margin-top: 12px; }
:root[data-font-size="large"] .answer-box textarea { min-height: 10rem; }
:root[data-font-size="xlarge"] .answer-box textarea { min-height: 13rem; }

.ending { padding: clamp(28px, 6vw, 64px); }
.ending-title { color: var(--cyan); }
.ending-narrative { max-width: 720px; margin: 26px 0; color: var(--text); font-size: 1.12rem; line-height: 1.85; white-space: pre-wrap; }
.record-list { margin-top: 30px; }
.record { padding: 18px 0; border-top: 1px solid var(--line); }
.record-choice { color: var(--cyan); }
.record-reason { margin-bottom: 0; color: var(--muted); }
.history-page h1 { max-width: 18ch; font-size: clamp(2rem, 5vw, 3.8rem); }
.history-list { margin-top: 30px; }
.history-chapter { border-top: 1px solid var(--line); }
.history-chapter:last-child { border-bottom: 1px solid var(--line); }
.history-chapter summary { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 20px 4px; cursor: pointer; color: var(--cyan); font-weight: 700; }
.history-chapter summary small { color: var(--muted); font-weight: 400; text-align: right; }
.history-body { padding: 0 18px 22px; }
.reflection { margin-top: 18px; padding: 18px; border-left: 3px solid var(--cyan-strong); background: rgba(4, 10, 17, .5); }
.reflection p { margin: 8px 0 0; line-height: 1.7; white-space: pre-wrap; }
.empty { color: var(--muted); }
.loading { min-height: 60vh; display: grid; place-items: center; color: var(--muted); }
.error { padding: 24px; border: 1px solid rgba(255, 141, 152, .4); color: var(--danger); background: rgba(74, 16, 28, .28); }
.toast { position: fixed; right: 24px; bottom: 24px; max-width: min(360px, calc(100vw - 48px)); padding: 13px 17px; color: #031014; background: var(--cyan); font-weight: 700; opacity: 0; transform: translateY(14px); pointer-events: none; transition: .18s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.copy-fallback { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, .82); }
.copy-fallback-panel { width: min(100%, 620px); padding: 22px; border: 1px solid var(--line); border-radius: 16px; background: #101923; }
.copy-fallback-panel p { margin: 0 0 14px; font-size: 1rem; line-height: 1.6; }
.copy-fallback-panel textarea { width: 100%; min-height: min(52vh, 400px); font-size: 16px; line-height: 1.6; resize: vertical; -webkit-user-select: text; user-select: text; }
.copy-fallback-panel h2 { margin-bottom: 12px; }
.copy-fallback-panel input { font-size: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.dialog-actions .button { margin-top: 0; }

/* Large-text modes keep secondary information readable instead of letting
   component-specific small sizes cancel the user's font preference. */
:root[data-font-size="large"] :is(
  .font-size-control > span,
  .eyebrow,
  .status,
  label,
  .tiny,
  .chapter-line,
  .ending-progress p,
  .save-card span,
  .save-ending-progress b,
  .cloud-save-note p,
  .fan-disclaimer,
  .history-chapter summary small
) { font-size: .96rem; line-height: 1.65; }

:root[data-font-size="xlarge"] :is(
  .font-size-control > span,
  .eyebrow,
  .status,
  label,
  .tiny,
  .chapter-line,
  .ending-progress p,
  .save-card span,
  .save-ending-progress b,
  .cloud-save-note p,
  .fan-disclaimer,
  .history-chapter summary small
) { font-size: 1.05rem; line-height: 1.7; }

:root[data-font-size="large"] .protagonist-card strong { font-size: 1.08rem; }
:root[data-font-size="large"] .protagonist-card span { font-size: .86rem; line-height: 1.5; }
:root[data-font-size="xlarge"] .protagonist-card strong { font-size: 1.12rem; }
:root[data-font-size="xlarge"] .protagonist-card span { font-size: .9rem; line-height: 1.5; }
:root[data-font-size="large"] .copy-fallback-panel :is(textarea, input) { font-size: 1rem; }
:root[data-font-size="xlarge"] .copy-fallback-panel :is(textarea, input) { font-size: 1.08rem; }

@media (max-width: 820px) {
  .home-grid, .game-layout { grid-template-columns: 1fr; }
  .new-save { order: -1; }
  .sidebar { position: static; }
  .topbar { align-items: flex-start; }
  .topbar-tools { align-items: flex-end; flex-direction: column-reverse; gap: 9px; }
  .save-card { align-items: stretch; flex-direction: column; }
  .save-actions { justify-content: flex-start; }
  .status { margin-top: 6px; }
}

@media (max-width: 520px) {
  .shell { width: min(100% - 20px, 1120px); padding-top: 16px; }
  .topbar { align-items: stretch; flex-direction: column; margin-bottom: 18px; }
  .topbar-tools { width: 100%; flex-wrap: wrap; align-items: stretch; flex-direction: row; justify-content: space-between; gap: 8px; }
  .language-control { min-width: 0; flex: 1 1 100%; }
  .language-control select { min-width: 0; flex: 1; }
  .font-size-control { min-width: 0; flex: 1 1 100%; }
  .font-size-control button { flex: 1; min-width: 0; min-height: 44px; }
  .status { flex: 1 1 100%; align-self: flex-start; overflow-wrap: anywhere; }
  .brand small { display: none; }
  .home-copy, .new-save, .scene, .ending { padding: 22px; }
  .protagonists { gap: 6px; margin-top: 18px; }
  .protagonist-card div { right: 7px; bottom: 7px; left: 7px; }
  .protagonist-card strong { font-size: .88rem; }
  .protagonist-card span { font-size: .67rem; }
  .chapter-line { flex-direction: column; margin-bottom: 24px; }
  .save-card { align-items: flex-start; flex-direction: column; }
  .save-actions { width: 100%; }
  .save-card .button { width: 100%; }
  .history-chapter summary { align-items: flex-start; flex-direction: column; gap: 6px; }
  .history-chapter summary small { text-align: left; }
  .answer-actions { flex-direction: column; }
  .answer-box { padding: 16px; }
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions .button { width: 100%; }
}

@media (max-width: 520px) and (min-resolution: 1dppx) {
  :root[data-font-size="large"] h1,
  :root[data-font-size="xlarge"] h1 { font-size: clamp(2.15rem, 11vw, 3.25rem); line-height: 1.04; }
  :root[data-font-size="xlarge"] .home-copy,
  :root[data-font-size="xlarge"] .new-save,
  :root[data-font-size="xlarge"] .scene,
  :root[data-font-size="xlarge"] .ending { padding: 18px; }
  :root[data-font-size="xlarge"] .answer-box { padding: 14px; }
  :root[data-font-size="xlarge"] .choice { grid-template-columns: 48px minmax(0, 1fr); padding-right: 12px; }
  :root[data-font-size="large"] .active-context li,
  :root[data-font-size="xlarge"] .active-context li { grid-template-columns: 1fr; gap: 3px; }
  :root[data-font-size="large"] .protagonist-card strong,
  :root[data-font-size="xlarge"] .protagonist-card strong { font-size: 1rem; }
  :root[data-font-size="large"] .protagonist-card span,
  :root[data-font-size="xlarge"] .protagonist-card span { font-size: .8rem; line-height: 1.45; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
.relationship-notice { border-left: 3px solid #79c7e6; background: rgba(121,199,230,.08); padding: .65rem 1rem; margin: 1rem 0; font-size: 1rem; line-height: 1.6; }
.relationship-notice p { margin: .2rem 0; overflow-wrap: anywhere; }

.scene-reference { margin: 1.25rem 0; }
.scene-reference img { display: block; width: 100%; height: auto; object-fit: contain; border-radius: 0.6rem; }
.scene-reference figcaption { margin-top: 0.5rem; font-size: 0.875rem; line-height: 1.6; color: var(--muted, #aab7c8); overflow-wrap: anywhere; }
.scene-reference a { color: inherit; text-decoration: underline; text-underline-offset: 0.15em; }
