:root,
html[data-theme="light"] {
  color-scheme: light;
  --background: #F6F8FC;
  --surface: #FFFFFF;
  --surface-elevated: #EAF0F7;
  --text-primary: #001C4F;
  --text-secondary: #40556F;
  --text-muted: #667990;
  --primary: #03437E;
  --primary-hover: #001C4F;
  --primary-text: #FFFFFF;
  --accent-teal: #006B82;
  --accent-teal-hover: #025F74;
  --accent-gold: #8A5F00;
  --accent-gold-hover: #704D00;
  --decorative-gold: #EEBD13;
  --decorative-cyan: #27DCEB;
  --accent: var(--accent-gold);
  --accent-hover: var(--accent-gold-hover);
  --accent-text: #FFFFFF;
  --border: #D5DFEA;
  --focus-ring: #03437E;
  --link: #03437E;
  --danger: #B42336;
  --success: #197A57;
  --surface-glass: rgba(255, 255, 255, 0.9);
  --surface-soft: rgba(234, 240, 247, 0.72);
  --primary-soft: rgba(3, 67, 126, 0.09);
  --primary-border: rgba(3, 67, 126, 0.24);
  --teal-soft: rgba(0, 107, 130, 0.1);
  --teal-border: rgba(0, 107, 130, 0.25);
  --accent-soft: rgba(138, 95, 0, 0.1);
  --accent-border: rgba(138, 95, 0, 0.24);
  --danger-soft: rgba(180, 35, 54, 0.09);
  --danger-border: rgba(180, 35, 54, 0.24);
  --success-soft: rgba(25, 122, 87, 0.1);
  --success-border: rgba(25, 122, 87, 0.24);
  --overlay: rgba(0, 11, 40, 0.64);
  --shadow-color: rgba(0, 28, 79, 0.16);
  --ink: var(--text-primary);
  --ink-soft: var(--text-secondary);
  --ink-faint: var(--text-muted);
  --paper: var(--surface-elevated);
  --night: var(--background);
  --night-raised: var(--surface);
  --night-soft: var(--surface-elevated);
  --wine: var(--primary);
  --wine-bright: var(--primary-hover);
  --rose: var(--accent-teal);
  --gold: var(--accent-gold);
  --line: rgba(3, 67, 126, 0.12);
  --line-strong: rgba(3, 67, 126, 0.22);
  --shadow: 0 30px 80px var(--shadow-color);
  --serif: "Newsreader", Georgia, serif;
  --sans: "DM Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --app-header-height: 72px;
  --book-cover-ratio: 1122 / 1402;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --background: #020921;
  --surface: #071A3A;
  --surface-elevated: #0B2A54;
  --text-primary: #F6F8FC;
  --text-secondary: #B8C7DB;
  --text-muted: #8397B1;
  --primary: #0392B2;
  --primary-hover: #27DCEB;
  --primary-text: #020921;
  --accent-teal: #0392B2;
  --accent-teal-hover: #27DCEB;
  --accent-gold: #EEBD13;
  --accent-gold-hover: #FCE542;
  --decorative-gold: #EEBD13;
  --decorative-cyan: #27DCEB;
  --accent: #EEBD13;
  --accent-hover: #FCE542;
  --accent-text: #001C4F;
  --border: #17446B;
  --focus-ring: #27DCEB;
  --link: #27DCEB;
  --danger: #E65B68;
  --success: #4FC59A;
  --surface-glass: rgba(7, 26, 58, 0.92);
  --surface-soft: rgba(11, 42, 84, 0.72);
  --primary-soft: rgba(3, 146, 178, 0.13);
  --primary-border: rgba(39, 220, 235, 0.28);
  --teal-soft: rgba(3, 146, 178, 0.13);
  --teal-border: rgba(39, 220, 235, 0.28);
  --accent-soft: rgba(238, 189, 19, 0.1);
  --accent-border: rgba(238, 189, 19, 0.28);
  --danger-soft: rgba(230, 91, 104, 0.12);
  --danger-border: rgba(230, 91, 104, 0.3);
  --success-soft: rgba(79, 197, 154, 0.12);
  --success-border: rgba(79, 197, 154, 0.26);
  --overlay: rgba(2, 9, 33, 0.86);
  --shadow-color: rgba(0, 0, 0, 0.38);
  --ink: var(--text-primary);
  --ink-soft: var(--text-secondary);
  --ink-faint: var(--text-muted);
  --paper: var(--surface-elevated);
  --night: var(--background);
  --night-raised: var(--surface);
  --night-soft: var(--surface-elevated);
  --wine: var(--primary);
  --wine-bright: var(--primary-hover);
  --rose: var(--accent-teal);
  --gold: var(--accent-gold);
  --line: rgba(39, 220, 235, 0.13);
  --line-strong: rgba(39, 220, 235, 0.24);
  --shadow: 0 30px 80px var(--shadow-color);
}

* { box-sizing: border-box; }
.sprite-definitions { position: absolute; }
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  background: var(--night);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; }
button { color: inherit; touch-action: manipulation; }
img { max-width: 100%; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 2px solid var(--rose);
  outline-offset: 3px;
}
[hidden] { display: none !important; }

.icon {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  overflow: hidden;
  place-items: center;
  border: 1px solid rgba(213, 183, 123, 0.42);
  border-radius: 50%;
  color: var(--gold);
}
.brand-mark img { width: 100%; height: 100%; object-fit: cover; }

.library-view {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at 14% 20%, rgba(120, 45, 67, 0.21), transparent 32%),
    radial-gradient(circle at 88% 5%, rgba(213, 183, 123, 0.09), transparent 27%),
    linear-gradient(145deg, #151014 0%, #0d0b0d 58%, #141013 100%);
}
.library-view::before {
  position: absolute;
  inset: 0;
  background-image: linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px);
  background-size: 48px 48px;
  content: "";
  mask-image: linear-gradient(to bottom, black, transparent 75%);
  pointer-events: none;
}
.library-orb {
  position: absolute;
  right: -16vw;
  bottom: -43vw;
  width: 72vw;
  height: 72vw;
  border: 1px solid rgba(213, 183, 123, 0.1);
  border-radius: 50%;
  box-shadow: inset 0 0 100px rgba(114, 45, 67, 0.05);
  pointer-events: none;
}
.library-orb::before, .library-orb::after {
  position: absolute;
  inset: 8%;
  border: inherit;
  border-radius: inherit;
  content: "";
}
.library-orb::after { inset: 18%; }

.library-header {
  position: relative;
  z-index: 2;
  display: flex;
  width: min(1220px, calc(100% - 48px));
  margin: 0 auto;
  padding: 28px 0;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.wordmark { display: flex; gap: 12px; align-items: center; }
.wordmark-copy strong {
  display: block;
  font-family: var(--serif);
  font-size: 1.28rem;
  font-weight: 600;
  letter-spacing: .02em;
}
.wordmark-copy span {
  display: block;
  margin-top: -2px;
  color: var(--ink-faint);
  font-size: .68rem;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.library-main {
  position: relative;
  z-index: 1;
  width: min(1220px, calc(100% - 48px));
  margin: 0 auto;
  padding: clamp(64px, 9vh, 110px) 0 90px;
}
.library-intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 28px;
  margin-bottom: 42px;
  align-items: end;
}
.eyebrow {
  display: flex;
  gap: 12px;
  margin: 0 0 16px;
  align-items: center;
  color: var(--gold);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .21em;
  text-transform: uppercase;
}
.eyebrow::before { width: 28px; height: 1px; background: currentColor; content: ""; }
.library-intro h1 {
  max-width: 760px;
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(3.4rem, 7vw, 6.4rem);
  font-weight: 500;
  letter-spacing: -.055em;
  line-height: .9;
}
.library-intro h1 em { color: var(--rose); font-weight: 500; }
.library-intro-note {
  max-width: 270px;
  margin: 0 0 7px;
  color: var(--ink-soft);
  font-size: .91rem;
  line-height: 1.7;
}
.mobile-break { display: none; }
.section-heading {
  display: flex;
  margin-bottom: 18px;
  align-items: center;
  justify-content: space-between;
}
.section-heading h2 {
  margin: 0;
  font-size: .73rem;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.story-count { color: var(--ink-faint); font-size: .78rem; }

.story-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 24px;
}
.story-card {
  position: relative;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--night-raised);
  box-shadow: 0 20px 50px rgba(0,0,0,.23);
  cursor: pointer;
  text-align: left;
  transition: transform .35s ease, border-color .35s ease, box-shadow .35s ease;
}
.story-card:hover {
  border-color: rgba(233, 165, 177, .4);
  box-shadow: 0 26px 70px rgba(0,0,0,.4);
  transform: translateY(-7px);
}
.story-card:focus-visible { outline-offset: 5px; }
.story-card-cover {
  position: relative;
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  transition: filter .35s ease;
}
.story-card:not(:has(.story-card-cover)) {
  aspect-ratio: var(--book-cover-ratio);
}
.story-card:hover .story-card-cover { filter: brightness(1.06); }
.story-card-shade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to top, rgba(12,9,11,.98) 0%, rgba(12,9,11,.82) 35%, transparent 68%),
    linear-gradient(to right, rgba(12,9,11,.16), transparent);
}
.story-card-top {
  position: absolute;
  top: 18px;
  right: 18px;
  left: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.availability, .save-badge {
  display: inline-flex;
  gap: 7px;
  padding: 7px 10px;
  align-items: center;
  border: 1px solid rgba(255,255,255,.17);
  border-radius: 999px;
  background: rgba(16,13,16,.68);
  backdrop-filter: blur(12px);
  font-size: .67rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.availability::before {
  width: 6px;
  height: 6px;
  background: #72c994;
  border-radius: 50%;
  content: "";
}
.save-badge { color: var(--gold); }
.story-card-content {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 30px;
}
.story-kicker {
  margin: 0 0 9px;
  color: var(--gold);
  font-size: .67rem;
  font-weight: 700;
  letter-spacing: .15em;
  text-transform: uppercase;
}
.story-card h3 {
  max-width: 90%;
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2rem, 3vw, 2.8rem);
  font-weight: 500;
  letter-spacing: -.03em;
  line-height: .95;
}
.story-meta {
  display: flex;
  gap: 9px;
  margin-top: 18px;
  align-items: center;
  color: var(--ink-soft);
  font-size: .74rem;
}
.story-meta .dot { width: 3px; height: 3px; background: var(--ink-faint); border-radius: 50%; }
.story-open {
  position: absolute;
  right: 25px;
  bottom: 31px;
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 50%;
  background: rgba(255,255,255,.08);
  transition: background .25s, color .25s;
}
.story-card:hover .story-open { background: var(--paper); color: var(--night); }

.empty-library, .library-error {
  padding: 40px;
  border: 1px dashed var(--line-strong);
  border-radius: 20px;
  color: var(--ink-soft);
  text-align: center;
}
.empty-library {
  display: grid;
  min-height: 260px;
  place-content: center;
  justify-items: center;
  gap: 10px;
}
.empty-library-mark {
  display: grid;
  width: 48px;
  height: 48px;
  margin-bottom: 5px;
  place-items: center;
  border: 1px solid var(--teal-border);
  border-radius: 50%;
  background: var(--teal-soft);
  color: var(--accent-teal);
}
.empty-library-mark .icon { width: 22px; height: 22px; }
.empty-library strong { color: var(--text-primary); font: 500 1.55rem var(--serif); }
.empty-library p { max-width: 390px; margin: 0; font-size: .82rem; line-height: 1.65; }

.story-dialog {
  width: min(1200px, calc(100% - 32px));
  max-height: min(720px, calc(100dvh - 32px));
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 24px;
  background: #181317;
  color: var(--ink);
  box-shadow: var(--shadow);
}
.story-dialog::backdrop {
  background: rgba(5,4,5,.78);
  backdrop-filter: blur(10px);
}
html:has(.story-dialog[open]),
body:has(.story-dialog[open]) { overflow: hidden; }
.dialog-layout {
  display: grid;
  height: min(680px, calc(100dvh - 32px));
  min-height: 0;
  grid-template-columns: auto minmax(0, 1fr);
}
.dialog-art {
  position: relative;
  width: auto;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
.dialog-art img { display: block; width: auto; height: 100%; object-fit: contain; }
.dialog-art::after {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(24,19,23,.85), transparent 55%);
  content: "";
}
.dialog-panel {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: minmax(0, 1fr) auto;
  background: #181317;
}
.dialog-copy {
  display: flex;
  min-height: 0;
  padding: clamp(30px, 3.5vw, 44px) clamp(34px, 4vw, 50px) 28px;
  overflow-y: auto;
  flex-direction: column;
  justify-content: flex-start;
  scrollbar-width: thin;
}
.dialog-close {
  position: absolute;
  z-index: 2;
  top: 18px;
  right: 18px;
  display: grid;
  width: 38px;
  height: 38px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: rgba(16,13,16,.72);
  cursor: pointer;
}
.dialog-copy h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2.25rem, 3.5vw, 3.2rem);
  font-weight: 500;
  letter-spacing: -.045em;
  line-height: .96;
}
.dialog-description {
  margin: 17px 0 19px;
  color: var(--ink-soft);
  font-size: .86rem;
  line-height: 1.62;
}
.genre-row { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.genre-chip {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-soft);
  font-size: .68rem;
}
.dialog-actions {
  display: grid;
  padding: 18px clamp(34px, 4vw, 50px) 22px;
  border-top: 1px solid var(--line);
  background: rgba(16,13,16,.96);
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}
.primary-button, .secondary-button, .danger-button {
  display: flex;
  width: 100%;
  min-height: 54px;
  padding: 0 17px;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  cursor: pointer;
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .02em;
  transition: transform .2s, background .2s, opacity .2s;
}
.primary-button {
  border: 1px solid var(--paper);
  background: var(--paper);
  color: #261b1e;
}
.primary-button:hover, .secondary-button:hover, .danger-button:hover { transform: translateY(-2px); }
.secondary-button { border: 1px solid var(--line-strong); background: transparent; }
.secondary-button:hover { background: rgba(255,255,255,.05); }
.danger-button { border: 1px solid rgba(233,165,177,.36); background: rgba(114,45,67,.22); color: #ffdbe1; }
button:disabled { opacity: .42; cursor: not-allowed; transform: none !important; }
.save-context {
  display: flex;
  gap: 9px;
  margin: 0 0 14px;
  align-items: flex-start;
  color: var(--ink-faint);
  font-size: .72rem;
  line-height: 1.4;
}
.save-context .icon { width: 16px; height: 16px; color: var(--gold); }
.journey-section {
  display: grid;
  margin-top: 4px;
  padding-top: 19px;
  border-top: 1px solid var(--line);
  gap: 12px;
}
.journey-section[hidden] { display: none; }
.journey-section-header {
  display: flex;
  min-width: 0;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}
.journey-section-header h3 {
  margin: 3px 0 0;
  color: var(--ink);
  font: 600 1.35rem/1.1 var(--serif);
}
.journey-section-count {
  color: var(--ink-faint);
  font-size: .63rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.journey-list {
  display: grid;
  gap: 10px;
}
.journey-row {
  display: grid;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.035);
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
}
.journey-copy { min-width: 0; }
.journey-copy strong,
.journey-copy span {
  display: block;
  overflow-wrap: anywhere;
}
.journey-copy strong { color: var(--ink); font-size: .85rem; }
.journey-copy span { margin-top: 4px; color: var(--ink-faint); font-size: .66rem; line-height: 1.45; }
.journey-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.journey-actions button {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: .66rem;
  font-weight: 700;
}
.journey-actions [data-resume-journey] {
  border-color: var(--accent-gold);
  background: var(--accent-gold);
  color: var(--accent-text);
}
.journey-actions [data-resume-journey]:hover {
  border-color: var(--accent-gold-hover);
  background: var(--accent-gold-hover);
}
.journey-actions [data-delete-journey] {
  display: grid;
  width: 38px;
  min-width: 38px;
  padding: 0;
  flex: 0 0 38px;
  place-items: center;
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}
.journey-actions [data-delete-journey]:hover {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}
.journey-actions [data-delete-journey] .icon {
  width: 17px;
  height: 17px;
}
.journey-actions [data-preview-continuation] {
  border-color: var(--accent);
  background: rgba(238,189,19,.1);
  color: var(--accent-gold, var(--accent));
}
.start-warning {
  padding: 14px;
  border: 1px solid rgba(233,165,177,.25);
  border-radius: 12px;
  background: rgba(114,45,67,.13);
}
.start-warning p { margin: 0 0 12px; color: var(--ink-soft); font-size: .77rem; line-height: 1.5; }
.warning-actions { display: flex; gap: 8px; }
.warning-actions button { min-height: 42px; }
.setup-dialog, .class-selection-dialog {
  width: min(1080px, calc(100% - 28px));
  max-height: calc(100dvh - 28px);
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(39,220,235,.24);
  border-radius: 24px;
  background: #020921;
  color: #f6f8fc;
  box-shadow: 0 32px 100px rgba(0,0,0,.55);
}
.setup-dialog::backdrop, .class-selection-dialog::backdrop {
  background: rgba(1,4,16,.88);
  backdrop-filter: blur(12px);
}
.continuation-route {
  display: grid;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.025);
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}
.continuation-route span {
  color: var(--ink-faint);
  font-size: .65rem;
  font-weight: 800;
  letter-spacing: .07em;
  text-transform: uppercase;
}
.continuation-route strong { display: block; margin-top: 3px; }
.continuation-route-arrow {
  color: var(--accent) !important;
  font-size: 1.1rem !important;
}
.continuation-preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.continuation-preview-panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.continuation-preview-panel h3 { margin: 0 0 8px; font-size: .85rem; }
.continuation-preview-panel p,
.continuation-preview-panel li {
  color: var(--ink-soft);
  font-size: .73rem;
  line-height: 1.5;
}
.continuation-preview-panel p { margin: 0; }
.continuation-preview-panel ul { margin: 0; padding-left: 18px; }
.continuation-cutoff {
  padding: 14px;
  border: 1px solid rgba(233,165,177,.32);
  border-radius: 12px;
  background: rgba(114,45,67,.13);
}
.continuation-cutoff strong { display: block; margin-bottom: 6px; }
.continuation-cutoff p {
  margin: 4px 0;
  color: var(--ink-soft);
  font-size: .73rem;
  line-height: 1.5;
}
.continuation-acknowledgement {
  display: flex;
  margin-top: 12px;
  align-items: flex-start;
  gap: 9px;
  color: var(--ink);
  cursor: pointer;
  font-size: .73rem;
  line-height: 1.45;
}
.continuation-acknowledgement input {
  width: 18px;
  height: 18px;
  margin: 1px 0 0;
  flex: 0 0 auto;
  accent-color: var(--accent);
}
.setup-shell, .class-selection-shell {
  display: flex;
  max-height: calc(100dvh - 28px);
  min-height: min(760px, calc(100dvh - 28px));
  flex-direction: column;
}
#setupDialog .setup-shell {
  display: grid;
  grid-template-columns: 238px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
}
.setup-header, .class-selection-header {
  display: grid;
  padding: 30px 72px 22px 34px;
  align-items: end;
  grid-template-columns: 1fr auto;
  gap: 20px;
  border-bottom: 1px solid #17446b;
  background: linear-gradient(135deg, rgba(3,146,178,.13), transparent 60%);
}
#setupDialog .setup-header {
  grid-column: 1 / -1;
  grid-row: 1;
}
.setup-header h2, .class-selection-header h2 {
  margin: 4px 0 0;
  font: 500 clamp(2rem, 5vw, 3.4rem)/1 var(--serif);
  letter-spacing: -.04em;
}
.setup-header p, .class-selection-header p { margin: 0; color: #b8c7db; font-size: .78rem; line-height: 1.55; }
.setup-step-counter {
  padding: 7px 10px;
  border: 1px solid rgba(39,220,235,.24);
  border-radius: 999px;
  background: rgba(39,220,235,.07);
  color: #27dceb;
  font-size: .65rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.setup-progress {
  min-width: 0;
  padding: 22px 16px 22px 20px;
  overflow-x: hidden;
  overflow-y: auto;
  border-right: 1px solid rgba(23,68,107,.78);
  background: linear-gradient(180deg, rgba(3,146,178,.06), transparent 55%);
  scrollbar-width: thin;
}
#setupDialog .setup-progress {
  grid-column: 1;
  grid-row: 2 / 4;
}
.setup-progress-track {
  position: relative;
  display: grid;
  margin: 0;
  padding: 0;
  gap: 4px;
  list-style: none;
}
.setup-progress-track::before {
  position: absolute;
  z-index: 0;
  top: 24px;
  bottom: 24px;
  left: 23px;
  width: 1px;
  background: rgba(23,68,107,.9);
  content: '';
}
.setup-progress-step {
  position: relative;
  z-index: 1;
  display: grid;
  min-width: 0;
  min-height: 49px;
  padding: 7px 9px;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  color: #8397b1;
}
.setup-progress-number {
  position: relative;
  z-index: 1;
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid #17446b;
  border-radius: 50%;
  background: #061632;
  color: #8397b1;
  font-size: .62rem;
  font-weight: 800;
}
.setup-progress-label {
  min-width: 0;
  font-size: .65rem;
  font-weight: 750;
  letter-spacing: .025em;
  line-height: 1.32;
}
.setup-progress-step.active {
  border-color: rgba(39,220,235,.42);
  background: rgba(39,220,235,.1);
  color: #f6f8fc;
}
.setup-progress-step.active .setup-progress-number {
  border-color: #27dceb;
  background: #0b2848;
  color: #f6f8fc;
  box-shadow: 0 0 0 3px rgba(39,220,235,.1);
}
.setup-progress-step.complete { color: #75ceb0; }
.setup-progress-step.complete .setup-progress-number {
  border-color: rgba(79,197,154,.68);
  background: #09263a;
  color: #4fc59a;
  font-size: 0;
}
.setup-progress-step.complete .setup-progress-number::after {
  content: '\2713';
  font-size: .72rem;
}
.setup-body, .class-selection-body {
  min-height: 0;
  padding: 28px 34px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
#setupDialog .setup-body {
  grid-column: 2;
  grid-row: 2;
}
#setupDialog .setup-footer {
  grid-column: 2;
  grid-row: 3;
}
#setupDialog .setup-progress[hidden] ~ .setup-body,
#setupDialog .setup-progress[hidden] ~ .setup-footer {
  grid-column: 1 / -1;
}
.setup-lede { max-width: 720px; margin: 0 0 22px; color: #b8c7db; line-height: 1.6; }
.builder-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.builder-fields[data-builder-layout="identity"] {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.builder-fields,
.builder-optional,
.intensity-controls { overflow: visible; }
.builder-field {
  display: grid;
  align-content: start;
  gap: 7px;
  color: #b8c7db;
  font-size: .67rem;
  font-weight: 800;
  letter-spacing: .04em;
}
.builder-label {
  display: flex;
  min-height: 2.9em;
  align-items: flex-end;
  line-height: 1.45;
}
.builder-field[hidden] { display: none; }
.builder-help {
  min-height: 1.45em;
  color: #8397b1;
  font-size: .6rem;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.45;
}
.builder-help-empty { visibility: hidden; }
.builder-field input, .builder-field select, .builder-field textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid #17446b;
  border-radius: 10px;
  background: #071a3a;
  color: #f6f8fc;
  font: 400 16px/1.35 var(--sans);
  outline: none;
}
.builder-field input:focus, .builder-field select:focus, .builder-field textarea:focus {
  border-color: #27dceb;
  box-shadow: 0 0 0 3px rgba(39,220,235,.15);
}
.builder-field small { min-height: 1em; color: #e65b68; font-weight: 600; letter-spacing: 0; }
.builder-conflict-alternatives { display: flex; flex-wrap: wrap; gap: 6px; }
.builder-conflict-alternatives button {
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid #0392b2;
  border-radius: 8px;
  background: rgba(3,146,178,.12);
  color: #27dceb;
  cursor: pointer;
  font: 700 .63rem var(--sans);
}
.provisional-details {
  margin: 14px 0 0;
  padding: 12px;
  border: 1px solid rgba(39,220,235,.2);
  border-radius: 12px;
  background: rgba(39,220,235,.06);
  color: #b8c7db;
  font-size: .68rem;
  line-height: 1.5;
}
.builder-field.invalid input, .builder-field.invalid select, .builder-field.invalid textarea { border-color: #e65b68; }
.builder-field.full { grid-column: 1 / -1; }
.skin-tone-field {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.skin-tone-field legend { padding: 0; color: #b8c7db; }
.skin-tone-palette {
  display: grid;
  grid-template-columns: repeat(6, minmax(42px, 1fr));
  gap: 10px;
}
.skin-tone-option {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 50px;
  border: 1px solid #17446b;
  border-radius: 12px;
  background: #071a3a;
  cursor: pointer;
}
.skin-tone-option:hover { border-color: #27dceb; }
.skin-tone-option:has(input:focus-visible),
.skin-tone-option:has(input:checked) {
  border-color: #27dceb;
  box-shadow: 0 0 0 3px rgba(39,220,235,.18);
}
.skin-tone-option input {
  position: absolute;
  width: 1px;
  min-height: 1px;
  opacity: 0;
  pointer-events: none;
}
.skin-tone-swatch {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(246,248,252,.38);
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(2,9,33,.2);
}
.skin-tone-swatch svg { width: 100%; height: 100%; display: block; border-radius: inherit; }
.skin-tone-random {
  justify-self: start;
  min-height: 40px;
  padding: 7px 11px;
  border: 1px solid #17446b;
  border-radius: 9px;
  background: transparent;
  color: #27dceb;
  cursor: pointer;
  font: 700 .62rem var(--sans);
}
.skin-tone-random:hover, .skin-tone-random:focus-visible {
  border-color: #27dceb;
  outline: none;
}
.intensity-controls {
  display: grid;
  gap: 14px;
}
.intensity-control {
  padding: 16px;
  border: 1px solid #17446b;
  border-radius: 14px;
  background: #071a3a;
}
.intensity-control-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}
.intensity-control-heading label {
  color: #f6f8fc;
  font: 600 1.1rem var(--serif);
}
.intensity-control-heading output {
  color: #27dceb;
  font-size: .69rem;
  font-weight: 850;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.intensity-control p {
  margin: 6px 0 13px;
  color: #8397b1;
  font-size: .65rem;
  line-height: 1.5;
}
.intensity-control input[type="range"] {
  width: 100%;
  min-height: 32px;
  margin: 0;
  accent-color: #27dceb;
  cursor: pointer;
  touch-action: pan-y;
}
.intensity-control input[type="range"]:focus-visible {
  border-radius: 999px;
  outline: 3px solid rgba(39,220,235,.38);
  outline-offset: 3px;
}
.intensity-position-labels {
  display: grid;
  margin-top: 3px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  color: #8397b1;
  font-size: .52rem;
  line-height: 1.25;
  text-align: center;
}
.intensity-position-labels span:first-child { text-align: left; }
.intensity-position-labels span:last-child { text-align: right; }
.intensity-position-labels .unsupported {
  opacity: .36;
  text-decoration: line-through;
}
.required-theme-panel {
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid rgba(238,189,19,.28);
  border-radius: 13px;
  background: rgba(238,189,19,.07);
  color: #d8c98d;
  font-size: .66rem;
  line-height: 1.55;
}
.required-theme-panel strong {
  display: block;
  margin-bottom: 5px;
  color: #fce542;
  font-size: .6rem;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.required-theme-panel ul { margin: 7px 0 0; padding-left: 18px; }
.intensity-settings-note {
  margin: 0 0 18px;
  color: #b8c7db;
  line-height: 1.55;
}
.intensity-settings-note strong { color: #f6f8fc; }
.intensity-summary {
  margin-top: 16px;
  padding: 12px;
  border: 1px solid rgba(39,220,235,.2);
  border-radius: 12px;
  background: rgba(39,220,235,.06);
  color: #b8c7db;
  font-size: .67rem;
  line-height: 1.55;
}
.intensity-summary strong { color: #f6f8fc; }
.intensity-dialog { width: min(780px, calc(100% - 28px)); }
.intensity-dialog .setup-shell { min-height: min(700px, calc(100dvh - 28px)); }
.intensity-dialog .setup-header { grid-template-columns: 1fr; }
.intensity-dialog .setup-footer { justify-content: flex-end; }
.intensity-dialog-status {
  min-height: 1.2em;
  margin-right: auto;
  align-self: center;
  color: #8397b1;
  font-size: .64rem;
}
.story-intensity-button {
  width: 100%;
  min-height: 40px;
  border: 1px solid rgba(3,146,178,.35);
  border-radius: 9px;
  background: rgba(3,146,178,.1);
  color: var(--link);
  cursor: pointer;
  font: 750 .62rem var(--sans);
}
.scene-image-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.scene-image-info {
  position: relative;
  width: 24px;
  min-width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid rgba(3,146,178,.35);
  border-radius: 50%;
  background: rgba(3,146,178,.08);
  color: var(--link);
  cursor: help;
  font: 800 .68rem var(--sans);
}
.scene-image-tooltip {
  position: absolute;
  z-index: 20;
  right: 0;
  bottom: calc(100% + 8px);
  width: min(280px, calc(100vw - 48px));
  padding: 10px 12px;
  border: 1px solid rgba(3,146,178,.4);
  border-radius: 10px;
  background: var(--surface-raised, #172236);
  box-shadow: 0 12px 30px rgba(0,0,0,.25);
  color: var(--text-primary);
  font: 600 .62rem/1.5 var(--sans);
  text-align: left;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity .16s ease, transform .16s ease;
}
.scene-image-info:hover .scene-image-tooltip,
.scene-image-info:focus-visible .scene-image-tooltip {
  opacity: 1;
  transform: translateY(0);
}
.scene-image-toggle {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  cursor: pointer;
  color: var(--text-primary);
  font: 750 .65rem var(--sans);
}
.scene-image-toggle input {
  width: 38px;
  height: 22px;
  margin: 0;
  accent-color: #0392b2;
  cursor: pointer;
}
.scene-image-toggle input:disabled { cursor: not-allowed; opacity: .55; }
.scene-image-cost-note {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: .6rem;
  line-height: 1.5;
}
.story-intensity-button:hover:not(:disabled) {
  border-color: #0392b2;
  background: rgba(3,146,178,.18);
}
.story-intensity-button:disabled { cursor: not-allowed; opacity: .55; }
.builder-optional { margin-top: 22px; border-top: 1px solid rgba(23,68,107,.7); }
details.builder-optional:not([open]) > .builder-fields { display: none; }
.builder-optional summary {
  padding: 18px 0;
  color: #27dceb;
  cursor: pointer;
  font-size: .66rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.setup-footer {
  display: flex;
  padding: 18px 34px max(18px, env(safe-area-inset-bottom));
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid #17446b;
  background: #020921;
}
.setup-footer .primary-button, .setup-footer .secondary-button { width: auto; min-width: 150px; }
#setupDialog .setup-footer .primary-button { margin-left: auto; }
.setup-footer .primary-button, .class-confirm-button {
  border-color: #eebd13;
  background: #eebd13;
  color: #001c4f;
}
.character-result {
  display: grid;
  grid-template-columns: minmax(180px, 240px) minmax(0, 1fr);
  align-items: start;
  gap: 32px;
}
#setupDialog .setup-shell:has(.character-result) { min-height: 0; }
.setup-step-counter:empty { display: none; }
.result-portrait {
  min-width: 0;
  padding: 10px;
  border: 1px solid #17446b;
  border-radius: 16px;
  background: #071a3a;
}
.result-portrait-open { display: block; width: 100%; padding: 0; border: 0; border-radius: 8px; background: transparent; cursor: zoom-in; }
.result-portrait img { display: block; width: 100%; height: 260px; object-fit: contain; }
.portrait-status {
  padding: 10px 2px 2px;
  color: #b8c7db;
  font-size: .65rem;
  line-height: 1.4;
}
.result-sheet { min-width: 0; }
.result-sheet h3 { margin: 0; font: 500 clamp(1.8rem, 4vw, 2.6rem)/1.1 var(--serif); letter-spacing: -.025em; overflow-wrap: anywhere; }
.result-identity, .result-location { margin: 10px 0; color: #b8c7db; font-size: .78rem; line-height: 1.5; overflow-wrap: anywhere; }
.result-location strong { color: #8397b1; font-weight: 500; }
.result-knack { margin: 20px 0; padding-left: 14px; border-left: 2px solid #0392b2; font-size: .8rem; }
.result-knack p { margin: 5px 0 0; color: #b8c7db; line-height: 1.5; }
.result-details { margin-top: 18px; font-size: .75rem; }
.result-details summary { padding: 10px 0; cursor: pointer; }
.result-details p { color: #b8c7db; line-height: 1.5; }
.result-portrait-action { margin-top: 8px; min-height: 44px; padding: 8px 0; border: 0; background: none; color: #b8c7db; font: inherit; font-size: .72rem; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.result-portrait-action:disabled { opacity: .5; cursor: default; }
.result-portrait-open:focus-visible, .result-portrait-action:focus-visible, .result-details summary:focus-visible { outline: 2px solid #27dceb; outline-offset: 4px; }
.result-attributes { display: grid; margin-top: 16px; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.result-attribute { padding: 9px; border-radius: 9px; background: rgba(39,220,235,.07); color: #b8c7db; font-size: .65rem; }
.result-attribute b { float: right; color: #f6f8fc; }
.result-actions { display: flex; margin-top: 22px; flex-wrap: wrap; gap: 10px; }
.result-actions button { min-height: 44px; width: auto; }
#setupDialog .result-actions .primary-button { background: #eebd13; border-color: #eebd13; color: #001c4f; }
#setupDialog .result-actions .secondary-button { background: #0b2a45; border-color: #17446b; color: #f6f8fc; }

.class-selection-dialog { width: min(1240px, calc(100% - 28px)); }
.class-selection-header {
  align-items: start;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}
.class-selection-header h2 {
  font-size: clamp(1.65rem, 3vw, 2.25rem);
  line-height: 1.1;
}
.class-selection-body { padding-top: 22px; }
.class-disclaimer {
  padding: 12px 14px;
  border: 1px solid rgba(238,189,19,.28);
  border-radius: 12px;
  background: rgba(238,189,19,.08);
  color: #d8c98d;
  font-size: .72rem;
  line-height: 1.55;
}
.class-group { margin-top: 28px; }
.class-group-header { display: flex; margin-bottom: 12px; align-items: end; justify-content: space-between; gap: 18px; }
.class-group-header h3 { margin: 0; font: 500 1.6rem var(--serif); }
.class-group-header p { margin: 0; color: #8397b1; font-size: .67rem; }
.class-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.class-card {
  display: flex;
  min-height: 260px;
  padding: 17px;
  flex-direction: column;
  border: 1px solid #17446b;
  border-radius: 14px;
  background: #071a3a;
  color: inherit;
  text-align: left;
}
.class-card[data-class-id] { align-self: start; }
.class-card-meta {
  display: flex;
  min-height: 22px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.class-card h4 { margin: 4px 0 7px; font: 600 1.28rem var(--serif); }
.class-title-row { display: flex; align-items: center; gap: 10px; }
.story-icon {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border: 1px solid rgba(39,220,235,.28);
  border-radius: 9px;
  background-color: rgba(7,26,58,.86);
  box-shadow: inset 0 0 12px rgba(39,220,235,.08);
}
.story-icon-image { width: 100%; height: 100%; display: block; border-radius: inherit; }
.story-icon.evolution-branch-0 { --evolution-accent: #27dceb; }
.story-icon.evolution-branch-1 { --evolution-accent: #bd7cf5; }
.story-icon.evolution-branch-2 { --evolution-accent: #eebd13; }
.story-icon.evolution-icon {
  border-color: var(--evolution-accent);
  box-shadow:
    inset 0 0 12px color-mix(in srgb, var(--evolution-accent) 25%, transparent),
    0 0 0 1px color-mix(in srgb, var(--evolution-accent) 28%, transparent);
}
.evolution-icon-mark {
  position: absolute;
  right: -4px;
  bottom: -4px;
  display: grid;
  width: 17px;
  height: 17px;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--evolution-accent) 78%, white);
  border-radius: 999px;
  background: #071226;
  color: color-mix(in srgb, var(--evolution-accent) 72%, white);
  font: 900 .58rem/1 var(--sans);
  box-shadow: 0 2px 8px rgba(0,0,0,.42);
}
.class-icon { width: 42px; height: 42px; flex-basis: 42px; border-color: rgba(238,189,19,.42); }
.ability-icon, .item-icon, .profession-icon { width: 30px; height: 30px; flex-basis: 30px; }
.class-family { color: #27dceb; font-size: .56rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.class-fit {
  flex: 0 0 auto;
  padding: 4px 7px;
  border: 1px solid rgba(238,189,19,.32);
  border-radius: 999px;
  background: rgba(238,189,19,.1);
  color: #fce542;
  font-size: .56rem;
  font-weight: 850;
  letter-spacing: .04em;
  white-space: nowrap;
}
.class-card > p { margin: 0 0 10px; color: #b8c7db; font-size: .68rem; line-height: 1.5; }
.class-reason { color: #d8c98d !important; }
.class-tags { display: flex; margin: 3px 0 12px; flex-wrap: wrap; gap: 5px; }
.class-tags span { padding: 4px 6px; border-radius: 999px; background: rgba(39,220,235,.08); color: #8397b1; font-size: .53rem; }
.starter-list { display: grid; gap: 6px; margin: 0 0 14px; padding: 0; list-style: none; }
.starter-list li { display: flex; align-items: flex-start; gap: 8px; color: #b8c7db; font-size: .6rem; line-height: 1.4; }
.starter-list b { color: #f6f8fc; }
.ability-rules { display: block; margin-top: 3px; color: #b8c7db; }
.class-card-details {
  margin: 0 0 12px;
  border-top: 1px solid rgba(39,220,235,.12);
  color: #b8c7db;
}
.class-card-details summary {
  padding: 9px 0 2px;
  color: #27dceb;
  cursor: pointer;
  font-size: .61rem;
  font-weight: 800;
}
.class-card-details .class-reason { margin: 8px 0; font-size: .6rem; line-height: 1.45; }
.class-card-details .starter-list { margin-top: 9px; }
.class-card-details h5 { margin: 16px 0 8px; font: 700 .72rem var(--sans); }
.starter-gear-list { display: grid; gap: 12px; padding: 0; margin: 0; list-style: none; color: #b8c7db; font-size: .68rem; line-height: 1.5; }
.starter-gear-list li { display: grid; gap: 3px; }
.starter-gear-list strong { color: #f6f8fc; }
.class-card button { margin-top: auto; min-height: 40px; border: 1px solid #0392b2; border-radius: 9px; background: rgba(3,146,178,.14); color: #27dceb; cursor: pointer; font-weight: 800; }
.class-card[data-class-id] > button { margin-top: 0; flex-shrink: 0; }
.class-card[data-class-id] > .class-card-details { margin: 12px 0 0; }
.class-card button:hover { background: #0392b2; color: #020921; }

.progression-hud { display: grid; gap: 10px; }
.player-card {
  display: grid;
  padding: 12px;
  grid-template-columns: 58px 1fr;
  gap: 11px;
  border: 1px solid rgba(3,67,126,.18);
  border-radius: 14px;
  background: rgba(255,255,255,.44);
}
.player-card img { width: 58px; height: 72px; border-radius: 10px; object-fit: contain; }
.player-card h3 { margin: 1px 0 3px; font: 600 1rem var(--serif); }
.player-card p { margin: 0; color: #667990; font-size: .6rem; line-height: 1.4; }
.xp-track { width: 100%; height: 5px; margin-top: 8px; overflow: hidden; border: 0; border-radius: 99px; background: rgba(3,67,126,.12); appearance: none; }
.xp-track::-webkit-progress-bar { background: rgba(3,67,126,.12); }
.xp-track::-webkit-progress-value { background: linear-gradient(90deg, #0392b2, #27dceb); }
.xp-track::-moz-progress-bar { background: linear-gradient(90deg, #0392b2, #27dceb); }
.hud-clock { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; color: #40556f; font-size: .65rem; }
.hud-clock b { color: #001c4f; }
.hud-attributes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.hud-attribute {
  display: flex;
  min-height: 32px;
  padding: 5px 7px;
  align-items: center;
  justify-content: space-between;
  border-radius: 8px;
  background: rgba(3,67,126,.06);
  color: #40556f;
  font-size: .55rem;
}
.hud-attribute b { color: #001c4f; }
.hud-attribute button {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid rgba(3,146,178,.32);
  border-radius: 50%;
  background: rgba(3,146,178,.1);
  color: #006b82;
  cursor: pointer;
}
.hud-section { padding: 10px; border: 1px solid rgba(3,67,126,.12); border-radius: 11px; }
.hud-section > strong { display: block; margin-bottom: 7px; color: #667990; font-size: .52rem; letter-spacing: .1em; text-transform: uppercase; }
.hud-list { display: grid; gap: 5px; color: #40556f; font-size: .59rem; line-height: 1.4; }
.key-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.key-state { padding: 7px 4px; border-radius: 8px; background: rgba(3,67,126,.06); color: #667990; font-size: .5rem; text-align: center; text-transform: uppercase; }
.key-state.acquired, .key-state.substituted { background: rgba(79,197,154,.13); color: #197a57; }

@media (max-width: 760px) {
  .setup-dialog, .class-selection-dialog { width: 100%; max-height: 100dvh; border: 0; border-radius: 0; }
  .setup-shell, .class-selection-shell { min-height: 100dvh; max-height: 100dvh; }
  .setup-header, .class-selection-header { padding: max(24px, env(safe-area-inset-top)) 58px 18px 20px; grid-template-columns: 1fr; gap: 8px; }
  .setup-body, .class-selection-body { padding: 20px; }
  .builder-fields,
  .builder-fields[data-builder-layout="identity"],
  .character-result { grid-template-columns: 1fr; }
  .builder-field.full { grid-column: auto; }
  .skin-tone-palette { grid-template-columns: repeat(4, minmax(44px, 1fr)); }
  .result-attributes { grid-template-columns: repeat(2, 1fr); }
  .setup-footer { padding: 13px 20px max(16px, env(safe-area-inset-bottom)); }
  .setup-footer .primary-button, .setup-footer .secondary-button { min-width: 0; flex: 1; }
  .intensity-dialog .setup-footer { flex-wrap: wrap; }
  .intensity-dialog-status { width: 100%; margin: 0; text-align: center; }
  .intensity-position-labels { font-size: .46rem; }
  .continuation-preview-grid { grid-template-columns: 1fr; }
  .continuation-route { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
  .class-grid { grid-template-columns: 1fr; }
  .class-card { min-height: 0; }
}

.app-view { display: flex; flex-direction: column; height: 100vh; height: 100dvh; background: #eee5d9; color: #2e2729; }
.app-header {
  position: sticky;
  flex-shrink: 0;
  z-index: 20;
  top: 0;
  display: grid;
  min-height: calc(var(--app-header-height) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(24px, env(safe-area-inset-right)) 0 max(24px, env(safe-area-inset-left));
  align-items: center;
  border-bottom: 1px solid rgba(46,39,41,.12);
  background: rgba(243,235,224,.91);
  backdrop-filter: blur(18px);
}
.app-nav-left, .app-nav-right { display: flex; gap: 9px; align-items: center; }
.app-nav-right { justify-content: flex-end; }
.app-story-title { text-align: center; }
.app-story-title strong { display: block; font-family: var(--serif); font-size: 1.12rem; font-weight: 600; }
.app-story-title span { color: #8d7f7c; font-size: .61rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
.app-story-meta { display: flex; align-items: center; justify-content: center; gap: 7px; }
.nav-button {
  display: inline-flex;
  gap: 8px;
  min-height: 40px;
  padding: 0 13px;
  align-items: center;
  border: 1px solid rgba(46,39,41,.13);
  border-radius: 10px;
  background: rgba(255,255,255,.34);
  color: #463b3e;
  cursor: pointer;
  font-size: .73rem;
  font-weight: 700;
}
.nav-button:hover { background: rgba(255,255,255,.72); }
.nav-button .icon { width: 17px; height: 17px; }
.theme-toggle .icon { transition: transform .25s ease; }
.theme-toggle:hover .icon { transform: rotate(12deg); }
.scroll-latest-button {
  position: fixed;
  z-index: 19;
  bottom: 92px;
  left: 50%;
  display: inline-flex;
  min-height: 42px;
  padding: 0 15px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid rgba(114,45,67,.2);
  border-radius: 999px;
  background: rgba(250,244,236,.94);
  color: #633448;
  box-shadow: 0 12px 32px rgba(55,35,42,.2);
  cursor: pointer;
  font-size: .67rem;
  font-weight: 800;
  letter-spacing: .05em;
  transform: translateX(-50%);
  backdrop-filter: blur(12px);
  transition: background .2s, transform .2s, opacity .2s;
}
.scroll-latest-button:hover { background: #fffaf3; transform: translateX(-50%) translateY(-2px); }
.scroll-latest-button .icon { width: 16px; height: 16px; }
.scroll-latest-button[hidden] { display: none; }

.workspace {
  display: grid;
  width: min(1540px, 100%);
  flex: 1;
  min-height: 0;
  margin: 0 auto;
  overflow: hidden;
  align-items: start;
  grid-template-columns: 270px minmax(420px, 1fr);
}
.workspace-sidebar {
  height: 100%;
  padding: 28px 22px;
  overflow-y: auto;
  overscroll-behavior: contain;
  align-self: start;
  border-right: 1px solid rgba(46,39,41,.1);
  scrollbar-color: rgba(114,45,67,.22) transparent;
  scrollbar-width: thin;
}
.sidebar-section + .sidebar-section { margin-top: 30px; }
.sidebar-label {
  display: flex;
  margin: 0 0 14px;
  align-items: center;
  justify-content: space-between;
  color: #7d706f;
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: .15em;
  text-transform: uppercase;
}
.sidebar-toggle {
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
}
.sidebar-toggle:hover { color: var(--wine); }
.sidebar-label-meta { display: inline-flex; gap: 7px; align-items: center; }
.sidebar-toggle .icon {
  width: 14px;
  height: 14px;
  transition: transform .2s ease;
}
.sidebar-toggle[aria-expanded="false"] .icon { transform: rotate(-90deg); }
.collapsible-content[hidden] { display: none; }
.character-stack { display: grid; gap: 9px; }
.character-item {
  display: grid;
  width: 100%;
  padding: 8px;
  align-items: center;
  grid-template-columns: 46px 1fr;
  gap: 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  text-align: left;
}
.character-item:hover, .character-item:focus-visible { border-color: rgba(114,45,67,.18); background: rgba(255,255,255,.46); outline: none; }
.character-item img {
  width: 46px;
  height: 52px;
  border-radius: 9px;
  object-fit: cover;
  box-shadow: 0 5px 14px rgba(40,25,30,.14);
}
.character-item-static { cursor: default; }
.character-avatar-placeholder {
  display: grid;
  width: 46px;
  height: 52px;
  place-items: center;
  border: 1px solid rgba(122, 91, 70, .18);
  border-radius: 9px;
  background: rgba(122, 91, 70, .08);
  color: #79645c;
  font-family: var(--serif);
  font-size: .86rem;
  font-weight: 700;
  letter-spacing: .04em;
}
.character-identity { display: flex; min-width: 0; align-items: center; gap: 7px; }
.character-name { display: block; min-width: 0; overflow: hidden; font-family: var(--serif); font-size: .94rem; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.character-note { display: -webkit-box; margin-top: 2px; overflow: hidden; color: #928481; font-size: .62rem; line-height: 1.25; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.character-class { display: flex; min-width: 0; margin-top: 4px; align-items: center; gap: 6px; color: #6f625f; font-size: .62rem; font-weight: 700; line-height: 1.2; }
.character-class .story-icon { width: 20px; height: 20px; flex-basis: 20px; border: 0; border-radius: 5px; background-color: transparent; box-shadow: none; }
.character-class-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.character-relationship { display: -webkit-box; margin-top: 3px; overflow: hidden; color: #80616a; font-size: .64rem; line-height: 1.3; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.relationship-value {
  display: inline-grid;
  min-width: 30px;
  height: 20px;
  padding: 0 6px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid rgba(122, 91, 70, .18);
  border-radius: 999px;
  background: rgba(122, 91, 70, .08);
  color: #79645c;
  font-family: var(--sans);
  font-size: .58rem;
  font-weight: 800;
  letter-spacing: .03em;
}
.relationship-value.positive { border-color: rgba(57, 126, 91, .2); background: rgba(57, 126, 91, .1); color: #31704f; }
.relationship-value.negative { border-color: rgba(160, 54, 67, .2); background: rgba(160, 54, 67, .1); color: #963847; }
.character-photo-count { display: block; margin-top: 4px; color: #a29490; font-size: .56rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.character-loading { padding: 15px 0; color: #928481; font-size: .72rem; }

.character-gallery-dialog {
  width: min(980px, calc(100% - 32px));
  max-height: min(820px, calc(100vh - 32px));
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 24px;
  background: #181317;
  color: var(--ink);
  box-shadow: var(--shadow);
}
.character-gallery-dialog::backdrop { background: rgba(5,4,5,.82); backdrop-filter: blur(10px); }
.character-gallery-body { max-height: min(820px, calc(100vh - 32px)); overflow-y: auto; padding: clamp(26px, 5vw, 52px); }
.character-gallery-header {
  display: grid;
  margin-bottom: 26px;
  align-items: center;
  grid-template-columns: 82px 1fr;
  gap: 18px;
}
.character-gallery-avatar { width: 82px; height: 96px; border-radius: 15px; object-fit: cover; box-shadow: 0 15px 32px rgba(0,0,0,.32); }
.character-gallery-header h2 { margin: 0 0 7px; font-family: var(--serif); font-size: clamp(2rem, 5vw, 3.3rem); font-weight: 500; letter-spacing: -.035em; }
.character-gallery-header p { max-width: 650px; margin: 0; color: var(--ink-soft); font-size: .82rem; line-height: 1.55; }
.character-gallery-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.gallery-photo {
  position: relative;
  display: block;
  width: 100%;
  min-height: 250px;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 16px;
  background: rgba(255,255,255,.04);
  color: inherit;
  font: inherit;
  cursor: zoom-in;
  appearance: none;
}
.gallery-photo img { width: 100%; height: 100%; min-height: 250px; object-fit: cover; transition: transform .25s; }
.gallery-photo:hover img { transform: scale(1.025); }
.gallery-photo:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.gallery-photo span {
  position: absolute;
  right: 10px;
  bottom: 10px;
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(20,15,18,.78);
  color: #e9d8d9;
  font-size: .57rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.generated-image-dialog {
  width: min(1180px, calc(100% - 28px));
  max-height: calc(100vh - 28px);
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 22px;
  background: #100d10;
  color: var(--ink);
  box-shadow: var(--shadow);
}
.generated-image-dialog::backdrop { background: rgba(5,4,5,.88); backdrop-filter: blur(12px); }
.generated-image-dialog-body {
  display: grid;
  max-height: calc(100vh - 28px);
  padding: 48px 24px 22px;
  overflow: auto;
  place-items: center;
  gap: 16px;
}
.generated-image-dialog img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: calc(100vh - 130px);
  border-radius: 14px;
  object-fit: contain;
  box-shadow: 0 22px 70px rgba(0,0,0,.48);
}
.generated-image-dialog p {
  max-width: 850px;
  margin: 0;
  color: var(--ink-soft);
  font-size: .72rem;
  line-height: 1.55;
  text-align: center;
}

.scene-card {
  padding: 17px;
  border: 1px solid rgba(114,45,67,.14);
  border-radius: 15px;
  background: rgba(255,255,255,.34);
}
.scene-card .scene-icon {
  display: grid;
  width: 34px;
  height: 34px;
  margin-bottom: 12px;
  place-items: center;
  border-radius: 50%;
  background: #3c2d32;
  color: #f4e6d5;
}
.scene-card .scene-icon .icon { width: 16px; height: 16px; }
.scene-card-heading {
  display: flex;
  margin-bottom: 12px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.scene-card-heading .scene-icon { margin-bottom: 0; }
.journey-turn {
  display: inline-flex;
  min-height: 28px;
  padding: 0 9px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-secondary);
  font-size: .58rem;
  font-weight: 800;
  letter-spacing: .04em;
  white-space: nowrap;
}
#sceneHeader { margin: 0; color: #5e5052; font-family: var(--serif); font-size: .9rem; line-height: 1.45; white-space: pre-wrap; }

.stat-list { display: grid; gap: 7px; }
.stat-card {
  padding: 12px;
  border: 1px solid rgba(46,39,41,.09);
  border-radius: 11px;
  background: rgba(255,255,255,.28);
}
.stat-card strong { display: block; margin-bottom: 5px; color: #807170; font-size: .57rem; letter-spacing: .13em; text-transform: uppercase; }
.stat-card p { margin: 0; overflow: visible; color: #514547; font-size: .72rem; line-height: 1.5; overflow-wrap: anywhere; white-space: pre-wrap; }
.character-state-list { gap: 11px; }
.character-state-card {
  padding: 16px;
  border-color: rgba(114,45,67,.14);
  border-radius: 15px;
  background:
    radial-gradient(circle at 100% 0, rgba(181,143,74,.11), transparent 42%),
    rgba(255,255,255,.4);
  box-shadow: 0 8px 22px rgba(63,43,48,.055);
}
.character-state-card > strong {
  margin-bottom: 11px;
  color: var(--wine);
  font-size: .6rem;
}
.state-details { display: grid; gap: 6px; }
.state-subheading {
  display: block;
  margin: 8px 0 1px;
  color: #9a7441;
  font-size: .58rem;
  font-weight: 800;
  letter-spacing: .13em;
  text-transform: uppercase;
}
.state-row {
  display: grid;
  padding: 7px 0;
  align-items: baseline;
  grid-template-columns: minmax(84px, .8fr) minmax(0, 1.2fr);
  gap: 10px;
  border-bottom: 1px solid rgba(46,39,41,.07);
}
.state-row:last-child { border-bottom: 0; }
.state-row b { color: #6d5a5e; font-size: .66rem; font-weight: 700; }
.state-row span { color: #3f3437; font-family: var(--serif); font-size: .76rem; line-height: 1.45; text-align: right; }
.state-copy { display: block; color: #514547; font-size: .7rem; line-height: 1.55; }
.status-card {
  border-color: rgba(181,143,74,.23);
  background:
    linear-gradient(135deg, rgba(181,143,74,.1), transparent 55%),
    rgba(255,255,255,.43);
}
.status-entry {
  position: relative;
  padding: 5px 0 5px 13px;
}
.status-entry::before {
  position: absolute;
  top: .88em;
  left: 1px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #b58f4a;
  box-shadow: 0 0 0 3px rgba(181,143,74,.1);
  content: "";
}
.inventory-coins { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; }
.coin { padding: 10px; border-radius: 10px; background: rgba(255,255,255,.32); font-size: .65rem; }
.coin b { display: block; margin-bottom: 2px; font-family: var(--serif); font-size: 1.05rem; }
.inventory-items { display: grid; margin: 10px 0 0; padding: 0; gap: 7px; color: #6d5f60; font-size: .69rem; line-height: 1.55; list-style: none; }
.inventory-item {
  position: relative;
  display: flex;
  min-width: 0;
  padding: 7px;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(3,67,126,.14);
  border-radius: 10px;
  background: rgba(255,255,255,.28);
  cursor: help;
  outline: none;
}
.inventory-item:focus-visible { border-color: #0392b2; box-shadow: 0 0 0 3px rgba(3,146,178,.13); }
.inventory-item-name { min-width: 0; overflow: hidden; color: #3f3437; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.inventory-item-tooltip {
  position: absolute;
  z-index: 30;
  right: 0;
  bottom: calc(100% + 7px);
  display: none;
  width: min(260px, 74vw);
  padding: 10px 11px;
  border: 1px solid rgba(39,220,235,.4);
  border-radius: 10px;
  background: #071a3a;
  box-shadow: 0 12px 30px rgba(0,9,33,.28);
  color: #dbe6f5;
  font-size: .66rem;
  line-height: 1.45;
}
.inventory-item-tooltip b { display: block; margin-bottom: 4px; color: #fce542; text-transform: capitalize; }
.inventory-item-tooltip .item-stat-line {
  display: block;
  margin-bottom: 6px;
  color: #72f2c8;
  font-weight: 750;
}
.inventory-item:hover .inventory-item-tooltip,
.inventory-item:focus-visible .inventory-item-tooltip { display: block; }
.sidebar-label-action {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(3,146,178,.3);
  border-radius: 999px;
  background: rgba(3,146,178,.08);
  color: #03758f;
  cursor: pointer;
  font: 800 .54rem var(--sans);
  letter-spacing: .07em;
  text-transform: uppercase;
}
.sidebar-label-action:hover,
.sidebar-label-action:focus-visible {
  border-color: #0392b2;
  box-shadow: 0 0 0 3px rgba(3,146,178,.12);
  outline: none;
}
.inventory-equipped {
  margin-left: auto;
  padding: 3px 6px;
  border-radius: 999px;
  background: rgba(3,146,178,.11);
  color: #03758f;
  font-size: .5rem;
  font-weight: 850;
  letter-spacing: .05em;
  text-transform: uppercase;
}
.equipment-dialog {
  width: min(1160px, calc(100% - 28px));
  max-height: calc(100dvh - 28px);
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(39,220,235,.28);
  border-radius: 24px;
  background:
    radial-gradient(circle at 50% 26%, rgba(3,146,178,.18), transparent 34%),
    linear-gradient(145deg, #061632, #020921 64%);
  color: #f6f8fc;
  box-shadow: 0 34px 110px rgba(0,0,0,.62);
}
.equipment-dialog::backdrop {
  background: rgba(1,4,16,.9);
  backdrop-filter: blur(13px);
}
.equipment-shell {
  display: flex;
  max-height: calc(100dvh - 28px);
  min-height: 0;
  flex-direction: column;
}
.equipment-header {
  display: flex;
  padding: 24px 72px 18px 28px;
  flex: 0 0 auto;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid rgba(39,220,235,.14);
}
.equipment-header h2 {
  margin: 3px 0 0;
  font: 600 clamp(1.8rem, 4vw, 2.7rem)/1 var(--serif);
  letter-spacing: -.035em;
}
.equipment-header p { margin: 0; color: #8397b1; font-size: .7rem; line-height: 1.5; }
.equipment-free-action {
  padding: 7px 10px;
  border: 1px solid rgba(39,220,235,.28);
  border-radius: 999px;
  background: rgba(39,220,235,.07);
  color: #27dceb !important;
  font-size: .57rem !important;
  font-weight: 850;
  letter-spacing: .08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.equipment-body {
  min-height: 0;
  padding: 22px 28px 26px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.equipment-paperdoll {
  display: grid;
  max-width: 970px;
  margin: 0 auto;
  grid-template-columns: minmax(180px, 1fr) minmax(220px, .9fr) minmax(180px, 1fr);
  align-items: center;
  gap: 18px;
}
.equipment-slot-column { display: grid; gap: 10px; }
.equipment-character {
  position: relative;
  display: grid;
  min-height: 390px;
  padding: 22px;
  place-items: end center;
  overflow: hidden;
  border: 1px solid rgba(238,189,19,.28);
  border-radius: 999px 999px 24px 24px;
  background: linear-gradient(180deg, rgba(39,220,235,.08), rgba(2,9,33,.9));
  box-shadow: inset 0 0 50px rgba(39,220,235,.06);
}
.equipment-character::before {
  position: absolute;
  inset: 14px;
  border: 1px solid rgba(39,220,235,.12);
  border-radius: inherit;
  content: "";
  pointer-events: none;
}
.equipment-character img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: .88;
  object-fit: cover;
  object-position: center top;
  mask-image: linear-gradient(to bottom, #000 70%, transparent 100%);
}
.equipment-character-copy {
  position: relative;
  z-index: 1;
  width: 100%;
  padding: 54px 10px 2px;
  background: linear-gradient(to top, #020921 18%, transparent);
  text-align: center;
}
.equipment-character-copy strong { display: block; font: 600 1.45rem var(--serif); }
.equipment-character-copy span { display: block; margin-top: 4px; color: #b8c7db; font-size: .64rem; }
.equipment-slot {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 68px;
  padding: 9px 10px;
  align-items: center;
  border: 1px solid #17446b;
  border-radius: 13px;
  background: rgba(7,26,58,.78);
  grid-template-columns: 38px minmax(0, 1fr) auto;
  gap: 10px;
  transition: border-color .16s, box-shadow .16s, opacity .16s, transform .16s;
}
.equipment-slot-icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid rgba(39,220,235,.18);
  border-radius: 10px;
  background: rgba(2,9,33,.74);
  color: #8397b1;
  font: 700 .95rem var(--serif);
}
.equipment-slot-copy { min-width: 0; }
.equipment-slot-label {
  display: block;
  color: #8397b1;
  font-size: .5rem;
  font-weight: 850;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.equipment-slot-name {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: #f6f8fc;
  font-size: .68rem;
  font-weight: 780;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.equipment-slot-empty { color: #5f7693; font-weight: 600; }
.equipment-slot button {
  min-width: 34px;
  min-height: 34px;
  padding: 0 8px;
  border: 1px solid rgba(39,220,235,.2);
  border-radius: 9px;
  background: rgba(39,220,235,.06);
  color: #27dceb;
  cursor: pointer;
  font: 800 .55rem var(--sans);
}
.equipment-slot.is-compatible {
  border-color: #27dceb;
  box-shadow: 0 0 0 3px rgba(39,220,235,.18), 0 0 24px rgba(39,220,235,.13);
  transform: translateY(-1px);
}
.equipment-slot.is-compatible::after {
  position: absolute;
  inset: -5px;
  border: 1px solid rgba(39,220,235,.34);
  border-radius: 17px;
  content: "";
  pointer-events: none;
}
.equipment-slot.is-incompatible { opacity: .34; }
.equipment-slot.is-drag-over {
  border-color: #fce542;
  box-shadow: 0 0 0 4px rgba(252,229,66,.17), 0 0 30px rgba(252,229,66,.16);
  transform: scale(1.025);
}
.equipment-accessory-row {
  display: grid;
  max-width: 970px;
  margin: 12px auto 0;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.equipment-inventory-panel {
  max-width: 970px;
  margin: 20px auto 0;
  padding-top: 18px;
  border-top: 1px solid rgba(39,220,235,.14);
}
.equipment-inventory-heading {
  display: flex;
  margin-bottom: 10px;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
}
.equipment-inventory-heading h3 { margin: 0; font: 600 1.25rem var(--serif); }
.equipment-inventory-heading p { margin: 0; color: #8397b1; font-size: .62rem; }
.equipment-inventory-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
}
.equipment-item {
  display: grid;
  min-width: 0;
  min-height: 66px;
  padding: 9px;
  border: 1px solid #17446b;
  border-radius: 12px;
  background: rgba(7,26,58,.72);
  color: inherit;
  cursor: pointer;
  font: inherit;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  text-align: left;
}
.equipment-item:hover,
.equipment-item:focus-visible,
.equipment-item[aria-pressed="true"] {
  border-color: #27dceb;
  box-shadow: 0 0 0 3px rgba(39,220,235,.13);
  outline: none;
}
.equipment-item[aria-pressed="true"] { background: rgba(39,220,235,.12); }
.equipment-item.is-equipped { border-color: rgba(238,189,19,.42); }
.equipment-item.is-carried-only { cursor: default; opacity: .58; }
.equipment-item-copy { min-width: 0; }
.equipment-item-copy strong,
.equipment-item-copy span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.equipment-item-copy strong { font-size: .67rem; }
.item-stat-summary {
  color: #72f2c8;
  font-weight: 750;
  letter-spacing: .01em;
}
.rarity-common { color: #dbe6f5; }
.rarity-uncommon { color: #72f2c8; }
.rarity-rare { color: #64b5ff; }
.rarity-epic { color: #c792ff; }
.rarity-legendary { color: #ffb347; }
.rarity-mythic { color: #ff6fae; }
.rarity-godlike { color: #fce542; text-shadow: 0 0 12px rgba(252,229,66,.35); }
.equipment-item-copy span { margin-top: 4px; color: #8397b1; font-size: .54rem; text-transform: capitalize; }
.equipment-detail {
  display: grid;
  max-width: 970px;
  min-height: 84px;
  margin: 12px auto 0;
  padding: 13px 15px;
  border: 1px solid rgba(238,189,19,.22);
  border-radius: 13px;
  background: rgba(238,189,19,.055);
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
}
.equipment-detail strong { color: #fce542; font: 600 1rem var(--serif); }
.equipment-detail p { margin: 5px 0 0; color: #b8c7db; font-size: .65rem; line-height: 1.48; }
.equipment-detail small { color: #8397b1; font-size: .55rem; line-height: 1.45; text-align: right; }
.item-lifecycle { display: grid; gap: 6px; margin: 12px 0 0; }
.item-lifecycle > div { display: grid; grid-template-columns: 68px minmax(0, 1fr); gap: 8px; }
.item-lifecycle dt { color: #27dceb; font-size: .54rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.item-lifecycle dd { margin: 0; color: #b8c7db; font-size: .61rem; line-height: 1.45; }
.item-lifecycle-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.item-lifecycle-actions button {
  padding: 7px 10px;
  border: 1px solid var(--primary-border);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text-primary);
  cursor: pointer;
  font-size: .58rem;
  font-weight: 800;
}
.item-lifecycle-actions button[data-item-lifecycle-action="discard"] {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}
.equipment-status { min-height: 1.2em; max-width: 970px; margin: 10px auto 0; color: #8397b1; font-size: .63rem; }
.equipment-status.error { color: #ff9cad; }
.ability-card {
  display: flex;
  align-items: flex-start;
  padding: 8px;
  gap: 8px;
  border: 1px solid rgba(3,67,126,.12);
  border-radius: 10px;
  background: rgba(255,255,255,.25);
}
.ability-card > div { flex: 1; min-width: 0; }
.ability-card strong { display: block; color: #001c4f; font-size: .95rem; }
.ability-card p { margin: 6px 0; color: #40556f; font-size: .875rem; line-height: 1.5; }
.ability-card small { display: block; color: #667990; font-size: .8rem; line-height: 1.5; }
.cooldown-panel { display: grid; gap: 6px; }
.cooldown-state { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: #40556f; font-size: .59rem; }
.cooldown-state b { color: #001c4f; }
.cooldown-state .recovering { color: #9a7441; }
.profession-seed { display: flex !important; align-items: center; gap: 8px; }
.profession-seed-copy { display: grid; min-width: 0; gap: 2px; }
.profession-seed-copy small { color: #667990; font-size: .54rem; line-height: 1.35; }
.journal-panel { display: grid; gap: 14px; }
.journal-section { display: grid; gap: 7px; }
.journal-section h3 {
  margin: 0;
  color: var(--ink-faint);
  font-size: .58rem;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.journal-list {
  display: grid;
  margin: 0;
  padding: 0;
  gap: 7px;
  list-style: none;
}
.journal-list li {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
  color: var(--ink-soft);
  font-family: var(--serif);
  font-size: .74rem;
  line-height: 1.42;
  overflow-wrap: anywhere;
}
.journal-disputed {
  display: inline-block;
  margin: 0 6px 3px 0;
  padding: 2px 6px;
  border: 1px solid var(--accent-border);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: .55rem;
  font-weight: 700;
  letter-spacing: .08em;
  line-height: 1.3;
  text-transform: uppercase;
}
.journal-entry-meta {
  display: flex;
  margin-top: 5px;
  gap: 0;
  flex-wrap: wrap;
  color: var(--ink-faint);
  font-size: .61rem;
  line-height: 1.35;
}
.journal-entry-meta-separator {
  padding: 0 8px;
}
.journal-empty {
  margin: 0;
  color: var(--ink-faint);
  font-size: .69rem;
  line-height: 1.5;
}
.personal-notes {
  display: grid;
  gap: 9px;
}
.personal-notes textarea {
  width: 100%;
  min-height: 120px;
  max-height: 320px;
  padding: 11px 12px;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: .72rem;
  line-height: 1.5;
}
.personal-notes textarea::placeholder { color: var(--ink-faint); }
.personal-notes-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}
.personal-notes-actions button {
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid var(--primary-border);
  border-radius: 9px;
  background: var(--primary-soft);
  color: var(--primary);
  cursor: pointer;
  font-size: .67rem;
  font-weight: 700;
}
.personal-notes-actions button:disabled { cursor: wait; opacity: .58; }
.personal-notes-status {
  color: var(--ink-faint);
  font-size: .62rem;
  line-height: 1.35;
  text-align: right;
}

.story-stage {
  --reader-gutter: max(12px, min(2vw, 24px), env(safe-area-inset-left), env(safe-area-inset-right));
  --reader-lane: min(760px, calc(100% - 2 * var(--reader-gutter)));
  display: flex;
  min-width: 0;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  flex-direction: column;
  scrollbar-gutter: stable both-edges;
  scrollbar-color: rgba(114,45,67,.34) transparent;
  scrollbar-width: thin;
}
.story-stage::-webkit-scrollbar { width: 8px; }
.story-stage::-webkit-scrollbar-track { background: transparent; }
.story-stage::-webkit-scrollbar-thumb { border: 2px solid transparent; border-radius: 999px; background: rgba(114,45,67,.34); background-clip: padding-box; }
.messages, .choices, .class-selection-prompt, .composer {
  width: var(--reader-lane);
  margin-inline: auto;
}
.messages {
  display: flex;
  margin: 0 auto;
  padding: 10px 0 34px;
  flex: 1;
  flex-direction: column;
  gap: 18px;
}
.message { display: flex; flex-direction: column; }
.message-heading {
  display: flex;
  min-height: 24px;
  margin: 0 0 6px 14px;
  align-items: center;
  gap: 6px;
}
.message-role {
  margin: 0;
  color: #998b88;
  font-size: .56rem;
  font-weight: 700;
  letter-spacing: .13em;
  text-transform: uppercase;
}
.turn-edit-button {
  display: inline-grid;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #796c6f;
  cursor: pointer;
  place-items: center;
}
.turn-edit-button .icon { width: 13px; height: 13px; }
.turn-edit-button:hover,
.turn-edit-button:focus-visible {
  background: rgba(111,46,67,.1);
  color: #6f2e43;
}
.turn-edit-button:disabled { cursor: wait; opacity: .45; }
.bubble {
  position: relative;
  width: 100%;
  padding: 18px 20px;
  border: 1px solid rgba(46,39,41,.09);
  border-radius: 6px 18px 18px 18px;
  background: rgba(255,255,255,.42);
  color: #4a3e40;
  font-family: var(--serif);
  font-size: 1.01rem;
  line-height: 1.68;
  white-space: pre-wrap;
}
.message.assistant .bubble {
  max-width: 100%;
  padding: 12px 8px 20px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
.message.user .bubble {
  border-color: #3f3035;
  border-radius: 18px 6px 18px 18px;
  background: #3f3035;
  color: #f7eee4;
  font-family: var(--sans);
  font-size: .86rem;
  line-height: 1.6;
}
.description { color: inherit; font-style: normal; }
em.description { font-style: italic; }
.message.user .description { color: #f0b6c7; }
.dialogue { color: #3f3436; font-style: normal; }
.message.user .dialogue { color: #fff3ea; }
.dialogue .description { color: inherit; }
.message.streaming .bubble::after {
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 3px;
  border-radius: 2px;
  background: #8b445c;
  content: "";
  vertical-align: -.12em;
  animation: typewriter-caret .8s steps(1) infinite;
}
.typewriter-waiting { color: #9a878b; letter-spacing: .18em; }
.prose-reveal-button {
  margin-left: auto;
  border: 0;
  padding: 4px 8px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.prose-reveal-button:hover { text-decoration: underline; }
.prose-reveal-button:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }

.system-milestone-card {
  margin: 18px 0 4px;
  padding: clamp(18px, 3vw, 28px);
  border: 1px solid color-mix(in srgb, var(--accent) 58%, var(--line));
  border-radius: 22px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--night-raised) 92%, var(--accent) 8%), var(--night-raised));
  box-shadow: 0 20px 60px color-mix(in srgb, var(--accent) 10%, transparent);
}
.system-milestone-card > header > span,
.system-milestone-entry > span {
  color: var(--accent);
  font: 800 .62rem/1.3 var(--sans);
  letter-spacing: .12em;
  text-transform: uppercase;
}
.system-milestone-card h3 {
  margin: 7px 0 8px;
  color: var(--ink);
  font: 600 clamp(1.6rem, 4vw, 2.5rem)/1 var(--serif);
}
.system-milestone-card header p,
.system-milestone-entry p { margin: 0; color: var(--ink-soft); }
.system-milestone-details { display: grid; gap: 8px; margin: 16px 0 0; }
.system-milestone-details div { display: grid; grid-template-columns: 90px 1fr; gap: 10px; }
.system-milestone-details dt { color: var(--ink-faint); font-size: .72rem; font-weight: 800; }
.system-milestone-details dd { margin: 0; color: var(--ink-soft); }
.system-milestone-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 18px;
}
.system-milestone-entry {
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--night-raised) 88%, transparent);
}
.system-milestone-entry strong { display: block; margin-bottom: 4px; color: var(--ink); }
.system-milestone-entry dl { display: grid; gap: 7px; margin: 12px 0 0; }
.system-milestone-entry dl div { display: grid; grid-template-columns: 70px 1fr; gap: 8px; }
.system-milestone-entry dt { color: var(--ink-faint); font-size: .7rem; font-weight: 700; }
.system-milestone-entry dd { margin: 0; color: var(--ink-soft); font-size: .78rem; }
.stream-failure {
  max-width: 92%;
  margin: 10px 0 0 8px;
  padding: 8px 10px;
  border: 1px solid rgba(150,56,71,.2);
  border-radius: 9px;
  background: rgba(150,56,71,.07);
  color: #883748;
  font-family: var(--sans);
  font-size: .68rem;
  font-weight: 650;
  line-height: 1.4;
}
@keyframes typewriter-caret { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .message.streaming .bubble::after { animation: none; }
}
/* Reveal follow-up UI in reading order without delaying authoritative state
   or the free-form composer. Image polls cannot override this presentation gate. */
.message[data-revealing-prose] .turn-updates,
.messages:has(> [data-revealing-prose]) ~ .choices {
  display: none;
}
.turn-updates {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  margin: 11px 0 0;
  gap: 4px;
  align-items: stretch;
  padding: 8px 10px;
  border: 1px solid rgba(114,45,67,.14);
  border-radius: 8px;
  background: rgba(114,45,67,.055);
  font-family: var(--sans);
}
.turn-updates-label {
  margin-bottom: 2px;
  color: #7c3d50;
  font-size: .6rem;
  font-weight: 800;
  letter-spacing: .08em;
  line-height: 1.35;
  text-transform: uppercase;
}
.turn-update {
  display: block;
  min-width: 0;
  padding: 2px 0 2px 9px;
  border-left: 1px solid rgba(114,45,67,.2);
  color: #7c3d50;
  font-size: .65rem;
  font-weight: 650;
  line-height: 1.35;
}
.transcript-note {
  display: flex;
  gap: 11px;
  margin-bottom: 14px;
  padding: 11px 12px;
  align-items: center;
  border-radius: 9px;
  background: rgba(114,45,67,.08);
  color: #7b5962;
  font-family: var(--sans);
  font-size: .67rem;
  font-weight: 700;
}
.transcript-note .icon { width: 17px; height: 17px; }
.empty-conversation { padding: 44px 20px; color: #8e807d; font-family: var(--serif); font-size: 1.12rem; text-align: center; }
.conversation-history-hint {
  margin: 0 0 4px;
  padding: 9px 12px;
  color: #998b88;
  font-size: .6rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-align: center;
  text-transform: uppercase;
}

.choices {
  margin: 0 auto 24px;
}
.class-selection-prompt {
  display: grid;
  margin: 0 auto 24px;
  padding: 20px;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  border: 1px solid rgba(3,146,178,.38);
  border-radius: 16px;
  background: linear-gradient(135deg, #071a3a, #0b2a54);
  color: #f6f8fc;
  box-shadow: 0 18px 42px rgba(2,9,33,.2);
}
.class-selection-prompt[hidden] { display: none; }
.class-selection-prompt .eyebrow { margin-bottom: 6px; color: #27dceb; }
.class-selection-prompt h2 { margin: 0 0 5px; font: 500 1.65rem/1.05 var(--serif); }
.class-selection-prompt p:last-child { margin: 0; color: #b8c7db; font-size: .7rem; line-height: 1.5; }
.class-selection-prompt button {
  min-height: 46px;
  padding: 0 17px;
  border: 1px solid #eebd13;
  border-radius: 10px;
  background: #eebd13;
  color: #001c4f;
  cursor: pointer;
  font-weight: 800;
  white-space: nowrap;
}
.class-selection-prompt button:hover { background: #fce542; }
.story-phase-actions {
  display: grid;
  min-width: 170px;
  gap: 8px;
}
.story-phase-actions button[hidden] { display: none; }
.story-phase-actions #openContinuationButton {
  border-color: #27dceb;
  background: rgba(39,220,235,.1);
  color: #27dceb;
}
.story-phase-actions #openContinuationButton:hover {
  background: #27dceb;
  color: #020921;
}
.danger-button {
  min-height: 42px;
  padding: 0 15px;
  border: 1px solid #c94755;
  border-radius: 9px;
  background: #9f2f40;
  color: #fff;
  cursor: pointer;
  font-weight: 800;
}
.danger-button:hover:not(:disabled) { background: #c94755; }
.danger-button:disabled { cursor: not-allowed; opacity: .55; }
.book-restart-warning { border-color: rgba(201,71,85,.46); }
.book-restart-settings { border-color: rgba(201,71,85,.28); }
.story-phase-prompt {
  border-color: rgba(238, 189, 19, .48);
  background:
    radial-gradient(circle at 100% 0, rgba(238, 189, 19, .12), transparent 42%),
    linear-gradient(135deg, #071a3a, #0b2a54);
}
.story-phase-prompt[data-state="complete"] {
  border-color: rgba(131, 151, 177, .38);
}
.choices-label { margin: 0 0 10px; color: #8e807d; font-size: .59rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
#options { display: grid; gap: 8px; }
.choice-row {
  display: grid;
  align-items: stretch;
  grid-template-columns: 42px minmax(0, 1fr);
  border: 1px solid rgba(114,45,67,.15);
  border-radius: 11px;
  background: rgba(255,255,255,.31);
  overflow: hidden;
}
.choice-edit {
  display: grid;
  width: 42px;
  padding: 0;
  place-items: center;
  border: 0;
  border-right: 1px solid rgba(114,45,67,.15);
  border-radius: 0;
  background: transparent;
  color: #80616a;
  cursor: pointer;
  transition: background .2s, color .2s;
}
.choice-edit:hover { background: rgba(255,255,255,.7); color: var(--wine); }
.choice-edit .icon { width: 15px; height: 15px; }
.choice-button {
  display: grid;
  width: 100%;
  padding: 12px 14px;
  align-items: center;
  grid-template-columns: 25px 1fr 18px;
  gap: 9px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #514346;
  cursor: pointer;
  text-align: left;
  transition: background .2s;
}
.choice-button:hover { background: rgba(255,255,255,.7); }
.choice-index { color: var(--wine); font-family: var(--serif); font-size: 1rem; }
.choice-text { font-family: var(--serif); font-size: .86rem; }
.choice-button .icon { width: 15px; height: 15px; color: #998b88; }

.generated-images {
  display: grid;
  width: 100%;
  margin: 14px 0 0;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr);
}
.generated-image-card {
  display: grid;
  min-width: 0;
  gap: 8px;
  align-content: start;
}
.generated-image-button {
  display: grid;
  width: 100%;
  padding: 0;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(114,45,67,.16);
  border-radius: 14px;
  background: transparent;
  cursor: zoom-in;
  transition: transform .22s, box-shadow .22s;
}
.generated-image-button:hover { transform: translateY(-2px); box-shadow: 0 18px 38px rgba(51,35,40,.16); }
.generated-image-button img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: min(52dvh, 600px);
  object-fit: contain;
  border-radius: inherit;
}
.image-generation-status {
  display: flex;
  min-height: 112px;
  padding: 20px;
  align-items: center;
  justify-content: center;
  gap: 13px;
  border: 1px dashed rgba(114,45,67,.24);
  border-radius: 14px;
  background: rgba(255,255,255,.22);
  color: #806d71;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .04em;
}
.image-generation-status .icon {
  width: 20px;
  height: 20px;
  color: var(--wine);
  animation: image-sparkle 1.35s ease-in-out infinite;
}
.image-generation-status.failed { border-style: solid; color: #963847; }
.image-generation-status.failed .icon { color: #963847; animation: none; }
.image-retry-button {
  padding: 7px 10px;
  border: 1px solid currentColor;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
}
.image-retry-button:hover { background: rgba(150,56,71,.08); }
.image-generation-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.image-variant-selector {
  display: inline-flex;
  min-height: 38px;
  padding: 0 9px;
  align-items: center;
  gap: 7px;
  border: 1px solid rgba(114,45,67,.2);
  border-radius: 9px;
  background: rgba(255,255,255,.32);
  color: #704155;
  font-size: .65rem;
  font-weight: 800;
}
.image-variant-selector select {
  max-width: 150px;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
}
.image-regenerate-button {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid rgba(114,45,67,.2);
  border-radius: 9px;
  background: rgba(255,255,255,.32);
  color: #704155;
  cursor: pointer;
  font-size: .65rem;
  font-weight: 800;
}
.image-regenerate-button:hover { background: rgba(255,255,255,.75); }
.portrait-controls .image-variant-selector {
  width: 100%;
  justify-content: space-between;
}
.portrait-controls .image-regenerate-button { width: 100%; }
.hud-portrait-note {
  color: var(--ink-faint);
  font-size: .68rem;
  line-height: 1.45;
}
.image-generation-warning {
  padding: 9px 11px;
  border: 1px solid rgba(150,56,71,.2);
  border-radius: 9px;
  background: rgba(150,56,71,.07);
  color: #883748;
  font-size: .68rem;
  font-weight: 650;
  line-height: 1.4;
}

.composer-wrap {
  position: sticky;
  z-index: 10;
  bottom: 0;
  padding: 14px 0 22px;
  background: linear-gradient(to top, #eee5d9 72%, rgba(238,229,217,0));
}
.composer {
  display: grid;
  margin: 0 auto;
  padding: 10px 10px 10px 18px;
  align-items: end;
  grid-template-columns: 1fr auto;
  gap: 12px;
  border: 1px solid rgba(76,52,59,.2);
  border-radius: 18px;
  background: rgba(255,255,255,.82);
  box-shadow: 0 16px 45px rgba(59,40,45,.13);
  backdrop-filter: blur(12px);
}
.composer textarea {
  align-self: center;
  width: 100%;
  max-height: 180px;
  field-sizing: content;
  padding: 8px 0;
  resize: none;
  overflow-y: auto;
  border: 0;
  outline: 0;
  background: transparent;
  color: #3a3032;
  line-height: 1.5;
}
.composer textarea::placeholder { color: #a39693; }
.send-button {
  display: grid;
  width: 46px;
  height: 46px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 13px;
  background: #662b3e;
  color: white;
  cursor: pointer;
  transition: transform .2s, background .2s;
}
.send-button:hover { background: #7d344b; transform: translateY(-2px); }
.send-button .icon { width: 19px; height: 19px; }
.composer-hint { margin: 7px auto 0; color: #9a8c89; font-size: .58rem; text-align: center; }

.loading-cover {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(16,13,16,.93);
  color: var(--ink);
}
.loading-inner { text-align: center; }
.loading-sigil {
  display: grid;
  width: 64px;
  height: 64px;
  margin: 0 auto 19px;
  place-items: center;
  border: 1px solid rgba(213,183,123,.25);
  border-radius: 50%;
  color: var(--gold);
  animation: breathe 1.5s ease-in-out infinite;
}
.loading-inner strong { display: block; font-family: var(--serif); font-size: 1.35rem; font-weight: 500; }
.loading-inner span { display: block; margin-top: 7px; color: var(--ink-faint); font-size: .72rem; }

.toast {
  position: fixed;
  z-index: 200;
  right: 22px;
  bottom: 22px;
  max-width: min(380px, calc(100% - 44px));
  padding: 13px 16px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 11px;
  background: #241c21;
  color: #f7eee4;
  box-shadow: 0 16px 35px rgba(0,0,0,.3);
  font-size: .75rem;
  line-height: 1.4;
  animation: toast-in .25s ease-out;
}
.toast.error { border-color: rgba(233,165,177,.35); }

@keyframes breathe { 50% { transform: scale(1.08); box-shadow: 0 0 30px var(--accent-soft); } }
@keyframes image-sparkle { 50% { opacity: .48; transform: scale(.82) rotate(12deg); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } }
.library-intro, .story-grid { animation: rise .65s ease-out both; }
.story-grid { animation-delay: .1s; }

@media (max-width: 1120px) {
  .story-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workspace { grid-template-columns: 230px minmax(420px, 1fr); }
}
@media (max-width: 820px) {
  .library-intro { grid-template-columns: 1fr; }
  .library-intro-note { max-width: 520px; }
  .workspace { display: block; }
  .workspace-sidebar { display: none; }
  .app-header { padding: 0 14px; }
  .nav-button span { display: none; }
}
@media (max-width: 640px) {
  .library-header, .library-main { width: min(calc(100% - 28px), 1220px); }
  .library-header { padding: 19px 0; }
  .library-main { padding-top: 58px; }
  .library-intro { margin-bottom: 34px; }
  .library-intro h1 { font-size: clamp(3.2rem, 17vw, 5rem); }
  .story-grid { grid-template-columns: 1fr; }
  .story-card { min-height: 0; }
  .story-dialog { max-height: calc(100vh - 20px); }
  .dialog-copy h2 { font-size: 2.7rem; }
  .app-story-title strong { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .app-nav-right .nav-button:first-child { display: none; }
  .class-selection-prompt {
    padding: 17px;
    grid-template-columns: 1fr;
  }
  .class-selection-prompt button { width: 100%; }
  .bubble { padding: 15px 16px; font-size: .94rem; }
  .composer-wrap { padding-block: 10px 14px; }
  .composer { border-radius: 15px; }
  .character-gallery-grid { grid-template-columns: 1fr; }
  .character-gallery-body { padding: 24px 18px; }
  .character-gallery-header { grid-template-columns: 64px 1fr; }
  .character-gallery-avatar { width: 64px; height: 76px; }
}

/* Touch-first responsive refinements for tablets and phones. */
@media (max-width: 1120px) {
  .app-header {
    padding-right: max(14px, env(safe-area-inset-right));
    padding-left: max(14px, env(safe-area-inset-left));
  }
  .nav-button { min-width: 44px; min-height: 44px; justify-content: center; }
  .character-gallery-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .gallery-photo, .gallery-photo img { min-height: 220px; }
}

@media (max-width: 900px) {
  :root { --app-header-height: 66px; }
  .library-intro, .library-intro > *, .library-intro-note { min-width: 0; }
  .library-intro-note { overflow-wrap: anywhere; }
  .workspace { display: block; }
  .workspace > .workspace-sidebar:not(.right) { display: none; }
  .story-stage {
    width: 100%;
    height: 100%;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }
  .bubble, .choice-text, #sceneHeader, .state-copy { overflow-wrap: anywhere; }
}

@media (max-width: 640px) {
  :root {
    --app-header-height: 62px;
    --mobile-gutter-left: max(14px, env(safe-area-inset-left));
    --mobile-gutter-right: max(14px, env(safe-area-inset-right));
    --mobile-content-width: calc(100vw - var(--mobile-gutter-left) - var(--mobile-gutter-right));
  }
  .library-view { min-height: 100dvh; }
  .library-header, .library-main {
    width: calc(100vw - 28px);
    max-width: none;
    margin-right: 14px;
    margin-left: 14px;
  }
  .library-header { padding: 16px 0; }
  .brand-mark { width: 40px; height: 40px; }
  .wordmark-copy strong { font-size: 1.16rem; }
  .wordmark-copy span { font-size: .58rem; }
  .library-main {
    padding-top: clamp(40px, 8vh, 62px);
    padding-bottom: max(48px, env(safe-area-inset-bottom));
  }
  .library-intro { width: calc(100vw - 28px); max-width: calc(100vw - 28px); gap: 18px; margin-bottom: 30px; }
  .library-intro h1 {
    max-width: 100%;
    font-size: clamp(2.65rem, 12vw, 3.6rem);
    line-height: .92;
    overflow-wrap: normal;
  }
  .library-intro-note {
    width: calc(100vw - 28px);
    max-width: calc(100vw - 28px);
    margin: 0;
    font-size: .85rem;
    line-height: 1.55;
    white-space: normal;
  }
  .mobile-break { display: initial; }
  .section-heading { margin-bottom: 14px; }
  .story-grid {
    width: calc(100vw - 28px);
    min-width: 0;
    max-width: calc(100vw - 28px);
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 360px));
    gap: 16px;
    justify-content: start;
  }
  .story-card {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 0;
    aspect-ratio: auto;
    border-radius: 18px;
  }
  .story-card-top {
    top: 14px;
    right: 14px;
    left: 14px;
    gap: 8px;
  }
  .availability, .save-badge {
    max-width: 48%;
    padding: 6px 8px;
    overflow: hidden;
    font-size: .58rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .story-card-content { padding: 22px; }
  .story-card h3 { max-width: calc(100% - 44px); font-size: clamp(1.9rem, 9vw, 2.3rem); }
  .story-meta { max-width: calc(100% - 48px); flex-wrap: wrap; }
  .story-open { right: 18px; bottom: 21px; width: 44px; height: 44px; }

  .app-header {
    min-width: 0;
    padding-right: max(8px, env(safe-area-inset-right));
    padding-left: max(8px, env(safe-area-inset-left));
    gap: 7px;
  }
  .app-nav-left, .app-nav-right { min-width: 0; gap: 5px; }
  .nav-button {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    border-radius: 12px;
  }
  .app-nav-right .nav-button:first-child { display: inline-flex; }
  .app-story-title { min-width: 0; overflow: hidden; }
  .app-story-title strong {
    max-width: 100%;
    overflow: hidden;
    font-size: .98rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .app-story-meta {
    min-width: 0;
    overflow: hidden;
    gap: 4px;
  }
  .app-story-title span {
    overflow: hidden;
    font-size: .52rem;
    letter-spacing: .09em;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .messages { padding: 8px 0 24px; gap: 15px; }
  .bubble {
    max-width: 100%;
    padding: 15px 16px;
    border-radius: 5px 15px 15px 15px;
    font-size: .97rem;
    line-height: 1.62;
  }
  .turn-updates-label { width: 100%; margin-bottom: 2px; }
  .turn-update { padding: 2px 0 2px 8px; }
  .message.user .bubble {
    border-radius: 15px 5px 15px 15px;
    font-size: .88rem;
  }
  .message-heading { margin-left: 9px; }
  .message-heading .message-role { margin: 0; }
  .choices { margin-bottom: 18px; }
  #options { gap: 9px; }
  .choice-row {
    grid-template-columns: 48px minmax(0, 1fr);
    border-radius: 13px;
  }
  .choice-edit { width: 48px; min-height: 54px; }
  .choice-button {
    min-height: 54px;
    padding: 12px;
    grid-template-columns: 22px minmax(0, 1fr) 16px;
    gap: 7px;
  }
  .choice-text { font-size: .91rem; line-height: 1.35; }
  .generated-image-button, .image-generation-status { border-radius: 13px; }

  .composer-wrap {
    padding-block: 9px max(10px, env(safe-area-inset-bottom));
  }
  .composer {
    min-width: 0;
    padding: 7px 7px 7px 14px;
    gap: 8px;
    border-radius: 16px;
  }
  .composer textarea {
    min-width: 0;
    max-height: min(160px, 34dvh);
    padding: 9px 0;
    font-size: 16px;
  }
  .send-button { width: 48px; height: 48px; border-radius: 13px; }
  .composer-hint { display: none; }
  .scroll-latest-button {
    bottom: max(76px, calc(66px + env(safe-area-inset-bottom)));
    min-height: 44px;
  }

  .character-item {
    min-height: 68px;
    padding: 8px 4px;
    grid-template-columns: 50px minmax(0, 1fr);
  }
  .character-item img { width: 50px; height: 58px; }
  .state-row { grid-template-columns: minmax(78px, .8fr) minmax(0, 1.2fr); }

  .story-dialog,
  .character-gallery-dialog,
  .generated-image-dialog {
    inset: 0;
    width: 100%;
    max-width: none;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }
  .story-dialog {
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }
  .story-dialog .dialog-layout {
    display: flex;
    height: auto;
    min-height: 100%;
    flex-direction: column;
  }
  .story-dialog .dialog-art {
    width: min(42vw, 340px);
    height: auto;
    min-height: 0;
    max-height: none;
    margin: max(24px, calc(12px + env(safe-area-inset-top))) auto 0;
    flex: 0 0 auto;
    aspect-ratio: auto;
    border: 1px solid var(--border);
    border-radius: 14px;
  }
  .dialog-copy {
    min-height: 0;
    padding: 26px max(20px, env(safe-area-inset-right)) max(26px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
    justify-content: flex-start;
  }
  .dialog-copy h2 { font-size: clamp(2.35rem, 13vw, 3.2rem); }
  .dialog-description { margin: 15px 0 20px; font-size: .87rem; line-height: 1.58; }
  .dialog-close {
    top: max(12px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
    width: 44px;
    height: 44px;
  }
  .primary-button, .secondary-button, .danger-button { min-height: 52px; }
  .warning-actions { display: grid; grid-template-columns: 1fr; }
  .character-gallery-body {
    max-height: 100dvh;
    padding: max(66px, calc(52px + env(safe-area-inset-top))) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }
  .character-gallery-grid { grid-template-columns: 1fr; gap: 12px; }
  .character-gallery-header { grid-template-columns: 64px minmax(0, 1fr); gap: 14px; }
  .character-gallery-header h2 { font-size: clamp(1.8rem, 10vw, 2.5rem); overflow-wrap: anywhere; }
  .character-gallery-avatar { width: 64px; height: 76px; }
  .gallery-photo { min-height: 0; aspect-ratio: 3 / 4; }
  .gallery-photo img { min-height: 0; }
  .generated-image-dialog-body {
    min-height: 100dvh;
    max-height: 100dvh;
    padding: max(68px, calc(54px + env(safe-area-inset-top))) max(12px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }
  .generated-image-dialog img { max-height: calc(100dvh - 126px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
  .toast {
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    left: max(10px, env(safe-area-inset-left));
    max-width: none;
    text-align: center;
  }
  .loading-inner { max-width: calc(100% - 40px); }
}

@media (max-width: 420px) {
  .app-story-meta { justify-content: center; }
  .journey-row { grid-template-columns: minmax(0, 1fr); }
  .journey-actions button { flex: 1; }
}

@media (max-width: 360px) {
  .app-header { gap: 4px; }
  .app-nav-right { gap: 3px; }
  .nav-button { width: 42px; min-width: 42px; }
  .app-story-title strong { font-size: .88rem; }
  .wordmark-copy span { display: none; }
}

@media (max-width: 900px) and (max-height: 560px) {
  :root { --app-header-height: 58px; }
  .dialog-art { min-height: 120px; height: 35dvh; }
  .story-dialog .dialog-layout { grid-template-rows: minmax(120px, 35dvh) auto; }
}

@media (hover: none), (pointer: coarse) {
  .story-card:hover,
  .primary-button:hover,
  .secondary-button:hover,
  .danger-button:hover,
  .choice-button:hover,
  .choice-edit:hover,
  .send-button:hover,
  .generated-image-button:hover { transform: none; }
}

html[data-theme="dark"] { color-scheme: dark; }
html[data-theme="dark"] .app-view {
  background:
    radial-gradient(circle at 54% 0, rgba(114,45,67,.11), transparent 34rem),
    #141114;
  color: #eee4dc;
}
html[data-theme="dark"] .app-header {
  border-bottom-color: rgba(244,232,218,.09);
  background: rgba(22,18,22,.92);
  box-shadow: 0 8px 30px rgba(0,0,0,.16);
}
html[data-theme="dark"] .app-story-title span,
html[data-theme="dark"] .message-role,
html[data-theme="dark"] .choices-label,
html[data-theme="dark"] .composer-hint { color: #9f9193; }
html[data-theme="dark"] .nav-button {
  border-color: rgba(244,232,218,.12);
  background: rgba(255,255,255,.035);
  color: #ded2ca;
}
html[data-theme="dark"] .nav-button:hover { background: rgba(255,255,255,.09); }
html[data-theme="dark"] .scroll-latest-button {
  border-color: rgba(213,183,123,.19);
  background: rgba(34,28,33,.94);
  color: #ead9cf;
  box-shadow: 0 14px 38px rgba(0,0,0,.4);
}
html[data-theme="dark"] .scroll-latest-button:hover { background: #2d252b; }
html[data-theme="dark"] .workspace-sidebar { border-color: rgba(244,232,218,.075); background: rgba(255,255,255,.012); }
html[data-theme="dark"] .sidebar-label { color: #9e9191; }
html[data-theme="dark"] .character-item:hover,
html[data-theme="dark"] .character-item:focus-visible {
  border-color: rgba(213,183,123,.16);
  background: rgba(255,255,255,.045);
}
html[data-theme="dark"] .character-item img { box-shadow: 0 7px 18px rgba(0,0,0,.32); }
html[data-theme="dark"] .character-relationship { color: #b89fa7; }
html[data-theme="dark"] .character-class { color: #c8b99f; }
html[data-theme="dark"] .character-photo-count,
html[data-theme="dark"] .character-loading,
html[data-theme="dark"] .character-note { color: #8e8184; }
html[data-theme="dark"] .relationship-value {
  border-color: rgba(213,183,123,.16);
  background: rgba(213,183,123,.08);
  color: #c8b99f;
}
html[data-theme="dark"] .relationship-value.positive {
  border-color: rgba(106,190,145,.2);
  background: rgba(70,145,105,.12);
  color: #8ed0ab;
}
html[data-theme="dark"] .relationship-value.negative {
  border-color: rgba(224,111,128,.22);
  background: rgba(174,66,84,.13);
  color: #efa0ae;
}
html[data-theme="dark"] .scene-card {
  border-color: rgba(213,183,123,.15);
  background: rgba(255,255,255,.035);
}
html[data-theme="dark"] .scene-card .scene-icon { background: #392732; color: #f2dfd3; }
html[data-theme="dark"] #sceneHeader { color: #d4c5c0; }
html[data-theme="dark"] .stat-card {
  border-color: rgba(244,232,218,.08);
  background: rgba(255,255,255,.025);
}
html[data-theme="dark"] .character-state-card {
  border-color: rgba(169,77,101,.18);
  background:
    radial-gradient(circle at 100% 0, rgba(213,183,123,.08), transparent 42%),
    rgba(255,255,255,.035);
  box-shadow: 0 10px 28px rgba(0,0,0,.13);
}
html[data-theme="dark"] .status-card {
  border-color: rgba(213,183,123,.17);
  background:
    linear-gradient(135deg, rgba(213,183,123,.07), transparent 55%),
    rgba(255,255,255,.035);
}
html[data-theme="dark"] .status-entry::before {
  background: #d5b77b;
  box-shadow: 0 0 0 3px rgba(213,183,123,.1);
}
html[data-theme="dark"] .character-state-card > strong { color: #d28aa0; }
html[data-theme="dark"] .stat-card strong,
html[data-theme="dark"] .state-row b { color: #a9979c; }
html[data-theme="dark"] .stat-card p,
html[data-theme="dark"] .state-row span,
html[data-theme="dark"] .state-copy { color: #d8ccc5; }
html[data-theme="dark"] .state-subheading { color: #d0ad72; }
html[data-theme="dark"] .state-row { border-bottom-color: rgba(244,232,218,.065); }
html[data-theme="dark"] .coin { background: rgba(255,255,255,.04); color: #c9bbb6; }
html[data-theme="dark"] .coin b { color: #f0e4da; }
html[data-theme="dark"] .inventory-items { color: #b8aaa7; }
html[data-theme="dark"] .bubble {
  border-color: rgba(244,232,218,.08);
  background: rgba(255,255,255,.04);
  color: #e4d9d1;
  box-shadow: 0 9px 24px rgba(0,0,0,.08);
}
html[data-theme="dark"] .message.user .bubble {
  border-color: #6e3449;
  background: #5d2c3f;
  color: #fff3ea;
}
html[data-theme="dark"] .turn-updates {
  border-color: rgba(210,138,160,.2);
  background: rgba(169,77,101,.1);
}
html[data-theme="dark"] .turn-updates-label,
html[data-theme="dark"] .turn-update {
  color: #d9a6b5;
}
html[data-theme="dark"] .stream-failure {
  border-color: rgba(233,165,177,.22);
  background: rgba(169,77,101,.12);
  color: #e6aebb;
}
html[data-theme="dark"] .description { color: inherit; }
html[data-theme="dark"] .dialogue { color: #f5ebe4; }
html[data-theme="dark"] .transcript-note {
  background: rgba(169,77,101,.11);
  color: #c59aaa;
}
html[data-theme="dark"] .empty-conversation { color: #9e9090; }
html[data-theme="dark"] .conversation-history-hint { color: #9e9090; }
html[data-theme="dark"] .image-generation-warning {
  border-color: rgba(233,165,177,.22);
  background: rgba(169,77,101,.12);
  color: #e6aebb;
}
html[data-theme="dark"] .story-stage { scrollbar-color: rgba(213,183,123,.26) transparent; }
html[data-theme="dark"] .story-stage::-webkit-scrollbar-thumb { background-color: rgba(213,183,123,.26); }
html[data-theme="dark"] .choice-button {
  border-color: rgba(169,77,101,.2);
  background: rgba(255,255,255,.03);
  color: #dfd2cc;
}
html[data-theme="dark"] .choice-button:hover { background: rgba(255,255,255,.075); }
html[data-theme="dark"] .choice-edit {
  border-color: rgba(169,77,101,.2);
  background: rgba(255,255,255,.025);
  color: #b9939f;
}
html[data-theme="dark"] .choice-edit:hover { background: rgba(255,255,255,.075); color: #e8a4b8; }
html[data-theme="dark"] .choice-index { color: #db8da4; }
html[data-theme="dark"] .choice-button .icon { color: #a9979c; }
html[data-theme="dark"] .generated-image-button {
  border-color: rgba(213,183,123,.13);
  background: rgba(255,255,255,.02);
}
html[data-theme="dark"] .generated-image-button:hover { box-shadow: 0 20px 46px rgba(0,0,0,.4); }
html[data-theme="dark"] .image-generation-status {
  border-color: rgba(213,183,123,.18);
  background: rgba(255,255,255,.025);
  color: #c4b3ae;
}
html[data-theme="dark"] .image-generation-status .icon { color: #d5b77b; }
html[data-theme="dark"] .image-generation-status.failed { border-color: rgba(224,111,128,.22); color: #efa0ae; }
html[data-theme="dark"] .image-generation-status.failed .icon { color: #efa0ae; }
html[data-theme="dark"] .composer-wrap {
  background: linear-gradient(to top, #141114 72%, rgba(20,17,20,0));
}
html[data-theme="dark"] .composer {
  border-color: rgba(213,183,123,.15);
  background: rgba(31,26,31,.93);
  box-shadow: 0 18px 50px rgba(0,0,0,.3);
}
html[data-theme="dark"] .composer textarea { color: #f0e4dc; }
html[data-theme="dark"] .composer textarea::placeholder { color: #8e8184; }
html[data-theme="dark"] .send-button { background: #8b3c56; }
html[data-theme="dark"] .send-button:hover { background: #a34a65; }

.auth-view {
  min-height: 100dvh;
  padding: max(28px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 18% 12%, rgba(117,47,68,.14), transparent 29rem),
    radial-gradient(circle at 82% 88%, rgba(184,146,82,.13), transparent 27rem),
    #f4ede3;
}
.auth-view[hidden] { display: none; }
.auth-shell { width: min(100%, 980px); display: grid; grid-template-columns: minmax(280px, .9fr) minmax(360px, 1.1fr); overflow: hidden; border: 1px solid rgba(92,43,58,.13); border-radius: 28px; background: rgba(255,252,247,.91); box-shadow: 0 30px 90px rgba(71,40,48,.16); }
.auth-art { min-height: 650px; padding: 52px; display: flex; flex-direction: column; justify-content: space-between; color: #fff8ef; background: radial-gradient(circle at 68% 22%, rgba(219,172,120,.3), transparent 17rem), radial-gradient(circle at 28% 76%, rgba(173,76,106,.3), transparent 21rem), linear-gradient(145deg, #78334a, #2c1923 72%); }
.auth-art .brand-mark { box-shadow: 0 7px 24px rgba(0,0,0,.24); }
.auth-art-copy p { max-width: 31ch; color: rgba(255,248,239,.75); line-height: 1.65; }
.auth-art-copy h1 { margin: 12px 0 18px; font: 500 clamp(2.8rem, 6vw, 4.6rem)/.94 var(--serif); letter-spacing: -.045em; }
.auth-panel { min-width: 0; padding: 52px clamp(30px, 6vw, 68px); display: flex; flex-direction: column; justify-content: center; }
.auth-brand-logo { width: min(100%, 280px); margin: 0 0 28px; }
.auth-panel h2 { margin: 0; color: var(--ink); font: 500 clamp(2rem, 4vw, 3rem)/1 var(--serif); letter-spacing: -.035em; }
.auth-lede { margin: 11px 0 26px; color: var(--ink-soft); font-size: .88rem; line-height: 1.55; }
.auth-socials { display: grid; gap: 10px; }
.social-auth-button, .account-provider-button { width: 100%; min-height: 50px; padding: 0 18px; display: flex; align-items: center; justify-content: center; gap: 11px; border: 1px solid rgba(72,43,51,.16); border-radius: 13px; background: #fffdfa; color: #2d2528; font: 700 .77rem var(--sans); cursor: pointer; transition: transform .18s ease, border-color .18s ease, background .18s ease; }
.social-auth-button:hover, .account-provider-button:hover { transform: translateY(-1px); border-color: rgba(109,43,63,.35); background: #fff; }
.social-mark { width: 23px; height: 23px; display: grid; place-items: center; border-radius: 50%; background: #f1ece7; font: 700 .78rem var(--sans); }
.social-auth-button.apple { background: #171417; color: #fff; border-color: #171417; }
.social-auth-button.apple .social-mark { background: transparent; font-size: 1.15rem; }
.auth-divider { margin: 22px 0; display: flex; align-items: center; gap: 12px; color: #a09596; font-size: .65rem; letter-spacing: .12em; text-transform: uppercase; }
.auth-divider::before, .auth-divider::after { content: ""; height: 1px; flex: 1; background: rgba(72,43,51,.12); }
.auth-tabs { margin-bottom: 18px; padding: 4px; display: grid; grid-template-columns: 1fr 1fr; border-radius: 12px; background: #eee6de; }
.auth-tab { min-height: 38px; border: 0; border-radius: 9px; background: transparent; color: #7e7073; font: 700 .72rem var(--sans); cursor: pointer; }
.auth-tab.active { background: #fffdfa; color: var(--wine); box-shadow: 0 3px 12px rgba(59,34,41,.09); }
.auth-form { display: grid; gap: 13px; }
.auth-field { display: grid; gap: 7px; color: #6f6265; font: 700 .65rem var(--sans); letter-spacing: .08em; text-transform: uppercase; }
.auth-field input { width: 100%; min-height: 49px; padding: 0 14px; border: 1px solid rgba(72,43,51,.16); border-radius: 11px; background: #fffdfa; color: var(--ink); font: 500 16px var(--sans); outline: none; }
.auth-field input:focus { border-color: rgba(114,43,65,.62); box-shadow: 0 0 0 3px rgba(114,43,65,.09); }
.auth-attestation { color: #6f6265; font-weight: 500; }
.auth-submit { min-height: 51px; margin-top: 4px; border: 0; border-radius: 12px; background: var(--wine); color: white; font: 700 .76rem var(--sans); cursor: pointer; }
.auth-submit:disabled, .social-auth-button:disabled { opacity: .52; cursor: wait; }
.auth-helper { min-height: 20px; margin: 13px 0 0; color: #887a7c; font-size: .75rem; line-height: 1.5; }
.auth-helper.error { color: #a52f4e; }
.auth-text-button { justify-self: start; padding: 0; border: 0; background: none; color: var(--wine); font: 700 .72rem var(--sans); cursor: pointer; }
.auth-legal {
  margin: 17px 0 0;
  color: var(--text-muted);
  font-size: .65rem;
  line-height: 1.55;
}
.auth-legal a { color: var(--link); font-weight: 700; }
.account-legal-links {
  display: flex;
  margin: 16px 0;
  justify-content: center;
  gap: 14px;
  font-size: .67rem;
  font-weight: 700;
}
.auth-setup-note { padding: 14px; border-radius: 12px; background: rgba(114,43,65,.07); color: #785762; font-size: .76rem; line-height: 1.5; }
.library-account-button { min-height: 38px; padding: 0 14px; display: inline-flex; align-items: center; gap: 8px; border: 1px solid rgba(72,43,51,.13); border-radius: 999px; background: rgba(255,255,255,.48); color: var(--ink); font: 700 .67rem var(--sans); cursor: pointer; }
.library-header-actions { display: flex; align-items: center; gap: 9px; }
.account-dialog, .eligibility-dialog, .allowance-confirmation-dialog, .allowance-pause-dialog, .allowance-notice-dialog { width: min(calc(100% - 28px), 520px); max-height: min(760px, calc(100dvh - 28px)); padding: 0; overflow: hidden; border: 0; border-radius: 22px; color: var(--ink); background: #fffaf4; box-shadow: 0 30px 100px rgba(35,22,27,.3); }
.account-dialog::backdrop, .eligibility-dialog::backdrop, .allowance-confirmation-dialog::backdrop, .allowance-pause-dialog::backdrop, .allowance-notice-dialog::backdrop { background: rgba(26,18,22,.68); backdrop-filter: blur(7px); }
.account-dialog-body { display: flex; max-height: min(760px, calc(100dvh - 28px)); flex-direction: column; }
.account-dialog-scroll { min-height: 0; padding: 38px 38px 8px; overflow-y: auto; overscroll-behavior: contain; }
.account-dialog-footer { flex: 0 0 auto; padding: 14px 38px 26px; border-top: 1px solid rgba(72,43,51,.11); background: #fffaf4; box-shadow: 0 -12px 28px rgba(35,22,27,.06); }
.account-identity { margin-bottom: 25px; display: grid; grid-template-columns: 56px 1fr; gap: 14px; align-items: center; }
.account-avatar { width: 56px; height: 56px; display: grid; place-items: center; overflow: hidden; border-radius: 50%; background: #eadde0; color: var(--wine); font: 600 1.35rem var(--serif); }
.account-avatar img { width: 100%; height: 100%; object-fit: cover; }
.account-identity h2 { margin: 0 0 4px; font: 500 1.8rem var(--serif); }
.account-identity p { margin: 0; color: var(--ink-soft); font-size: .78rem; overflow-wrap: anywhere; }
.account-section { padding: 20px 0; border-top: 1px solid rgba(72,43,51,.11); }
.account-section h3 { margin: 0 0 6px; font: 700 .66rem var(--sans); letter-spacing: .12em; text-transform: uppercase; color: #8b747a; }
.account-section > p { margin: 0 0 14px; color: var(--ink-soft); font-size: .76rem; line-height: 1.5; }
.account-allowance-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.account-allowance-source { min-width: 0; padding: 11px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-soft); }
.account-allowance-source strong { display: block; color: var(--ink); font: 700 .72rem var(--sans); overflow-wrap: anywhere; }
.account-allowance-source span { display: block; margin-top: 4px; color: var(--ink-faint); font-size: .62rem; line-height: 1.4; }
.account-allowance-lots { display: grid; margin: 8px 0 0; padding: 0; gap: 5px; list-style: none; }
.account-allowance-lots li { padding-top: 5px; border-top: 1px solid var(--border); color: var(--ink-soft); font-size: .61rem; line-height: 1.4; }
.account-allowance-lots button { min-height: 32px; margin-top: 6px; border: 1px solid var(--primary-border); border-radius: 8px; background: var(--primary-soft); color: var(--link); font: 750 .61rem var(--sans); cursor: pointer; }
.account-allowance-lots button:disabled { opacity: .6; cursor: wait; }
.account-purchase-actions { display: grid; margin: 12px 0 0; grid-template-columns: 1fr 1fr; gap: 8px; }
.account-purchase-actions a, .account-purchase-actions button { min-height: 46px; text-align: center; text-decoration: none; }
.top-up-offers { display: grid; margin-top: 12px; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.top-up-offer { display: grid; min-width: 0; padding: 11px; align-content: start; gap: 5px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-soft); }
.top-up-offer strong { color: var(--ink); font: 700 .75rem var(--sans); }
.top-up-offer span { color: var(--ink-soft); font-size: .65rem; line-height: 1.35; }
.top-up-offer button { min-height: 40px; margin-top: 4px; border: 1px solid var(--primary-border); border-radius: 9px; background: var(--primary-soft); color: var(--link); font-weight: 800; cursor: pointer; }
.top-up-offer button:disabled { opacity: .55; cursor: wait; }
.top-up-offer-status { min-height: 18px; margin: 9px 0 0; color: var(--ink-faint); font-size: .68rem; line-height: 1.45; }
.subscription-billing-status { min-height: 18px; margin: 9px 0 0; color: var(--ink-faint); font-size: .68rem; line-height: 1.45; }
.subscription-billing-actions { display: flex; margin-top: 8px; align-items: center; flex-wrap: wrap; gap: 8px; }
.subscription-billing-actions a { color: var(--link); font-size: .7rem; font-weight: 750; }
.subscription-payment-banner {
  position: sticky;
  z-index: 70;
  top: 0;
  display: flex;
  gap: 18px;
  padding: 14px clamp(18px, 4vw, 48px);
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--danger-border);
  background: color-mix(in srgb, var(--surface) 95%, var(--danger) 5%);
  box-shadow: 0 12px 30px var(--shadow-color);
  color: var(--text-primary);
}
.subscription-payment-banner-copy { min-width: 0; }
.subscription-payment-banner-copy strong {
  display: block;
  margin-bottom: 3px;
  font-size: .78rem;
}
.subscription-payment-banner-copy p {
  margin: 0;
  color: var(--text-secondary);
  font-size: .72rem;
  line-height: 1.5;
}
.subscription-payment-banner-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.subscription-payment-banner-actions button,
.subscription-payment-banner-actions a {
  display: inline-flex;
  min-height: 38px;
  padding: 8px 12px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-elevated);
  color: var(--text-primary);
  font-size: .68rem;
  font-weight: 750;
  text-decoration: none;
}
.subscription-payment-banner-actions button { cursor: pointer; }
.subscription-payment-banner-actions button:disabled {
  cursor: wait;
  opacity: .62;
}
.subscription-payment-banner-dismiss {
  min-width: 38px;
  padding: 8px !important;
}
.subscription-payment-banner-dismiss .icon {
  width: 16px;
  height: 16px;
}
.service-shutdown-banner {
  position: relative;
  border-color: color-mix(in srgb, var(--primary) 42%, transparent);
  background: color-mix(in srgb, var(--surface) 91%, var(--primary) 9%);
}
.account-allowance-list { display: grid; margin: 9px 0 0; padding: 0; gap: 7px; list-style: none; }
.account-allowance-list li { padding: 9px 10px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-soft); color: var(--ink-soft); font-size: .68rem; line-height: 1.45; overflow-wrap: anywhere; }
.account-allowance-list li[data-empty="true"] { color: var(--ink-faint); }
.account-allowance-heading { margin: 16px 0 0; color: var(--ink-faint); font-size: .61rem; letter-spacing: .1em; text-transform: uppercase; }
.provider-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.provider-chip { padding: 7px 10px; border-radius: 999px; background: #eee5df; color: #5d4f53; font: 700 .66rem var(--sans); text-transform: capitalize; }
.account-password-form { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.account-password-form input { min-width: 0; padding: 0 12px; border: 1px solid rgba(72,43,51,.16); border-radius: 10px; background: #fff; font-size: 16px; }
.account-password-form button { min-height: 46px; padding: 0 15px; grid-column: 1 / -1; border: 0; border-radius: 10px; background: var(--wine); color: #fff; font-weight: 700; cursor: pointer; }
.account-signout { display: flex; width: 100%; min-height: 46px; align-items: center; justify-content: center; gap: 9px; border: 1px solid rgba(146,45,66,.2); border-radius: 11px; background: rgba(146,45,66,.06); color: #962d47; font-weight: 700; cursor: pointer; }
.account-signout .icon { width: 17px; height: 17px; }
.account-merge-start { width: 100%; min-height: 44px; }
.account-merge-grid { display: grid; gap: 12px; }
.account-merge-card { padding: 15px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface-soft); }
.account-merge-card > label { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.account-merge-card h3 { margin: 0 0 3px; color: var(--ink); font: 650 1rem var(--serif); letter-spacing: 0; text-transform: none; }
.account-merge-card p { margin: 0; color: var(--ink-soft); font-size: .7rem; line-height: 1.45; overflow-wrap: anywhere; }
.account-merge-details { margin: 12px 0 0; padding: 0; list-style: none; }
.account-merge-details li { padding: 7px 0; border-top: 1px solid var(--border); color: var(--ink-soft); font-size: .68rem; line-height: 1.45; overflow-wrap: anywhere; }
.account-merge-warning { padding: 13px; border: 1px solid rgba(146,45,66,.22); border-radius: 11px; background: rgba(146,45,66,.06); color: var(--ink-soft); font-size: .72rem; line-height: 1.5; }
.account-merge-confirmation { display: grid; gap: 10px; margin-top: 16px; }
.account-merge-confirmation > label { display: grid; gap: 6px; color: var(--ink-soft); font-size: .7rem; line-height: 1.45; }
.account-merge-confirmation input[type="text"] { min-height: 44px; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--ink); font-size: 16px; }
.account-merge-confirmation .account-merge-checkbox { display: flex; grid-template-columns: none; gap: 9px; align-items: flex-start; }
.account-merge-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.account-merge-actions button { min-height: 46px; }
.account-deletion-start { width: 100%; min-height: 44px; }
.account-deletion-summary { margin: 0; padding: 0; list-style: none; }
.account-deletion-summary li { padding: 9px 0; border-top: 1px solid var(--border); color: var(--ink-soft); font-size: .72rem; line-height: 1.5; overflow-wrap: anywhere; }
.account-deletion-summary li:first-child { border-top: 0; }
.account-deletion-blocker { color: var(--danger); font-weight: 650; }
.admin-console-link { min-height: 48px; margin-bottom: 12px; padding: 0 15px; display: flex; align-items: center; justify-content: center; gap: 9px; border-radius: 11px; background: #2c2228; color: #fff7ef; font: 700 .74rem var(--sans); text-decoration: none; }
.eligibility-dialog-body { padding: 42px; }
.eligibility-dialog h2 { margin: 5px 0 12px; font: 500 clamp(2rem, 7vw, 2.8rem)/1.04 var(--serif); }
.eligibility-copy { margin: 0 0 24px; color: var(--ink-soft); font-size: .86rem; line-height: 1.65; }
.eligibility-form { display: grid; gap: 16px; }
.eligibility-form label:not(.eligibility-confirmation) { display: grid; gap: 7px; color: var(--ink-soft); font-size: .73rem; font-weight: 700; }
.eligibility-form input[type="date"] { width: 100%; min-height: 50px; padding: 0 14px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface); color: var(--text-primary); font-size: 16px; color-scheme: inherit; }
.eligibility-confirmation { display: grid; grid-template-columns: 20px minmax(0, 1fr); align-items: start; gap: 10px; color: var(--ink-soft); font-size: .77rem; line-height: 1.5; cursor: pointer; }
.eligibility-confirmation input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--primary); }
.eligibility-primary { min-height: 50px; border: 1px solid var(--accent-border); border-radius: 11px; background: var(--accent-gold); color: var(--accent-text); font-weight: 800; cursor: pointer; }
.eligibility-primary:disabled { opacity: .58; cursor: wait; }
.eligibility-signout { width: 100%; min-height: 44px; margin-top: 13px; border: 0; background: transparent; color: var(--link); font-weight: 700; cursor: pointer; }
.eligibility-legal { display: flex; margin-top: 22px; justify-content: center; gap: 16px; font-size: .72rem; }
.eligibility-denied { padding: 15px; border: 1px solid var(--danger-border); border-radius: 12px; background: var(--danger-soft); color: var(--danger); font-size: .8rem; line-height: 1.55; }
.allowance-confirmation-body { display: flex; max-height: min(760px, calc(100dvh - 28px)); flex-direction: column; }
.allowance-confirmation-copy { min-height: 0; padding: 42px 42px 24px; overflow-y: auto; overscroll-behavior: contain; }
.allowance-confirmation-dialog h2 { margin: 5px 0 12px; font: 500 clamp(2rem, 7vw, 2.8rem)/1.04 var(--serif); }
.allowance-confirmation-description { margin: 0; color: var(--ink-soft); font-size: .86rem; line-height: 1.65; }
.allowance-confirmation-status { min-height: 20px; margin: 13px 0 0; color: var(--ink-faint); font-size: .7rem; line-height: 1.45; }
.action-confirmation-field { display: grid; margin-top: 18px; gap: 7px; color: var(--ink-soft); font-size: .74rem; font-weight: 700; }
.action-confirmation-field input { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 10px; color: var(--ink); background: var(--surface); font: inherit; }
.allowance-confirmation-footer { display: grid; padding: 14px 42px 26px; border-top: 1px solid var(--border); background: #fffaf4; box-shadow: 0 -12px 28px rgba(35,22,27,.06); grid-template-columns: 1fr 1fr; gap: 10px; }
.allowance-confirmation-footer button { min-height: 50px; }
.allowance-pause-body { display: flex; max-height: min(760px, calc(100dvh - 28px)); flex-direction: column; }
.allowance-pause-copy { min-height: 0; padding: 42px 42px 24px; overflow-y: auto; overscroll-behavior: contain; }
.allowance-pause-dialog h2 { margin: 5px 0 12px; font: 500 clamp(2rem, 7vw, 2.8rem)/1.04 var(--serif); }
.allowance-pause-description { margin: 0; color: var(--ink-soft); font-size: .86rem; line-height: 1.65; }
.allowance-pause-balance { margin: 18px 0 0; padding: 13px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-soft); color: var(--ink-soft); font-size: .74rem; line-height: 1.5; }
.allowance-purchase-actions { display: grid; margin-top: 14px; grid-template-columns: 1fr 1fr; gap: 9px; }
.allowance-purchase-actions a, .allowance-purchase-actions button { min-height: 46px; text-align: center; text-decoration: none; }
.allowance-pause-status { min-height: 20px; margin: 14px 0 0; color: var(--ink-faint); font-size: .7rem; line-height: 1.45; }
.allowance-pause-footer { padding: 14px 42px 26px; border-top: 1px solid var(--border); background: #fffaf4; box-shadow: 0 -12px 28px rgba(35,22,27,.06); }
.allowance-pause-footer button { width: 100%; min-height: 50px; }
.allowance-notice-body { display: flex; max-height: min(760px, calc(100dvh - 28px)); flex-direction: column; }
.allowance-notice-copy { min-height: 0; padding: 42px 42px 24px; overflow-y: auto; overscroll-behavior: contain; }
.allowance-notice-dialog h2 { margin: 5px 0 12px; font: 500 clamp(2rem, 7vw, 2.8rem)/1.04 var(--serif); }
.allowance-notice-copy > p { color: var(--ink-soft); font-size: .82rem; line-height: 1.6; }
.allowance-notice-footer { padding: 14px 42px 26px; border-top: 1px solid var(--border); background: #fffaf4; box-shadow: 0 -12px 28px rgba(35,22,27,.06); }
.allowance-notice-footer button { width: 100%; min-height: 50px; }
.top-up-processing-dialog { width: min(calc(100% - 28px), 520px); max-height: min(720px, calc(100dvh - 28px)); padding: 0; overflow: hidden; border: 0; border-radius: 22px; color: var(--ink); background: #fffaf4; box-shadow: 0 30px 100px rgba(35,22,27,.3); }
.top-up-processing-dialog::backdrop { background: rgba(26,18,22,.68); backdrop-filter: blur(7px); }
.top-up-processing-body { display: flex; max-height: min(720px, calc(100dvh - 28px)); flex-direction: column; }
.top-up-processing-copy { min-height: 0; padding: 42px 42px 26px; overflow-y: auto; overscroll-behavior: contain; }
.top-up-processing-dialog h2 { margin: 5px 0 12px; font: 500 clamp(2rem, 7vw, 2.3rem)/1.04 var(--serif); }
.top-up-processing-description { margin: 0; color: var(--ink-soft); font-size: .86rem; line-height: 1.65; }
.top-up-processing-status { margin: 18px 0 0; padding: 13px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-soft); color: var(--ink-soft); font-size: .75rem; line-height: 1.5; }
.top-up-processing-support { display: inline-block; margin-top: 14px; color: var(--link); font-size: .72rem; font-weight: 750; }
.top-up-processing-footer { padding: 14px 42px 26px; border-top: 1px solid var(--border); background: #fffaf4; box-shadow: 0 -12px 28px rgba(35,22,27,.06); }
.top-up-processing-footer button { width: 100%; min-height: 50px; }
html[data-theme] .top-up-processing-dialog { background: var(--surface); color: var(--text-primary); }
html[data-theme] .top-up-processing-footer { border-color: var(--border); background: var(--surface); box-shadow: 0 -12px 28px var(--shadow-color); }

html[data-theme="dark"] .auth-view { background: radial-gradient(circle at 20% 15%, rgba(131,48,74,.16), transparent 30rem), #141114; }
html[data-theme="dark"] .auth-shell { border-color: rgba(255,255,255,.08); background: #1f1a1f; box-shadow: 0 30px 90px rgba(0,0,0,.45); }
html[data-theme="dark"] .auth-panel h2, html[data-theme="dark"] .account-dialog, html[data-theme="dark"] .eligibility-dialog, html[data-theme="dark"] .allowance-confirmation-dialog, html[data-theme="dark"] .allowance-pause-dialog, html[data-theme="dark"] .allowance-notice-dialog { color: #f0e4da; }
html[data-theme="dark"] .auth-lede, html[data-theme="dark"] .auth-helper, html[data-theme="dark"] .account-section > p, html[data-theme="dark"] .account-identity p { color: #a99b9e; }
html[data-theme="dark"] .social-auth-button, html[data-theme="dark"] .account-provider-button, html[data-theme="dark"] .auth-field input { border-color: rgba(255,255,255,.11); background: #292329; color: #f0e4da; }
html[data-theme="dark"] .social-auth-button.apple { background: #eee6de; color: #171417; }
html[data-theme="dark"] .auth-tabs { background: #171317; }
html[data-theme="dark"] .auth-tab.active { background: #312831; color: #e9a2b6; box-shadow: none; }
html[data-theme="dark"] .auth-field { color: #ad9da0; }
html[data-theme="dark"] .auth-divider::before, html[data-theme="dark"] .auth-divider::after, html[data-theme="dark"] .account-section { border-color: rgba(255,255,255,.09); }
html[data-theme="dark"] .account-dialog,
html[data-theme="dark"] .eligibility-dialog,
html[data-theme="dark"] .allowance-confirmation-dialog,
html[data-theme="dark"] .allowance-pause-dialog,
html[data-theme="dark"] .allowance-notice-dialog,
html[data-theme="dark"] .account-dialog-footer,
html[data-theme="dark"] .allowance-confirmation-footer,
html[data-theme="dark"] .allowance-pause-footer,
html[data-theme="dark"] .allowance-notice-footer { background: #211b20; }
html[data-theme="dark"] .account-avatar, html[data-theme="dark"] .provider-chip { background: #332830; color: #e4b2c0; }
html[data-theme="dark"] .account-password-form input { border-color: rgba(255,255,255,.12); background: #2b242a; color: #f0e4da; }

/* Lorebraid semantic palette mapping. Keep component structure independent
   from theme colors so both modes share the same visual hierarchy. */
html[data-theme] body {
  background: var(--background);
  color: var(--text-primary);
}
html[data-theme] a { color: var(--link); }
html[data-theme] button:focus-visible,
html[data-theme] input:focus-visible,
html[data-theme] textarea:focus-visible,
html[data-theme] summary:focus-visible {
  outline-color: var(--focus-ring);
}
html[data-theme] .brand-mark {
  border-color: var(--accent-border);
  color: var(--decorative-gold);
}

html[data-theme] .library-view {
  background:
    radial-gradient(circle at 14% 20%, var(--primary-soft), transparent 32%),
    radial-gradient(circle at 88% 5%, var(--accent-soft), transparent 27%),
    linear-gradient(145deg, var(--surface-elevated), var(--background) 58%, var(--surface));
  color: var(--text-primary);
}
html[data-theme] .library-view::before {
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
}
html[data-theme] .library-orb {
  border-color: var(--accent-border);
  box-shadow: inset 0 0 100px var(--primary-soft);
}
html[data-theme] .library-header { border-bottom-color: var(--line); }
html[data-theme] .wordmark-copy span,
html[data-theme] .story-count,
html[data-theme] .save-context { color: var(--text-muted); }
html[data-theme] .availability::before {
  background: var(--success);
  box-shadow: 0 0 12px var(--success-soft);
}
html[data-theme] .eyebrow { color: var(--accent-teal); }
html[data-theme] .library-intro h1 em { color: var(--accent-teal); }
html[data-theme] .library-intro-note { color: var(--text-secondary); }
html[data-theme] .story-card {
  border-color: var(--border);
  background: var(--surface);
  color: #F6F8FC;
  box-shadow: 0 20px 50px var(--shadow-color);
}
html[data-theme] .story-card:hover {
  border-color: var(--teal-border);
  box-shadow: 0 26px 70px var(--shadow-color);
}
html[data-theme] .story-card-shade {
  background:
    linear-gradient(to top, rgba(2, 9, 33, .98) 0%, rgba(2, 9, 33, .82) 35%, transparent 68%),
    linear-gradient(to right, rgba(2, 9, 33, .18), transparent);
}
html[data-theme] .availability,
html[data-theme] .save-badge {
  border-color: rgba(246, 248, 252, .22);
  background: rgba(2, 9, 33, .72);
  color: #F6F8FC;
}
html[data-theme] .save-badge,
html[data-theme] .story-kicker { color: var(--decorative-gold); }
html[data-theme] .story-meta { color: #B8C7DB; }
html[data-theme] .story-meta .dot { background: #8397B1; }
html[data-theme] .story-open {
  border-color: rgba(246, 248, 252, .28);
  background: rgba(246, 248, 252, .09);
}
html[data-theme] .story-card:hover .story-open {
  background: var(--primary-hover);
  color: var(--primary-text);
}
html[data-theme] .empty-library,
html[data-theme] .library-error {
  border-color: var(--border);
  color: var(--text-secondary);
}

html[data-theme] .story-dialog,
html[data-theme] .character-gallery-dialog,
html[data-theme] .generated-image-dialog {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text-primary);
}
html[data-theme] .dialog-panel,
html[data-theme] .dialog-actions { background: var(--surface); }
html[data-theme] .journey-section,
html[data-theme] .journey-row,
html[data-theme] .dialog-actions { border-color: var(--border); }
html[data-theme] .journey-row { background: var(--surface-elevated); }
html[data-theme] .journey-section-header h3,
html[data-theme] .journey-copy strong { color: var(--text-primary); }
html[data-theme] .journey-section-count,
html[data-theme] .journey-copy span { color: var(--text-muted); }
html[data-theme] .story-dialog::backdrop,
html[data-theme] .character-gallery-dialog::backdrop,
html[data-theme] .generated-image-dialog::backdrop,
html[data-theme] .account-dialog::backdrop,
html[data-theme] .eligibility-dialog::backdrop,
html[data-theme] .allowance-confirmation-dialog::backdrop,
html[data-theme] .allowance-pause-dialog::backdrop,
html[data-theme] .allowance-notice-dialog::backdrop {
  background: var(--overlay);
}
html[data-theme] .dialog-art::after {
  background: linear-gradient(to top, rgba(2, 9, 33, .8), transparent 55%);
}
html[data-theme] .dialog-close {
  border-color: rgba(246, 248, 252, .24);
  background: rgba(2, 9, 33, .72);
  color: #F6F8FC;
}
html[data-theme] .dialog-description,
html[data-theme] .character-gallery-header p,
html[data-theme] .generated-image-dialog p { color: var(--text-secondary); }
html[data-theme] .genre-chip {
  border-color: var(--border);
  color: var(--text-secondary);
}
html[data-theme] .primary-button,
html[data-theme] .auth-submit,
html[data-theme] .account-password-form button {
  border-color: var(--accent-gold);
  background: var(--accent-gold);
  color: var(--accent-text);
}
html[data-theme] .primary-button:hover,
html[data-theme] .auth-submit:hover,
html[data-theme] .account-password-form button:hover {
  border-color: var(--accent-gold-hover);
  background: var(--accent-gold-hover);
}
html[data-theme] .secondary-button {
  border-color: var(--border);
  background: var(--surface-elevated);
  color: var(--text-primary);
}
html[data-theme] .secondary-button:hover {
  border-color: var(--primary-border);
  background: var(--primary-soft);
}
html[data-theme] .danger-button,
html[data-theme] .account-signout {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}
html[data-theme] .save-context .icon { color: var(--accent-gold); }
html[data-theme] .start-warning {
  border-color: var(--danger-border);
  background: var(--danger-soft);
}
html[data-theme] .start-warning p { color: var(--text-secondary); }

html[data-theme] .app-view {
  background:
    radial-gradient(circle at 54% 0, var(--primary-soft), transparent 34rem),
    var(--background);
  color: var(--text-primary);
}
html[data-theme] .app-header {
  border-bottom-color: var(--line);
  background: var(--surface-glass);
  box-shadow: 0 8px 30px var(--shadow-color);
}
html[data-theme] .app-story-title span,
html[data-theme] .message-role,
html[data-theme] .choices-label,
html[data-theme] .composer-hint {
  color: var(--text-muted);
}
html[data-theme] .turn-edit-button { color: var(--text-muted); }
html[data-theme] .turn-edit-button:hover,
html[data-theme] .turn-edit-button:focus-visible {
  background: var(--accent-soft);
  color: var(--accent);
}
html[data-theme] .nav-button,
html[data-theme] .library-account-button {
  border-color: var(--border);
  background: var(--surface-elevated);
  color: var(--text-primary);
}
html[data-theme] .nav-button:hover,
html[data-theme] .library-account-button:hover {
  border-color: var(--primary-border);
  background: var(--primary-soft);
  color: var(--primary-hover);
}
html[data-theme] .scroll-latest-button {
  border-color: var(--primary-border);
  background: var(--surface-glass);
  color: var(--link);
  box-shadow: 0 12px 32px var(--shadow-color);
}
html[data-theme] .scroll-latest-button:hover {
  background: var(--surface-elevated);
  color: var(--primary-hover);
}
html[data-theme] .workspace-sidebar {
  border-color: var(--line);
  background: transparent;
  scrollbar-color: var(--primary-border) transparent;
}
html[data-theme] .sidebar-label { color: var(--text-muted); }
html[data-theme] .sidebar-toggle:hover { color: var(--primary-hover); }
html[data-theme] .character-item:hover,
html[data-theme] .character-item:focus-visible {
  border-color: var(--primary-border);
  background: var(--primary-soft);
}
html[data-theme] .character-item img {
  box-shadow: 0 7px 18px var(--shadow-color);
}
html[data-theme] .character-note,
html[data-theme] .character-photo-count,
html[data-theme] .character-loading { color: var(--text-muted); }
html[data-theme] .character-relationship { color: var(--text-secondary); }
html[data-theme] .character-class { color: var(--text-muted); }
html[data-theme] .relationship-value {
  border-color: var(--primary-border);
  background: var(--primary-soft);
  color: var(--primary);
}
html[data-theme] .relationship-value.positive {
  border-color: var(--success-border);
  background: var(--success-soft);
  color: var(--success);
}
html[data-theme] .relationship-value.negative {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}

html[data-theme] .gallery-photo {
  border-color: var(--border);
  background: var(--surface-elevated);
}
html[data-theme] .gallery-photo:focus-visible { outline-color: var(--focus-ring); }
html[data-theme] .gallery-photo span {
  background: rgba(2, 9, 33, .8);
  color: #F6F8FC;
}
html[data-theme] .generated-image-dialog img,
html[data-theme] .character-gallery-avatar {
  box-shadow: 0 22px 70px var(--shadow-color);
}

html[data-theme] .scene-card,
html[data-theme] .stat-card {
  border-color: var(--border);
  background: var(--surface-soft);
}
html[data-theme] .scene-card .scene-icon {
  background: var(--primary);
  color: var(--primary-text);
}
html[data-theme] #sceneHeader,
html[data-theme] .stat-card p,
html[data-theme] .state-row span,
html[data-theme] .state-copy { color: var(--text-secondary); }
html[data-theme] .stat-card strong,
html[data-theme] .state-row b { color: var(--text-muted); }
html[data-theme] .character-state-card {
  border-color: var(--primary-border);
  background:
    radial-gradient(circle at 100% 0, var(--primary-soft), transparent 42%),
    var(--surface-soft);
  box-shadow: 0 8px 22px var(--shadow-color);
}
html[data-theme] .character-state-card > strong { color: var(--accent-teal); }
html[data-theme] .state-subheading { color: var(--accent-teal); }
html[data-theme] .state-row { border-bottom-color: var(--line); }
html[data-theme] .status-card {
  border-color: var(--primary-border);
  background:
    linear-gradient(135deg, var(--primary-soft), transparent 55%),
    var(--surface-soft);
}
html[data-theme] .status-entry::before {
  background: var(--accent-teal);
  box-shadow: 0 0 0 3px var(--teal-soft);
}
html[data-theme] .coin {
  background: var(--surface-elevated);
  color: var(--text-secondary);
}
html[data-theme] .coin b { color: var(--text-primary); }
html[data-theme] .inventory-items { color: var(--text-secondary); }
html[data-theme] .inventory-item,
html[data-theme] .ability-card {
  border-color: var(--border);
  background: var(--surface-elevated);
}
html[data-theme] .inventory-item-name,
html[data-theme] .ability-card strong,
html[data-theme] .cooldown-state b { color: var(--text-primary); }
html[data-theme] .ability-card p,
html[data-theme] .ability-card small,
html[data-theme] .profession-seed-copy small,
html[data-theme] .cooldown-state { color: var(--text-secondary); }
html[data-theme] .cooldown-state .recovering { color: var(--accent-gold); }
html[data-theme] .player-card,
html[data-theme] .hud-section { border-color: var(--border); background: var(--surface); }
html[data-theme] .player-card p,
html[data-theme] .hud-clock,
html[data-theme] .hud-list,
html[data-theme] .hud-attribute { color: var(--text-secondary); }
html[data-theme] .player-card h3,
html[data-theme] .hud-clock b,
html[data-theme] .hud-attribute b { color: var(--text-primary); }
html[data-theme] .hud-attribute,
html[data-theme] .key-state { background: var(--surface-elevated); }

html[data-theme] .story-stage {
  scrollbar-color: var(--primary-border) transparent;
}
html[data-theme] .story-stage::-webkit-scrollbar-thumb {
  background-color: var(--primary-border);
}
html[data-theme] .bubble {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: 0 9px 24px var(--shadow-color);
}
html[data-theme] .message.assistant .bubble {
  border: 0;
  background: transparent;
  color: var(--accent-teal);
  box-shadow: none;
}
html[data-theme] .message.user .bubble {
  border-color: var(--primary-border);
  background: var(--primary);
  color: var(--primary-text);
}
html[data-theme] .description { color: inherit; }
html[data-theme] .message.assistant .description { color: var(--accent-teal); }
html[data-theme] .dialogue { color: var(--text-primary); }
html[data-theme] .message.assistant .dialogue .description { color: inherit; }
html[data-theme] .inline-system-notice { color: var(--text-primary); }
html[data-theme] .message.assistant .dialogue { margin-inline-end: 0.18em; }
html[data-theme] .message.user .description,
html[data-theme] .message.user .dialogue { color: var(--primary-text); }
html[data-theme] .message.streaming .bubble::after { background: var(--decorative-cyan); }
html[data-theme] .typewriter-waiting,
html[data-theme] .empty-conversation,
html[data-theme] .conversation-history-hint { color: var(--text-muted); }
html[data-theme] .stream-failure,
html[data-theme] .image-generation-warning {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}
html[data-theme] .turn-updates {
  border-color: var(--accent-border);
  background: var(--accent-soft);
}
html[data-theme] .turn-updates-label,
html[data-theme] .turn-update {
  color: var(--text-primary);
}
html[data-theme] .system-milestone-card header p,
html[data-theme] .system-milestone-entry p,
html[data-theme] .system-milestone-details dd {
  color: var(--text-primary);
}
html[data-theme] .transcript-note {
  background: var(--teal-soft);
  color: var(--accent-teal);
}

html[data-theme] .choice-row,
html[data-theme] .choice-edit,
html[data-theme] .choice-button {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text-primary);
}
html[data-theme] .choice-edit { color: var(--accent-teal); }
html[data-theme] .choice-edit:focus-visible,
html[data-theme] .choice-button:focus-visible { outline-offset: -3px; }
html[data-theme] .choice-edit:hover,
html[data-theme] .choice-button:hover {
  border-color: var(--teal-border);
  background: var(--teal-soft);
  color: var(--primary-hover);
}
html[data-theme] .choice-index { color: var(--accent-teal); }
html[data-theme] .choice-button .icon { color: var(--text-muted); }
html[data-theme] .generated-image-button {
  border-color: var(--border);
  background: var(--surface);
}
html[data-theme] .generated-image-button:hover {
  border-color: var(--teal-border);
  box-shadow: 0 18px 38px var(--shadow-color);
}
html[data-theme] .image-generation-status {
  border-color: var(--teal-border);
  background: var(--teal-soft);
  color: var(--text-secondary);
}
html[data-theme] .image-generation-status .icon { color: var(--decorative-cyan); }
html[data-theme] .image-variant-selector,
html[data-theme] .image-regenerate-button {
  border-color: var(--teal-border);
  background: var(--surface-soft);
  color: var(--text-secondary);
}
html[data-theme] .image-variant-selector select { color: var(--text-primary); }
html[data-theme] .image-regenerate-button:hover { background: var(--teal-soft); }
html[data-theme] .image-generation-status.failed {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}
html[data-theme] .image-generation-status.failed .icon { color: var(--danger); }
html[data-theme] .image-retry-button:hover { background: var(--danger-soft); }
html[data-theme] .composer-wrap {
  background: linear-gradient(to top, var(--background) 72%, transparent);
}
html[data-theme] .composer {
  border-color: var(--primary-border);
  background: var(--surface-glass);
  box-shadow: 0 16px 45px var(--shadow-color);
}
html[data-theme] .composer textarea { color: var(--text-primary); }
html[data-theme] .composer textarea::placeholder { color: var(--text-muted); }
html[data-theme] .send-button {
  background: var(--primary);
  color: var(--primary-text);
}
html[data-theme] .send-button:hover { background: var(--primary-hover); }

html[data-theme] .loading-cover {
  background: var(--overlay);
  color: #F6F8FC;
}
html[data-theme] .loading-sigil {
  border-color: var(--accent-border);
  color: var(--decorative-gold);
}
html[data-theme] .loading-inner span { color: #B8C7DB; }
html[data-theme] .toast {
  border-color: var(--border);
  background: var(--surface-elevated);
  color: var(--text-primary);
  box-shadow: 0 16px 35px var(--shadow-color);
}
html[data-theme] .toast.error {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}

html[data-theme] .auth-view {
  background:
    radial-gradient(circle at 18% 12%, var(--primary-soft), transparent 29rem),
    radial-gradient(circle at 82% 88%, var(--accent-soft), transparent 27rem),
    var(--background);
}
html[data-theme] .auth-shell {
  border-color: var(--border);
  background: var(--surface-glass);
  box-shadow: 0 30px 90px var(--shadow-color);
}
html[data-theme] .auth-art {
  color: #F6F8FC;
  background:
    radial-gradient(circle at 68% 22%, rgba(39, 220, 235, .22), transparent 17rem),
    radial-gradient(circle at 28% 76%, rgba(238, 189, 19, .16), transparent 21rem),
    linear-gradient(145deg, #03437E, #020921 72%);
}
html[data-theme] .auth-art-copy p { color: #B8C7DB; }
html[data-theme] .auth-panel h2,
html[data-theme] .account-dialog,
html[data-theme] .eligibility-dialog,
html[data-theme] .allowance-confirmation-dialog,
html[data-theme] .allowance-pause-dialog,
html[data-theme] .allowance-notice-dialog { color: var(--text-primary); }
html[data-theme] .auth-lede,
html[data-theme] .auth-helper,
html[data-theme] .account-section > p,
html[data-theme] .account-identity p { color: var(--text-secondary); }
html[data-theme] .social-auth-button,
html[data-theme] .account-provider-button,
html[data-theme] .auth-field input,
html[data-theme] .account-password-form input {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text-primary);
}
html[data-theme] .social-auth-button:hover,
html[data-theme] .account-provider-button:hover {
  border-color: var(--primary-border);
  background: var(--primary-soft);
}
html[data-theme] .social-mark {
  background: var(--surface-elevated);
  color: var(--text-primary);
}
html[data-theme] .social-auth-button.apple {
  border-color: var(--text-primary);
  background: var(--text-primary);
  color: var(--background);
}
html[data-theme] .social-auth-button.apple .social-mark {
  background: transparent;
  color: inherit;
}
html[data-theme] .auth-divider { color: var(--text-muted); }
html[data-theme] .auth-divider::before,
html[data-theme] .auth-divider::after {
  border-color: var(--border);
  background: var(--border);
}
html[data-theme] .auth-tabs { background: var(--surface-elevated); }
html[data-theme] .auth-tab { color: var(--text-muted); }
html[data-theme] .auth-tab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 3px 12px var(--shadow-color);
}
html[data-theme] .auth-field { color: var(--text-secondary); }
html[data-theme] .auth-field input:focus {
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
html[data-theme] .auth-helper.error { color: var(--danger); }
html[data-theme] .auth-text-button { color: var(--link); }
html[data-theme] .auth-setup-note {
  background: var(--primary-soft);
  color: var(--text-secondary);
}
html[data-theme] .account-dialog,
html[data-theme] .eligibility-dialog,
html[data-theme] .allowance-confirmation-dialog,
html[data-theme] .allowance-pause-dialog,
html[data-theme] .allowance-notice-dialog { background: var(--surface); }
html[data-theme] .account-dialog-footer,
html[data-theme] .allowance-confirmation-footer,
html[data-theme] .allowance-pause-footer,
html[data-theme] .allowance-notice-footer {
  border-color: var(--border);
  background: var(--surface);
  box-shadow: 0 -12px 28px var(--shadow-color);
}
html[data-theme] .account-avatar,
html[data-theme] .provider-chip {
  background: var(--surface-elevated);
  color: var(--primary);
}
html[data-theme] .account-section { border-color: var(--border); }
html[data-theme] .account-section h3 { color: var(--text-muted); }
html[data-theme] .admin-console-link {
  border: 1px solid var(--primary-border);
  background: var(--primary-soft);
  color: var(--link);
}
html[data-theme="dark"] .auth-brand-logo {
  filter: brightness(6.5) saturate(.6) contrast(.8) drop-shadow(0 0 14px rgba(39, 220, 235, .16));
}

/* Mobile modal system.
 * Every dialog becomes a single, safe-area-aware viewport with exactly
 * one internal vertical scroller.
 */
@media (max-width: 900px) {
  .story-dialog,
  .setup-dialog,
  .class-selection-dialog,
  .equipment-dialog,
  .character-gallery-dialog,
  .generated-image-dialog,
  .account-dialog,
  .eligibility-dialog,
  .allowance-confirmation-dialog,
  .allowance-pause-dialog,
  .allowance-notice-dialog,
  .top-up-processing-dialog {
    inset: 0;
    box-sizing: border-box;
    width: 100%;
    max-width: none;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    overscroll-behavior: contain;
    border: 0;
    border-radius: 0;
  }
  .setup-shell,
  .class-selection-shell,
  .equipment-shell,
  .account-dialog-body,
  .eligibility-dialog-body,
  .allowance-confirmation-body,
  .allowance-pause-body,
  .allowance-notice-body,
  .top-up-processing-body {
    width: 100%;
    height: 100%;
    min-height: 0;
    max-height: none;
  }
  #setupDialog .setup-shell {
    display: flex;
    flex-direction: column;
  }
  .setup-header,
  .class-selection-header {
    flex: 0 0 auto;
    min-width: 0;
    padding:
      max(22px, env(safe-area-inset-top))
      max(64px, calc(48px + env(safe-area-inset-right)))
      18px
      max(22px, env(safe-area-inset-left));
  }
  .setup-header > *,
  .class-selection-header > * { min-width: 0; }
  .setup-header h2,
  .class-selection-header h2 {
    font-size: clamp(1.85rem, 7vw, 2.75rem);
    overflow-wrap: anywhere;
  }
  .setup-progress {
    padding: 11px max(22px, env(safe-area-inset-right)) 12px max(22px, env(safe-area-inset-left));
    flex: 0 0 auto;
    overflow: hidden;
    border-right: 0;
    border-bottom: 1px solid rgba(23,68,107,.78);
    background: rgba(3,146,178,.035);
  }
  .setup-progress-track {
    display: grid;
    grid-auto-columns: minmax(0, 1fr);
    grid-auto-flow: column;
    gap: 6px;
  }
  .setup-progress-track::before { display: none; }
  .setup-progress-step {
    display: block;
    min-height: 6px;
    padding: 0;
    overflow: hidden;
    border: 0;
    border-radius: 999px;
    background: #17446b;
  }
  .setup-progress-step.active {
    background: #27dceb;
    box-shadow: 0 0 10px rgba(39,220,235,.34);
  }
  .setup-progress-step.complete { background: #4fc59a; }
  .setup-progress-number,
  .setup-progress-label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }
  .setup-body,
  .class-selection-body,
  .equipment-body,
  .account-dialog-scroll,
  .character-gallery-body,
  .generated-image-dialog-body,
  .allowance-confirmation-copy,
  .allowance-pause-copy,
  .allowance-notice-copy,
  .top-up-processing-copy {
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }
  .setup-body,
  .class-selection-body {
    flex: 1 1 auto;
    padding-right: max(22px, env(safe-area-inset-right));
    padding-left: max(22px, env(safe-area-inset-left));
  }
  .setup-footer {
    position: relative;
    z-index: 1;
    flex: 0 0 auto;
    padding-right: max(22px, env(safe-area-inset-right));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    padding-left: max(22px, env(safe-area-inset-left));
    box-shadow: 0 -14px 30px rgba(2, 9, 33, .42);
  }
  .dialog-close {
    position: fixed;
    z-index: 5;
    top: max(12px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
    width: 44px;
    height: 44px;
  }
  .story-dialog {
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }
  .story-dialog .dialog-layout {
    display: flex;
    height: auto;
    min-height: 100%;
    flex-direction: column;
  }
  .story-dialog .dialog-art {
    width: min(42vw, 180px);
    height: auto;
    min-height: 0;
    max-height: none;
    margin: max(24px, calc(12px + env(safe-area-inset-top))) auto 0;
    flex: 0 0 auto;
    aspect-ratio: auto;
    border: 1px solid var(--border);
    border-radius: 14px;
  }
  .story-dialog .dialog-panel { display: contents; }
  .story-dialog .dialog-copy { overflow: visible; }
  .story-dialog .dialog-actions {
    padding-right: max(22px, env(safe-area-inset-right));
    padding-bottom: max(22px, env(safe-area-inset-bottom));
    padding-left: max(22px, env(safe-area-inset-left));
    background: transparent;
    grid-template-columns: minmax(0, 1fr);
  }
  .journey-row { grid-template-columns: minmax(0, 1fr); }
  .journey-actions { justify-content: stretch; }
  .journey-actions button { flex: 1 1 110px; }
  .character-gallery-body {
    width: 100%;
    height: 100%;
    max-height: none;
    padding:
      max(72px, calc(56px + env(safe-area-inset-top)))
      max(22px, env(safe-area-inset-right))
      max(28px, env(safe-area-inset-bottom))
      max(22px, env(safe-area-inset-left));
  }
  .generated-image-dialog-body {
    width: 100%;
    height: 100%;
    max-height: none;
    padding:
      max(72px, calc(56px + env(safe-area-inset-top)))
      max(14px, env(safe-area-inset-right))
      max(22px, env(safe-area-inset-bottom))
      max(14px, env(safe-area-inset-left));
  }
  .generated-image-dialog img {
    max-height: calc(100dvh - 140px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }
  .account-dialog-scroll {
    flex: 1 1 auto;
    padding:
      max(76px, calc(60px + env(safe-area-inset-top)))
      max(24px, env(safe-area-inset-right))
      12px
      max(24px, env(safe-area-inset-left));
  }
  .eligibility-dialog-body {
    display: flex;
    min-height: 100%;
    padding:
      max(76px, calc(60px + env(safe-area-inset-top)))
      max(24px, env(safe-area-inset-right))
      max(30px, env(safe-area-inset-bottom))
      max(24px, env(safe-area-inset-left));
    flex-direction: column;
    justify-content: flex-start;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .allowance-confirmation-copy,
  .allowance-pause-copy,
  .allowance-notice-copy,
  .top-up-processing-copy {
    flex: 1 1 auto;
    padding:
      max(76px, calc(60px + env(safe-area-inset-top)))
      max(24px, env(safe-area-inset-right))
      24px
      max(24px, env(safe-area-inset-left));
  }
  .account-dialog-footer {
    flex: 0 0 auto;
    padding:
      13px
      max(24px, env(safe-area-inset-right))
      max(22px, env(safe-area-inset-bottom))
      max(24px, env(safe-area-inset-left));
  }
  .allowance-confirmation-footer,
  .allowance-pause-footer,
  .allowance-notice-footer,
  .top-up-processing-footer {
    flex: 0 0 auto;
    padding:
      13px
      max(24px, env(safe-area-inset-right))
      max(22px, env(safe-area-inset-bottom))
      max(24px, env(safe-area-inset-left));
  }
  .account-allowance-summary, .top-up-offers { grid-template-columns: minmax(0, 1fr); }
  .class-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .class-group-header {
    display: grid;
    align-items: start;
    justify-content: stretch;
    gap: 5px;
  }
  .class-group-header p {
    max-width: 48rem;
    font-size: .7rem;
    line-height: 1.45;
  }
  .class-card button { min-height: 48px; }
  .equipment-shell { max-height: none; }
  .equipment-header {
    padding:
      max(22px, env(safe-area-inset-top))
      max(64px, calc(48px + env(safe-area-inset-right)))
      16px
      max(20px, env(safe-area-inset-left));
  }
  .equipment-body {
    flex: 1 1 auto;
    padding:
      18px
      max(18px, env(safe-area-inset-right))
      max(28px, env(safe-area-inset-bottom))
      max(18px, env(safe-area-inset-left));
  }
  .equipment-paperdoll {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }
  .equipment-character {
    min-height: 330px;
    grid-column: 1 / -1;
    grid-row: 1;
    border-radius: 22px;
  }
  .equipment-slot-column { grid-row: 2; }
  .equipment-inventory-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .auth-view { padding: 0; align-items: stretch; }
  .auth-shell { min-height: 100dvh; border: 0; border-radius: 0; grid-template-columns: 1fr; }
  .auth-art { min-height: 230px; padding: max(24px, env(safe-area-inset-top)) 24px 26px; background-position: center 19%; }
  .auth-art-copy h1 { margin-bottom: 0; font-size: 2.65rem; }
  .auth-art-copy p { display: none; }
  .auth-panel { padding: 32px max(22px, env(safe-area-inset-right)) max(36px, env(safe-area-inset-bottom)) max(22px, env(safe-area-inset-left)); justify-content: flex-start; }
  .account-password-form { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .setup-header,
  .class-selection-header {
    padding-right: max(62px, calc(48px + env(safe-area-inset-right)));
    padding-left: max(18px, env(safe-area-inset-left));
  }
  .setup-header .eyebrow,
  .class-selection-header .eyebrow { font-size: .54rem; }
  .setup-header h2,
  .class-selection-header h2 { font-size: clamp(1.7rem, 9vw, 2.25rem); }
  .class-selection-header > p { font-size: .7rem; line-height: 1.4; }
  .setup-progress {
    padding: 10px max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
  }
  .setup-progress-track { gap: 4px; }
  .setup-body,
  .class-selection-body {
    padding: 18px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left));
  }
  .builder-fields,
  .builder-fields[data-builder-layout="identity"],
  .character-result { grid-template-columns: minmax(0, 1fr); }
  .builder-field.full { grid-column: auto; }
  .builder-field input,
  .builder-field select,
  .builder-field textarea { min-height: 50px; }
  .setup-footer {
    padding: 12px max(16px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }
  .setup-footer .primary-button,
  .setup-footer .secondary-button {
    min-width: 0;
    min-height: 50px;
    flex: 1 1 0;
  }
  .character-result { gap: 20px; }
  .result-portrait img { height: 180px; }
  .result-attributes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .result-actions button { width: 100%; min-height: 50px; }
  .class-grid { grid-template-columns: minmax(0, 1fr); }
  .class-group { margin-top: 24px; }
  .class-card { min-width: 0; min-height: 0; padding: 16px; }
  .class-card-meta { align-items: flex-start; }
  .class-family { overflow-wrap: anywhere; }
  .class-tags { margin-bottom: 14px; }
  .equipment-header { align-items: start; flex-direction: column; gap: 8px; }
  .equipment-header h2 { font-size: 1.8rem; }
  .equipment-free-action { display: none; }
  .equipment-paperdoll { grid-template-columns: minmax(0, 1fr); }
  .equipment-character { min-height: 300px; grid-column: auto; grid-row: auto; }
  .equipment-slot-column { grid-row: auto; }
  .equipment-accessory-row { grid-template-columns: minmax(0, 1fr); }
  .equipment-inventory-heading { align-items: start; flex-direction: column; gap: 5px; }
  .equipment-inventory-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .equipment-detail { grid-template-columns: minmax(0, 1fr); }
  .equipment-detail small { text-align: left; }
  .account-identity { grid-template-columns: 52px minmax(0, 1fr); }
  #exportButton { display: none; }
}

@media (max-width: 900px) and (max-height: 560px) {
  .setup-header,
  .class-selection-header {
    padding-top: max(10px, env(safe-area-inset-top));
    padding-bottom: 10px;
  }
  .setup-header .eyebrow,
  .class-selection-header .eyebrow,
  .class-selection-header > p { display: none; }
  .setup-header h2,
  .class-selection-header h2 { font-size: 1.65rem; }
  .setup-progress { padding-top: 7px; padding-bottom: 7px; }
  .setup-progress-step { min-height: 5px; }
  .setup-body,
  .class-selection-body { padding-top: 14px; }
  .setup-footer { padding-top: 8px; }
  .setup-footer .primary-button,
  .setup-footer .secondary-button { min-height: 44px; }
}

@media (max-width: 720px) {
  .subscription-payment-banner {
    position: relative;
    gap: 10px;
    padding: 12px 14px;
    align-items: flex-start;
    flex-direction: column;
  }
  .subscription-payment-banner-actions {
    width: 100%;
    justify-content: flex-start;
  }
}

/* Story workspace information architecture. */
.app-header {
  grid-template-columns: minmax(0, 1fr) minmax(180px, 2fr) minmax(0, 1fr);
  gap: clamp(10px, 1.5vw, 24px);
}
.app-nav-left { justify-self: start; }
.app-nav-right { justify-self: end; }
.workspace-action-button[aria-current="true"],
#openSettingsButton[aria-current="true"] {
  border-color: var(--primary-border);
  background: var(--primary-soft);
  color: var(--primary);
}
.app-story-title {
  min-width: 0;
}
.app-story-title strong {
  max-width: none;
  overflow-wrap: anywhere;
  white-space: normal;
  line-height: 1.25;
  text-wrap: balance;
}
.app-story-title span {
  display: block;
  margin-top: 2px;
  letter-spacing: .06em;
  text-transform: none;
}
.workspace {
  width: min(1380px, 100%);
  grid-template-columns: 250px minmax(420px, 1fr) 220px;
}
.workspace-sidebar {
  padding-top: 24px;
}
.workspace-pulse {
  display: grid;
  gap: 10px;
}
.workspace-pulse-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.workspace-pulse-heading .sidebar-label {
  margin: 0;
}
.workspace-objective {
  margin: 0;
  color: var(--text-secondary);
  font-family: var(--serif);
  font-size: .86rem;
  line-height: 1.5;
}
.story-stage {
  border-right: 1px solid var(--line);
}
.workspace-action-rail {
  display: grid;
  height: 100%;
  min-width: 0;
  padding: 24px 16px;
  overflow-y: auto;
  align-content: space-between;
  gap: 24px;
  border-left: 1px solid var(--line);
  background: var(--surface-soft);
  scrollbar-width: thin;
}
.workspace-action-menu {
  display: grid;
  gap: 9px;
}
.workspace-action-button {
  width: 100%;
  min-height: 46px;
  justify-content: flex-start;
  border-color: transparent;
  background: transparent;
}
.workspace-action-button:hover {
  border-color: var(--border);
  background: var(--surface);
}
.workspace-currency-panel {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}
.workspace-currency-heading {
  display: flex;
  margin-bottom: 10px;
  align-items: center;
  gap: 7px;
  color: var(--text-muted);
  font-size: .58rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.workspace-currency-heading .icon { width: 15px; height: 15px; }
.workspace-currency {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}
.workspace-coin {
  display: flex;
  min-width: 0;
  padding: 8px;
  align-items: baseline;
  justify-content: space-between;
  gap: 5px;
  border-radius: 9px;
  background: var(--surface-soft);
}
.workspace-coin b { font-size: .76rem; }
.workspace-coin span {
  color: var(--text-muted);
  font-size: .52rem;
  font-weight: 800;
  text-transform: uppercase;
}
.messages {
  padding-top: clamp(36px, 6vh, 72px);
}
.workspace-dialog {
  width: min(980px, calc(100% - 28px));
  max-height: calc(100dvh - 28px);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: var(--shadow);
}
.workspace-dialog::backdrop {
  background: var(--overlay);
  backdrop-filter: blur(10px);
}
.workspace-dialog-shell {
  display: flex;
  max-height: calc(100dvh - 28px);
  min-height: min(680px, calc(100dvh - 28px));
  flex-direction: column;
}
.workspace-dialog-header {
  display: flex;
  padding: 28px 74px 22px 30px;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-glass);
}
.workspace-dialog-header h2 {
  margin: 3px 0 0;
  font-family: var(--serif);
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  font-weight: 600;
  letter-spacing: -.025em;
}
.workspace-dialog-header > p {
  max-width: 380px;
  margin: 0;
  color: var(--text-muted);
  font-size: .72rem;
  line-height: 1.5;
  text-align: right;
}
.workspace-dialog-body {
  min-height: 0;
  padding: 26px 30px 34px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.character-overview-grid {
  display: block;
}
.relationships-workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, .8fr);
  gap: 20px;
}
.relationships-panel {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface-soft);
}
.relationships-panel-heading {
  display: flex;
  margin-bottom: 14px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.relationships-panel-heading h3 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.2rem;
}
.relationships-count {
  color: var(--text-muted);
  font-size: .62rem;
  font-weight: 800;
}
.faction-relationships { display: grid; gap: 9px; }
.faction-relationship {
  display: grid;
  padding: 12px;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
}
.faction-relationship strong { min-width: 0; overflow-wrap: anywhere; }
.faction-standing { font-weight: 850; }
.faction-standing.positive { color: var(--success); }
.faction-standing.negative { color: var(--danger); }
.faction-relationship small {
  grid-column: 1 / -1;
  color: var(--text-muted);
  font-size: .62rem;
}
.player-character-dialog .progression-hud {
  grid-template-columns: minmax(0, 1fr);
  gap: 22px;
  max-width: 780px;
  margin: 0 auto;
}
.player-character-dialog .player-card {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  padding: 0;
  border: 0;
  background: none;
}
.player-character-dialog .player-card h3 { font-size: 1.35rem; }
.player-character-dialog .player-card p { font-size: .85rem; line-height: 1.6; }
.character-class-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.character-class-line .class-icon { width: 24px; height: 24px; flex-basis: 24px; }
.character-portrait-button { padding: 0; border: 0; background: none; cursor: pointer; }
.character-portrait-button img { display: block; }
.character-resources { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 0; }
.character-resources > div { padding: 10px 12px; border-radius: 10px; background: var(--surface-elevated); }
.character-resources dt { color: var(--text-secondary); font-size: .8rem; }
.character-resources dd { margin: 3px 0 0; color: var(--text-primary); font-size: 1.1rem; font-weight: 750; }
.character-injuries p { margin: 10px 0 0; color: var(--text-secondary); font-size: .875rem; }
.character-section h3 { margin: 0 0 12px; color: var(--text-primary); font-size: 1rem; }
.character-section-heading { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; }
.character-points { color: var(--text-primary); font-size: .8rem; font-weight: 750; }
.character-allocation-help { color: var(--text-secondary); font-size: .85rem; }
.player-character-dialog .editing-attributes .hud-attribute { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
.character-allocation-input { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.character-allocation-input input { width: 5rem; min-height: 40px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text-primary); font: inherit; }
.character-allocation-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; }
.character-allocation-actions [role="status"] { flex: 1 1 100%; font-size: .85rem; color: var(--text-secondary); }
.character-allocation-actions button, [data-spend-attributes] { min-height: 40px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; color: var(--text-primary); background: var(--surface); font: inherit; }
.character-abilities { display: grid; gap: 8px; }
.character-ability { border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.character-ability summary { display: flex; min-height: 68px; align-items: center; gap: 12px; padding: 12px; cursor: pointer; list-style: none; }
.character-ability summary::-webkit-details-marker { display: none; }
.character-ability summary::after { content: '⌄'; flex: 0 0 auto; color: var(--text-secondary); }
.character-ability[open] summary::after { transform: rotate(180deg); }
.character-ability-copy { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.character-ability-copy strong { display: block; color: var(--text-primary); font-size: .9rem; }
.character-ability-copy small { display: block; margin-top: 4px; color: var(--text-secondary); font-size: .8rem; }
.character-readiness { flex: 0 1 140px; text-align: right; color: var(--success); font-size: .8rem; }
.character-readiness.recovering { color: var(--text-primary); }
.character-detail-copy { padding: 0 14px 10px; color: var(--text-secondary); font-size: .875rem; line-height: 1.55; }
.character-detail-copy p { margin: 8px 0; }
.character-recovery { margin-top: 12px; }
.character-recovery summary, .character-development summary { min-height: 36px; padding: 8px 0; color: var(--text-secondary); cursor: pointer; font-size: .875rem; }
.player-character-dialog .hud-attributes { gap: 8px; }
.player-character-dialog .hud-attribute { min-height: 48px; gap: 8px; padding: 8px 10px; font-size: .8rem; }
.character-attribute-value { display: grid; margin-left: auto; text-align: right; }
.character-attribute-value small { font-size: .7rem; }
.player-character-dialog .hud-attribute button { flex: 0 0 36px; width: 36px; height: 36px; color: var(--text-primary); }
.character-inventory-link { padding: 10px 0; margin-top: 5px; border: 0; background: none; color: var(--text-primary); font-size: .85rem; text-align: left; cursor: pointer; }
.character-development { border-top: 1px solid var(--border); padding-top: 8px; }
.character-development .hud-list { font-size: .875rem; }
.journal-workspace-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 16px;
}
.journal-dialog .workspace-dialog-shell {
  min-height: 0;
}
.journal-panel {
  min-width: 0;
  padding: 18px;
  align-content: start;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface-soft);
}
.journal-notes-card,
.settings-card {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface-soft);
}
.journal-notes-card h3,
.settings-card h3 {
  margin: 0 0 5px;
  font-family: var(--serif);
  font-size: 1.2rem;
}
.journal-notes-card > p,
.settings-card > p {
  margin: 0 0 14px;
  color: var(--text-muted);
  font-size: .7rem;
  line-height: 1.5;
}
.journal-notes-card .personal-notes textarea {
  min-height: 190px;
}
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.settings-card {
  display: grid;
  align-content: start;
  gap: 10px;
}
.settings-card-wide { grid-column: 1 / -1; }
.settings-card .story-intensity-button,
.settings-card .image-regenerate-button,
.settings-card .secondary-button {
  width: 100%;
  min-height: 44px;
}
.settings-portrait {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
}
.settings-portrait img {
  width: 82px;
  height: 104px;
  border-radius: 12px;
  object-fit: cover;
}
.settings-portrait-controls {
  display: grid;
  min-width: 0;
  gap: 9px;
}
.settings-portrait-controls .image-variant-selector {
  width: 100%;
  justify-content: space-between;
}
.settings-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.equipment-wallet {
  margin-bottom: 16px;
}
.equipment-wallet .inventory-coins {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.equipment-item { overflow: visible; }
.equipment-item .inventory-item-tooltip {
  top: calc(100% + 8px);
  right: auto;
  bottom: auto;
  left: 0;
  z-index: 8;
}
.equipment-item:hover .inventory-item-tooltip,
.equipment-item:focus-visible .inventory-item-tooltip {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 220px minmax(400px, 1fr) 190px; }
}
@media (max-width: 900px) {
  .workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .workspace > .workspace-sidebar { display: none; }
  .story-stage {
    grid-row: 1;
    border-right: 0;
  }
  .workspace-action-rail {
    grid-row: 2;
    height: auto;
    padding: 7px max(10px, env(safe-area-inset-right)) max(7px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    overflow: visible;
    align-content: initial;
    gap: 6px;
    border-top: 1px solid var(--border);
    border-left: 0;
    background: var(--surface-glass);
  }
  .workspace-action-menu {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
  }
  .workspace-action-button {
    min-width: 0;
    min-height: 44px;
    padding: 3px 5px;
    justify-content: center;
    flex-direction: column;
    gap: 1px;
    font-size: .54rem;
  }
  .workspace-action-button .icon { width: 16px; height: 16px; }
  .workspace-currency-panel {
    order: -1;
    padding: 5px 8px;
    border: 0;
    background: transparent;
  }
  .workspace-currency-heading { display: none; }
  .workspace-currency { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
  .workspace-coin { min-height: 24px; padding: 3px 7px; }
  .workspace-coin b { font-size: .66rem; }
  .relationships-workspace-grid,
  .character-overview-grid,
  .journal-workspace-grid { grid-template-columns: minmax(0, 1fr); }
  .player-character-dialog .progression-hud { grid-template-columns: minmax(0, 1fr); }
  .character-resources { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .player-character-dialog .hud-attributes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .player-character-dialog .hud-attribute { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 6px; }
  .player-character-dialog .hud-attribute > span:first-child { grid-column: 1; }
  .character-attribute-value { grid-column: 1; margin-left: 0; text-align: left; }
  .character-attribute-value small { white-space: nowrap; font-size: .65rem; }
  .character-allocation-input { flex-direction: column; align-items: stretch; gap: 4px; }
  .character-allocation-input input { width: 100%; }
  .player-character-dialog .hud-attribute button { grid-column: 2; grid-row: 1 / 3; }
  .character-ability summary { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px 8px; }
  .character-ability-copy { grid-column: 2; }
  .character-ability summary > .ability-icon { grid-column: 1; grid-row: 1 / 3; }
  .character-ability summary::after { grid-column: 3; grid-row: 1 / 3; }
  .character-readiness { grid-column: 2; max-width: none; text-align: left; }
}
@media (max-width: 700px) {
  :root { --app-header-height: 62px; }
  .app-header {
    min-height: calc(var(--app-header-height) + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
    grid-template-columns: minmax(89px, 1fr) minmax(0, 2fr) minmax(89px, 1fr);
    grid-template-rows: minmax(62px, auto);
    grid-template-areas:
      "library scene account";
    gap: 8px;
  }
  .app-nav-left { grid-area: library; }
  .app-story-title { grid-area: scene; }
  .app-story-title strong { font-size: .9rem; }
  .app-story-title span { font-size: .54rem; }
  .app-nav-right { grid-area: account; }
  .app-nav-left .nav-button span,
  .app-nav-right .nav-button span { display: none; }
  .app-nav-left .nav-button,
  .app-nav-right .nav-button { min-width: 42px; padding: 0; }
  .messages { padding-top: 24px; }
  .workspace-dialog {
    width: 100%;
    max-height: 100dvh;
    border: 0;
    border-radius: 0;
  }
  .workspace-dialog-shell {
    min-height: 100dvh;
    max-height: 100dvh;
  }
  .journal-dialog .workspace-dialog-shell { min-height: 100dvh; }
  .workspace-dialog-header {
    padding: max(22px, env(safe-area-inset-top)) max(64px, calc(50px + env(safe-area-inset-right))) 16px max(18px, env(safe-area-inset-left));
    align-items: start;
    flex-direction: column;
    gap: 6px;
  }
  .workspace-dialog-header > p { text-align: left; }
  .workspace-dialog-body {
    padding: 18px max(16px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }
  .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .settings-card-wide { grid-column: auto; }
  .settings-actions { grid-template-columns: minmax(0, 1fr); }
  #exportButton { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
  .settings-portrait { grid-template-columns: 66px minmax(0, 1fr); }
  .settings-portrait img { width: 66px; height: 84px; }
  .equipment-wallet .inventory-coins { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* End mobile modal system. */

@media (max-width: 900px) {
  .story-dialog .dialog-art img { width: 100%; height: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
:root {
  --usage-color: #22bfae;
}
.usage-bar { display: flex; align-items: center; gap: .6rem; color: var(--text-primary); min-width: 12rem; }
.usage-shortcut { padding: .45rem .7rem; border: 1px solid var(--border-color, #52677a); border-radius: .75rem; background: transparent; cursor: pointer; font: inherit; }
.usage-label, .usage-count { font-size: .78rem; font-weight: 650; white-space: nowrap; }
.usage-track { display: block; flex: 1; min-width: 4rem; height: .55rem; overflow: hidden; border-radius: 1rem; background: color-mix(in srgb, currentColor 15%, transparent); }
.workspace-usage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  width: 100%;
  min-width: 0;
  margin-bottom: 24px;
  padding: 12px;
  border-color: var(--border);
  background: var(--surface-soft);
  text-align: left;
}
.workspace-usage:hover { border-color: var(--primary-border); }
.workspace-usage .usage-track { grid-column: 1 / -1; grid-row: 2; width: 100%; min-width: 0; height: 6px; }
.usage-fill { display: block; height: 100%; background: var(--usage-color); border-radius: inherit; transition: width .3s ease; }
.usage-bar[data-layer="1"] { --usage-color: #4b9ee8; }
.usage-bar[data-layer="2"] { --usage-color: #a679e0; }
.usage-bar[data-layer="3"] { --usage-color: #dba738; }
.usage-bar[data-low="true"] { --usage-color: #d24c4c; }
.membership-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.membership-card { display: flex; flex-direction: column; gap: .5rem; text-align: left; padding: 1rem; border-radius: .8rem; background: transparent; color: inherit; border: 1px solid var(--border-color, #52677a); font: inherit; }
.membership-card[aria-pressed="true"] { border-color: var(--usage-color); box-shadow: inset 0 0 0 1px var(--usage-color); }
.membership-card:disabled { opacity: .75; }
.membership-card small { font-size: .7rem; line-height: 1.4; }
@media (max-width: 650px) {
  .usage-shortcut { min-width: 6rem; gap: .4rem; }
  .usage-shortcut .usage-label { display: none; }
  .usage-shortcut .usage-track { min-width: 2rem; }
  .membership-cards { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { .usage-fill { transition: none; } }
