:root {
  --bg: #0a0a0f; --bg2: #101018; --surface: #15151f; --surface2: #1c1c29; --surface3: #262638;
  --line: #24243a; --line2: #33334b;
  --text: #ede9df; --text2: #c7c2b6; --muted: #8b879a; --faint: #5c596d;
  --accent: #f0a83c; --accent2: #ffcd6e; --accent-ink: #1b1306;
  --sys: #6bdcff; --warn: #ff8f5e; --danger: #ff5f70; --ok: #5ee0a0;
  --r: 16px; --r-sm: 11px;
  --serif: 'Literata', Georgia, 'Times New Roman', serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --display: 'Cinzel', 'Literata', Georgia, serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(1100px 520px at 78% -12%, color-mix(in srgb, var(--accent) 7.5%, transparent), transparent 62%),
    radial-gradient(900px 520px at -12% 112%, rgba(107,220,255,.05), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text); font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
a { color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }
.ic { width: 20px; height: 20px; flex: none; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ------------------------------------------------------------------ shell */
.shell { display: flex; min-height: 100dvh; }
#view { flex: 1; min-width: 0; padding-bottom: calc(70px + var(--safe-b)); }
.side { display: none; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(62px + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; background: rgba(10,10,15,.9); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 11px; font-weight: 500; text-decoration: none; }
.tabbar a.on { color: var(--accent); }
.tabbar a.forge .ic { width: 34px; height: 34px; padding: 7px; border-radius: 12px; background: linear-gradient(180deg, var(--accent2), var(--accent)); color: var(--accent-ink); }
body.in-session .tabbar { display: none; }
body.in-session #view { padding-bottom: 0; }

@media (min-width: 900px) {
  .side {
    display: flex; flex-direction: column; gap: 4px; width: 232px; flex: none;
    position: sticky; top: 0; height: 100dvh; padding: 22px 14px;
    border-right: 1px solid var(--line); background: rgba(16,16,24,.55);
  }
  .side .brand { margin: 0 8px 22px; }
  .side a.nav { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 12px; color: var(--text2); text-decoration: none; font-weight: 500; }
  .side a.nav:hover { background: var(--surface); }
  .side a.nav.on { background: var(--surface2); color: var(--accent); }
  .side .side-foot { margin-top: auto; padding: 10px 12px; color: var(--faint); font-size: 12px; }
  .tabbar { display: none; }
  #view { padding-bottom: 0; }
}

.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand-mark { width: 40px; height: 40px; border-radius: 11px; box-shadow: 0 4px 18px color-mix(in srgb, var(--accent) 25%, transparent); }
.brand-name { font: 700 19px/1.1 var(--display); letter-spacing: .06em; color: var(--text); }
.brand-sub { font-size: 12px; color: var(--muted); }

.page { max-width: 1140px; margin: 0 auto; padding: calc(18px + var(--safe-t)) 16px 28px; }
.page-narrow { max-width: 760px; }
h1, h2, h3 { margin: 0; }
.h-display { font: 700 26px/1.15 var(--display); letter-spacing: .04em; }
.sec { margin-top: 28px; }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.sec-title { font: 700 13px/1 var(--sans); letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }

/* ------------------------------------------------------------------ buttons + inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 16px; border-radius: 12px; border: 1px solid var(--line2);
  background: var(--surface2); color: var(--text); font: 600 14px/1.1 var(--sans);
  text-decoration: none; white-space: nowrap; transition: transform .08s, background .15s, border-color .15s;
}
.btn:hover { border-color: var(--faint); }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(180deg, var(--accent2), var(--accent)); color: var(--accent-ink); border-color: transparent; box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 22%, transparent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 8px 12px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; border: 0; background: transparent; color: var(--text2); text-decoration: none; flex: none; }
.icon-btn:hover { background: var(--surface); color: var(--text); }

.field { margin-bottom: 16px; }
.field > label, .lbl { display: block; font: 600 11.5px/1.2 var(--sans); color: var(--muted); text-transform: uppercase; letter-spacing: .1em; margin-bottom: 7px; }
.hint { font-size: 12.5px; color: var(--faint); margin-top: 6px; line-height: 1.45; }
.inp, input[type=text], input[type=password], input[type=url], input[type=number], select, textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--line2); color: var(--text);
  border-radius: var(--r-sm); padding: 11px 12px; font: 15px/1.4 var(--sans); outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 84px; }
.inp:focus, input:focus, select:focus, textarea:focus { border-color: color-mix(in srgb, var(--accent) 55%, transparent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 9%, transparent); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { min-width: 0; }
.grow { flex: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip { padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line2); background: transparent; color: var(--text2); font-size: 13px; font-weight: 500; white-space: nowrap; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.tag { display: inline-block; padding: 3px 9px; border-radius: 999px; background: rgba(255,255,255,.07); color: var(--text2); font-size: 11.5px; font-weight: 500; }

.seg { display: flex; background: var(--surface); border: 1px solid var(--line2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 9px 6px; border-radius: 9px; font-size: 13px; font-weight: 600; }
.seg button.on { background: var(--surface3); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.05) inset; }

.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--surface3); border: 1px solid var(--line2); transition: .2s; }
.switch span::after { content: ''; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--text2); transition: .2s; }
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); background: var(--accent-ink); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.toggle-row:last-child { border-bottom: 0; }
.toggle-row b { font-weight: 600; display: block; }
.toggle-row small { color: var(--muted); }
input[type=range] { width: 100%; accent-color: var(--accent); }

.panel-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }

/* ------------------------------------------------------------------ home */
.home-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
@media (min-width: 900px) { .home-top .brand { display: none; } }
.hero-line { margin: 22px 0 4px; font: 600 clamp(24px, 5vw, 34px)/1.15 var(--serif); letter-spacing: -.01em; }
.hero-line em { font-style: italic; color: var(--accent2); }
.hero-sub { color: var(--muted); margin: 0; }
.banner { display: flex; gap: 12px; align-items: center; margin-top: 16px; padding: 12px 14px; border-radius: 12px; border: 1px solid rgba(255,143,94,.35); background: rgba(255,143,94,.07); color: #ffd9c8; font-size: 14px; }
.banner .ic { color: var(--warn); }

.hscroll { display: flex; gap: 12px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px 6px; scroll-snap-type: x mandatory; }
.hscroll::-webkit-scrollbar { display: none; }
.cont { flex: 0 0 min(300px, 82%); scroll-snap-align: start; display: flex; gap: 12px; padding: 10px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--line); text-decoration: none; }
.cont .cover { width: 62px; flex: none; border-radius: 10px; }
.cont b { display: block; font: 600 15px/1.25 var(--serif); }
.cont small { display: block; color: var(--muted); font-size: 12px; margin: 2px 0 4px; }
.cont p { margin: 0; color: var(--text2); font-size: 13px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; } }
@media (min-width: 1080px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.cover { position: relative; aspect-ratio: 3/4; border-radius: var(--r); overflow: hidden; background: linear-gradient(155deg, hsl(var(--h, 30) 42% 24%), hsl(calc(var(--h, 30) + 50) 48% 8%)); }
.cover .fb { position: absolute; inset: 0; display: grid; place-items: center; font: 700 64px/1 var(--display); color: rgba(255,255,255,.12); }
.cover .fb::before { content: ''; position: absolute; inset: 14%; border: 1px solid rgba(255,255,255,.08); transform: rotate(45deg); border-radius: 8px; }
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .6s; }
.cover img.ok { opacity: 1; }
.card { position: relative; display: block; text-decoration: none; border-radius: var(--r); transition: transform .15s; }
.card:active { transform: scale(.98); }
.card .cover::after { content: ''; position: absolute; inset: 0; background: linear-gradient(to top, rgba(6,6,10,.96) 0%, rgba(6,6,10,.55) 34%, transparent 62%); }
.card-meta { position: absolute; left: 0; right: 0; bottom: 0; padding: 12px; z-index: 2; }
.card-title { font: 600 16px/1.2 var(--serif); text-shadow: 0 2px 10px rgba(0,0,0,.6); }
.card-tag { font-size: 12px; color: var(--text2); margin-top: 4px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-genre { position: absolute; top: 10px; left: 10px; z-index: 2; padding: 3px 8px; border-radius: 99px; background: rgba(10,10,15,.7); backdrop-filter: blur(6px); font-size: 10.5px; font-weight: 600; letter-spacing: .04em; color: var(--accent2); }
.card-mine { position: absolute; top: 10px; right: 10px; z-index: 2; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); }
.card-mine .ic { width: 14px; height: 14px; }
.card.new { display: grid; place-items: center; aspect-ratio: 3/4; border: 1.5px dashed var(--line2); color: var(--muted); text-align: center; padding: 16px; }
.card.new .ic { width: 34px; height: 34px; color: var(--accent); margin-bottom: 8px; }

/* ------------------------------------------------------------------ story page */
.story-hero { position: relative; overflow: hidden; }
.story-hero .bg { position: absolute; inset: -40px; background-size: cover; background-position: center; filter: blur(34px) saturate(1.2); opacity: .38; transform: scale(1.1); }
.story-hero::after { content: ''; position: absolute; inset: 0; background: linear-gradient(to bottom, rgba(10,10,15,.2), var(--bg) 96%); }
.story-hero .inner { position: relative; z-index: 2; max-width: 1000px; margin: 0 auto; padding: calc(10px + var(--safe-t)) 16px 22px; }
.story-head { display: flex; gap: 18px; align-items: flex-end; margin-top: 8px; }
.story-head .cover { width: 132px; flex: none; box-shadow: 0 18px 50px rgba(0,0,0,.55); }
.story-head h1 { font: 700 clamp(22px, 5.5vw, 34px)/1.12 var(--display); letter-spacing: .03em; }
.story-head .tagline { color: var(--text2); font: italic 15px/1.45 var(--serif); margin: 8px 0 10px; }
.story-head .insp { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.story-actions { display: flex; gap: 10px; margin-top: 18px; }
.story-actions .btn { padding: 14px 16px; }
.story-actions .btn.primary { flex: 1 1 auto; font-size: 15px; }
@media (max-width: 380px) { .story-actions { gap: 8px; } .story-actions .btn { padding: 14px 12px; } } /* 360 px Androids: keep the ⋯ button on screen */
@media (min-width: 700px) { .story-head .cover { width: 180px; } .story-actions .btn.primary { flex: 0 0 auto; padding: 14px 22px; } }
.story-body { max-width: 1000px; margin: 0 auto; padding: 0 16px 40px; }
.story-body .block { margin-top: 26px; }
.story-body p.desc { font: 16.5px/1.65 var(--serif); color: var(--text2); margin: 10px 0 0; }
.scen { display: flex; gap: 12px; padding: 14px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface); margin-top: 10px; cursor: pointer; transition: border-color .15s; }
.scen.on { border-color: var(--accent); background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 8%, transparent), transparent); }
.scen .dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line2); flex: none; margin-top: 2px; }
.scen.on .dot { border-color: var(--accent); background: radial-gradient(circle, var(--accent) 45%, transparent 50%); }
.scen b { font: 600 15px/1.3 var(--serif); display: block; }
.scen p { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }
.rules { list-style: none; padding: 0; margin: 10px 0 0; counter-reset: r; }
.rules li { position: relative; padding: 10px 0 10px 36px; border-bottom: 1px solid var(--line); color: var(--text2); font-size: 14.5px; line-height: 1.5; counter-increment: r; }
.rules li::before { content: counter(r, upper-roman); position: absolute; left: 0; top: 10px; font: 700 12px/20px var(--display); color: var(--accent); width: 26px; text-align: center; }
.kv { margin-top: 12px; font-size: 14px; color: var(--text2); line-height: 1.55; }
.kv b { color: var(--text); }
.cast { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; margin-top: 10px; }
.char { padding: 14px; border-radius: var(--r-sm); background: var(--surface); border: 1px solid var(--line); cursor: pointer; }
.char .av { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font: 700 18px var(--display); color: #fff; background: linear-gradient(150deg, hsl(var(--h) 55% 45%), hsl(calc(var(--h) + 40) 55% 25%)); flex: none; }
.char b { font: 600 15px/1.2 var(--serif); }
.char small { color: var(--accent2); font-size: 12px; }
.char p { margin: 8px 0 0; font-size: 13.5px; color: var(--text2); line-height: 1.45; }
.char .more { display: none; }
.char.open .more { display: block; }
.char .more p { color: var(--muted); }

.list-item { display: flex; gap: 12px; align-items: center; padding: 12px; border-radius: var(--r-sm); background: var(--surface); border: 1px solid var(--line); text-decoration: none; margin-bottom: 10px; }
.list-item .cover { width: 54px; flex: none; border-radius: 9px; }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item b { font: 600 15px/1.25 var(--serif); display: block; }
.list-item small { color: var(--muted); font-size: 12px; }
.list-item p { margin: 3px 0 0; font-size: 13px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty .ic { width: 40px; height: 40px; color: var(--faint); margin-bottom: 10px; }

/* ------------------------------------------------------------------ create */
.tabs { display: flex; gap: 6px; margin: 18px 0; }
.forge-card { position: relative; overflow: hidden; }
.forge-card::before { content: ''; position: absolute; width: 420px; height: 420px; right: -160px; top: -200px; background: radial-gradient(circle, color-mix(in srgb, var(--accent) 12%, transparent), transparent 65%); pointer-events: none; }
.idea { font: 17px/1.55 var(--serif) !important; min-height: 110px; }
.freedom-scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.freedom-scale button { border: 1px solid var(--line2); background: var(--surface); border-radius: 11px; padding: 10px 4px; color: var(--muted); font-size: 12px; font-weight: 600; line-height: 1.2; }
.freedom-scale button b { display: block; font: 700 17px/1 var(--display); margin-bottom: 4px; color: var(--faint); }
.freedom-scale button.on { border-color: var(--accent); color: var(--text); background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 14%, transparent), color-mix(in srgb, var(--accent) 3%, transparent)); }
.freedom-scale button.on b { color: var(--accent); }
.freedom-desc { font-size: 13px; color: var(--muted); margin-top: 8px; min-height: 2.8em; line-height: 1.45; }
.repeat { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 14px; margin-bottom: 12px; background: var(--bg2); }
.repeat-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; font-weight: 600; color: var(--text2); font-size: 13px; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
@media (min-width: 640px) { .grid2 { grid-template-columns: 1fr 1fr; } }

.forging { text-align: center; padding: 50px 20px; }
.rune-ring { width: 96px; height: 96px; margin: 0 auto 22px; border-radius: 50%; position: relative; background: conic-gradient(from 0deg, transparent, var(--accent), transparent 40%, var(--sys), transparent 80%); animation: spin 2.4s linear infinite; }
.rune-ring::after { content: ''; position: absolute; inset: 5px; border-radius: 50%; background: var(--bg); }
.rune-ring::before { content: '\2726'; position: absolute; inset: 0; display: grid; place-items: center; z-index: 2; font-size: 30px; color: var(--accent2); animation: spin 2.4s linear infinite reverse; }
.forging h3 { font: 700 20px var(--display); letter-spacing: .06em; }
.forging p { color: var(--muted); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ session */
.session { display: flex; flex-direction: column; height: 100dvh; }
.s-top { display: flex; align-items: center; gap: 6px; padding: calc(8px + var(--safe-t)) 8px 8px; border-bottom: 1px solid var(--line); background: rgba(10,10,15,.88); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); z-index: 5; }
.s-title { flex: 1; min-width: 0; }
.s-title b { display: block; font: 600 15.5px/1.2 var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.s-title small { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mode-chip { display: inline-flex; align-items: center; gap: 6px; padding: 8px 11px; border-radius: 11px; border: 1px solid var(--line2); background: var(--surface); font-size: 13px; font-weight: 600; flex: none; }
.mode-chip .ic { width: 16px; height: 16px; color: var(--accent); }
.mode-chip .ic.dn { color: var(--muted); width: 14px; height: 14px; }
.s-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; position: relative; }
.s-inner { max-width: 720px; margin: 0 auto; padding: 22px 20px 30px; }
.disclaimer { color: var(--faint); font: italic 14px/1.5 var(--serif); margin: 0 0 22px; }

.prose { font: 18px/1.68 var(--serif); color: var(--text); overflow-wrap: anywhere; }
@media (max-width: 420px) { .prose { font-size: 17px; } }
.prose p { margin: 0 0 .9em; }
.prose em { color: var(--muted); font-style: italic; }
.prose strong { color: #fff; font-weight: 600; }
.prose hr { border: 0; height: 1px; margin: 1.5em 0; background: linear-gradient(90deg, transparent, var(--line2) 20%, var(--line2) 80%, transparent); }
.pnl { position: relative; margin: 1.1em 0 1.2em; padding: 14px 16px 12px; border: 1px solid rgba(107,220,255,.38); border-radius: 10px; background: linear-gradient(180deg, rgba(107,220,255,.11), rgba(107,220,255,.03)); box-shadow: inset 0 0 0 1px rgba(107,220,255,.05), 0 0 26px rgba(107,220,255,.08); font: 15.5px/1.55 var(--sans); color: #dcf5ff; }
.pnl::before, .pnl::after { content: ''; position: absolute; width: 10px; height: 10px; border: 2px solid var(--sys); }
.pnl::before { left: -1px; top: -1px; border-right: 0; border-bottom: 0; border-top-left-radius: 10px; }
.pnl::after { right: -1px; bottom: -1px; border-left: 0; border-top: 0; border-bottom-right-radius: 10px; }
.pnl-h { font: 700 11.5px/1.3 var(--sans); letter-spacing: .2em; color: var(--sys); margin-bottom: 8px; text-transform: uppercase; display: flex; align-items: center; gap: 8px; }
.pnl-h::before { content: ''; width: 7px; height: 7px; background: var(--sys); transform: rotate(45deg); box-shadow: 0 0 10px var(--sys); flex: none; }
.pnl p { margin: .2em 0; }
.pnl strong { color: #fff; }
.pnl em { color: #9fc8d8; }
.pnl.warn { border-color: rgba(255,143,94,.45); background: linear-gradient(180deg, rgba(255,143,94,.12), rgba(255,143,94,.03)); color: #ffe4d8; box-shadow: 0 0 26px rgba(255,143,94,.08); }
.pnl.warn::before, .pnl.warn::after { border-color: var(--warn); }
.pnl.warn .pnl-h { color: var(--warn); }
.pnl.warn .pnl-h::before { background: var(--warn); box-shadow: 0 0 10px var(--warn); }
.pnl.wanted { border: 2px solid #8a6a40; background: linear-gradient(180deg, #2c2215, #20180f); color: #f0dfc0; text-align: center; font-family: var(--serif); box-shadow: 0 8px 30px rgba(0,0,0,.4); }
.pnl.wanted::before, .pnl.wanted::after { display: none; }
.pnl.wanted .pnl-h { justify-content: center; font: 700 22px/1.2 var(--display); letter-spacing: .25em; color: #e9c58a; }
.pnl.wanted .pnl-h::before { display: none; }

.msg { position: relative; }
.msg.me { margin: 18px 0 22px; padding: 14px 0 6px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.msg.me .prose { color: var(--text2); }
.msg.me.dir .prose { font: 15px/1.5 var(--sans); color: var(--accent2); }
.dir-tag { display: inline-flex; align-items: center; gap: 6px; font: 700 10.5px var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--accent); margin-bottom: 6px; }
.dir-tag .ic { width: 13px; height: 13px; }
.tools { display: flex; gap: 8px; margin: 2px 0 20px; }
.msg.me .tools { margin-bottom: 8px; }
.tbtn { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line2); background: transparent; color: var(--muted); display: grid; place-items: center; transition: color .15s, border-color .15s, background .15s; }
.tbtn .ic { width: 17px; height: 17px; }
.tbtn:hover { color: var(--text); border-color: var(--faint); }
.tbtn.busy { animation: pulse 1s infinite; }
.msg.live .tools { visibility: hidden; }
.typing { display: inline-flex; gap: 6px; padding: 10px 0 18px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); opacity: .3; animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 50% { opacity: 1; transform: translateY(-3px); } }
@keyframes pulse { 50% { opacity: .4; } }
.caret::after { content: ''; display: inline-block; width: 2px; height: 1em; background: var(--accent); vertical-align: -0.15em; margin-left: 2px; animation: pulse .9s infinite; }
.msg-err { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 12px 14px; margin: 6px 0 18px; border-radius: 12px; border: 1px solid rgba(255,95,112,.35); background: rgba(255,95,112,.07); color: #ffd6db; font-size: 14px; }
.msg-edit textarea { font: 17px/1.55 var(--serif); min-height: 120px; }
.msg-edit .row { margin: 8px 0 18px; justify-content: flex-end; }

.m-imgs { display: grid; gap: 10px; margin: 4px 0 12px; }
.m-img { position: relative; margin: 0; border-radius: 14px; overflow: hidden; background: var(--surface); border: 1px solid var(--line); aspect-ratio: 4/3; }
.m-img img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .7s; cursor: zoom-in; }
.m-img.ok img { opacity: 1; }
.m-img .wait { position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: 10px; color: var(--muted); font-size: 13px; background: linear-gradient(110deg, var(--surface) 30%, var(--surface2) 50%, var(--surface) 70%); background-size: 250% 100%; animation: shimmer 1.8s linear infinite; text-align: center; padding: 10px; }
.m-img.ok .wait { display: none; }
.m-img.fail .wait { animation: none; }
.m-img .x { position: absolute; top: 8px; right: 8px; width: 30px; height: 30px; border-radius: 50%; border: 0; background: rgba(0,0,0,.55); color: #fff; display: grid; place-items: center; opacity: 0; transition: opacity .2s; }
.m-img:hover .x, .m-img.fail .x { opacity: 1; }
@media (pointer: coarse) { .m-img .x { opacity: .85; } }
@keyframes shimmer { to { background-position: -150% 0; } }

.sugg-wrap { margin-top: 6px; }
.sugg-label { display: flex; align-items: center; gap: 8px; font: 700 11px var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }
.sugg-label .ic { width: 15px; height: 15px; color: var(--accent); }
.sugg { display: flex; align-items: stretch; gap: 8px; margin-bottom: 10px; }
.sugg .sbtn { width: 44px; flex: none; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); display: grid; place-items: center; }
.sugg .sbtn:hover { color: var(--text); }
.sugg .stext { flex: 1; min-width: 0; padding: 12px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); font: 16px/1.5 var(--serif); color: var(--text2); cursor: pointer; }
.sugg .stext em { color: var(--muted); }
.sugg .stext:hover { border-color: var(--line2); color: var(--text); }

.to-bottom { position: absolute; right: 16px; bottom: 96px; z-index: 6; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--text); color: var(--bg); display: grid; place-items: center; box-shadow: 0 8px 24px rgba(0,0,0,.5); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; transform: translateY(8px); }
.to-bottom.show { opacity: 1; pointer-events: auto; transform: none; }

.composer { padding: 8px 12px calc(10px + var(--safe-b)); border-top: 1px solid var(--line); background: rgba(10,10,15,.94); position: relative; }
.comp-box { max-width: 720px; margin: 0 auto; background: var(--surface); border: 1px solid var(--line2); border-radius: 18px; padding: 6px 6px 6px 14px; transition: border-color .2s, box-shadow .2s; }
.comp-box:focus-within { border-color: color-mix(in srgb, var(--accent) 50%, transparent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 8%, transparent); }
.comp-box.dir { border-color: rgba(255,205,110,.6); }
.comp-box textarea { width: 100%; resize: none; border: 0; outline: 0; box-shadow: none; background: transparent; padding: 7px 0 4px; min-height: 0; max-height: 38vh; color: var(--text); font: 16px/1.45 var(--serif); }
.comp-box textarea:focus { box-shadow: none; }
.comp-row { display: flex; align-items: center; gap: 6px; }
.cbtn { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line2); background: transparent; color: var(--text2); display: grid; place-items: center; }
.cbtn .ic { width: 17px; height: 17px; }
.cbtn.on { border-color: var(--accent); color: var(--accent); }
.cbtn.spark { color: var(--accent2); }
.send { width: 46px; height: 40px; border-radius: 12px; border: 0; background: var(--text); color: var(--bg); display: grid; place-items: center; margin-left: auto; transition: background .2s, transform .1s; }
.send:active { transform: scale(.95); }
.send.stop { background: var(--danger); color: #fff; }
.comp-hint { max-width: 720px; margin: 6px auto 0; font-size: 11.5px; color: var(--faint); text-align: center; }

/* ------------------------------------------------------------------ sheets, menus, toasts */
.sheet-wrap { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.55); backdrop-filter: blur(3px); display: flex; align-items: flex-end; justify-content: center; animation: fade .18s; }
.sheet { width: 100%; max-width: 640px; max-height: 90dvh; display: flex; flex-direction: column; background: var(--bg2); border: 1px solid var(--line2); border-bottom: 0; border-radius: 22px 22px 0 0; animation: rise .25s cubic-bezier(.2,.8,.2,1); padding-bottom: var(--safe-b); }
.sheet:focus { outline: none; } /* the panel takes focus when it opens; its buttons keep their rings */
.sheet-h { display: flex; align-items: center; gap: 8px; padding: 12px 10px 12px 18px; border-bottom: 1px solid var(--line); }
.sheet-h h3 { flex: 1; font: 700 17px var(--display); letter-spacing: .05em; }
.sheet-b { overflow-y: auto; padding: 16px 18px 20px; }
.sheet-f { padding: 12px 18px 14px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; }
@media (min-width: 700px) { .sheet-wrap { align-items: center; } .sheet { border-radius: 22px; border-bottom: 1px solid var(--line2); max-height: 86vh; } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }

.menu-pop { position: fixed; z-index: 70; min-width: 220px; padding: 6px; border-radius: 14px; background: var(--surface2); border: 1px solid var(--line2); box-shadow: 0 18px 50px rgba(0,0,0,.55); animation: fade .12s; }
.menu-pop button { display: flex; width: 100%; align-items: center; gap: 12px; padding: 11px 12px; border: 0; border-radius: 10px; background: transparent; text-align: left; font-size: 14.5px; }
.menu-pop button:hover { background: var(--surface3); }
.menu-pop button.danger { color: var(--danger); }
.menu-pop button small { display: block; color: var(--muted); font-size: 12px; }
.menu-pop button.on { color: var(--accent); }
.menu-pop .ic { width: 18px; height: 18px; }

#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + var(--safe-b)); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: calc(100% - 32px); max-width: 460px; }
.toast { padding: 11px 16px; border-radius: 12px; background: var(--surface3); border: 1px solid var(--line2); box-shadow: 0 10px 30px rgba(0,0,0,.45); font-size: 14px; animation: rise .2s; pointer-events: auto; }
.toast.err { border-color: rgba(255,95,112,.5); color: #ffd6db; }
.toast.ok { border-color: rgba(94,224,160,.45); }

.mem-tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin-bottom: 14px; }
.mem-tabs::-webkit-scrollbar { display: none; }
.mem-item { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.mem-item .row { margin-bottom: 8px; }
.mem-item textarea { min-height: 70px; font-size: 14.5px; }

.lightbox { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.92); display: grid; place-items: center; padding: 20px; animation: fade .15s; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; }

.skel { background: linear-gradient(110deg, var(--surface) 30%, var(--surface2) 50%, var(--surface) 70%); background-size: 250% 100%; animation: shimmer 1.6s linear infinite; border-radius: var(--r); }
.lan-url { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; background: var(--bg2); border: 1px solid var(--line); font: 600 15px/1.2 ui-monospace, Consolas, monospace; color: var(--accent2); margin-top: 8px; word-break: break-all; }
.status-line { font-size: 13.5px; margin-top: 10px; min-height: 1.4em; }
.status-line.ok { color: var(--ok); } .status-line.err { color: var(--danger); }
.stat-row { display: flex; gap: 10px; align-items: flex-start; padding: 7px 0; }
.stat-row + .stat-row { border-top: 1px solid var(--line); }
.stat-row .ic { width: 18px; height: 18px; flex: none; margin-top: 2px; }
.stat-row.ok .ic { color: var(--ok); }
.stat-row.bad .ic { color: var(--warn); }
.stat-row b { display: block; font-size: 13px; }
.stat-row small { color: var(--text2); word-break: break-word; }
