/* PixelRealm Tavern: design system.
   All colours/fonts/radii come from CSS custom properties that public/js/themes.js sets per theme
   (these :root values are the Midnight fallback until the theme is applied). */
:root {
  --bg: #0e1018; --bg-2: #131622; --surface: #181b28; --surface-2: #20243a; --border: #2c3250;
  --text: #e9ebf4; --muted: #9aa2bd; --accent: #8b7cf6; --accent-ink: #100d28; --accent-text: #a99dfb;
  --danger: #f08a93; --ok: #7dd3a0; --warn: #e6b455; --speech: #f1dba5; --action: #b4bdd8;
  --bubble-user: #242a4d; --bubble-char: #181b28;
  --shadow: 0 10px 30px rgba(0,0,0,.38); --shadow-sm: 0 2px 8px rgba(0,0,0,.3);
  --radius: 14px; --radius-lg: 20px; --radius-sm: 9px;
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --font-head: var(--font-ui); --font-read: var(--font-ui); --font-chat: var(--font-ui);
  --head-weight: 650; --head-tracking: -0.01em; --head-transform: none;
  --chat-size: 16px; --chat-width: 760px;
  --wp-url: none; --wp-dim: .45; --wp-blur: 0px; --panel-alpha: 1; --sheet-alpha: 0;
  --accent-soft: color-mix(in srgb, var(--accent) 16%, transparent);
  --ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent-text);
  --panel: color-mix(in srgb, var(--surface) calc(var(--panel-alpha) * 100%), transparent);
  --panel-2: color-mix(in srgb, var(--surface-2) calc(var(--panel-alpha) * 100%), transparent);
  --ease: cubic-bezier(.2, .7, .2, 1);
}

* { box-sizing: border-box; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100%; height: 100%; font: 15px/1.55 var(--font-ui); background: var(--bg); color: var(--text); display: flex; flex-direction: column; overflow-x: hidden; -webkit-font-smoothing: antialiased; }
::selection { background: color-mix(in srgb, var(--accent) 45%, transparent); }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
h1, h2, h3, h4 { margin: 0 0 .55em; font-family: var(--font-head); font-weight: var(--head-weight); letter-spacing: var(--head-tracking); text-transform: var(--head-transform); line-height: 1.2; }
h2 { font-size: 1.55rem; } h3 { font-size: 1.1rem; } h4 { font-size: 1rem; }
[hidden] { display: none !important; }
.muted { color: var(--muted); } .small { font-size: .84rem; } .error { color: var(--danger); } .ok { color: var(--ok); }
.pad { padding: 1rem; } .grow { flex: 1; min-width: 0; } .spacer { flex: 1; } .pre { white-space: pre-wrap; }
.clip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
code { background: var(--surface-2); padding: .1em .4em; border-radius: 6px; font: .86em/1.4 "JetBrains Mono", ui-monospace, monospace; word-break: break-all; }
.ico { flex: none; vertical-align: -0.2em; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-sm); }

/* ---------- wallpaper layer ---------- */
#wallpaper { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
#wallpaper::before { content: ""; position: absolute; inset: -24px; background: var(--wp-url) center / cover no-repeat; filter: blur(var(--wp-blur)); }
#wallpaper::after { content: ""; position: absolute; inset: 0; background: var(--bg); opacity: var(--wp-dim); }
html[data-wp="off"] #wallpaper { display: none; }
/* a quiet sheet behind page content keeps loose text readable over any picture */
html[data-wp="on"] .page { background: color-mix(in srgb, var(--bg) calc(var(--sheet-alpha) * 100%), transparent); border-radius: var(--radius-lg); margin-top: .8rem; margin-bottom: .8rem; }

/* ---------- controls ---------- */
button, .btn, select, input, textarea { font: inherit; color: inherit; }
button, .btn { min-height: 40px; background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .45em 1em; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: .5em; transition: background .15s, border-color .15s, transform .15s var(--ease), box-shadow .15s; text-decoration: none; color: var(--text); }
button:hover, .btn:hover { border-color: var(--accent); text-decoration: none; }
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: default; border-color: var(--border); transform: none; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; box-shadow: var(--shadow-sm); }
button.primary:hover, .btn.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); } button.danger:hover { border-color: var(--danger); }
button.ghost { background: transparent; border-color: transparent; padding: .35em .6em; }
button.ghost:hover { background: var(--accent-soft); border-color: transparent; }
button.icon, .icon-btn { min-width: 40px; padding: .4em; }
input[type=text], input[type=password], input[type=search], input[type=number], input[type=email], input[type=date], select, textarea { width: 100%; min-height: 42px; background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .55em .8em; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
textarea { resize: vertical; line-height: 1.5; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 1.15em; height: 1.15em; flex: none; }
input[type=range] { accent-color: var(--accent); width: 100%; min-height: 28px; }
input[type=color] { width: 52px; height: 42px; padding: 2px; background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; }
select { width: auto; max-width: 100%; }
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .95rem; }
.field > span { font-weight: 600; font-size: .9rem; }
label.inline { display: inline-flex; align-items: center; gap: .5rem; font-size: .92rem; min-height: 32px; }
.check { align-items: flex-start; line-height: 1.4; padding: .25rem 0; }
.row { display: flex; align-items: center; gap: .55rem; } .wrap { flex-wrap: wrap; } .col { display: flex; flex-direction: column; gap: .5rem; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.1rem 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow-sm); }
.card.note { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); }
.badge { display: inline-flex; align-items: center; gap: .3em; font-size: .72rem; line-height: 1.5; border: 1px solid var(--border); border-radius: 999px; padding: 0 .6em; color: var(--muted); white-space: nowrap; }
.badge.paid, .badge.warn, .badge.pending { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 55%, transparent); }
.badge.sub, .badge.confirmed { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 55%, transparent); }
.badge.rejected { color: var(--danger); border-color: var(--danger); }
.chip { display: inline-flex; align-items: center; gap: .35rem; background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: .1rem .55rem .1rem .3rem; font-size: .85rem; }
.chip .x { padding: 0 .3em; min-height: 24px; min-width: 24px; }
.tags { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .3rem; }
.tag { font-size: .72rem; background: var(--accent-soft); color: var(--accent-text); border-radius: 999px; padding: .05em .65em; }
table { width: 100%; border-collapse: collapse; } th, td { text-align: left; padding: .5rem .65rem; border-bottom: 1px solid var(--border); font-size: .9rem; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
tr.clickable { cursor: pointer; } tr.clickable:hover { background: var(--accent-soft); }
.table-wrap { overflow-x: auto; }
.neg { color: var(--danger); } .pos { color: var(--ok); }
dialog.modal { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-lg); width: min(440px, 92vw); padding: 1.2rem; box-shadow: var(--shadow); }
dialog.modal::backdrop { background: rgba(0,0,0,.55); }
dialog.rules { width: min(540px, 92vw); } dialog.rules p { line-height: 1.65; }
#toasts { position: fixed; bottom: 1rem; right: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 100; max-width: calc(100vw - 2rem); }
.toast { background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--radius-sm); padding: .65rem .95rem; box-shadow: var(--shadow); max-width: 360px; animation: toast-in .22s var(--ease); }
.toast.error { border-left-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- top bar ---------- */
#topbar { display: flex; align-items: center; gap: .7rem; padding: 0 1rem; min-height: 58px; background: var(--panel); border-bottom: 1px solid var(--border); flex: none; position: relative; z-index: 5; }
.brand { flex: none; display: flex; align-items: center; gap: .6rem; color: var(--text); font-family: var(--font-head); font-weight: var(--head-weight); text-transform: var(--head-transform); letter-spacing: var(--head-tracking); font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand b { font-weight: 400; color: var(--accent-text); }
#nav { display: flex; gap: .15rem; margin-left: .6rem; flex: none; }
#nav a { display: inline-flex; align-items: center; gap: .5rem; color: var(--muted); padding: 0 .85rem; min-height: 40px; border-radius: var(--radius-sm); font-weight: 500; transition: background .15s, color .15s; }
#nav a:hover { background: var(--accent-soft); color: var(--text); text-decoration: none; }
#nav a.active { background: var(--accent-soft); color: var(--accent-text); }
.balance { display: inline-flex; align-items: center; gap: .4em; background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 .8em; min-height: 34px; color: var(--text); font-weight: 600; font-size: .9rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.balance:hover { text-decoration: none; border-color: var(--accent); }
.balance.low { border-color: color-mix(in srgb, var(--warn) 60%, transparent); }
.plan-badge { color: var(--accent-text); border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; font-size: .66rem; min-height: 24px; align-items: center; }
.plan-badge:hover { text-decoration: none; background: var(--accent-soft); }
#lang-switch { min-height: 36px; padding: .25em .5em; border-radius: var(--radius-sm); font-size: .88rem; }
#logout { min-width: 40px; padding: .35em .7em; }
#app { flex: 1; min-height: 0; overflow: auto; }
body[data-route="chat"] #app { overflow: hidden; display: flex; }
.emblem .px-foam { fill: #fff4dc; } .emblem .px-body { fill: var(--accent); }
.emblem .px-hi { fill: color-mix(in srgb, var(--accent) 55%, #fff); } .emblem .px-shade { fill: color-mix(in srgb, var(--accent) 70%, #000); }
.emblem .px-edge { fill: color-mix(in srgb, var(--accent) 35%, #000); } .emblem .px-spark { fill: #fff4dc; opacity: .8; }

/* ---------- login / hero ---------- */
.hero { position: relative; min-height: 100%; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); align-items: center; gap: 2rem; padding: 2rem clamp(1rem, 5vw, 4.5rem); overflow: hidden; isolation: isolate; }
.hero-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: -2; }
.hero::before { content: ""; position: absolute; inset: 0; z-index: -1; background: linear-gradient(100deg, color-mix(in srgb, var(--bg) 88%, transparent) 0%, color-mix(in srgb, var(--bg) 60%, transparent) 55%, color-mix(in srgb, var(--bg) 35%, transparent) 100%); }
.hero-copy { max-width: 520px; }
.hero-mark { display: flex; align-items: center; gap: .9rem; margin-bottom: 1.6rem; }
.hero-mark .wm { font-family: var(--font-head); font-weight: var(--head-weight); text-transform: var(--head-transform); letter-spacing: var(--head-tracking); font-size: 1.4rem; }
.hero-mark .wm b { font-weight: 400; color: var(--accent-text); }
.hero-title { font-size: clamp(2rem, 5vw, 3.4rem); line-height: 1.08; margin: 0 0 1rem; }
.hero-lead { font-size: 1.1rem; color: var(--muted); max-width: 440px; margin: 0 0 1.4rem; }
.hero-points { display: flex; flex-wrap: wrap; gap: .5rem 1.1rem; color: var(--muted); font-size: .9rem; padding: 0; margin: 0; list-style: none; }
.hero-points li { display: inline-flex; align-items: center; gap: .45rem; } .hero-points .ico { color: var(--accent-text); }
.login { width: min(420px, 100%); justify-self: center; display: flex; flex-direction: column; gap: .75rem; padding: 1.5rem; margin: 0; box-shadow: var(--shadow); background: color-mix(in srgb, var(--surface) 94%, transparent); }
.login-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; } .login-head h1 { margin: 0; font-size: 1.25rem; }
.login form { display: flex; flex-direction: column; gap: .7rem; }
.login .btn.google, .btn.google { justify-content: center; width: 100%; }
.login .links { gap: .4rem 1.1rem; font-size: .9rem; } a.link { color: var(--accent-text); }
.rules-peek { font-size: .88rem; color: var(--muted); } .rules-peek summary { cursor: pointer; min-height: 32px; }
.center-screen { min-height: 100%; display: grid; place-items: center; padding: 1rem; }

/* ---------- pages ---------- */
.page { padding: 1.4rem clamp(1rem, 3vw, 2rem); max-width: 1240px; margin: 0 auto; }
.page.narrow { max-width: 860px; }
.toolbar { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.toolbar h2 { margin: 0; } .toolbar input[type=search] { width: min(300px, 100%); }
.search-wrap { position: relative; } .search-wrap .ico { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; } .search-wrap input { padding-left: 2.2rem; }
.back { display: inline-flex; align-items: center; gap: .3rem; margin-bottom: .8rem; color: var(--muted); min-height: 36px; }
.list { display: flex; flex-direction: column; gap: .55rem; }
.list-item { display: flex; gap: .75rem; align-items: center; padding: .65rem .85rem; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); text-align: left; width: 100%; min-height: 56px; transition: border-color .15s, transform .15s var(--ease); }
.list-item:hover { border-color: var(--accent); text-decoration: none; transform: translateX(2px); }
.list-item .grow { min-width: 0; } .list-item .row > strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--panel)); }
.avatars { display: flex; } .avatars > * + * { margin-left: -10px; box-shadow: 0 0 0 2px var(--surface); }
.avatar, .avatar-sm, .avatar-xs, .avatar-lg, .avatar-xl { border-radius: 50%; object-fit: cover; flex: none; background: var(--surface-2); }
.avatar { width: 40px; height: 40px; } .avatar-sm { width: 36px; height: 36px; } .avatar-xs { width: 22px; height: 22px; }
.avatar-lg { width: 84px; height: 84px; border-radius: var(--radius); } .avatar-xl { width: 140px; height: 140px; border-radius: var(--radius-lg); }
.ph { display: grid; place-items: center; font-weight: 700; color: var(--accent-text); background: color-mix(in srgb, var(--accent) 18%, var(--surface-2)); font-family: var(--font-head); }
.avatar-xs.ph { font-size: .65rem; } .avatar-lg.ph { font-size: 2rem; } .avatar-xl.ph { font-size: 3rem; }
.dropzone { position: fixed; inset: 0; background: color-mix(in srgb, var(--bg) 85%, transparent); border: 3px dashed var(--accent); display: grid; place-items: center; font-size: 1.4rem; z-index: 50; pointer-events: none; }

/* library: posters */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 1.1rem; }
.poster { position: relative; display: flex; flex-direction: column; border-radius: var(--radius-lg); overflow: hidden; background: var(--panel); border: 1px solid var(--border); color: var(--text); transition: transform .22s var(--ease), box-shadow .22s var(--ease), border-color .22s; }
.poster:hover { transform: translateY(-5px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); text-decoration: none; }
.poster-art { position: relative; aspect-ratio: 4 / 5; background: var(--surface-2); overflow: hidden; }
.poster-art img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .5s var(--ease); }
.poster:hover .poster-art img { transform: scale(1.04); }
.poster-art .ph { width: 100%; height: 100%; font-size: 4.2rem; background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 30%, var(--surface-2)), var(--surface-2)); }
.poster-shade { position: absolute; left: 0; right: 0; bottom: 0; padding: 3rem .85rem .75rem; background: linear-gradient(to top, rgba(6,6,10,.9) 0%, rgba(6,6,10,.62) 45%, rgba(6,6,10,0) 100%); color: #fff; }
.poster-name { font-family: var(--font-head); font-weight: var(--head-weight); font-size: 1.08rem; line-height: 1.2; display: flex; align-items: center; gap: .4rem; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
.poster-tags { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .4rem; max-height: 3.4rem; overflow: hidden; }
.poster-tags span { font-size: .68rem; background: rgba(255,255,255,.18); color: #fff; border-radius: 999px; padding: 0 .55em; }
.poster-owner { position: absolute; top: .55rem; left: .55rem; font-size: .7rem; background: rgba(6,6,10,.62); color: #fff; padding: 0 .6em; border-radius: 999px; }
.poster-lock { position: absolute; top: .55rem; right: .55rem; background: rgba(6,6,10,.62); color: #fff; border-radius: 999px; padding: .2rem; display: grid; place-items: center; }
.poster-desc { margin: .7rem .9rem .85rem; padding: 0; color: var(--muted); font-size: .85rem; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.9em; }
.empty { text-align: center; padding: 2.5rem 1rem; max-width: 460px; margin: 0 auto; }
.empty .illustration { margin-bottom: .6rem; max-width: 100%; height: auto; }
.empty h3 { font-size: 1.3rem; } .empty p { color: var(--muted); }
.illustration .il-shadow { fill: rgba(0,0,0,.28); } .illustration .il-wall { fill: var(--surface-2); stroke: var(--border); stroke-width: 2; }
.illustration .il-roof { fill: color-mix(in srgb, var(--accent) 55%, var(--surface-2)); } .illustration .il-roof-line { stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.illustration .il-door { fill: color-mix(in srgb, var(--accent) 25%, var(--bg)); } .illustration .il-door-line { stroke: color-mix(in srgb, var(--accent) 60%, var(--bg)); stroke-width: 2; }
.illustration .il-knob { fill: var(--warn); } .illustration .il-window { fill: var(--warn); opacity: .85; }
.illustration .il-bracket { stroke: var(--border); stroke-width: 3; stroke-linecap: round; } .illustration .il-glow { fill: var(--warn); } .illustration .il-halo { fill: var(--warn); opacity: .16; }
.illustration .il-sign { fill: var(--surface); stroke: var(--accent); stroke-width: 2; } .illustration .il-sign-line { stroke: var(--accent-text); stroke-width: 2; stroke-linecap: round; } .illustration .il-stars { fill: var(--accent-text); opacity: .7; }

/* character page */
.char-hero { position: relative; border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 1rem; isolation: isolate; color: #fff; box-shadow: var(--shadow-sm); border: 1px solid var(--border); }
.char-hero-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; filter: blur(26px) saturate(1.25) brightness(.62); transform: scale(1.3); z-index: -2; }
.char-hero-bg.plain { filter: none; transform: none; background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 55%, #000), color-mix(in srgb, var(--accent) 20%, #000)); }
.char-hero::before { content: ""; position: absolute; inset: 0; z-index: -1; background: linear-gradient(to top, rgba(6,6,10,.78), rgba(6,6,10,.25) 70%); }
.char-hero-inner { display: flex; gap: 1.6rem; align-items: flex-end; padding: 2.6rem 1.8rem 1.6rem; }
.portrait { width: 190px; aspect-ratio: 3 / 4; flex: none; border-radius: var(--radius-lg); object-fit: cover; box-shadow: 0 14px 34px rgba(0,0,0,.5); border: 3px solid rgba(255,255,255,.2); background: var(--surface-2); }
.portrait.ph { font-size: 4.5rem; color: #fff; }
.char-hero h2 { font-size: clamp(1.7rem, 4vw, 2.5rem); margin-bottom: .3rem; text-shadow: 0 2px 10px rgba(0,0,0,.5); }
.char-hero .tag { background: rgba(255,255,255,.2); color: #fff; }
.char-hero .byline { color: rgba(255,255,255,.82); font-size: .9rem; }
.greeting-card { position: relative; padding: 1.1rem 1.3rem 1.1rem 1.6rem; }
.greeting-card::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 4px; border-radius: 4px; background: var(--accent); }
.greeting-card .label { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; display: flex; align-items: center; gap: .4rem; margin-bottom: .4rem; }
.greeting-card .body { font-family: var(--font-read); font-size: 1.02rem; }
.cta-row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-top: .9rem; }
.cta-row .primary.big { min-height: 48px; padding: .6em 1.6em; font-size: 1.02rem; border-radius: var(--radius); }

/* editor */
.avatar-row { align-items: flex-start; margin-bottom: 1rem; }
.avatar-preview { width: 132px; aspect-ratio: 3 / 4; border-radius: var(--radius-lg); overflow: hidden; background: var(--surface-2); flex: none; border: 1px solid var(--border); }
.avatar-preview img, .avatar-preview .ph { width: 100%; height: 100%; object-fit: cover; font-size: 2.6rem; }
.alts { display: flex; flex-direction: column; gap: .5rem; margin-bottom: .5rem; } .alt { display: flex; gap: .4rem; align-items: flex-start; }
.form-actions { margin: 1.2rem 0 3rem; }

/* ---------- chat ---------- */
.chat-shell { flex: 1; display: grid; grid-template-columns: 270px minmax(0, 1fr) 320px; min-height: 0; min-width: 0; width: 100%; position: relative; }
.pane { background: var(--panel); overflow-y: auto; min-height: 0; }
.pane.left { border-right: 1px solid var(--border); padding: .7rem; } .pane.right { border-left: 1px solid var(--border); }
.pane-head { display: flex; align-items: center; justify-content: space-between; padding: .3rem .4rem .7rem; font-family: var(--font-head); font-weight: var(--head-weight); }
.pane.right .pane-head { padding: .9rem 1rem .2rem; } .pane-body { padding: .5rem 1rem 1.2rem; }
.list.compact .list-item { padding: .5rem .6rem; min-height: 48px; } .list.compact .avatars { display: none; }
.center { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.chat-head { padding: .55rem 1rem; border-bottom: 1px solid var(--border); background: var(--panel); display: flex; flex-direction: column; gap: .4rem; }
.chat-head .title { font-family: var(--font-head); font-weight: var(--head-weight); font-size: 1.08rem; text-transform: var(--head-transform); letter-spacing: var(--head-tracking); max-width: 40vw; }
.chat-head .sub:empty { display: none; }
.chat-head select { min-height: 38px; min-width: 0; max-width: 100%; text-overflow: ellipsis; }
.chat-head .model-sel { flex: 0 1 280px; }
.chat-head .title { flex: 0 1 auto; }
.chat-head > .row:first-child { flex-wrap: nowrap; }
.tool { position: relative; }
.popover { position: absolute; right: 0; top: calc(100% + 8px); z-index: 30; width: min(340px, 86vw); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: .9rem; animation: pop-in .16s var(--ease); }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px); } }
.messages { flex: 1; overflow-y: auto; padding: 1.2rem clamp(.6rem, 4vw, 2rem) 1.4rem; display: flex; flex-direction: column; gap: 1.05rem; scroll-behavior: auto; }
.scroll-bottom { position: absolute; right: 1.4rem; bottom: 5.6rem; width: 44px; height: 44px; min-height: 44px; border-radius: 50%; padding: 0; box-shadow: var(--shadow); background: var(--surface); z-index: 6; opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity .18s, transform .18s var(--ease); }
.scroll-bottom.show { opacity: 1; pointer-events: auto; transform: none; }

.msg { display: flex; gap: .8rem; max-width: var(--chat-width); width: 100%; margin: 0 auto; align-items: flex-start; }
.msg.enter { animation: msg-in .24s var(--ease) both; }
@keyframes msg-in { from { opacity: 0; transform: translateY(8px); } }
.msg .bubble { flex: 1; min-width: 0; background: var(--bubble-char); border: 1px solid var(--border); border-radius: 5px var(--radius-lg) var(--radius-lg) var(--radius-lg); padding: .65rem .95rem .8rem; box-shadow: var(--shadow-sm); }
.msg.user { flex-direction: row-reverse; }
.msg.user .bubble { background: var(--bubble-user); border-color: color-mix(in srgb, var(--accent) 25%, var(--border)); border-radius: var(--radius-lg) 5px var(--radius-lg) var(--radius-lg); }
.msg-head { display: flex; align-items: center; gap: .5rem; font-size: .84rem; min-height: 30px; }
.msg-head strong { font-family: var(--font-head); font-weight: var(--head-weight); text-transform: var(--head-transform); letter-spacing: var(--head-tracking); font-size: .95rem; }
.msg .actions { display: flex; opacity: 0; transition: opacity .12s; } .msg:hover .actions, .msg:focus-within .actions { opacity: 1; }
.msg .actions button { min-height: 32px; min-width: 32px; padding: .25em; color: var(--muted); }
@media (hover: none) { .msg .actions { opacity: .85; } }
.body { font-family: var(--font-chat); font-size: var(--chat-size); line-height: 1.7; overflow-wrap: anywhere; margin-top: .2rem; }
.body em { color: var(--action); font-style: italic; } .body .speech { color: var(--speech); } .body strong { font-weight: 700; }
.thinking { margin: .3rem 0 .5rem; border: 1px dashed color-mix(in srgb, var(--muted) 50%, var(--border)); border-radius: var(--radius); background: color-mix(in srgb, var(--surface-2) 55%, transparent); padding: .3rem .8rem; color: var(--muted); font-size: .86rem; }
.thinking summary { cursor: pointer; user-select: none; min-height: 30px; display: flex; align-items: center; gap: .45rem; font-style: italic; list-style: none; }
.thinking summary::-webkit-details-marker { display: none; }
.thinking summary::after { content: ""; width: 6px; height: 6px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); margin-left: auto; transition: transform .2s; }
.thinking[open] summary::after { transform: rotate(-135deg); }
.think-body { white-space: pre-wrap; padding: .15rem 0 .5rem; max-height: 260px; overflow-y: auto; font-family: var(--font-read); font-style: italic; }
.swipes { display: flex; align-items: center; gap: .2rem; margin-top: .5rem; flex-wrap: wrap; }
.swipes button { min-height: 34px; color: var(--muted); font-size: .85rem; }
.msg.system-error .bubble { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--surface)); color: var(--danger); display: flex; gap: .6rem; align-items: baseline; flex-wrap: wrap; }
.msg.system-error { margin: 0 auto; } .edit-area { width: 100%; margin: .3rem 0 .4rem; font-family: var(--font-chat); font-size: var(--chat-size); }
.typing-dots { display: inline-flex; gap: 5px; padding: .5rem .2rem .3rem; } .typing-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: dot 1.1s infinite ease-in-out; }
.typing-dots i:nth-child(2) { animation-delay: .16s; } .typing-dots i:nth-child(3) { animation-delay: .32s; }
@keyframes dot { 0%, 70%, 100% { opacity: .25; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-4px); } }
.streaming .body:not(:empty) ~ .typing-dots { display: none; }

/* message styles */
html[data-msgstyle="compact"] .messages { gap: .45rem; }
html[data-msgstyle="compact"] .msg { gap: .5rem; } html[data-msgstyle="compact"] .msg .bubble { padding: .3rem .7rem .45rem; box-shadow: none; border-radius: var(--radius); }
html[data-msgstyle="compact"] .msg-head { min-height: 24px; } html[data-msgstyle="compact"] .avatar { width: 28px; height: 28px; font-size: .8rem; }
html[data-msgstyle="compact"] .body { line-height: 1.5; }
html[data-msgstyle="novel"] .messages { gap: 1.7rem; padding-top: 1.8rem; }
html[data-msgstyle="novel"] .msg { gap: 1rem; } html[data-msgstyle="novel"] .msg.user { flex-direction: row; }
html[data-msgstyle="novel"] .msg .bubble { background: transparent; border: 0; box-shadow: none; padding: 0; border-radius: 0; }
html[data-msgstyle="novel"] .msg-head strong { font-family: var(--font-read); font-size: .8rem; font-weight: 600; font-variant: all-small-caps; letter-spacing: .14em; text-transform: none; color: var(--accent-text); }
html[data-msgstyle="novel"] .msg.user .msg-head strong { color: var(--muted); }
html[data-msgstyle="novel"] .body { line-height: 1.85; margin-top: .1rem; }
html[data-msgstyle="novel"] .msg.user .body { border-left: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); padding-left: .9rem; }
html[data-msgstyle="novel"] .avatar:not(.portrait) { display: none; }
html[data-msgstyle="novel"][data-avatar="large"] .avatar { display: grid; }
html[data-msgstyle="novel"] .msg.char + .msg.char { margin-top: -.4rem; }
html[data-msgstyle="novel"] .msg.system-error .bubble { border: 1px solid var(--danger); padding: .5rem .8rem; border-radius: var(--radius); }
/* large avatar: a tall portrait card next to the text */
html[data-avatar="large"] .msg > .avatar { width: 92px; height: 122px; border-radius: var(--radius); box-shadow: var(--shadow-sm); border: 1px solid var(--border); font-size: 2.2rem; }
html[data-avatar="large"][data-msgstyle="compact"] .msg > .avatar { width: 56px; height: 74px; font-size: 1.4rem; }
html[data-avatar="large"][data-msgstyle="novel"] .msg > .avatar { width: 104px; height: 138px; }

.composer { padding: .7rem clamp(.6rem, 4vw, 2rem) calc(.8rem + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--panel); display: flex; gap: .6rem; align-items: flex-end; }
.composer textarea { flex: 1; max-height: 200px; resize: none; border-radius: var(--radius); padding: .65em .9em; font-family: var(--font-chat); font-size: max(15px, calc(var(--chat-size) - 1px)); }
.composer .send { width: 44px; min-height: 44px; padding: 0; border-radius: 50%; } .composer .row button { min-height: 44px; }
.only-narrow { display: none; }

/* ---------- settings: appearance ---------- */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.theme-card { position: relative; text-align: left; display: block; min-height: 0; padding: 0; border-radius: var(--radius-lg); border: 2px solid var(--border); background: var(--bg); color: var(--text); overflow: hidden; cursor: pointer; transition: transform .2s var(--ease), border-color .2s, box-shadow .2s; }
.theme-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-sm); }
.theme-card[aria-pressed="true"] { border-color: var(--sel, var(--accent)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--sel, var(--accent)) 30%, transparent); }
.tc-top { display: flex; align-items: center; gap: .3rem; padding: .35rem .5rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.tc-top i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); } .tc-top i + i { background: var(--border); }
.tc-body { padding: .6rem .5rem; display: flex; flex-direction: column; gap: .35rem; background: var(--bg); }
.tc-bub { font-size: .7rem; border-radius: 4px var(--radius-sm) var(--radius-sm) var(--radius-sm); padding: .25rem .45rem; background: var(--bubble-char); border: 1px solid var(--border); max-width: 88%; font-family: var(--font-read); }
.tc-bub .q { color: var(--speech); } .tc-bub em { color: var(--action); }
.tc-bub.u { align-self: flex-end; background: var(--bubble-user); border-radius: var(--radius-sm) 4px var(--radius-sm) var(--radius-sm); }
.tc-btn { align-self: flex-start; font-size: .68rem; background: var(--accent); color: var(--accent-ink); border-radius: var(--radius-sm); padding: .1rem .55rem; font-weight: 600; }
.tc-name { padding: .45rem .6rem .55rem; font-family: var(--font-head); font-weight: var(--head-weight); font-size: .9rem; background: var(--surface); border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; text-transform: var(--head-transform); letter-spacing: var(--head-tracking); }
.tc-name .ico { color: var(--accent-text); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--panel-2); max-width: 100%; flex-wrap: wrap; }
.seg button { border: 0; border-radius: 0; background: transparent; min-height: 38px; padding: .3em .9em; font-size: .9rem; } .seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.range-row { display: grid; grid-template-columns: 7.5rem 1fr 3.2rem; gap: .7rem; align-items: center; margin-bottom: .5rem; } .range-row output { font-variant-numeric: tabular-nums; color: var(--muted); text-align: right; }
.wp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: .6rem; margin-bottom: .8rem; }
.wp-thumb { position: relative; padding: 0; min-height: 0; aspect-ratio: 16 / 10; border-radius: var(--radius-sm); overflow: hidden; border: 2px solid var(--border); background: var(--surface-2); }
.wp-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; } .wp-thumb[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.wp-thumb .lbl { position: absolute; left: 0; right: 0; bottom: 0; font-size: .66rem; text-align: center; padding: .1rem; background: rgba(0,0,0,.55); color: #fff; }
.wp-thumb.none { display: grid; place-items: center; color: var(--muted); font-size: .8rem; }
.preview-chat { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1rem; background: color-mix(in srgb, var(--bg) 70%, transparent); display: flex; flex-direction: column; gap: .8rem; margin-top: .8rem; }
.preview-chat .msg { margin: 0; max-width: 100%; }
.section-title { display: flex; align-items: center; gap: .5rem; margin: 1.2rem 0 .6rem; color: var(--accent-text); } .section-title:first-child { margin-top: 0; }

/* ---------- plans ---------- */
.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1.2rem; align-items: stretch; margin-bottom: 1.4rem; padding-top: .6rem; }
.plan-card { position: relative; display: flex; flex-direction: column; margin: 0; transition: transform .2s var(--ease), box-shadow .2s; }
.plan-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.plan-card h3 { display: flex; gap: .5rem; align-items: center; font-size: 1.2rem; } .plan-card h3 .ico { color: var(--accent-text); }
.plan-card ul { padding: 0; margin: .5rem 0 1.1rem; list-style: none; display: flex; flex-direction: column; gap: .45rem; font-size: .92rem; flex: 1; }
.plan-card li { display: flex; gap: .55rem; align-items: flex-start; } .plan-card li .ico { color: var(--ok); margin-top: .22em; }
.plan-card.current { border-color: var(--accent); }
.plan-card.featured { border: 2px solid var(--accent); background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 12%, var(--panel)), var(--panel) 55%); box-shadow: var(--shadow); }
@media (min-width: 900px) { .plan-card.featured { transform: translateY(-8px); } .plan-card.featured:hover { transform: translateY(-11px); } }
.ribbon { position: absolute; top: -13px; left: 50%; transform: translateX(-50%); background: var(--accent); color: var(--accent-ink); font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; padding: .15rem .9rem; border-radius: 999px; box-shadow: var(--shadow-sm); white-space: nowrap; }
.price { font-family: var(--font-head); font-size: 2rem; font-weight: 700; line-height: 1.1; } .price small { font-size: .9rem; font-weight: 400; color: var(--muted); font-family: var(--font-ui); } .price-ruby { font-weight: 400; font-size: .86rem; font-family: var(--font-ui); }
.gem { vertical-align: -2px; flex: none; } .rubies { display: inline-flex; align-items: center; gap: .25em; white-space: nowrap; }
.pay-box { margin-top: .8rem; display: flex; flex-direction: column; gap: .55rem; }
details.pay > summary { list-style: none; cursor: pointer; display: inline-flex; width: 100%; } details.pay > summary::-webkit-details-marker { display: none; }
.kv { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; } code.ref, code.big { font-size: 1.1rem; letter-spacing: .06em; padding: .2em .55em; }
input.amount { width: 6.5rem; } .reason { flex: 1; min-width: 10rem; }
.claim-card.confirmed, .claim-card.rejected { opacity: .75; }

/* ---------- admin ---------- */
.tabs { display: flex; gap: .2rem; margin-bottom: 1.2rem; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: .55em 1em; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; min-height: 42px; display: inline-flex; align-items: center; } .tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.active { color: var(--accent-text); border-color: var(--accent); }
.model-rows { display: flex; flex-direction: column; gap: .5rem; margin-bottom: .7rem; }
.model-row { display: grid; grid-template-columns: 1.6fr 1fr auto auto; gap: .5rem; align-items: center; }
.funds > * { flex: 0 1 auto; } .funds input[type=number] { width: 8rem; } .funds input[type=text] { flex: 1; min-width: 10rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .2rem 1rem; } select.multi { min-height: 6.5rem; }
.badge.pending { color: var(--warn); }

/* ---------- phones & tablets ---------- */
@media (max-width: 1020px) {
  .chat-shell { grid-template-columns: minmax(0, 1fr); }
  .pane.left, .pane.right { position: absolute; top: 0; bottom: 0; z-index: 20; width: min(340px, 88vw); transition: transform .22s var(--ease); box-shadow: var(--shadow); background: var(--surface); }
  .pane.left { left: 0; transform: translateX(-105%); } .pane.right { right: 0; transform: translateX(105%); }
  .chat-shell.show-left .pane.left, .chat-shell.show-right .pane.right { transform: none; }
  .only-narrow { display: inline-flex; }
  .hero { grid-template-columns: minmax(0, 1fr); align-content: center; gap: 1.2rem; padding: 1.4rem 1rem 2rem; }
  .hero-copy { max-width: none; } .hero-title { font-size: clamp(1.7rem, 7vw, 2.4rem); } .hero-lead { font-size: 1rem; }
  .hero::before { background: linear-gradient(to bottom, color-mix(in srgb, var(--bg) 80%, transparent), color-mix(in srgb, var(--bg) 55%, transparent)); }
}
@media (max-width: 640px) {
  body { font-size: 15px; }
  #topbar { gap: .25rem; padding: 0 .5rem; min-height: 54px; }
  .brand .wm { display: none; } #nav { margin-left: .1rem; gap: 0; }
  #nav a { padding: 0; min-width: 40px; justify-content: center; } #nav a .lbl, #logout .lbl { display: none; }
  .plan-badge { flex: 0 1 auto; min-width: 0; max-width: 72px; overflow: hidden; text-overflow: ellipsis; padding: 0 .45em; font-size: .6rem; }
  #nav a { min-width: 38px; } #topbar > * { min-width: 0; }
  #lang-switch { padding: .2em .25em; font-size: .85rem; min-height: 40px; } #logout { min-width: 40px; padding: 0; }
  .balance { padding: 0 .55em; font-size: .82rem; min-height: 36px; }
  .page { padding: 1rem .85rem; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
  .poster-art .ph { font-size: 3rem; } .poster-name { font-size: .98rem; } .poster-desc { font-size: .8rem; margin: .55rem .7rem .7rem; }
  .char-hero-inner { flex-direction: column; align-items: center; text-align: center; padding: 1.6rem 1rem 1.2rem; } .portrait { width: 150px; } .char-hero .tags, .char-hero .cta-row { justify-content: center; }
  .msg { gap: .5rem; } .msg > .avatar { width: 32px; height: 32px; } .messages { padding: .8rem .55rem 1rem; gap: .8rem; }
  html[data-avatar="large"] .msg > .avatar { width: 60px; height: 80px; } html[data-avatar="large"][data-msgstyle="novel"] .msg > .avatar { width: 66px; height: 88px; }
  .msg .actions { opacity: 1; } .msg .actions button { min-width: 40px; min-height: 40px; }
  .chat-head { padding: .4rem .6rem; gap: .25rem; } .chat-head .title { max-width: none; flex: 1; }
  .swipes button { min-height: 40px; } .chip .x { min-width: 40px; min-height: 40px; margin: -9px -8px -9px -4px; }
  .chat-head > .row:first-child { flex-wrap: wrap; } .chat-head .model-sel { order: 10; flex: 1 0 100%; } .chat-head .row > .spacer { display: none; }
  .chat-head button.ghost, .chat-head button.icon { min-width: 40px; }
  .composer { flex-direction: row; gap: .45rem; padding-inline: .55rem; } .composer .row { gap: .35rem; }
  .scroll-bottom { right: .8rem; bottom: 5.2rem; }
  .model-row { grid-template-columns: 1fr 1fr auto; } .model-row .badge { display: none; }
  .range-row { grid-template-columns: 6rem 1fr 2.8rem; }
  .theme-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .wp-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .hero { padding-top: 1rem; } .hero-mark { margin-bottom: .8rem; } .hero-points { display: none; }
  .login { padding: 1.1rem; }
  dialog.modal { padding: 1rem; }
  .list-item { min-height: 56px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
