/* ---------- Tokens ---------- */
:root {
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --radius-s: 8px;
  --radius: 14px;
  --radius-l: 20px;
  --sidebar-w: 280px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --grad: linear-gradient(135deg, #7c6cff 0%, #ff7ab8 100%);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e0e11;
  --bg-2: #141418;
  --surface: #1a1a20;
  --surface-2: #22222a;
  --hover: #26262f;
  --border: #2a2a33;
  --border-strong: #3a3a46;
  --text: #ececf1;
  --text-2: #b4b4c0;
  --muted: #80808e;
  --accent: #9a8cff;
  --accent-ink: #0e0e11;
  --accent-soft: rgba(154, 140, 255, .14);
  --danger: #ff6b7a;
  --danger-soft: rgba(255, 107, 122, .12);
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --skeleton-a: #1c1c23;
  --skeleton-b: #2a2a35;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #fbfbfd;
  --bg-2: #f3f3f7;
  --surface: #ffffff;
  --surface-2: #f1f1f6;
  --hover: #ebebf2;
  --border: #e2e2ea;
  --border-strong: #cfcfda;
  --text: #17171c;
  --text-2: #45454f;
  --muted: #74747f;
  --accent: #5b47f5;
  --accent-ink: #ffffff;
  --accent-soft: rgba(91, 71, 245, .10);
  --danger: #d92d43;
  --danger-soft: rgba(217, 45, 67, .08);
  --shadow: 0 10px 30px rgba(20, 20, 40, .12);
  --skeleton-a: #ececf3;
  --skeleton-b: #f8f8fc;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
html { touch-action: pan-x pan-y; } /* no pinch-zoom of the whole page (iPhone ignores user-scalable=no) */
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
img { display: block; max-width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

#app { height: 100dvh; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font-weight: 550; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: 10px;
  border: 0; background: transparent; color: var(--text-2);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

.field { display: grid; gap: 6px; }
.field label { font-size: 13px; font-weight: 550; color: var(--text-2); }
.input {
  width: 100%; height: 44px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg-2); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.hint { font-size: 12.5px; color: var(--muted); }
.error-text { color: var(--danger); font-size: 13.5px; min-height: 1.2em; }

/* ---------- Auth screens ---------- */
.auth {
  height: 100dvh; overflow: auto;
  display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(800px 400px at 20% -10%, rgba(124, 108, 255, .18), transparent 60%),
    radial-gradient(700px 400px at 110% 110%, rgba(255, 122, 184, .14), transparent 60%),
    var(--bg);
}
.auth-card {
  width: min(400px, 100%);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-l);
  padding: 32px 28px; box-shadow: var(--shadow);
  display: grid; gap: 18px;
}
.auth-card.wide { width: min(720px, 100%); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.brand img { width: 32px; height: 32px; border-radius: 9px; }
.auth h1 { margin: 4px 0 0; font-size: 24px; letter-spacing: -.02em; }
.auth p { margin: 0; color: var(--text-2); }
.setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.setup-grid fieldset { margin: 0; padding: 18px; border: 1px solid var(--border); border-radius: var(--radius); display: grid; gap: 12px; }
.setup-grid legend { padding: 0 6px; font-weight: 650; }
@media (max-width: 640px) { .setup-grid { grid-template-columns: 1fr; } }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; height: 100dvh; }
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--bg-2); border-right: 1px solid var(--border);
  padding: calc(12px + var(--safe-t)) 10px 10px;
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 12px; }
.mobile-close { display: none; }
@media (max-width: 860px) { .mobile-close { display: inline-grid; } }
.new-chat { width: 100%; justify-content: flex-start; margin-bottom: 6px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border-radius: 10px; border: 0; background: none;
  color: var(--text-2); text-decoration: none; font-weight: 500; text-align: left;
}
.nav-link:hover { background: var(--hover); color: var(--text); }
.nav-link.active { background: var(--surface-2); color: var(--text); }
.section-label { padding: 14px 10px 6px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.chat-list { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; overscroll-behavior: contain; }
.chat-item { position: relative; display: flex; align-items: center; border-radius: 10px; }
.chat-item a {
  flex: 1; min-width: 0; padding: 9px 10px; color: var(--text-2); text-decoration: none;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis; border-radius: 10px;
}
.chat-item:hover { background: var(--hover); }
.chat-item:hover a { color: var(--text); }
.chat-item.active { background: var(--surface-2); }
.chat-item.active a { color: var(--text); }
.chat-item .icon-btn { width: 30px; height: 30px; opacity: 0; margin-right: 4px; }
.chat-item:hover .icon-btn, .chat-item.active .icon-btn, .chat-item .icon-btn:focus-visible { opacity: 1; }
@media (hover: none) { .chat-item .icon-btn { opacity: 1; } }
.empty-list { padding: 8px 10px; color: var(--muted); font-size: 13.5px; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 8px; position: relative; }
.user-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border-radius: 10px; border: 0; background: none; text-align: left; }
.user-btn:hover { background: var(--hover); }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff; background: var(--grad); flex: none; }
.user-btn .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }

.menu {
  position: absolute; bottom: calc(100% + 6px); left: 0; right: 0; z-index: 30;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 6px; display: grid; gap: 2px;
  animation: pop .14s var(--ease);
}
.menu button, .menu a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  border: 0; background: none; text-align: left; color: var(--text); text-decoration: none;
}
.menu button:hover, .menu a:hover { background: var(--hover); }
/* Pop-up menus sit above the slide-out sidebar (40) but below dialogs (60). */
.menu.floating { position: fixed; bottom: auto; right: auto; width: 170px; z-index: 48; }
@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(.98); } }

.main { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.topbar { display: none; }

/* ---------- Chat ---------- */
.thread { flex: 1; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: smooth; }
.thread-inner { width: min(760px, 100%); margin: 0 auto; padding: 28px 20px 24px; display: grid; gap: 28px; }
.msg { display: grid; gap: 12px; animation: rise .25s var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.bubble {
  justify-self: end; max-width: min(560px, 92%);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 10px 14px; border-radius: 18px 18px 6px 18px;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.meta { justify-self: end; display: flex; gap: 6px; flex-wrap: wrap; margin-top: -6px; }
.chip { font-size: 12px; color: var(--muted); background: transparent; border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; font-variant-numeric: tabular-nums; }

.result { justify-self: start; width: min(var(--w, 512px), 100%); }
.frame {
  position: relative; width: 100%; aspect-ratio: var(--ar, 1); border-radius: var(--radius);
  overflow: hidden; background: var(--surface); border: 1px solid var(--border);
}
.frame img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; opacity: 0; transition: opacity .35s; }
.frame img.loaded { opacity: 1; }
.pending {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 16px;
  background: linear-gradient(110deg, var(--skeleton-a) 30%, var(--skeleton-b) 50%, var(--skeleton-a) 70%) 0 0 / 300% 100%;
  animation: shimmer 1.6s linear infinite;
}
@keyframes shimmer { to { background-position: -300% 0; } }
.pending-body { position: relative; display: grid; gap: 10px; justify-items: center; color: var(--text-2); font-size: 14px; }
.spark { width: 34px; height: 34px; animation: twinkle 1.8s ease-in-out infinite; }
@keyframes twinkle { 50% { transform: scale(.82) rotate(20deg); opacity: .7; } }
.bar { width: 160px; height: 4px; border-radius: 4px; background: var(--border); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--grad); transition: width .35s var(--ease); }

.failed {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px;
  border-radius: var(--radius); border: 1px solid var(--danger); background: var(--danger-soft); color: var(--text);
}
.failed svg { color: var(--danger); margin-top: 2px; }
.failed .actions-inline { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.failed .btn { height: 34px; padding: 0 12px; font-size: 14px; }

.actions { display: flex; gap: 2px; margin-top: 6px; flex-wrap: wrap; }
.result .actions { width: max-content; max-width: calc(100vw - 40px); }
a.icon-btn { text-decoration: none; }
.actions .icon-btn { width: auto; padding: 0 10px; gap: 6px; display: inline-flex; align-items: center; font-size: 13.5px; height: 32px; }
.actions .icon-btn span { display: inline; }
@media (max-width: 520px) { .actions .icon-btn span { display: none; } .actions .icon-btn { padding: 0 9px; } }

/* Empty state */
.welcome { min-height: 100%; display: grid; place-items: center; padding: 24px 20px; }
.welcome-inner { width: min(640px, 100%); text-align: center; display: grid; gap: 18px; justify-items: center; }
.welcome h2 { margin: 0; font-size: clamp(24px, 4vw, 32px); letter-spacing: -.02em; }
.welcome h2 em { font-style: normal; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.welcome p { margin: 0; color: var(--text-2); }

/* ---------- Composer ---------- */
.composer-wrap { padding: 0 16px calc(16px + var(--safe-b)); background: linear-gradient(to top, var(--bg) 70%, transparent); }
.composer {
  width: min(760px, 100%); margin: 0 auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-l);
  box-shadow: var(--shadow); padding: 10px 10px 8px 14px;
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--border-strong); }
.change-chip {
  display: flex; align-items: center; gap: 10px; margin: 0 0 6px; padding: 6px;
  border-radius: 12px; background: var(--accent-soft); border: 1px solid var(--accent-soft);
}
.change-chip .src-thumb { width: 34px; height: 34px; }
.change-text { flex: 1; font-size: 13.5px; color: var(--text-2); }
.change-chip .icon-btn { width: 30px; height: 30px; }
.composer textarea {
  width: 100%; border: 0; outline: none; resize: none; background: transparent;
  max-height: 200px; min-height: 26px; padding: 6px 0 4px; line-height: 1.5;
}
.composer textarea::placeholder { color: var(--muted); }
.composer-row { display: flex; align-items: center; gap: 6px; }
.composer-row .spacer { flex: 1; }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--border); }
.seg button {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px;
  border: 0; border-radius: 7px; background: none; color: var(--muted); font-size: 13px; font-weight: 550;
}
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.shape { display: inline-block; border: 1.6px solid currentColor; border-radius: 2px; }
.shape.sq { width: 12px; height: 12px; } .shape.po { width: 10px; height: 14px; } .shape.la { width: 15px; height: 10px; }
@media (max-width: 520px) { .seg .lbl { display: none; } }
.seed-toggle { font-size: 13px; color: var(--muted); height: 34px; padding: 0 10px; border-radius: 9px; border: 0; background: none; display: inline-flex; align-items: center; gap: 6px; }
.seed-toggle:hover { background: var(--hover); color: var(--text); }
.seed-toggle.on { color: var(--accent); }
.seed-row { display: flex; align-items: center; gap: 8px; padding: 6px 0 8px; }
.seed-row .input { height: 34px; width: 220px; font-family: var(--mono); font-size: 13.5px; }
.send {
  width: 38px; height: 38px; border-radius: 12px; border: 0; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); transition: transform .1s, opacity .15s, filter .15s;
}
.send:hover { filter: brightness(1.08); }
.send:active { transform: scale(.94); }
.send:disabled { opacity: .35; cursor: default; transform: none; filter: none; }
.counter { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.counter.over { color: var(--danger); }

/* ---------- Gallery ---------- */
.page { flex: 1; overflow-y: auto; }
.page-inner { width: min(1200px, 100%); margin: 0 auto; padding: 28px 20px calc(28px + var(--safe-b)); }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-head h2 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.page-head .count { color: var(--muted); }
.grid { columns: 4 220px; column-gap: 12px; }
.tile {
  break-inside: avoid; margin-bottom: 12px; position: relative; border-radius: 12px; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); cursor: zoom-in; display: block; width: 100%; padding: 0;
}
.tile img { width: 100%; height: auto; aspect-ratio: var(--ar); object-fit: cover; opacity: 0; transition: opacity .35s, transform .4s var(--ease); }
.tile img.loaded { opacity: 1; }
.tile:hover img { transform: scale(1.03); }
.tile .cap {
  position: absolute; inset: auto 0 0 0; padding: 28px 12px 10px; font-size: 13px; color: #fff; text-align: left;
  background: linear-gradient(transparent, rgba(0, 0, 0, .7)); opacity: 0; transition: opacity .2s;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.tile:hover .cap { opacity: 1; }
.head-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.clean-btn { height: 36px; padding: 0 10px; color: var(--text-2); }
.install-steps { margin: 0; padding-left: 20px; display: grid; gap: 6px; color: var(--text-2); font-size: 14.5px; }
.cleanup-seg { align-self: start; flex-wrap: wrap; }
.cleanup-seg button { height: 32px; }
.cleanup-count { font-weight: 550; color: var(--text) !important; min-height: 1.5em; }
@media (max-width: 520px) { .clean-btn .lbl { display: none; } .page-head { flex-wrap: wrap; } }
.seg button svg.i { width: 14px; height: 14px; }
.tile-fav { position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: rgba(0, 0, 0, .45); color: #ff6b8b; }
.tile-fav svg.i { width: 16px; height: 16px; fill: currentColor; }
.icon-btn.fav.on { color: #ff6b8b; }
.icon-btn.fav.on svg.i { fill: currentColor; }
.empty-page { text-align: center; padding: 80px 20px; color: var(--muted); display: grid; gap: 14px; justify-items: center; }
.empty-page svg { width: 40px; height: 40px; opacity: .6; }

/* ---------- Admin ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card h3 { margin: 0 0 4px; font-size: 16px; }
.card > p { margin: 0 0 16px; color: var(--text-2); font-size: 14px; }
.user-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.user-row:first-of-type { border-top: 0; }
.user-row .who { flex: 1; min-width: 140px; display: flex; align-items: center; gap: 10px; font-weight: 550; }
.badge { font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.user-block { border-top: 1px solid var(--border); padding-bottom: 10px; }
.user-block:first-of-type { border-top: 0; }
.user-block .user-row { border-top: 0; }
.filter-row { padding: 2px 0 4px 40px; }
.menu-note { display: flex; align-items: center; gap: 10px; padding: 8px 10px; font-size: 13px; color: var(--text-2); }
.reset-form { display: flex; gap: 8px; flex-wrap: wrap; }
.reset-form .input { height: 38px; width: 220px; }
.reset-form .btn { height: 38px; }
.admin-inner { width: min(760px, 100%); }
.link-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.link-row:first-of-type { border-top: 0; }
.link-text { flex: 1; min-width: 0; display: grid; gap: 2px; }
.link-text code { font-family: var(--mono); font-size: 14px; overflow-wrap: anywhere; color: var(--text); user-select: all; }
.link-text code.big { font-size: 17px; font-weight: 600; }
.status-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.status-row:first-of-type { border-top: 0; }
.status-text { flex: 1; min-width: 0; }
.status-title { font-weight: 600; }
.web-form { display: grid; gap: 12px; }
.web-form > p { margin: 0; color: var(--text-2); font-size: 14px; }
.agree { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; color: var(--text-2); }
.agree input { margin-top: 3px; accent-color: var(--accent); }
.setting-row { display: flex; align-items: center; gap: 16px; cursor: pointer; }
.switch { position: relative; flex: none; width: 44px; height: 26px; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch .knob { position: absolute; inset: 0; border-radius: 999px; background: var(--border-strong); transition: background .15s; pointer-events: none; }
.switch .knob::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .18s var(--ease); box-shadow: 0 1px 3px rgba(0, 0, 0, .3); }
.switch input:checked + .knob { background: var(--accent); }
.switch input:checked + .knob::after { transform: translateX(18px); }
.switch input:focus-visible + .knob { outline: 2px solid var(--accent); outline-offset: 2px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.ok { background: #3ecf8e; box-shadow: 0 0 0 4px rgba(62, 207, 142, .15); }
.dot.warn { background: #f5b84a; box-shadow: 0 0 0 4px rgba(245, 184, 74, .15); }
.dot.bad { background: var(--danger); box-shadow: 0 0 0 4px var(--danger-soft); }
.dot.busy { background: var(--accent); animation: twinkle 1.4s ease-in-out infinite; }

/* ---------- Lightbox & dialogs ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(5, 5, 8, .86);
  display: grid; grid-template-rows: 1fr auto; animation: fade .18s;
  padding: calc(12px + var(--safe-t)) 12px calc(12px + var(--safe-b));
  backdrop-filter: blur(6px);
}
@keyframes fade { from { opacity: 0; } }
.overlay { height: 100dvh; }
.lb-img { min-height: 0; overflow: hidden; display: grid; place-items: center; }
.lb-img img { max-width: 100%; max-height: calc(100dvh - 150px - var(--safe-t) - var(--safe-b)); width: auto; height: auto; object-fit: contain; border-radius: 10px; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); }
.lb-bar { width: min(760px, 100%); margin: 12px auto 0; color: #e8e8ee; display: grid; gap: 8px; }
.lb-bar .prompt { font-size: 14px; color: #c8c8d2; max-height: 4.5em; overflow: auto; }
.lb-bar .actions .icon-btn { color: #d0d0da; }
.lb-bar .actions .icon-btn:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.lb-close { position: absolute; top: calc(10px + var(--safe-t)); right: 10px; color: #fff; background: rgba(255, 255, 255, .1); }
.lb-close:hover { background: rgba(255, 255, 255, .2); color: #fff; }

.pc-banner {
  display: flex; align-items: flex-start; gap: 10px; margin: 12px auto 0; width: min(760px, calc(100% - 28px));
  padding: 10px 14px; border-radius: 12px; font-size: 14px;
  background: rgba(245, 184, 74, .12); border: 1px solid rgba(245, 184, 74, .35); color: var(--text);
}
.pc-banner svg { color: #f5b84a; margin-top: 1px; }
.pc-banner span { color: var(--text-2); }

/* Editor */
.editor {
  position: fixed; inset: 0; z-index: 55; height: 100dvh; display: grid; grid-template-rows: auto 1fr auto;
  background: var(--bg); animation: fade .15s;
  padding: var(--safe-t) 0 var(--safe-b);
}
.editor-top { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.editor-title { flex: 1; font-weight: 600; }
.editor-tools { display: flex; gap: 4px; }
.editor-tools .btn { height: 36px; padding: 0 10px; }
@media (max-width: 520px) { .editor-tools .lbl { display: none; } }
.editor-stage { min-height: 0; display: grid; place-items: center; padding: 14px; overflow: hidden; background: var(--bg-2); }
.editor-art { position: relative; border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); user-select: none; }
.editor-art img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.paint { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .5; touch-action: none; cursor: none; }
.brush-cursor {
  position: absolute; left: 0; top: 0; border-radius: 50%; pointer-events: none;
  border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .5), inset 0 0 0 1px rgba(0, 0, 0, .5);
}
.editor-bottom { width: min(760px, 100%); margin: 0 auto; padding: 10px 14px 14px; display: grid; gap: 8px; }
.brush-row { display: flex; align-items: center; gap: 10px; color: var(--text-2); }
.brush-row input[type=range] { flex: 1; max-width: 260px; accent-color: var(--accent); }
.editor-hint { min-height: 1.3em; }
.editor-composer { padding: 8px 8px 8px 14px; }
.editor-composer textarea { flex: 1; border: 0; outline: none; resize: none; background: transparent; padding: 6px 0; max-height: 120px; line-height: 1.5; }
@media (max-width: 860px) { .editor-composer textarea { font-size: 16px; } }

.edit-bubble { display: flex; align-items: center; gap: 10px; }
.src-thumb { width: 40px; height: 40px; flex: none; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.chip.accent { color: var(--accent); border-color: var(--accent-soft); background: var(--accent-soft); }

.dialog-back { position: fixed; inset: 0; z-index: 60; background: rgba(5, 5, 8, .6); display: grid; place-items: center; padding: 16px; animation: fade .15s; }
.dialog {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-l); padding: 22px; box-shadow: var(--shadow); display: grid; gap: 10px; animation: pop .16s var(--ease);
}
.dialog h3 { margin: 0; font-size: 17px; }
.dialog p { margin: 0; color: var(--text-2); font-size: 14.5px; }
.dialog .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; z-index: 70; left: 50%; transform: translateX(-50%); bottom: calc(110px + var(--safe-b)); display: grid; gap: 8px; width: min(420px, calc(100% - 32px)); pointer-events: none; }
.toast {
  pointer-events: auto; background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 12px;
  font-size: 14px; box-shadow: var(--shadow); animation: rise .2s var(--ease);
}
.toast.err { background: var(--danger); color: #fff; }

/* ---------- Mobile ---------- */
.scrim { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 40; inset: 0 auto 0 0; width: min(300px, 86vw);
    transform: translateX(-102%); transition: transform .25s var(--ease); box-shadow: var(--shadow);
    padding-bottom: calc(10px + var(--safe-b));
  }
  .shell.nav-open .sidebar { transform: none; }
  .shell.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, .5); animation: fade .2s; }
  .topbar {
    display: flex; align-items: center; gap: 6px; padding: calc(8px + var(--safe-t)) 8px 8px;
    border-bottom: 1px solid var(--border); background: var(--bg);
  }
  .topbar .title { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; text-align: center; }
  .thread-inner { padding: 20px 14px 16px; gap: 24px; }
  .composer-wrap { padding: 0 10px calc(10px + var(--safe-b)); }
  .composer textarea { font-size: 16px; } /* stops iOS zooming on focus */
  .input { font-size: 16px; }
  .page-inner { padding: 20px 14px calc(20px + var(--safe-b)); }
  .grid { columns: 2 140px; column-gap: 8px; }
  .tile { margin-bottom: 8px; }
  .tile .cap { display: none; }
  .auth-card { padding: 26px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
