/* The app shell in the style of a cloud console: thin top bar, folding left menu, cards on light grey.
   Colours are tokens; dark mode follows the system unless the page sets data-theme. */
:root {
  --bg: #f8f9fa; --surface: #ffffff; --surface-2: #f1f3f4; --line: #dadce0;
  --text: #202124; --text-2: #5f6368; --primary: #1a73e8; --primary-text: #ffffff; --primary-soft: #e8f0fe;
  --ok: #188038; --ok-soft: #e6f4ea; --warn: #b06000; --warn-soft: #fef7e0; --bad: #d93025; --bad-soft: #fce8e6;
  --shadow: 0 1px 2px rgba(60,64,67,.3), 0 1px 3px 1px rgba(60,64,67,.15);
  --radius: 8px; --topbar: 56px; --nav: 256px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1f1f1f; --surface: #2a2a2a; --surface-2: #333; --line: #444746;
    --text: #e3e3e3; --text-2: #a8abaf; --primary: #8ab4f8; --primary-text: #062e6f; --primary-soft: #1e3a5f;
    --ok: #81c995; --ok-soft: #1e3a2a; --warn: #fdd663; --warn-soft: #3d3420; --bad: #f28b82; --bad-soft: #3c2422;
    --shadow: 0 1px 3px rgba(0,0,0,.6); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1f1f1f; --surface: #2a2a2a; --surface-2: #333; --line: #444746;
  --text: #e3e3e3; --text-2: #a8abaf; --primary: #8ab4f8; --primary-text: #062e6f; --primary-soft: #1e3a5f;
  --ok: #81c995; --ok-soft: #1e3a2a; --warn: #fdd663; --warn-soft: #3d3420; --bad: #f28b82; --bad-soft: #3c2422;
  --shadow: 0 1px 3px rgba(0,0,0,.6); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 "Roboto", system-ui, sans-serif; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.material-symbols-outlined { font-size: 20px; vertical-align: middle; }

/* top bar */
.topbar { position: fixed; inset: 0 0 auto 0; height: var(--topbar); max-width: 100vw; display: flex; align-items: center; gap: 8px;
  padding: 0 12px; background: var(--surface); border-bottom: 1px solid var(--line); z-index: 20; overflow: hidden; }
.topbar .brand { display: flex; align-items: center; gap: 8px; font-size: 18px; color: var(--text); font-weight: 500; white-space: nowrap; flex: none; }
.topbar .brand .logo { width: 28px; height: 28px; border-radius: 6px; background: var(--primary); color: var(--primary-text);
  display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.topbar .area { color: var(--text-2); padding-left: 12px; margin-left: 4px; border-left: 1px solid var(--line); }
.topbar .spacer { flex: 1; }
.icon-btn { border: 0; background: none; color: var(--text-2); width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center; flex: none; }
.icon-btn:hover { background: var(--surface-2); text-decoration: none; }
.icon-btn[aria-current="page"] { background: var(--primary-soft); color: var(--primary); }
.topbar .icon-btn .material-symbols-outlined, .nav .material-symbols-outlined { width: 20px; overflow: hidden; flex: none; }
.topbar .balance-pill { display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; height: 32px; border-radius: 16px;
  background: var(--primary-soft); color: var(--primary); font-weight: 500; font-size: 13px; white-space: nowrap; flex: none; }
.topbar .balance-pill:hover { filter: brightness(.97); text-decoration: none; }
.topbar .balance-pill .material-symbols-outlined { font-size: 17px; width: 17px; overflow: hidden; flex: none; }

/* left menu */
.nav { position: fixed; top: var(--topbar); bottom: 0; left: 0; width: var(--nav); background: var(--surface);
  border-right: 1px solid var(--line); padding: 8px 0; overflow-y: auto; z-index: 15; transition: transform .2s; }
.nav a { display: flex; align-items: center; gap: 16px; padding: 0 24px; height: 40px; color: var(--text);
  border-radius: 0 20px 20px 0; margin-right: 12px; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 500; }
.nav .section { padding: 16px 24px 4px; color: var(--text-2); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.nav-group { margin: 0 12px; display: grid; gap: 2px; }
.nav-group + .nav-group { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.nav-group .section { padding: 4px 10px; font-size: 11px; font-weight: 500; }
.nav-group a { padding: 0 10px; gap: 12px; min-height: 38px; height: auto; border-radius: 8px; margin: 0; }
.nav-group a .material-symbols-outlined { color: var(--text-2); flex: none; }
.nav-group a[aria-current="page"] { background: var(--primary-soft); color: var(--primary); font-weight: 500; }
.nav-group a[aria-current="page"] .material-symbols-outlined { color: inherit; }
.nav-group a:focus-visible { outline-offset: -2px; }
body.nav-folded .nav { transform: translateX(-100%); }
body.nav-folded main { margin-left: 0; }

/* page */
main { margin: var(--topbar) 0 0 var(--nav); padding: 24px; min-height: calc(100vh - var(--topbar)); min-width: 0; max-width: 100%; transition: margin .2s; }
/* form pages keep labels near their fields on wide screens (cards, lists and grids stay full width) */
main.form-page > * { max-width: 1100px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 22px; font-weight: 400; margin: 0; }
.page-head .spacer { flex: 1; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.section-head h2 { font-size: 16px; font-weight: 500; margin: 0; }
.crumbs { color: var(--text-2); font-size: 13px; margin-bottom: 4px; }
@keyframes shimmer { to { background-position: -200% 0; } }  /* loading placeholders (tables, cards) */
/* the loading bar along the top edge, under the top bar (ui/shell.js turns it on while data loads) */
.page-loader { position: fixed; top: var(--topbar); left: 0; right: 0; height: 3px; z-index: 30; overflow: hidden;
  opacity: 0; visibility: hidden; transition: opacity .15s, visibility .15s; pointer-events: none; }
.page-loader.on { opacity: 1; visibility: visible; }
.page-loader.on::before { content: ""; position: absolute; top: 0; bottom: 0; width: 40%; background: var(--primary);
  animation: page-loader 1.1s ease-in-out infinite; }
@keyframes page-loader { from { left: -40%; } to { left: 100%; } }
/* "back to …" link above a page */
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--text-2); margin-bottom: 8px; }
.back .material-symbols-outlined { font-size: 18px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card h2 { font-size: 16px; font-weight: 500; margin: 0 0 12px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.stack { display: grid; gap: 16px; }
/* room between blocks stacked in plain page flow (a .stack or .grid has its own gap; margins here collapse with any
   margin already there): a card never touches what is above or below it, and a button row never touches a table */
:where(main, #scenes, main > div:not(.stack):not(.grid)) > :where(.card + *, * + .card) { margin-top: 16px; }
:where(main, .card:not(.stack), main > div:not(.stack):not(.grid)) > :where(* + .toolbar, .table-wrap + *) { margin-top: 12px; }
.stack > *, .grid > * { min-width: 0; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 13px; word-break: break-word; overflow-wrap: anywhere; }
pre { overflow-x: auto; max-width: 100%; white-space: pre-wrap; word-break: break-word; }
.muted { color: var(--text-2); }
.empty { padding: 32px; text-align: center; color: var(--text-2); }

/* buttons, fields, chips */
.btn { border: 1px solid var(--line); background: var(--surface); color: var(--primary); border-radius: 4px; height: 36px;
  padding: 0 16px; font: 500 14px "Roboto", sans-serif; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--primary-soft); text-decoration: none; }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.field { display: grid; gap: 4px; margin-bottom: 12px; align-content: start; min-width: 0; }
.field label { font-size: 12px; color: var(--text-2); }
input, select, textarea { font: 14px "Roboto", sans-serif; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 4px; padding: 8px 10px; min-height: 36px; width: 100%; max-width: 100%; }
input[type="file"] { width: auto; flex: 1 1 200px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); border-color: transparent; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar > * { max-width: 100%; }
.toolbar input, .toolbar select { width: auto; min-width: 140px; }
/* tick boxes stay tick-sized everywhere (the text-box rules above would stretch them) */
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; min-width: 0; min-height: 0; padding: 0; flex: none; cursor: pointer; }
.chip { display: inline-block; padding: 0 10px; border-radius: 12px; font-size: 12px; line-height: 22px; background: var(--surface-2); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.info { background: var(--primary-soft); color: var(--primary); }

/* phones: the menu slides over the page */
@media (max-width: 800px) {
  main { margin-left: 0; padding: 16px; }
  body:not(.nav-open) .nav { transform: translateX(-100%); }
  body.nav-open .nav { box-shadow: var(--shadow); }
  .topbar .area { display: none; }
}
@media (max-width: 640px) {
  .topbar { gap: 4px; padding: 0 8px; }
  .topbar .brand { font-size: 16px; gap: 6px; min-width: 0; flex: 0 1 auto; }
  .topbar .brand .logo { flex: none; }
  .topbar .brand span:last-child { overflow: hidden; text-overflow: ellipsis; }
  .topbar .balance-pill { padding: 0 9px; font-size: 12px; }
  .icon-btn { width: 36px; height: 36px; }
}
@media (max-width: 440px) {
  .topbar .lang-btn { margin-right: 0; padding-inline: 7px; }
  /* "1,234 credits" in full: the logo stands for the name, the pill drops its icon and shrinks only past that */
  .topbar:has(.balance-pill) .brand span:last-child, .topbar .balance-pill .material-symbols-outlined { display: none; }
  .topbar .balance-pill { flex: 0 1 auto; min-width: 0; }
  .topbar #topBalance { overflow: hidden; text-overflow: ellipsis; }
}
.page-head select { width: auto; }
.row-actions { display: inline-flex; gap: 8px; white-space: nowrap; }
html, body { overflow-x: hidden; }
[hidden] { display: none !important; }
/* forms: fields side by side that wrap on a phone, and a ticked choice */
.form-row { display: grid; gap: 0 16px; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); align-items: start; }
.form-row > * { min-width: 0; }
.check { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.pick-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.pick { display: flex; gap: 8px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; cursor: pointer; }
.pick img { width: 36px; height: 36px; border-radius: 6px; object-fit: contain; object-position: center; background: var(--surface-2); flex: none; }
.pick span { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-grid + b { display: block; margin-top: 14px; }
.pick:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.pick, .pick span { min-width: 0; }  /* a long name is cut with "…", never drawn over the next card */
.pick .no-pic { width: 36px; height: 36px; border-radius: 6px; background: var(--surface-2); flex: none; }
/* a voice dropdown with its play button (ui/voice_picker.js) */
.voice-picker { display: flex; gap: 6px; align-items: center; }
.voice-picker select { flex: 1; min-width: 0; }
/* Settings sits at the bottom of the menu (below everything when the menu is longer than the screen) */
.nav { display: flex; flex-direction: column; }
.nav > * { flex: none; }
.nav-group.nav-bottom { margin-top: auto; padding-top: 8px; border-top: 1px solid var(--line); }
/* the big notice on every page: a frozen account, a storage bill the balance cannot pay, storage nearly full */
.storage-notice { display: flex; gap: 12px; align-items: flex-start; padding: 16px 18px; margin-bottom: 16px; border-radius: var(--radius);
  font-size: 16px; font-weight: 500; line-height: 1.45; background: var(--warn-soft); color: var(--warn); border: 2px solid currentColor; }
.storage-notice.bad { background: var(--bad-soft); color: var(--bad); }
.storage-notice .material-symbols-outlined { font-size: 30px; }
.storage-notice a { color: inherit; text-decoration: underline; }
/* a paid step running (script/ui/shell.js): stays at the top while the page scrolls */
.paid-now { position: sticky; top: calc(var(--topbar) + 8px); z-index: 20; align-items: center; }
.paid-now.done { background: var(--ok-soft, var(--warn-soft)); color: var(--ok, var(--warn)); }
.paid-now .spin, .btn .spin { animation: paid-spin 1s linear infinite; }
@keyframes paid-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .paid-now .spin, .btn .spin { animation: none; } }
/* the promotion form's episode pictures: tap to pick (a tick on picked ones), the picked ones in a strip */
.ref-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.ref-strip { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.ref-strip .ref-thumb { width: 96px; }
.ref-thumb { position: relative; padding: 0; border: 2px solid var(--line); border-radius: 8px; overflow: hidden; cursor: pointer;
  background: var(--surface-2); aspect-ratio: 1; }
.ref-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ref-thumb.on { border-color: var(--primary); }
.ref-thumb .material-symbols-outlined { position: absolute; top: 4px; right: 4px; color: #fff; background: rgba(0, 0, 0, .55);
  border-radius: 50%; font-size: 20px; }
/* the language switch in the top bar (script/ui/i18n.js) */
.lang-btn { border: 1px solid var(--line); background: none; color: inherit; border-radius: 999px; padding: 4px 10px; font: inherit;
  font-size: 13px; cursor: pointer; margin-right: 6px; }
.lang-btn:hover { background: var(--surface-2); }
/* a picture shown large (ui/shell.js): any page picture that is not a link opens here */
main img:not(a img, button img, label img, .video-card img, .cast-card img) { cursor: zoom-in; }
.picture-preview img { max-width: min(92vw, 1100px); max-height: 86vh; border-radius: 10px; object-fit: contain; box-shadow: var(--shadow); }
.picture-preview .preview-close { position: fixed; top: 12px; right: 12px; background: var(--surface); }
/* phones and tablets (also turned sideways): fields at 16px, so tapping one does not zoom the page in (iOS zooms into smaller text) */
@media (max-width: 640px), (pointer: coarse) {
  input, select, textarea { font-size: 16px !important; }  /* beats class rules such as font: inherit */
}
