/* ==========================================================================
   Themes. Every colour, shape and font comes from these tokens; a theme is
   one block. The chosen theme is set on <html data-theme> (see index.html).
   ========================================================================== */
:root, [data-theme="moonwind"] {
  /* Moonwind: an indigo night, periwinkle petals, a silver moon. Its panels are glass:
     see-through, and blurred where they're small (--blur). */
  --bg: #0a0d24;
  --stars:
    radial-gradient(1px 1px at 12% 18%, #ffffffcc 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 72% 12%, #D5D2E3cc 50%, transparent 51%),
    radial-gradient(1px 1px at 38% 64%, #ffffffaa 50%, transparent 51%),
    radial-gradient(1px 1px at 88% 48%, #D5D2E3aa 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 58% 86%, #ffffffbb 50%, transparent 51%),
    radial-gradient(1px 1px at 22% 92%, #D5D2E399 50%, transparent 51%),
    radial-gradient(1px 1px at 92% 82%, #ffffff99 50%, transparent 51%);
  --glow:
    radial-gradient(ellipse 60% 50% at 88% -5%, #7b6cf040, transparent 70%),
    radial-gradient(ellipse 50% 45% at 0% 100%, #b65ad52e, transparent 70%),
    radial-gradient(ellipse 80% 70% at 45% 50%, #26307a40, transparent 75%);
  --page: rgba(30, 35, 82, .58);
  --surface: rgba(19, 24, 60, .66);
  --surface-2: rgba(124, 131, 212, .16);
  --field: rgba(8, 11, 32, .55);
  --border: rgba(172, 178, 240, .17);
  --field-border: rgba(160, 166, 232, .42);
  --text: #e4e3f4;
  --muted: #a9aad2;
  --accent: #c6c7f7;          /* lavender text, readable on the night */
  --accent-soft: #7c83d4;     /* periwinkle: ornaments, borders, glows */
  --accent-bg: #c3c6f4;       /* silver-lavender buttons */
  --accent-ink: #0d1030;
  --player: rgba(124, 131, 212, .24);
  --good: #9fd8b8;
  --bad: #f2a7b0;
  --shadow-soft: 0 18px 44px -18px #02031acc;
  color-scheme: dark;
}

[data-theme="moonwind-day"] {
  --bg: #F1EFF6;
  --stars: none;
  --glow: radial-gradient(ellipse at 80% -10%, #D5D2E3, transparent 65%);
  --page: #FFFFFF;
  --surface: #E9E6F1;
  --surface-2: #D5D2E3;
  --field: #FFFFFF;
  --border: #D5D2E3;
  --field-border: #8a82a0;
  --text: #353a4a;
  --muted: #5b546d;
  --accent: #6E6182;
  --accent-soft: #7E718F;
  --accent-bg: #565E71;
  --accent-ink: #FFFFFF;
  --player: #E4E1EE;
  --good: #276b47;
  --bad: #a8334a;
  --shadow-soft: 0 18px 40px -20px #565E7166;
  color-scheme: light;
}

[data-theme="parchment"] {
  --bg: #EDE3CC;
  --stars: none;
  --glow: radial-gradient(ellipse at 50% 0%, #fbf5e6, transparent 70%);
  --page: #FBF5E6;
  --surface: #F3EADA;
  --surface-2: #E8DCC4;
  --field: #FFFBF2;
  --border: #DCCBA9;
  --field-border: #a48d68;
  --text: #3B2A1E;
  --muted: #6E5843;
  --accent: #9E2A2B;          /* ribbon red */
  --accent-soft: #b9895a;
  --accent-bg: #9E2A2B;
  --accent-ink: #FFF8EC;
  --player: #EADBC0;
  --good: #3d6b35;
  --bad: #9E2A2B;
  --shadow-soft: 0 18px 40px -20px #6e584366;
  color-scheme: light;
}

[data-theme="night"] {
  --bg: #12131b;
  --stars:
    radial-gradient(1px 1px at 15% 25%, #f3e3b955 50%, transparent 51%),
    radial-gradient(1px 1px at 70% 70%, #f3e3b944 50%, transparent 51%),
    radial-gradient(1px 1px at 85% 20%, #f3e3b944 50%, transparent 51%);
  --glow: radial-gradient(ellipse at 20% 110%, #e2b66622, transparent 60%);
  --page: #191b26;
  --surface: #1b1d28;
  --surface-2: #262938;
  --field: #12131b;
  --border: #30344a;
  --field-border: #5a6078;
  --text: #ECE6DA;
  --muted: #A6A4B0;
  --accent: #E2B666;          /* candle gold */
  --accent-soft: #a8874b;
  --accent-bg: #E2B666;
  --accent-ink: #1b1608;
  --player: #2a3350;
  --good: #8fcf8f;
  --bad: #ec8a7c;
  --shadow-soft: 0 18px 40px -18px #000000cc;
  color-scheme: dark;
}

:root {
  --radius: 16px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --story-font: "Literata", Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  --ui-font: "Quicksand", "Segoe UI Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --heading-font: "Cormorant Garamond", "Cormorant", Georgia, serif;
  --title-font: "Cinzel", "Cormorant Garamond", Georgia, serif;   /* the library's names */
}

/* ==========================================================================
   Base
   ========================================================================== */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--glow), var(--bg);
  color: var(--text);
  font: 500 15px/1.55 var(--ui-font);
  display: flex;
  flex-direction: column;
  position: relative;
}
/* A faint, slowly twinkling starfield (dark themes only). */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background: var(--stars); background-size: 420px 420px;
  animation: twinkle 7s ease-in-out infinite alternate;
}
body > * { position: relative; z-index: 1; }
body > .toast { position: fixed; z-index: 20; }
@keyframes twinkle { from { opacity: .55; } to { opacity: 1; } }

button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
::selection { background: var(--accent-soft); color: var(--accent-ink); }

/* ---------- top bar ---------- */
.topbar { z-index: 5;   /* its menus open over the story and panel below */
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px; border-bottom: 1px solid var(--border); background: var(--surface);
  backdrop-filter: blur(var(--blur, 0px));
}
.brand { font: italic 600 22px/1 var(--heading-font); letter-spacing: .02em; color: var(--accent); white-space: nowrap; }
a.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-moon { width: 24px; height: 24px; flex-shrink: 0; fill: var(--accent-soft); }
.brand .tagline { font: italic 500 15px var(--heading-font); color: var(--muted); letter-spacing: 0; margin-left: 6px; }
.tagline-line { margin: -2px 0 14px; font: italic 500 18px var(--heading-font); color: var(--muted); }
a.brand:hover { color: var(--accent-ink); }
/* ---------- the library: a rail down the left, beside every screen ---------- */
.shell { flex: 1; display: flex; min-height: 0; }
.shell > .layout, .shell > .screen { flex: 1; min-width: 0; }
.rail { flex-shrink: 0; width: 184px; display: flex; flex-direction: column; gap: 6px; padding: 16px 10px;
  border-right: 1px solid var(--border); background: var(--surface); overflow-y: auto;
  backdrop-filter: blur(var(--blur, 0px)); }
.rail button { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px;
  background: transparent; border: 1px solid transparent; color: var(--muted); font-size: 14px; text-align: left; white-space: nowrap; }
.rail button:hover { color: var(--text); background: var(--surface-2); border-color: transparent; }
.rail button.active { color: var(--accent); border-color: color-mix(in srgb, var(--accent-soft) 55%, transparent);
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent-soft) 30%, transparent), transparent);
  box-shadow: inset 3px 0 0 var(--accent); }
.rail svg { width: 21px; height: 21px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round; }
.rail .label { overflow: hidden; text-overflow: ellipsis; }
.rail-gap { flex: 1; }
/* While playing the story needs the room: icons only (their names are in the tooltips). */
body.in-game .rail { width: 62px; padding: 14px 8px; }
body.in-game .rail .label { display: none; }
body.in-game .rail button { justify-content: center; padding: 10px 0; }

/* ---------- the library's pages: tiles, two to a row ---------- */
.library { max-width: 1000px; margin: 0 auto; }
.library-title, .card h1.library-title { margin: 0; font: 600 34px/1.15 var(--title-font); letter-spacing: .06em; color: var(--accent); }
.library-sub { margin: 4px 0 22px; color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.tile { position: relative; display: flex; flex-direction: column; gap: 10px; min-width: 0; overflow: hidden;
  padding: 22px 24px; border-radius: 20px; text-align: left; font-weight: 500; color: var(--text);
  border: 1px solid var(--border);
  background:
    radial-gradient(circle at 100% 0%, color-mix(in srgb, var(--accent-soft) 26%, transparent), transparent 55%),
    linear-gradient(160deg, color-mix(in srgb, var(--surface-2) 75%, transparent), color-mix(in srgb, var(--page) 92%, transparent));
  box-shadow: var(--shadow-soft), var(--edge, 0 0 #0000);
  backdrop-filter: blur(var(--blur, 0px)); transition: transform .15s, border-color .15s, box-shadow .15s; }
.tile.wide { grid-column: 1 / -1; }
button.tile, .tile.open { cursor: pointer; }
button.tile:hover, .tile.open:hover { transform: translateY(-2px); border-color: var(--accent-soft);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent-soft) 60%, transparent), 0 22px 44px -22px var(--accent-soft); }
.tile-name { margin: 0; font: 600 21px/1.25 var(--title-font); letter-spacing: .04em; color: var(--accent);
  overflow-wrap: anywhere; }
.tile .facts { display: grid; grid-template-columns: auto 1fr; gap: 3px 14px; margin: 0; font-size: 14px; }
.tile .facts dt { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; padding-top: 2px; }
.tile .facts dd { margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .when { color: var(--muted); font-size: 12px; margin-top: auto; }
.tile .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.tile .badge { position: absolute; top: 14px; right: 16px; padding: 2px 10px; border-radius: var(--radius-pill);
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  background: var(--accent-bg); color: var(--accent-ink); }
.tile .clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; font-size: 14px; }
/* The first tile: a big + to begin something new. */
.tile.new { align-items: center; justify-content: center; min-height: 190px; border-style: dashed; border-width: 1.5px;
  border-color: var(--accent-soft); color: var(--accent); font: 600 17px var(--title-font); letter-spacing: .06em; }
.tile.new .plus { width: 64px; height: 64px; display: grid; place-items: center; border-radius: 50%;
  border: 1.5px solid var(--accent-soft); font: 300 40px/1 var(--ui-font);
  box-shadow: 0 0 24px -4px var(--accent-soft), inset 0 0 18px -6px var(--accent-soft); }
/* A story's character, in a small circle beside its name. */
.tile-head { display: flex; align-items: center; gap: 12px; min-width: 0; padding-right: 70px; }
.avatar { width: 44px; height: 44px; flex-shrink: 0; border-radius: 50%; object-fit: cover; border: 1.5px solid var(--accent-soft); }

/* A character's card: an arched portrait beside the sheet. */
.char-tile { flex-direction: row; gap: 18px; }
.char-tile .body { display: flex; flex-direction: column; gap: 8px; min-width: 0; flex: 1; }
.portrait { width: 112px; height: 152px; flex-shrink: 0; padding: 0; overflow: hidden; cursor: pointer;
  border-radius: 999px 999px 16px 16px; border: 1.5px solid var(--accent-soft);
  box-shadow: 0 0 26px -8px var(--accent-soft); display: grid; place-items: center;
  font: 600 46px var(--title-font); color: #fff; text-shadow: 0 2px 12px #0008; }
.portrait img { width: 100%; height: 100%; object-fit: cover; display: block; }
.portrait.emblem, .avatar.emblem { background: #1f233c; }
.portrait:hover { border-color: var(--accent); }
.char-tile .edit-box { flex-basis: 100%; }
.char-tile:not(.wide) .edit-box { display: none; }
.char-tile.wide { flex-wrap: wrap; }

/* A character's profile card (Characters page): one per row, wide like a poster. The
   portrait sits in the middle and fades into the card; the text frames it. */
#character-list { grid-template-columns: minmax(0, 1fr); }
#character-list .tile.new { min-height: 110px; }
.profile { position: relative; display: grid; grid-template-columns: minmax(0, 34%) minmax(0, 1fr) minmax(0, 30%);
  grid-template-areas: "left . right" "foot foot foot"; min-height: 400px; overflow: hidden; padding: 22px 26px 16px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.pf-portrait { position: absolute; inset: 0 30% 0 26%; padding: 0; border: 0; border-radius: 0; background: transparent; cursor: pointer;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 22%, #000 72%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 22%, #000 72%, transparent); }
.pf-portrait img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 18%; display: block; }
.pf-portrait.emblem img { object-fit: contain; opacity: .55; }
.pf-left, .pf-right { position: relative; z-index: 1; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.pf-left { grid-area: left; }
.pf-right { grid-area: right; }
.pf-world { display: flex; gap: 10px; align-items: flex-start; }
.pf-world-art { width: 58px; height: 58px; flex-shrink: 0; border-radius: 6px; border: 1px solid var(--accent-soft); }
.pf-world-name { font: 600 17px var(--heading-font); }
.pf-world-text { font-size: 12px; color: var(--muted); line-height: 1.35; }
.pf-name { display: flex; flex-direction: column; margin-top: auto; }
.pf-label { font: 600 34px/1 var(--title-font); letter-spacing: .04em; text-transform: uppercase; }
.pf-script { font: 600 30px/1.2 var(--heading-font); padding-left: 10px; overflow-wrap: anywhere; }
.pf-who { display: flex; gap: 10px; align-items: flex-start; }
.pf-crest { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; flex-shrink: 0; border: 1px solid var(--accent-soft); }
.pf-who-head { display: block; font: 600 16px var(--heading-font); margin-bottom: 2px; }
.pf-text { margin: 0; font-size: 13px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.pf-who .pf-text { -webkit-line-clamp: 4; }
.pf-eyes { height: 46px; border: 1px solid var(--accent-soft); border-radius: 4px; overflow: hidden; }
.pf-eyes img { width: 100%; height: 330%; object-fit: cover; object-position: 50% 22%; transform: translateY(-34%); display: block; }
.pf-block h4 { margin: 0 0 4px; font: 600 22px var(--heading-font); }
.pf-foot { grid-area: foot; position: relative; z-index: 1; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.pf-foot .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
.pf-kept { font-size: 12px; color: var(--muted); font-style: italic; }
.profile .edit-box { grid-column: 1 / -1; position: relative; z-index: 1; }
.profile:not(.wide) .edit-box { display: none; }
.profile.wide .pf-portrait { inset: 0 30% auto 26%; height: 400px; }
/* In the game's Character tab: the same look, small. */
.pc-head { display: flex; gap: 14px; align-items: center; margin-bottom: 8px; }
.pc-face { width: 86px; height: 110px; flex-shrink: 0; border-radius: 999px 999px 12px 12px; overflow: hidden; border: 1px solid var(--accent-soft); }
.pc-face img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 18%; display: block; }
.pc-face.emblem { background: #1f233c; }
.pc-id { min-width: 0; }
.pc-id .pf-label { font-size: 15px; }
.pc-id .pf-script { font-size: 30px; padding-left: 4px; }
@media (max-width: 760px) {
  .profile { grid-template-columns: minmax(0, 1fr); grid-template-areas: "pic" "left" "right" "foot"; }
  .pf-portrait { position: relative; inset: auto; grid-area: pic; height: 330px; margin: -22px -26px 0;
    -webkit-mask-image: linear-gradient(#000 55%, transparent); mask-image: linear-gradient(#000 55%, transparent); }
  .profile.wide .pf-portrait { inset: auto; height: 330px; }
  .pf-name { order: -1; margin-top: -78px; }
  .pf-eyes { display: none; }
}

/* A world's card: painted sky and a planet, its name over it. */
.world-tile { padding: 0; }
.world-art { position: relative; height: 128px; display: flex; align-items: flex-end; padding: 16px 22px;
  border-bottom: 1px solid var(--border); }
.world-art::after { content: ""; position: absolute; right: 26px; top: 18px; width: 70px; height: 70px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffffffcc, var(--planet) 40%, #0000 72%); filter: blur(.3px); opacity: .85; }
.world-art .tile-name { color: #fff; text-shadow: 0 2px 14px #000a; position: relative; z-index: 1; }
.world-tile .inner { display: flex; flex-direction: column; gap: 10px; padding: 16px 22px 20px; flex: 1; }
.world-tile.new { padding: 22px; }

.seeds { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 26px; }

/* Plain looks: the hero is just the title; Moonwind's ornaments stay hidden. */
.hero { margin-bottom: 4px; }
.hero-mark, .orn, .rail-moon, .new-art, .portrait-wrap .spark { display: none; }
.portrait-wrap { position: relative; flex-shrink: 0; }
.new-label { display: block; }
.session-title { flex: 1; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font: italic 16px var(--heading-font); }
.top-actions { display: flex; gap: 8px; align-items: center; position: relative; }
.top-actions button { display: inline-flex; align-items: center; gap: 8px; }
.ico { width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round; }
button.small .ico { width: 15px; height: 15px; }
button .ico + * { margin-left: 0; }
.tile .actions button { display: inline-flex; align-items: center; gap: 6px; }
.tile .actions button.round { width: 30px; height: 30px; padding: 0; justify-content: center; border-radius: 50%; }

button {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-pill);
  padding: 6px 14px; cursor: pointer; font-weight: 600;
  transition: border-color .15s, background .15s, transform .1s;
}
button:hover:not(:disabled) { border-color: var(--accent-soft); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--primary, var(--accent-bg)); color: var(--accent-ink); border-color: var(--accent-bg); font-weight: 700; }
button.ghost { background: transparent; }
button.small { padding: 3px 10px; font-size: 13px; }
button.on { border-color: var(--accent); color: var(--accent); }

textarea, input[type=text], input[type=password], input[type=number], select {
  width: 100%; background: var(--field); border: 1px solid var(--field-border); border-radius: var(--radius-sm); padding: 8px 12px;
}
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- theme picker ---------- */
.theme-menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 30; min-width: 220px;
  background: var(--solid, var(--surface)); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-soft); padding: 8px; display: flex; flex-direction: column; gap: 4px;
}
.theme-choice { display: flex; align-items: center; gap: 10px; text-align: left; border-radius: var(--radius-sm);
  background: transparent; border-color: transparent; }
.theme-choice.on { border-color: var(--accent-soft); background: var(--surface-2); }
.swatch { display: inline-flex; }
.swatch i { width: 14px; height: 14px; border-radius: 50%; margin-left: -4px; border: 1.5px solid var(--surface); }
.swatch i:first-child { margin-left: 0; }
.theme-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.theme-row .theme-choice { border-color: var(--border); }
.theme-row .theme-choice.on { border-color: var(--accent); }

/* ==========================================================================
   Layout: the story is a book page
   ========================================================================== */
.layout { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 380px; min-height: 0; }
.story-col { display: flex; flex-direction: column; align-items: center; min-height: 0; padding: 18px 16px 16px; }
.story {
  flex: 1; overflow-y: auto; width: min(100%, 820px);
  padding: 32px clamp(18px, 5vw, 64px) 24px;
  background: var(--page); border: 1px solid var(--border); border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow-soft), var(--edge, 0 0 #0000);
}
.composer {
  display: flex; justify-content: center; gap: 8px; width: min(100%, 820px);
  padding: 12px 16px 14px; background: var(--page); border: 1px solid var(--border); border-top: 1px dashed var(--border);
  border-radius: 0 0 var(--radius) var(--radius); box-shadow: var(--shadow-soft);
}
/* About as wide as the story text, so a message doesn't look lost in a huge box. */
.composer textarea { max-width: 600px; min-height: 112px; max-height: 40vh; resize: vertical;
  border-radius: 18px; padding: 12px 16px; line-height: 1.55; }
.composer button { padding: 10px 20px; white-space: nowrap; }
.composer .send-col { display: flex; flex-direction: column; gap: 6px; align-self: flex-end; }
.composer .send-col .small { padding: 6px 10px; font-size: 12px; }
.composer .send-col #roll-btn.on { border-color: var(--accent-soft); color: var(--accent); font-weight: 700; }
.roll-ask {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; width: min(100%, 820px);
  padding: 10px 16px 0; background: var(--page); border: 1px solid var(--border); border-top: 0; border-bottom: 0;
}
.roll-ask[hidden] { display: none; }
.roll-ask select { flex: 0 1 260px; min-width: 0; }
.roll-ask input { flex: 1 1 220px; min-width: 0; }

.sidebar { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-left: 1px solid var(--border); }
/* Tabs are bookmark ribbons; the open one hangs a little lower. */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; padding: 12px 12px 10px; border-bottom: 1px solid var(--border); }
.tabs button { padding: 5px 9px; font-size: 13px; border-radius: 8px 8px 3px 3px; }
.tabs button.active {
  background: var(--accent-bg); color: var(--accent-ink); border-color: var(--accent-bg);
  padding-bottom: 10px; margin-bottom: -5px;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% calc(100% - 5px), 0 100%);
}
.tabs .gm-tab { margin-left: auto; padding: 5px 7px; border-style: dashed; display: inline-flex; align-items: center; }
.tabs .gm-tab .ico { width: 17px; height: 17px; }
.tabs .gm-tab + .panel-close { margin-left: 4px; }
.panel-btn, .panel-close { display: none; }
.panel { flex: 1; overflow-y: auto; padding: 16px 18px 24px; }

/* ==========================================================================
   Story
   ========================================================================== */
.msg { max-width: 680px; margin: 0 auto 20px; }
.msg.player { text-align: right; }
.msg.player .bubble {
  display: inline-block; text-align: left; background: var(--player); border-radius: 18px 18px 4px 18px;
  padding: 10px 16px; white-space: pre-wrap; max-width: 92%;
}
.msg.gm .text { font: 16px/1.7 var(--story-font); white-space: pre-wrap; }
/* The first page of a chapter starts with a drop cap. */
.msg.gm.opening .text::first-letter {
  float: left; font: 600 3.4em/.85 var(--heading-font); color: var(--accent); padding: 6px 10px 0 0;
}
.msg.arriving { animation: arrive .5s ease-out; }
@keyframes arrive { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg .label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.status { color: var(--muted); font-style: italic; font-size: 14px; }
.status::before { content: "✦ "; font-style: normal; color: var(--accent-soft); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 12px; }
.toolbar .swipes { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 13px; }
.toolbar .sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
/* Facts recorded in a scene (the Chronicle) and choices waiting (Quests): fixable by hand. */
.facts { margin-top: 8px; }
.facts .fact { padding: 3px 0; border-top: 1px dashed var(--border); }
.facts form, .choices-waiting form { margin-top: 6px; }
.grow { flex: 1 1 auto; min-width: 0; }
.choices-waiting { margin-bottom: 14px; }
.choices-waiting input, .facts input { flex: 1 1 160px; min-width: 0; }
.popover { margin-top: 10px; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.popover .row { margin-top: 8px; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: var(--radius-pill); border: 1px solid var(--border); color: var(--muted); }
.badge.accent { border-color: var(--accent-soft); color: var(--accent); }
.badge.good { border-color: var(--good); color: var(--good); }
.badge.bad { border-color: var(--bad); color: var(--bad); }

/* ---------- chapters and scenes ---------- */
.heading { max-width: 680px; margin: 34px auto 18px; text-align: center; color: var(--muted);
  font: italic 17px/1.4 var(--heading-font); letter-spacing: .03em; }
.heading.scene::before {
  content: "☾ ✦ ☽"; display: block; font: 12px/1 var(--ui-font); letter-spacing: .6em; color: var(--accent-soft); margin-bottom: 8px;
}
.heading.chapter { color: var(--accent); font-size: 28px; font-style: italic; font-weight: 600; margin-top: 44px; }
.heading.chapter::before { content: "✦"; display: block; font: 14px/1 var(--ui-font); color: var(--accent-soft); margin-bottom: 10px; }
.heading.chapter::after {
  content: ""; display: block; width: 140px; height: 1px; margin: 12px auto 0;
  background: linear-gradient(90deg, transparent, var(--accent-soft), transparent);
}
.heading:first-child { margin-top: 4px; }
.scene-end, .debrief { max-width: 680px; margin: 12px auto 18px; }
.debrief .talk { margin: 10px 0; display: flex; flex-direction: column; gap: 8px; }
.type-pick { display: grid; gap: 6px; margin-top: 6px; }
.type-pick select { max-width: 100%; }
.progress-strip { display: grid; gap: 4px; margin: 6px 0; }
.debrief .recap { margin: 10px 0 4px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); }
.debrief .recap p { margin: 4px 0 0; font: 15px/1.65 var(--story-font); }
.debrief .say { font-size: 14px; }
.debrief .say.player { color: var(--accent); }
.proposals { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.proposal { border-top: 1px solid var(--border); padding-top: 8px; }
.proposal textarea { margin: 6px 0; }
.dice { margin-top: 8px; color: var(--muted); font-family: var(--ui-font); }
.diary { font: 15px/1.7 var(--story-font); margin: 6px 0; }
.person .stance { gap: 4px; margin: 4px 0; }
.quest-now { margin: 6px 0 2px; }
.threads-panel details { margin: 8px 0; }
.thread-row { padding: 8px 0; border-bottom: 1px dashed var(--border); display: flex; flex-direction: column; gap: 3px; }
.thread-row .thread-name { font-weight: 600; font-size: 14px; }
.thread-meta { flex-wrap: nowrap; align-items: center; }
.thread-row select { max-width: 40%; padding: 3px 8px; font-size: 12px; }
.quest-news { margin: 4px 0; opacity: .85; }
/* The People tab: a framed card per person, text only. */
.person.pp, .quest.pp { position: relative; padding: 12px 14px; margin-bottom: 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--field); display: flex; flex-direction: column; gap: 6px; }
.person.pp:last-child, .quest.pp:last-child { border-bottom: 1px solid var(--border); }
/* Quests in the same frame: sections with small-caps labels, no boxes inside. */
.qq { container-type: inline-size; min-width: 0; }
.qq-status { color: var(--accent); }
.qq-status.good { color: var(--good); }
.qq-status.bad { color: var(--bad, #e07a8a); }
.qq-where::before { content: "⌖ "; opacity: .7; }
.qq-now { font-size: 13px; line-height: 1.45; font-style: italic; }
.qq-sec { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.qq-label { font: 600 10px var(--title-font, var(--ui-font)); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.qq-lines { margin: 0; padding-left: 16px; font-size: 13px; line-height: 1.4; }
.qq-lines li { margin: 1px 0; }
.qq-lines b { font-weight: 600; }
.qq-danger li::marker { color: var(--bad, #e07a8a); }
.qq-news { opacity: .85; }
.qq-text { font-size: 13px; line-height: 1.4; }
.qq-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
@container (max-width: 480px) { .qq-cols { grid-template-columns: minmax(0, 1fr); } }
.qq .pp-menu-list select { width: 100%; }
/* A step inside a main quest: no second frame, just the line down its side. */
.step > .quest.pp { border: 0; border-radius: 0; background: none; box-shadow: none; padding: 6px 0; margin: 0; }
.step .qq-name { font-size: 17px; }
.qq-leads li::marker { content: "◇  "; color: var(--accent); }
.main-title .main-mark { margin-right: 6px; font-size: .8em; vertical-align: 2px; }
.pp.pp-here { border-color: var(--accent-soft); }
.pp-head { display: flex; align-items: flex-start; gap: 8px; }
.pp-names { flex: 1; min-width: 0; }
.pp-name { font: 600 19px/1.2 var(--heading-font); display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.pp-here-dot { font: 600 10px var(--ui-font); letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
.pp-here-dot::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 4px;
  background: var(--accent); box-shadow: 0 0 6px var(--accent); vertical-align: 1px; }
.pp-role { margin-top: 2px; font: 600 11px var(--title-font, var(--ui-font)); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.pp-role > span + span::before { content: "·"; margin: 0 6px; color: var(--muted); }
.pp-what.bad { color: var(--bad, #e07a8a); }
.pp-what.good, .pp-bond { color: var(--good); }
.pp-status { color: var(--accent); }
.pp-feel { display: flex; flex-wrap: wrap; gap: 4px; }
.pp-chip { font-size: 11px; padding: 1px 8px; border-radius: var(--radius-pill); border: 1px solid var(--border); color: var(--muted); }
.pp-att.bad { color: var(--bad, #e07a8a); border-color: currentColor; }
.pp-att.good { color: var(--good); border-color: currentColor; }
.pp-alias { font-size: 12px; font-style: italic; color: var(--muted); }
.pp-desc { font-size: 13px; line-height: 1.45; cursor: pointer; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pp-desc.open { display: block; }
.pp-menu { position: relative; flex-shrink: 0; }
.pp-menu > summary { list-style: none; cursor: pointer; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%;
  border: 1px solid var(--border); font-size: 18px; line-height: 1; color: var(--muted); }
.pp-menu > summary::-webkit-details-marker { display: none; }
.pp-menu[open] > summary { color: var(--accent); border-color: var(--accent-soft); }
.pp-menu-list { position: absolute; right: 0; top: 36px; z-index: 5; display: flex; flex-direction: column; gap: 4px; padding: 6px;
  min-width: 130px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--solid, var(--surface)); box-shadow: var(--shadow-soft); }
.pp-menu-list button { justify-content: flex-start; text-align: left; }
/* The plan the reply on screen was written from. */
.plan.in-use { border-left: 3px solid var(--accent); padding-left: 12px; background: var(--surface-2); border-radius: var(--radius-sm); }
.plan-notes { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.judgement { margin: 6px 0; padding: 6px 10px; background: var(--field); border-radius: var(--radius-sm); }
.subtabs { display: flex; flex-wrap: wrap; gap: 4px; margin: 10px 0 4px; }
.subtabs button.on { background: var(--surface-2); border-color: var(--accent); color: var(--accent); }
.debug-inline { margin-top: 10px; padding: 6px 12px; border-left: 2px solid var(--accent-soft); color: var(--muted);
  font-family: var(--ui-font); }
.panel details summary .badge { margin-left: 6px; }
.panel select { margin-bottom: 6px; }

/* ==========================================================================
   Side panels
   ========================================================================== */
.panel h2 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 20px 0 8px; }
.panel h2::before { content: "✦ "; color: var(--accent-soft); }
.panel h2:first-child { margin-top: 0; }
.panel h3 { margin: 0 0 2px; font: 600 19px/1.3 var(--heading-font); }
.panel p { margin: 4px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.empty { color: var(--muted); font-style: italic; text-align: center; padding: 18px 8px; }
.empty::before { content: "☾"; display: block; font-style: normal; font-size: 22px; color: var(--accent-soft); margin-bottom: 6px; }
.item, .person, .entry, .quest, .plan { padding: 12px 0; border-bottom: 1px dashed var(--border); }
.item:last-child, .person:last-child, .entry:last-child { border-bottom: 0; }
/* A quest card: the hook on top, the goals beside where, people & clues beside dangers, how it can end. */
.quest-card { display: flex; flex-direction: column; gap: 10px; container-type: inline-size; min-width: 0; }
.quest-hook { padding: 10px 12px; border: 1px solid var(--accent-soft); border-radius: var(--radius); background: var(--field); }
.quest-hook b { font-size: 15px; }
.quest-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 4px; }
.quest-top { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 38%); gap: 10px; align-items: start; }
.quest-top > :only-child { grid-column: 1 / -1; }
.quest-where, .quest-col { padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); }
.quest-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.quest-end { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border-radius: var(--radius); background: var(--surface); }
.quest-lines { margin: 0; padding-left: 18px; font-size: 13px; }
.quest-goals { list-style: none; margin: 0; padding: 0; font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
.quest-goals label.row { align-items: flex-start; cursor: pointer; flex-wrap: nowrap; }
.quest-goals label > span:first-of-type { min-width: 0; }
/* Done: a filled green tick and the text struck through; open: an empty box and full-strength text. */
.quest-goals input { width: 18px; height: 18px; margin: 1px 0 0; flex: none; accent-color: var(--good); cursor: pointer; }
.quest-goals li.done span:not(.badge) { text-decoration: line-through; color: var(--muted); }
/* A quest in progress stands out; a finished or dropped one steps back. */
.quest-card:not(.muted-quest) .quest-hook { border-color: var(--accent); }
.muted-quest { opacity: .75; }
.muted-quest .quest-hook { background: transparent; border-style: dashed; border-color: var(--border); }
.quest-actions { flex-wrap: wrap; }
.quest-goals .badge { flex: none; }
/* A main quest holds its steps: the one in play open, done ones folded to a line. */
.quest-tools { margin-bottom: 10px; }
.main-quest { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--accent);
  border-radius: var(--radius); background: var(--field); margin-bottom: 12px; }
.main-title { font: 600 18px/1.2 var(--heading-font); }
.main-mark { color: var(--accent); }
.main-question { font-style: italic; color: var(--muted); }
.step { border-left: 2px solid var(--border); padding-left: 10px; }
.now-step { border-left-color: var(--accent); }
.now-step > .quest { border-bottom: 0; padding: 4px 0; }
.done-step summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.done-step .step-tick { display: inline-block; width: 1.2em; color: var(--good); }
.done-step[open] > .quest { opacity: .8; }
.leads li { margin: 2px 0; }
.quest-actions select { width: auto; max-width: 100%; }
@media (max-width: 520px) {
  .quest-top, .quest-cols { grid-template-columns: minmax(0, 1fr); }
}
/* Side by side only where the card itself is wide: the panel beside the story is narrow
   on any screen, and two columns there left a few words per line. */
@container (max-width: 560px) {
  .quest-top, .quest-cols { grid-template-columns: minmax(0, 1fr); }
}
.attrs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.attr { background: var(--field); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; text-align: center; }
.attr .n { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.attr .s { font: 600 26px/1.1 var(--heading-font); }
.attr .m { font-size: 13px; font-weight: 700; color: var(--accent); }
.attr.pick { cursor: pointer; }
.attr.selected { border-color: var(--accent); background: var(--surface-2); }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; font-size: 14px; }
.kv .k { color: var(--muted); }
details summary { cursor: pointer; color: var(--muted); margin: 6px 0; }
pre.json { white-space: pre-wrap; font-size: 12px; background: var(--field); padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.warn { border: 1px dashed var(--accent-soft); border-radius: var(--radius-sm); padding: 8px 12px; color: var(--accent); font-size: 13px; }

/* ==========================================================================
   Stories screen and creation wizard
   ========================================================================== */
.screen { flex: 1; overflow-y: auto; padding: 36px 16px; }
.card { max-width: 640px; margin: 0 auto; background: var(--page); border: 1px solid var(--border); border-radius: 22px;
  padding: 28px; box-shadow: var(--shadow-soft), var(--edge, 0 0 #0000); backdrop-filter: blur(var(--blur, 0px)); }
.card.wide { max-width: 760px; }
.card h1 { margin: 0 0 6px; font: italic 600 36px/1.15 var(--heading-font); color: var(--accent); }
.card h2 { margin: 0 0 4px; font: italic 600 28px/1.2 var(--heading-font); color: var(--accent); }
.list { display: flex; flex-direction: column; gap: 8px; margin: 16px 0; }
.list .choice { text-align: left; padding: 12px 16px; border-radius: var(--radius); }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.progress { height: 6px; background: var(--surface-2); border-radius: var(--radius-pill); overflow: hidden; margin: 6px 0 18px; }
.progress div { height: 100%; background: var(--accent-bg); border-radius: var(--radius-pill); }
.section-name { color: var(--accent); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; }
.question { font: 500 24px/1.3 var(--heading-font); margin: 6px 0 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { border-radius: var(--radius-pill); padding: 4px 12px; font-size: 14px; }
.chip.on { border-color: var(--accent); color: var(--accent); }
.classes { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin: 12px 0; }
.class-card { text-align: left; padding: 14px; border-radius: var(--radius); font-weight: 500; }
.class-card.on { border-color: var(--accent); background: var(--surface-2); }
.class-card b { display: block; margin-bottom: 4px; font: 600 19px/1.2 var(--heading-font); }
.kit-row { display: grid; grid-template-columns: 1fr 70px 32px; gap: 6px; margin-bottom: 6px; }
.kit-row textarea { grid-column: 1 / span 3; }
.field-label { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin: 12px 0 4px; }
.loading { padding: 32px 0; text-align: center; color: var(--muted); font-style: italic; }
.loading::before { content: "✦ ✦ ✦"; display: block; font-style: normal; letter-spacing: .5em; color: var(--accent-soft);
  margin-bottom: 8px; animation: twinkle 1.2s ease-in-out infinite alternate; }

.toast {
  left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(90vw, 560px);
  background: var(--solid, var(--surface-2)); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 18px;
  box-shadow: var(--shadow-soft);
}
.toast.error { border-color: var(--bad); }
/* The game's code changed under an open page: at the top, until the page reloads. */
.toast.stale { top: calc(12px + env(safe-area-inset-top, 0px)); bottom: auto; border-color: var(--accent);
  display: flex; gap: 10px; align-items: center; }

/* Short windows: a smaller writing box, so the story keeps the room. */
@media (max-height: 640px) {
  .composer textarea { min-height: 64px; }
}

@media (prefers-reduced-motion: reduce) {
  body::before, .loading::before, .msg.arriving { animation: none; }
  button { transition: none; }
}

/* ---------- narrow screens ---------- */
@media (max-width: 900px) {
  /* The story has the whole screen; the side panel is a drawer over it. */
  .layout { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr); }
  .story-col { position: relative; min-height: 0; padding: 8px 8px 8px; }
  .story { padding: 20px 16px; }
  .panel-btn { display: grid; place-items: center; position: absolute; top: 16px; right: 16px; z-index: 6;
    width: 38px; height: 38px; padding: 0; border-radius: 50%; background: var(--solid, var(--surface)); box-shadow: var(--shadow-soft); }
  .panel-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
  .sidebar { position: fixed; inset: 0; z-index: 50; border-left: 0; background: var(--solid, var(--surface)); }
  .sidebar.collapsed { display: none; }
  /* The open drawer covers the top bar too (the shell is its own layer under the bar). */
  .shell:has(#sidebar:not(.collapsed)) { z-index: 6; }
  .tabs { align-items: center; padding-top: calc(10px + env(safe-area-inset-top, 0px)); }
  .panel-close { display: block; margin-left: auto; padding: 4px 10px; font-size: 16px; }
  .top-actions button { padding: 5px 9px; font-size: 13px; }
  .session-title { display: none; }
  .brand { font-size: 19px; }
  .brand .tagline { display: none; }
  .heading.chapter { font-size: 24px; }
}

/* ---------- phones ----------
   Nothing may be wider than the screen: a page that is makes the phone's browser shrink
   all of it to fit, which leaves an empty band under the tabs. */
@media (max-width: 600px) {
  .topbar { gap: 8px; padding: 8px 10px; justify-content: space-between; }
  /* The library bar runs across the top, not down the side: the story keeps its width. */
  .shell { flex-direction: column; }
  .rail, body.in-game .rail { width: auto; flex-direction: row; align-items: center; gap: 4px; padding: 4px 8px;
    overflow-x: auto; overflow-y: hidden; border-right: 0; border-bottom: 1px solid var(--border); }
  .rail .label { display: none; }
  .rail button, body.in-game .rail button { justify-content: center; padding: 7px 14px; }
  .rail svg { width: 19px; height: 19px; }
  .rail button.active { box-shadow: inset 0 -2px 0 var(--accent); }
  .screen { padding: 20px 12px; }
  .tiles { grid-template-columns: 1fr; gap: 14px; }
  .tile { padding: 18px; }
  .library-title { font-size: 27px; }
  .portrait { width: 96px; height: 130px; font-size: 36px; }
  /* On a phone the portrait stands above the sheet. */
  .char-tile { flex-direction: column; align-items: center; gap: 12px; }
  .char-tile .body { align-self: stretch; }
  .brand { font-size: 17px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .top-actions { gap: 5px; flex-shrink: 0; }
  .top-actions button { padding: 5px 10px; }
  .top-actions .long { display: none; }
  /* The writing box gets the whole width; the buttons sit in a slim row under it. */
  .composer { flex-wrap: wrap; padding: 8px 8px 10px; gap: 6px; }
  .composer textarea { flex: 1 1 100%; max-width: none; min-height: 84px; padding: 10px 14px; }
  .composer .send-col { flex-direction: row; flex-wrap: wrap; justify-content: flex-end; align-items: center; width: 100%; align-self: auto; }
  .composer .send-col button { padding: 7px 16px; }
  .composer .send-col .small { min-width: 0; }
  .composer .send-col #send { order: 2; }       /* Send at the right edge, under the thumb */
  .composer .send-col .small { padding: 6px 12px; }
  .roll-ask { padding: 8px 8px 0; }
  .story-col, .story, .composer, .sidebar, .tabs, .panel { min-width: 0; max-width: 100%; }
  /* A smaller reading size on a phone. */
  .msg.gm .text { font-size: 15px; line-height: 1.65; }
  .msg.player .bubble { font-size: 14px; }
  .story { padding: 16px 14px; }
  .msg { margin-bottom: 16px; }
}

/* The settings menu and the Data tab's export options. */
.theme-menu { max-height: min(80vh, 560px); overflow-y: auto; min-width: 260px; }
.menu-head { font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 8px 4px 2px; }
.menu-head:first-child { margin-top: 2px; }
.theme-menu select { max-width: 160px; }
.row.wrap { flex-wrap: wrap; }
.setting-input { width: 110px; }

/* The Director's scene plan. */
.scene-plan { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface-2); margin-bottom: 8px; }
.scene-plan .situations { margin: 2px 0 0 18px; padding: 0; }
.scene-plan { font-size: 14px; }
.plan-section { margin-top: 10px; }
.plan-heading { font-weight: 600; margin-bottom: 6px; color: var(--accent); }
.plan-item { padding: 8px 10px; border-left: 3px solid var(--border); background: var(--surface); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.plan-item + .plan-item { margin-top: 10px; }
.plan-name { font-weight: 600; margin-bottom: 3px; }
.plan-field { margin: 2px 0 0 0; line-height: 1.45; }
.plan-label { font-weight: 600; margin-right: 6px; }
.plan-label::after { content: ":"; }
textarea.plan-text { width: 100%; min-height: 480px; font: 14px/1.55 inherit; box-sizing: border-box; resize: vertical; }
/* Markdown blocks: paragraphs with room, headings, lists. */
.md p { margin: 0 0 .7em; }
.md p:last-child { margin-bottom: 0; }
.md ul { margin: 0 0 .7em 18px; padding: 0; }
.md h3, .md h4, .md h5, .md h6 { margin: .8em 0 .3em; font-size: 1em; }


/* ---------- the landing page (signed out) and Home ---------- */
.landing { max-width: 860px; margin: 0 auto; }
.land-hero { text-align: center; padding: 5vh 0 24px; }
.land-moon { display: block; width: 40px; height: 60px; margin: 0 auto 10px; fill: none; stroke: var(--accent); stroke-width: 1.4; }
.land-moon .star { fill: var(--accent); stroke: none; }
.land-title { margin: 0; font: 500 clamp(40px, 7vw, 56px)/1.05 var(--heading-font); color: var(--accent); }
.land-tag { margin: 6px 0 0; font: italic 500 20px var(--heading-font); color: var(--muted); }
.land-pitch { max-width: 500px; margin: 16px auto 26px; font-size: 16px; line-height: 1.6; }
.land-hero #login-card { max-width: 380px; text-align: left; }
.beta-note { margin-bottom: 12px; text-align: center; font: 600 11px var(--title-font); letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.ch-num { font: 600 12px var(--title-font); letter-spacing: .2em; text-transform: uppercase; color: var(--muted); text-align: center; margin-bottom: 6px; }
.prologue { max-width: 620px; margin: 48px auto; font: 16px/1.75 var(--story-font); }
.prologue p { margin: 0 0 1em; }
.chapter { margin: 64px 0; }
.ch-head { margin-bottom: 18px; }
.ch-title { margin: 0; text-align: center; font: 500 34px/1.15 var(--heading-font); color: var(--accent); }
.ch-figure { margin: 0 0 22px; }
.plate { position: relative; display: grid; place-items: center; aspect-ratio: 16 / 9; border-radius: 18px; overflow: hidden;
  border: 1px solid var(--border); background: radial-gradient(ellipse at 30% 20%, var(--accent-soft), transparent 60%), var(--surface);
  background-size: cover; background-position: center; }
.plate.has-pic .plate-empty { display: none; }
.plate-empty { font: 600 12px var(--title-font); letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.caption { margin-top: 8px; text-align: center; font: italic 500 15px var(--heading-font); color: var(--muted); }
.ch-scene { max-width: 620px; margin: 0 auto; font: 16px/1.7 var(--story-font); }
.ch-scene p { margin: 0 0 1em; }
.ch-scene .you { font-style: italic; color: var(--muted); border-left: 2px solid var(--accent-soft); padding-left: 14px; }
.ch-dice { display: flex; align-items: center; gap: 8px; width: fit-content; margin: 0 auto 1em; padding: 4px 14px; border-radius: var(--radius-pill);
  border: 1px solid var(--accent-soft); font: 600 13px var(--ui-font); color: var(--accent); }
.footnote { max-width: 620px; margin: 6px auto 0; padding-top: 12px; border-top: 1px solid var(--border); font-size: 14px; line-height: 1.55; color: var(--muted); }
.fn-mark { color: var(--accent); margin-right: 8px; }
.land-faq { max-width: 620px; margin: 64px auto 0; }
.faq details { border-bottom: 1px solid var(--border); padding: 12px 4px; }
.faq summary { cursor: pointer; font: 600 19px/1.3 var(--heading-font); }
.faq details p { margin: 8px 0 2px; color: var(--muted); }
.land-foot { margin: 48px 0 8px; text-align: center; font-size: 13px; color: var(--muted); }

/* ==========================================================================
   The landing page, "edge" style: a sample story whose page breaks off like a cliff,
   then what the game does. Built from the theme's tokens, so it follows every look.
   ========================================================================== */
.edge-land { --edge: var(--bad); max-width: 1080px; margin: 0 auto; padding-bottom: 8px; }
.edge-land h1, .edge-land h2, .edge-land h3 { margin: 0; text-wrap: balance; }
.edge-land p { margin: 0; }
.edge-label { font: 600 12px var(--title-font); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.edge-nav { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; padding: 18px 0; }
.edge-brand { display: flex; align-items: baseline; gap: 4px; font: 400 36px/1.2 "Pinyon Script", var(--heading-font); color: var(--accent); }
.edge-brand i { display: inline-block; width: 14px; height: 3px; background: var(--edge); transform: translateY(-7px) rotate(-14deg); }
.edge-links { display: flex; gap: 6px; }
.edge-links button { background: none; border: 0; color: var(--muted); font: 600 14px var(--ui-font); cursor: pointer; padding: 6px 8px; }
.edge-links button:hover { color: var(--text); }

.edge-hero { display: grid; grid-template-columns: 1.05fr 1fr; gap: 48px; align-items: start; padding: 28px 0 64px; }
.edge-hero > * { min-width: 0; }
.edge-title { margin-top: 12px !important; font: 600 clamp(44px, 7vw, 88px)/1 var(--heading-font); letter-spacing: -.01em; color: var(--text); }
.edge-dot { position: relative; white-space: nowrap; font-style: italic; color: var(--accent); }
.edge-dot::after { content: ""; position: absolute; right: -.14em; bottom: .12em; width: .12em; height: .12em; border-radius: 50%; background: var(--edge); }
.edge-lede { margin-top: 20px !important; max-width: 40ch; font: 17px/1.65 var(--story-font); color: var(--muted); }
#edge-card-slot { margin-top: 26px; }
#edge-card-slot #login-card { max-width: 420px; margin: 0; }

.edge-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.edge-chip { padding: 6px 14px; border-radius: var(--radius-pill); border: 1px solid var(--border); background: transparent; color: var(--muted); font: 600 13px var(--ui-font); cursor: pointer; }
.edge-chip[aria-pressed="true"] { background: var(--accent-bg); color: var(--accent-ink); border-color: var(--accent-bg); }
.edge-sheet { display: flex; flex-direction: column; gap: 16px; min-height: 360px; padding: 28px 28px 64px; background: var(--page);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 26px), 91% calc(100% - 8px), 80% calc(100% - 30px), 66% calc(100% - 4px), 52% calc(100% - 24px), 38% 100%, 24% calc(100% - 22px), 11% calc(100% - 6px), 0 calc(100% - 28px)); }
.edge-meta { display: flex; justify-content: space-between; gap: 12px; }
.edge-text { font: 18px/1.7 var(--story-font); color: var(--text); }
.edge-text p + p { margin-top: 14px; }
.edge-hook { font-style: italic; font-weight: 600; }
.edge-hook::after { content: ""; display: inline-block; width: .55em; height: 2px; margin-left: 4px; vertical-align: middle; background: var(--edge); }
.edge-tbc { font: 600 12px var(--title-font); letter-spacing: .14em; text-transform: uppercase; color: var(--edge); }
.edge-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.edge-hint { font-size: 13px; color: var(--muted); }
.edge-rise { animation: edge-rise .5s ease both; }
@keyframes edge-rise { from { opacity: .15; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.edge-section { padding: 64px 0; border-top: 1px solid var(--border); }
.edge-head { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; align-items: end; margin-bottom: 36px; }
.edge-head > * { min-width: 0; }
.edge-head h2, .edge-drop h2 { font: 600 clamp(32px, 4.4vw, 50px)/1.05 var(--heading-font); color: var(--text); }
.edge-head p { max-width: 46ch; color: var(--muted); font-size: 16px; line-height: 1.6; }
.edge-term { font: 600 12px var(--title-font); letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
.edge-land h3 { font: 600 22px/1.2 var(--heading-font); color: var(--text); }

.edge-shelf { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.edge-spine { position: relative; display: flex; flex-direction: column; gap: 10px; min-width: 0; padding: 24px 22px 26px 30px; border-radius: 6px var(--radius) var(--radius) 6px;
  background: var(--surface); border: 1px solid var(--border); }
.edge-spine::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 7px; border-radius: 6px 0 0 6px; background: var(--accent-soft); }
.edge-spine:nth-child(2)::before { background: var(--accent); }
.edge-spine:nth-child(3)::before { background: var(--edge); }
.edge-spine p, .edge-feature p, .edge-promises p { color: var(--muted); font-size: 15px; line-height: 1.6; }

.edge-features { display: grid; grid-template-columns: repeat(2, 1fr); border-top: 1px solid var(--border); }
.edge-feature { display: grid; grid-template-columns: 140px 1fr; gap: 20px; padding: 26px 26px 26px 0; border-bottom: 1px solid var(--border); }
.edge-feature:nth-child(odd) { border-right: 1px solid var(--border); }
.edge-feature:nth-child(even) { padding: 26px 0 26px 26px; }
.edge-feature > * { min-width: 0; }
.edge-feature .edge-term { padding-top: 5px; }
.edge-feature h3 { margin-bottom: 6px; }

.edge-promises { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 26px 40px; }
.edge-promises li { display: grid; grid-template-columns: 26px 1fr; gap: 8px; min-width: 0; }
.edge-promises li > * { min-width: 0; }
.edge-mark { font: 700 22px/1.1 var(--heading-font); color: var(--edge); }
.edge-promises h3 { font-size: 20px; margin-bottom: 4px; }
#edge-faq .faq { max-width: 720px; }

.edge-drop { display: grid; gap: 18px; justify-items: start; margin-top: 8px; padding: 72px 40px 36px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); }
.edge-drop h2 { font-size: clamp(40px, 6.4vw, 80px); }
.edge-drop > p { color: var(--muted); font-size: 17px; }
.edge-foot { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; width: 100%; margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.land-style { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.land-style button[aria-pressed="true"] { background: var(--accent-bg); color: var(--accent-ink); border-color: var(--accent-bg); }
.land-foot .land-style { display: flex; justify-content: center; margin-top: 12px; }

[data-theme="moonwind"] .edge-brand { color: #f4f0ff; text-shadow: 0 0 22px rgba(180, 165, 255, .45); }
[data-theme="moonwind"] .edge-title { color: #f4f0ff; text-shadow: 0 2px 14px rgba(5, 6, 20, .6); }
[data-theme="moonwind"] .edge-sheet { background: linear-gradient(180deg, rgba(40, 46, 104, .74), rgba(22, 27, 70, .8)); }
[data-theme="moonwind"] .edge-spine, [data-theme="moonwind"] .edge-drop { border-color: rgba(206, 200, 255, .28); }

@media (max-width: 860px) {
  .edge-hero, .edge-head { grid-template-columns: 1fr; }
  .edge-hero { gap: 32px; padding-top: 8px; }
  .edge-shelf, .edge-features, .edge-promises { grid-template-columns: 1fr; }
  .edge-feature, .edge-feature:nth-child(even) { padding: 22px 0; border-right: 0; }
  .edge-links { display: none; }
  .edge-drop { padding: 48px 22px 28px; }
}
@media (max-width: 480px) {
  .edge-feature { grid-template-columns: 1fr; gap: 6px; }
  .edge-sheet { padding: 22px 20px 56px; }
}
@media (prefers-reduced-motion: reduce) { .edge-rise { animation: none; } }
.home-go { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 8px; }
.home-h { margin: 34px 0 12px; font: 600 13px var(--title-font); letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.home-look { margin-top: 34px; }
#home .faq { max-width: 760px; }

/* ==========================================================================
   Moonwind: the forest at night (art/), frames of moons and flowers, glass.
   Everything here is Moonwind only; the other looks never see it.
   ========================================================================== */
[data-theme="moonwind"] {
  /* Only here, not in the default block above, so other looks never inherit them. */
  --solid: #171c45;           /* menus and messages over the page stay opaque */
  --primary: linear-gradient(135deg, #e3e2fa, #a9adec);
  --edge: inset 0 1px 0 rgba(255, 255, 255, .07);
  --blur: 16px;
  --glow: linear-gradient(rgba(10, 13, 36, .30), rgba(10, 13, 36, .55)), url("/static/art/bg-forest.webp") center / cover no-repeat;
  --frame: rgba(186, 180, 240, .55);
}
/* While playing, the forest dims so the story reads easily. */
[data-theme="moonwind"] body.in-game {
  --glow: linear-gradient(rgba(8, 10, 30, .62), rgba(8, 10, 30, .72)), url("/static/art/bg-forest.webp") center / cover no-repeat;
}
[data-theme="moonwind"] body::before { opacity: .55; }

/* The top bar: night glass, the moon and the name, outlined buttons with icons. */
[data-theme="moonwind"] .topbar { background: rgba(10, 13, 38, .38); border-bottom-color: rgba(186, 180, 240, .14); padding: 12px 22px; }
[data-theme="moonwind"] .brand { font: 500 27px/1 var(--heading-font); font-style: normal; letter-spacing: .01em; color: #ece9ff; }
[data-theme="moonwind"] .brand-moon { width: 30px; height: 30px; fill: #d9d4fb; filter: drop-shadow(0 0 8px rgba(190, 180, 255, .55)); }
[data-theme="moonwind"] .top-actions button { background: rgba(18, 22, 58, .38); border-color: rgba(190, 186, 245, .38); padding: 8px 16px; color: #e6e3fb; }
[data-theme="moonwind"] .top-actions button:hover { border-color: rgba(214, 208, 255, .75); box-shadow: 0 0 16px -6px rgba(180, 170, 255, .7); }

/* The rail: a floating glass panel, the open page a glowing pill, a moon below. */
[data-theme="moonwind"] .rail { margin: 14px 0 14px 14px; border-radius: 24px; border: 1px solid rgba(186, 180, 240, .26);
  background: linear-gradient(180deg, rgba(22, 26, 66, .55), rgba(14, 16, 44, .38)); box-shadow: 0 0 30px -14px rgba(150, 140, 255, .5); padding-top: 22px; }
[data-theme="moonwind"] .rail button { font: 500 17px var(--heading-font); color: #d8d5f3; border-radius: 16px; }
[data-theme="moonwind"] .rail button.active { color: #fbfaff; border-color: rgba(206, 200, 255, .55); box-shadow: 0 0 20px -6px rgba(170, 160, 255, .75), inset 0 1px 0 rgba(255, 255, 255, .14);
  background: linear-gradient(90deg, rgba(160, 150, 240, .42), rgba(150, 140, 235, .16)); }
[data-theme="moonwind"] .rail button.active svg { fill: rgba(240, 238, 255, .9); }
[data-theme="moonwind"] .rail-moon { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 0 auto 18px; color: #d9d4fb; }
[data-theme="moonwind"] .rail-moon i { width: 1px; height: 46px; background: linear-gradient(transparent, rgba(214, 208, 255, .6), transparent); }
[data-theme="moonwind"] .rail-moon i:first-child { height: 70px; }
[data-theme="moonwind"] .rail-moon svg { width: 30px; height: 30px; fill: #ddd8fc; filter: drop-shadow(0 0 10px rgba(190, 180, 255, .7)); }
[data-theme="moonwind"] body.in-game .rail-moon { display: none; }

/* A page's hero: the forest steps behind its title, fading into the night. */
[data-theme="moonwind"] .library { max-width: 1120px; }
[data-theme="moonwind"] .hero { position: relative; isolation: isolate; display: flex; align-items: center; gap: 18px;
  min-height: 220px; margin: -20px 0 34px; padding: 30px 32px 34px 18px; }
[data-theme="moonwind"] .hero::before { content: ""; position: absolute; inset: 0 -16px 0 0; z-index: -1; border-radius: 0 26px 26px 0;
  background: url("/static/art/banner-forest.webp") right center / cover no-repeat;
  -webkit-mask-image: linear-gradient(90deg, transparent 0%, rgba(0, 0, 0, .55) 28%, #000 55%), linear-gradient(0deg, transparent 0%, #000 30%);
  -webkit-mask-composite: source-in; mask-image: linear-gradient(90deg, transparent 0%, rgba(0, 0, 0, .55) 28%, #000 55%), linear-gradient(0deg, transparent 0%, #000 30%);
  mask-composite: intersect; opacity: .92; }
[data-theme="moonwind"] .hero-mark { display: block; width: 46px; height: 70px; flex-shrink: 0; fill: none; stroke: #d6d0fa; stroke-width: 1.4;
  filter: drop-shadow(0 0 8px rgba(190, 180, 255, .6)); }
[data-theme="moonwind"] .hero-mark .star { fill: #f2efff; stroke: none; }
[data-theme="moonwind"] .hero .library-title { font: 500 52px/1.04 var(--heading-font); letter-spacing: .01em; color: #f4f0ff;
  text-shadow: 0 0 26px rgba(180, 165, 255, .45), 0 2px 10px rgba(5, 6, 20, .6); }
[data-theme="moonwind"] .hero .library-sub { margin: 10px 0 0; max-width: 520px; font: italic 500 19px/1.35 var(--heading-font); color: #dcd8f6;
  text-shadow: 0 1px 8px rgba(5, 6, 20, .8); }

/* Tiles: framed glass. */
[data-theme="moonwind"] .tiles { gap: 46px 30px; padding: 18px 14px 30px; }
[data-theme="moonwind"] .tile { --k: .34; overflow: visible; border-radius: 22px; padding: 30px 42px 28px; border: 1.5px solid var(--frame);
  background:
    radial-gradient(circle at 100% 0%, rgba(150, 120, 230, .22), transparent 50%),
    radial-gradient(circle at 0% 100%, rgba(190, 80, 200, .14), transparent 45%),
    linear-gradient(160deg, rgba(42, 44, 100, .62), rgba(16, 18, 50, .70));
  box-shadow: 0 0 0 1px rgba(120, 110, 220, .12), 0 0 26px -8px rgba(160, 150, 255, .55), var(--shadow-soft), inset 0 1px 0 rgba(255, 255, 255, .08); }
[data-theme="moonwind"] button.tile:hover, [data-theme="moonwind"] .tile.open:hover { border-color: rgba(214, 208, 255, .85);
  box-shadow: 0 0 0 1px rgba(170, 160, 255, .3), 0 0 34px -6px rgba(170, 160, 255, .75), var(--shadow-soft); }
[data-theme="moonwind"] .tile-name { color: #ece8ff; font-weight: 500; letter-spacing: .06em; }
[data-theme="moonwind"] .tile .facts dt { font: 500 12px var(--title-font); letter-spacing: .1em; color: #b7b3dc; padding-top: 4px; }
[data-theme="moonwind"] .tile .facts dd { font: 500 17px var(--heading-font); color: #eceaff; }
[data-theme="moonwind"] .tile { font-variant-numeric: lining-nums; }
[data-theme="moonwind"] .tile .clamp { font: 500 17px/1.3 var(--heading-font); color: #dcd9f2; }
[data-theme="moonwind"] .tile .when { font: italic 500 15px var(--heading-font); color: #aeaad3; }
[data-theme="moonwind"] .tile .actions button { font: 500 16px var(--heading-font); }
[data-theme="moonwind"] .tile .actions button.ghost { border-color: rgba(196, 190, 245, .5); color: #e6e3fb; }
[data-theme="moonwind"] .tile .badge { top: 18px; right: 22px; }
[data-theme="moonwind"] .profile { border: 1.5px solid rgba(206, 200, 255, .55); border-radius: 6px;
  background: radial-gradient(ellipse at 50% 0%, rgba(120, 110, 220, .18), transparent 60%), linear-gradient(160deg, #10112a, #07081a 70%);
  box-shadow: 0 0 0 4px rgba(10, 11, 30, .9), 0 0 0 5px rgba(206, 200, 255, .35), 0 0 34px -6px rgba(170, 160, 255, .6), var(--shadow-soft); }
[data-theme="moonwind"] .pf-label { color: #f2f0ff; text-shadow: 0 2px 14px #000; }
[data-theme="moonwind"] .pf-script { font: 400 40px/1.25 "Pinyon Script", var(--heading-font); color: #f6f4ff; text-shadow: 0 2px 14px #000; }
[data-theme="moonwind"] .pf-world-name, [data-theme="moonwind"] .pf-block h4, [data-theme="moonwind"] .pf-who-head { color: #ece8ff; }
[data-theme="moonwind"] .pf-block h4 { font: 500 26px "Cormorant Garamond", serif; }
[data-theme="moonwind"] .pf-text { color: #d6d3ee; font: 500 14.5px/1.4 var(--heading-font); }
[data-theme="moonwind"] .pf-eyes, [data-theme="moonwind"] .pf-world-art { border: 2px solid rgba(225, 222, 255, .8); box-shadow: 0 0 14px -4px rgba(190, 180, 255, .8); }
[data-theme="moonwind"] .pf-crest { border: 1.5px solid rgba(225, 222, 255, .8); box-shadow: 0 0 18px -4px rgba(200, 190, 255, .9); }
[data-theme="moonwind"] .pc-id .pf-script { font-size: 36px; }
[data-theme="moonwind"] .pp { border-color: rgba(206, 200, 255, .28); border-radius: 6px;
  background: linear-gradient(160deg, rgba(30, 32, 78, .55), rgba(10, 11, 32, .7)); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05); }
[data-theme="moonwind"] .pp.pp-here { border-color: rgba(206, 200, 255, .6); box-shadow: 0 0 18px -8px rgba(170, 160, 255, .8), inset 0 1px 0 rgba(255, 255, 255, .06); }
[data-theme="moonwind"] .pp-name { font: 500 22px/1.15 "Cormorant Garamond", serif; color: #f0eeff; }
[data-theme="moonwind"] .pp-desc { font: 500 15px/1.4 var(--heading-font); color: #d6d3ee; }
[data-theme="moonwind"] .step > .quest.pp { background: none; box-shadow: none; }
[data-theme="moonwind"] .step .qq-name { font-size: 19px; }
[data-theme="moonwind"] .main-quest.pp { border-color: rgba(206, 200, 255, .55); }
[data-theme="moonwind"] .qq-now { font: italic 500 15px/1.4 var(--heading-font); color: #d6d3ee; }
[data-theme="moonwind"] .pp-chip { border-color: rgba(206, 200, 255, .25); color: #c4c0e6; }
[data-theme="moonwind"] .pc-face { border-color: rgba(206, 200, 255, .7); box-shadow: 0 0 22px -6px rgba(170, 160, 255, .7); }

/* The frame's pieces, cut from one picture. Its lines run at x 54 and y 138.5 of 1774×887. */
[data-theme="moonwind"] .orn { display: block; position: absolute; z-index: 3; pointer-events: none;
  background: url("/static/art/frame-moon.webp") no-repeat; background-size: calc(1774px * var(--k)) auto; }
[data-theme="moonwind"] .orn.c { width: calc(190px * var(--k)); height: calc(200px * var(--k));
  background-position: calc(-30px * var(--k)) calc(-120px * var(--k)); }
[data-theme="moonwind"] .orn.tl { left: calc(-24px * var(--k)); top: calc(-18.5px * var(--k)); }
[data-theme="moonwind"] .orn.tr { right: calc(-24px * var(--k)); top: calc(-18.5px * var(--k)); transform: scaleX(-1); }
[data-theme="moonwind"] .orn.bl { left: calc(-24px * var(--k)); bottom: calc(-18.5px * var(--k)); transform: scaleY(-1); }
[data-theme="moonwind"] .orn.br { right: calc(-24px * var(--k)); bottom: calc(-18.5px * var(--k)); transform: scale(-1, -1); }
[data-theme="moonwind"] .orn.m { width: calc(295px * var(--k)); height: calc(195px * var(--k)); left: 50%;
  margin-left: calc(-147.5px * var(--k)); background-position: calc(-740px * var(--k)) calc(-30px * var(--k)); }
[data-theme="moonwind"] .orn.mt { top: calc(-108.5px * var(--k)); }

/* The "new" tile: a starred ring between crescents. */
[data-theme="moonwind"] .tile.new { border-style: solid; gap: 6px; }
[data-theme="moonwind"] .tile.new .plus { display: none; }
[data-theme="moonwind"] .new-art { display: block; width: min(100%, 340px); height: auto; fill: none; stroke: #ddd8fb; stroke-width: 1.4;
  stroke-linecap: round; filter: drop-shadow(0 0 7px rgba(190, 180, 255, .55)); }
[data-theme="moonwind"] .new-art .faint { stroke: rgba(214, 208, 255, .38); }
[data-theme="moonwind"] .new-art .plus { stroke: #f7f5ff; stroke-width: 2.2; }
[data-theme="moonwind"] .new-art .spark { fill: #f4f1ff; stroke: none; }
[data-theme="moonwind"] .tile.new .new-label { font: 500 25px var(--title-font); letter-spacing: .1em; color: #e9e5ff;
  text-shadow: 0 0 14px rgba(180, 165, 255, .5); }

/* Portraits: the arch with a star above and one below. */
[data-theme="moonwind"] .portrait { border-color: rgba(206, 200, 255, .7); box-shadow: 0 0 24px -6px rgba(170, 160, 255, .7); }
[data-theme="moonwind"] .portrait-wrap { padding: 12px 0; }
[data-theme="moonwind"] .portrait-wrap .spark { display: block; position: absolute; left: 50%; width: 18px; height: 18px; margin-left: -9px;
  fill: #f4f1ff; stroke: none; filter: drop-shadow(0 0 6px rgba(200, 190, 255, .9)); z-index: 1; }
[data-theme="moonwind"] .portrait-wrap .spark.top { top: 2px; }
[data-theme="moonwind"] .portrait-wrap .spark.bottom { bottom: 2px; }

/* World tiles keep their painted sky inside the frame. */
[data-theme="moonwind"] .tile.world-tile { padding: 0; }
[data-theme="moonwind"] .world-art { border-radius: 20px 20px 0 0; padding: 16px 42px; }
[data-theme="moonwind"] .world-tile .inner { padding: 18px 42px 26px; }

[data-theme="moonwind"] #login-card { border-color: var(--frame); }

/* The landing page and Home in Moonwind: glowing titles, framed plates. */
[data-theme="moonwind"] .land-title { color: #f4f0ff; text-shadow: 0 0 26px rgba(180, 165, 255, .45), 0 2px 10px rgba(5, 6, 20, .6); }
[data-theme="moonwind"] .land-tag, [data-theme="moonwind"] .land-pitch { color: #dcd8f6; text-shadow: 0 1px 8px rgba(5, 6, 20, .8); }
[data-theme="moonwind"] .land-moon { stroke: #d6d0fa; filter: drop-shadow(0 0 8px rgba(190, 180, 255, .6)); }
[data-theme="moonwind"] .land-moon .star { fill: #f2efff; }
[data-theme="moonwind"] .ch-title { color: #ece8ff; text-shadow: 0 0 20px rgba(180, 165, 255, .4); }
[data-theme="moonwind"] .plate { border: 1.5px solid var(--frame); box-shadow: 0 0 26px -8px rgba(160, 150, 255, .55);
  background-color: rgba(16, 18, 50, .7); background-image: radial-gradient(ellipse at 30% 20%, rgba(150, 120, 230, .3), transparent 60%); }
[data-theme="moonwind"] .ch-dice { border-color: rgba(206, 200, 255, .5); color: #ece8ff; background: rgba(30, 32, 78, .55); }
[data-theme="moonwind"] .prologue, [data-theme="moonwind"] .ch-scene .gm { color: #e8e6f8; }
[data-theme="moonwind"] .faq summary { color: #ece8ff; }

/* Books and Home: the card below the hero is glass too. */
[data-theme="moonwind"] .library > .card { border-color: var(--frame); background: linear-gradient(160deg, rgba(42, 44, 100, .55), rgba(16, 18, 50, .66)); }

@media (max-width: 600px) {
  [data-theme="moonwind"] .rail { margin: 6px 8px 0; border-radius: 16px; }
  [data-theme="moonwind"] .rail-moon { display: none; }
  [data-theme="moonwind"] .brand { font-size: 21px; }
  [data-theme="moonwind"] .brand-moon { width: 22px; height: 22px; }
  [data-theme="moonwind"] .top-actions button { padding: 7px 10px; }
  [data-theme="moonwind"] .hero { min-height: 140px; margin: -8px 0 22px; padding: 18px 12px 20px 4px; gap: 10px; }
  [data-theme="moonwind"] .hero-mark { width: 30px; height: 46px; }
  [data-theme="moonwind"] .hero .library-title { font-size: 34px; }
  [data-theme="moonwind"] .hero .library-sub { font-size: 16px; }
  [data-theme="moonwind"] .tiles { gap: 40px; padding: 14px 8px 24px; }
  [data-theme="moonwind"] .tile { --k: .26; padding: 24px 26px 22px; }
  [data-theme="moonwind"] .tile.new .new-label { font-size: 20px; }
}

/* Behind the screen: framed blocks with a small-caps label (the People and Quests cards' frame). */
.gm-block { padding: 12px 14px; margin: 0 0 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--field); display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.gm-block > summary { cursor: pointer; }
.gm-label { font: 600 10.5px var(--title-font, var(--ui-font)); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.gm-label.inline { margin-right: 8px; }
.gm-block .pp-name { font-size: 18px; }
/* A secret: blurred until tapped. */
.spoiler-row { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px; }
.spoiler { cursor: pointer; padding: 1px 6px; border-radius: 6px; background: color-mix(in srgb, var(--accent) 14%, transparent);
  filter: blur(4.5px); transition: filter .25s ease; user-select: none; }
.spoiler:hover { filter: blur(3.5px); }
.spoiler.shown { filter: none; user-select: text; background: transparent; }
.spoiler:focus-visible { outline: 2px solid var(--accent-soft); }
.spoiler-block > summary { list-style: none; }
.spoiler-block > summary::-webkit-details-marker { display: none; }
.spoiler-block > summary::before { content: "▸ "; color: var(--accent); }
.spoiler-block[open] > summary::before { content: "▾ "; }
/* Decisions: quests, choices, leads, each its own colour down the left. */
.dec { border-left: 3px solid var(--dec); }
.dec-quest { --dec: #e8c77a; }
.dec-choice { --dec: #f2a7b0; }
.dec-lead { --dec: #9fc6f0; }
.dec-head { display: flex; align-items: center; gap: 8px; }
.dec-icon { color: var(--dec); font-size: 16px; }
.dec-item { padding: 8px 0 8px 10px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px;
  border-left: 2px solid color-mix(in srgb, var(--dec, var(--accent)) 55%, transparent); }
.dec-name { font-weight: 600; }
.dec-text { font-size: 13.5px; line-height: 1.45; }
.pp-chip.on { color: var(--accent); border-color: var(--accent-soft); }
.pp-chip.good { color: var(--good); border-color: currentColor; }
.setting-row { padding: 3px 0; border-bottom: 1px dashed var(--border); }
.chapter-past > summary { cursor: pointer; font-weight: 600; }
/* The story: where a chapter ended, with its summary. */
.chapter-end { max-width: 560px; margin: 30px auto 6px; padding: 16px 20px; text-align: center;
  border: 1px solid var(--accent-soft); border-radius: var(--radius); background: var(--field); }
.ce-label { font: 600 11px var(--title-font, var(--ui-font)); letter-spacing: .16em; text-transform: uppercase; color: var(--accent); }
.ce-summary { margin: 8px 0 0; font-size: 14px; line-height: 1.5; font-style: italic; color: var(--muted); cursor: pointer;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.ce-summary.open { display: block; }
.gm-block > button, .gm-block > .row > button { align-self: flex-start; }
.gm-block > h2:first-child { margin-top: 0; }
.dec-item select { width: auto; max-width: 150px; flex-shrink: 0; }
.dec-item > .row { align-items: flex-start; flex-wrap: nowrap; }
.dec-name { min-width: 0; }
.panel details > summary .badge { white-space: normal; overflow-wrap: anywhere; }
[data-theme="moonwind"] .gm-block.dec { border-left: 3px solid var(--dec); }
[data-theme="moonwind"] .gm-block { border-color: rgba(206, 200, 255, .28); border-radius: 6px; }
[data-theme="moonwind"] .chapter-end { border-color: rgba(206, 200, 255, .45); border-radius: 6px; }

/* The stakes: a cost under the reply that paid it, the down card, wounds on the Character tab. */
.cost-mark { max-width: 560px; margin: 4px auto 14px; padding: 8px 14px; border-left: 3px solid var(--bad, #b5525c);
  border-radius: 8px; background: color-mix(in srgb, var(--bad, #b5525c) 8%, transparent); font-size: 13px; }
.cost-mark .cm-label { font-weight: 600; color: var(--bad, #b5525c); margin-right: 6px; }
.cost-mark .cm-text { color: var(--muted); font-style: italic; }
.down-card { max-width: 560px; margin: 18px auto; padding: 16px 18px; border: 1px solid var(--bad, #b5525c);
  border-radius: 12px; background: var(--solid, var(--surface)); }
.down-card .dc-label { font: 600 12px var(--title-font, var(--ui-font)); letter-spacing: .14em; text-transform: uppercase; color: var(--bad, #b5525c); }
.dc-choices { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.dc-choice { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.dc-choice select { width: auto; max-width: 220px; }
.costs .harm { display: inline-block; margin: 2px 0 8px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  color: #fff; background: #c98a3c; }
.costs .harm-2 { background: #b5525c; }
.costs .harm-3 { background: #7d2330; }
.cost-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.cost-item { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; font-size: 14px; }
.cost-item .cost-text { flex: 1; min-width: 140px; }
.cost-add select { width: auto; }
.cost-add input { flex: 1; min-width: 160px; }

/* The scene review: a contained window over the story, not more of the text. */
.popover.debrief { padding: 0; overflow: hidden; margin: 22px auto; border: 1px solid var(--border);
  border-radius: 14px; background: var(--solid, var(--surface)); box-shadow: 0 14px 44px rgba(0, 0, 0, .38); }
.debrief .win-bar { display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 16px;
  border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--accent) 12%, var(--solid, var(--surface))); }
.debrief .win-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.debrief .win-kicker { font: 600 10px var(--title-font, var(--ui-font)); letter-spacing: .16em; text-transform: uppercase; color: var(--accent); }
.debrief .win-title b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.debrief .win-bar .row { margin: 0; }
.debrief .win-close { width: 30px; height: 30px; padding: 0; border-radius: 50%; border: 1px solid var(--border);
  background: transparent; color: var(--muted); font-size: 14px; line-height: 1; cursor: pointer; }
.debrief .win-close:hover { color: var(--text); border-color: var(--accent); }
.debrief .win-body { padding: 12px 16px 16px; max-height: min(64vh, 640px); overflow-y: auto; }
.debrief .win-body > :first-child { margin-top: 0; }
@media (max-width: 600px) { .debrief .win-bar > .ghost { display: none; } }
.costs { margin-top: 18px; }

/* Places: a part of a site sits under it, with a thread line. */
.place-card.place-part { border-left: 2px solid var(--accent); }
.place-group { display: flex; flex-direction: column; gap: 6px; }
.place-group select { width: auto; max-width: 200px; }

.chip-x { all: unset; cursor: pointer; margin-left: 6px; opacity: .6; font-size: .8em; }
.chip-x:hover { opacity: 1; }
.place-add { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.place-add-row { display: block; }

/* A page loaded while the game master works (rejoin) */
.rejoin { position: fixed; z-index: 60; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 32px)); padding: 20px 22px; background: var(--solid, var(--surface));
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-soft); }
.rejoin h2 { margin: 0 0 8px; }
.rejoin-words { max-height: 45vh; overflow-y: auto; white-space: pre-wrap; margin: 10px 0 0; }
.rejoin-words:empty { display: none; }

/* The free demo */
.demo-card { margin-bottom: 18px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.demo-card h2 { margin: 0 0 6px; }
.demo-adult { margin: 8px 0 12px; align-items: center; }
.demo-adult input { width: auto; margin: 0; }
body.guest #rail [data-go="characters"], body.guest #rail [data-go="worlds"], body.guest #rail [data-go="books"] { display: none; }

/* The Scene tab: the place's zones, people as tokens. */
.board { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin: 10px 0; }
.zone { min-height: 92px; padding: 8px; border: 1px solid var(--line, rgba(255,255,255,.18)); border-radius: 10px; background: var(--soft, rgba(255,255,255,.04)); }
.zone.gone { min-height: 0; margin-bottom: 10px; border-style: dashed; }
.zone-name { display: block; width: 100%; padding: 0 0 6px; border: 0; background: none; color: var(--muted); font: 600 11px var(--ui-font); letter-spacing: .08em; text-transform: uppercase; text-align: left; cursor: pointer; }
.zone.gone .zone-name { cursor: default; }
.zone-top { display: flex; align-items: flex-start; gap: 4px; }
.zone-x { padding: 0 2px; border: 0; background: none; color: var(--muted); font-size: 11px; cursor: pointer; }
.place-head { margin-bottom: 8px; }
.place-head h3 { margin: 0; }
.place-head p { margin: 6px 0 0; }
.tokens { display: flex; flex-wrap: wrap; gap: 5px; }
.token { padding: 3px 9px; border: 1px solid var(--line, rgba(255,255,255,.25)); border-radius: 999px; background: var(--surface, rgba(255,255,255,.08)); color: inherit; font-size: 13px; cursor: grab; }
.token.you { border-color: var(--accent, #b9a7ff); font-weight: 600; }
.token.picked { outline: 2px solid var(--accent, #b9a7ff); }

/* Under the latest reply: threads waiting for an answer, and what the turn recorded. */
.recorded { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; font-family: var(--ui-font, inherit); }
.proposal { padding: 8px 12px; border: 1px solid var(--accent-soft); border-radius: var(--radius); background: var(--surface-2);
  display: flex; flex-direction: column; gap: 6px; }
.proposal .pr-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
.proposal select { width: auto; max-width: 180px; }
.rec-log > summary { cursor: pointer; }
.rec-log[open] { padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.rec-log .fix-row { flex-wrap: wrap; }
.rec-log select { width: auto; max-width: 170px; }

/* Behind the screen: square buttons in a horizontal box (the scene's tools, each part's ✎). */
.btn-bar { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px; margin: 8px 0; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface-2, transparent); width: fit-content; max-width: 100%; }
button.sq { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 56px; height: 52px; padding: 4px 6px; border-radius: 6px; line-height: 1.1; }
button.sq .sq-icon { font-size: 18px; }
button.sq .sq-cap { font-size: 11px; white-space: nowrap; }
button.sq:not(:has(.sq-cap)) { min-width: 30px; width: 30px; height: 30px; padding: 0; }
button.sq:not(:has(.sq-cap)) .sq-icon { font-size: 14px; }
.plan-head-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.plan-head-row .plan-heading { margin-bottom: 4px; }
.part-edit { display: flex; flex-direction: column; gap: 6px; }
.part-edit textarea, .part-edit input { width: 100%; box-sizing: border-box; }
.part-card { border: 1px solid var(--border); border-radius: 6px; padding: 8px; margin: 0 0 8px; display: flex; flex-direction: column; gap: 4px; }
.part-field { display: flex; flex-direction: column; gap: 2px; }
.part-line { align-items: flex-start; }
.part-line textarea { flex: 1; }
.subtabs button.gear { font-size: 15px; padding-inline: 10px; }
.record-text p, .ce-summary p, .chapter-past p { margin: 0 0 .7em; }
.record-text p:last-child, .ce-summary p:last-child, .chapter-past p:last-child { margin-bottom: 0; }

/* Quests: finished ones in one short line, folded; threads folded inside a main quest. */
.finished-quests { margin: 12px 0; }
.finished-quests > summary { cursor: pointer; margin-bottom: 6px; }
.quest-done { padding: 8px 10px; margin: 0 0 6px; border: 1px solid var(--border); border-radius: 6px; }
.quest-done .step-tick { opacity: .8; }
.quest-done-line { margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
.quest-done-line.open { display: block; }
.qq-threads > summary { cursor: pointer; }
.new-quest { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.quest-done > .row { flex-wrap: nowrap; align-items: baseline; }
.quest-done > .row > b { flex: 1; min-width: 0; }
.quest-done > .row > .qq-status { white-space: nowrap; flex: none; }

/* The owner's members page */
.member { display: flex; flex-direction: column; gap: 6px; }
.member select { max-width: 55%; }

/* Plans and prices; the line; the Admin tab */
.plan-prices { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin: 8px 0; }
.plan-price { border: 1px solid var(--border); border-radius: 8px; padding: 8px; text-align: center; }
.plan-price .price { font-size: 1.1em; margin: 2px 0 4px; }
.line-place { font-size: 1.4em; text-align: center; margin: 8px 0; }
.admin { max-width: 760px; }
.admin .setting-row select { max-width: 40%; }
