/* ================= wayrouter app ================= */
html { overscroll-behavior: none; }
body { overflow-x: clip; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.boot { padding: 40px; }
.grow { flex: 1; min-width: 0; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); min-height: 100dvh; }
.side { grid-row: 1 / 3; position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 22px; padding: 20px 12px 16px; border-right: 1px solid var(--line); background: var(--bg-2); overflow-y: auto; }
.side .wordmark { padding: 4px 10px 8px; }
.nav-list { display: grid; gap: 2px; }
.nav-list a { display: flex; align-items: center; gap: 12px; padding: 0.62rem 0.8rem; border-radius: var(--r-md); color: var(--muted); text-decoration: none; font-size: 0.93rem; font-weight: 500; transition: background 160ms, color 160ms; }
.nav-list a svg { width: 19px; height: 19px; flex: none; }
.nav-list a:hover { color: var(--text); background: var(--surface-2); }
.nav-list a.on { color: var(--text); background: var(--surface-3); }
.nav-list a.on svg { color: var(--accent); }
.nav-list .rule { height: 1px; background: var(--line); margin: 8px 6px; }
.side-foot { margin-top: auto; display: grid; gap: 12px; }
.me-card { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); }
.me-card .av { --s: 36px; }
.me-card .who { flex: 1; min-width: 0; display: grid; gap: 1px; line-height: 1.2; padding: 0; }
.me-card .nm { font-weight: 600; font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.me-card .st { font-size: 0.74rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.me-card .st::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); flex: none; }
.me-card .icon-btn { width: 32px; height: 32px; border: 0; background: transparent; color: var(--muted); }
.me-card .icon-btn:hover { background: var(--surface-3); color: var(--text); }
.me-card .icon-btn svg { width: 17px; height: 17px; }
.main { grid-column: 2; grid-row: 2; min-width: 0; padding: 6px 32px 72px; }
.main.chat-main { grid-row: 1 / 3; padding: 0; }
.shell.chat-mode .dtop { display: none; }

/* desktop top bar: search + credits */
.dtop { grid-column: 2; grid-row: 1; position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 14px 32px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(14px); }
.dtop-search { flex: 1; max-width: 640px; }
.dtop-search input { height: 46px; padding-top: 0; padding-bottom: 0; background-color: var(--surface); }
.dtop .grow { flex: 1; }
.pill-link { display: inline-flex; align-items: center; gap: 8px; min-height: 42px; padding: 0 1rem 0 0.85rem; border-radius: var(--r-pill); background: var(--surface); border: 1px solid var(--line); color: var(--text); text-decoration: none; font-size: 0.86rem; font-weight: 550; transition: background 160ms, border-color 160ms; }
.pill-link:hover { background: var(--surface-2); border-color: var(--line-2); }
.pill-link svg { width: 16px; height: 16px; color: var(--accent); }
.pill-link b { font-weight: 650; }
.topbar, .tabbar { display: none; }
.credit-pill { display: inline-flex; gap: 6px; align-items: center; padding: 0.4rem 0.85rem 0.4rem 0.7rem; border-radius: var(--r-pill); background: var(--surface-2); border: 1px solid var(--line); font-size: 0.85rem; text-decoration: none; color: var(--text); }
.credit-pill b { font-weight: 700; }
.credit-pill svg { width: 15px; height: 15px; color: var(--accent); }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head h1 { font: 600 2.2rem/1.05 var(--display); letter-spacing: -0.03em; }
.page-head p { color: var(--muted); margin-top: 8px; }
.h2 { font: 600 1.35rem/1.15 var(--display); letter-spacing: -0.02em; margin: 36px 0 14px; }

/* ---------- forms ---------- */
.field { display: grid; gap: 8px; margin-bottom: 18px; }
.field > label { font-size: 0.82rem; font-weight: 650; color: var(--text); display: flex; justify-content: space-between; gap: 10px; }
.field .hint { font-weight: 400; color: var(--faint); }
input[type='text'], input[type='email'], input[type='password'], input[type='search'], textarea {
  width: 100%; padding: 0.8rem 1rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); outline: none; font-size: 16px;
  transition: border-color 160ms, background 160ms, box-shadow 160ms;
}
textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
input:focus, textarea:focus { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 4px var(--accent-soft); }
input[type='search'] { padding-left: 2.6rem; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='none' stroke='%23a8a0ae' stroke-width='2' stroke-linecap='round'><circle cx='8' cy='8' r='6'/><path d='M13 13l4 4'/></svg>"); background-repeat: no-repeat; background-position: 14px 50%; border-radius: var(--r-pill); }
input[type='range'] { width: 100%; accent-color: var(--accent); height: 28px; }
.check { display: flex; gap: 12px; align-items: flex-start; font-size: 0.92rem; color: var(--muted); cursor: pointer; padding: 12px 14px; border-radius: var(--r-md); background: var(--surface-2); }
.check input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.err { color: var(--danger); font-size: 0.88rem; min-height: 1.3em; }

/* ---------- custom dropdown ---------- */
.dd { position: relative; display: inline-flex; min-width: 0; }
.dd-btn { display: inline-flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; min-width: 150px; max-width: 100%; padding: 0.55rem 0.8rem 0.55rem 1rem; border-radius: var(--r-pill); border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font-weight: 600; font-size: 0.92rem; cursor: pointer; transition: background 160ms, border-color 160ms; }
.dd-btn:hover { background: var(--surface-3); }
.dd-btn[aria-expanded='true'] { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.dd-btn svg { width: 16px; height: 16px; color: var(--muted); transition: transform 200ms var(--ease-out); flex: none; }
.dd-btn[aria-expanded='true'] svg { transform: rotate(180deg); }
.dd-val { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field .dd, .set-row .dd { display: flex; }
.field .dd-btn, .set-row .dd-btn { width: 100%; border-radius: var(--r-md); }
.dd.compact .dd-btn { min-width: 0; min-height: 38px; padding: 0.4rem 0.6rem 0.4rem 0.85rem; font-size: 0.85rem; }
.dd-pop { position: fixed; z-index: 80; max-height: min(420px, 70vh); overflow-y: auto; padding: 6px; border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-pop); opacity: 0; transform: translateY(-6px) scale(0.98); transform-origin: top; transition: opacity 160ms var(--ease-out), transform 220ms var(--ease-out); }
.dd-pop.in { opacity: 1; transform: none; }
.dd-list { display: grid; gap: 2px; }
.dd-opt { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px; min-height: 48px; border: 0; border-radius: 12px; background: transparent; color: var(--text); text-align: left; cursor: pointer; transition: background 120ms; }
.dd-opt:hover, .dd-opt:focus-visible { background: var(--surface-2); outline: none; }
.dd-opt.on { background: var(--accent-soft); }
.dd-opt.off { opacity: 0.6; }
.dd-l { flex: 1; min-width: 0; display: grid; gap: 2px; }
.dd-l b { font-weight: 650; font-size: 0.95rem; }
.dd-l small { color: var(--muted); font-size: 0.8rem; line-height: 1.35; }
.dd-badge { flex: none; font-size: 0.72rem; font-weight: 650; padding: 0.2rem 0.55rem; border-radius: var(--r-pill); background: var(--surface-3); color: var(--muted); }
.dd-badge.lock { background: var(--accent); color: var(--accent-ink); }
.dd-check { width: 18px; flex: none; color: var(--accent); }
.dd-check svg { width: 18px; height: 18px; }

/* ---------- sheets ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 90; background: rgba(5, 3, 8, 0); display: flex; align-items: flex-end; justify-content: center; transition: background 240ms; }
.sheet-wrap.in { background: rgba(5, 3, 8, 0.55); }
.sheet { width: 100%; max-width: 560px; max-height: 86dvh; overflow-y: auto; background: var(--surface); border-radius: var(--r-xl) var(--r-xl) 0 0; padding: 10px 16px calc(env(safe-area-inset-bottom) + 18px); transform: translateY(105%); transition: transform 460ms var(--ease-spring); box-shadow: var(--shadow-pop); overscroll-behavior: contain; }
.sheet-wrap.in .sheet { transform: none; }
.grab { width: 40px; height: 5px; border-radius: 99px; background: var(--line-2); margin: 2px auto 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-title { font: 600 1.25rem/1.2 var(--display); letter-spacing: -0.02em; padding: 0 4px 8px; }
.sheet-head .sheet-title { padding-bottom: 0; }
@media (min-width: 901px) {
  .sheet-wrap { align-items: center; }
  .sheet { border-radius: var(--r-xl); transform: translateY(24px) scale(0.97); opacity: 0; transition: transform 320ms var(--ease-out), opacity 200ms; padding: 18px 22px 24px; }
  .sheet-wrap.in .sheet { opacity: 1; }
  .sheet .grab { display: none; }
}
.set-list { display: grid; gap: 8px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px; border-radius: var(--r-lg); background: var(--surface-2); }
.set-row.col { display: grid; gap: 10px; align-items: stretch; }
.set-top { display: flex; justify-content: space-between; align-items: baseline; font-weight: 650; }
.set-row > div > span { font-weight: 650; }
.ctx-val { font: 600 1rem var(--display); color: var(--accent); }
.set-help { color: var(--muted); font-size: 0.82rem; margin-top: 4px; line-height: 1.45; }
.set-help a { color: var(--accent); }
.set-note { color: var(--ok); font-size: 0.85rem; padding: 4px 6px; }
.switch { position: relative; width: 52px; height: 32px; flex: none; border-radius: 99px; border: 0; background: var(--surface-3); cursor: pointer; transition: background 200ms; }
.switch i { position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.3); transition: transform 360ms var(--ease-spring); }
.switch.on { background: var(--accent); }
.switch.on i { transform: translateX(20px); }

/* ---------- auth ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: radial-gradient(60% 40% at 50% 0%, rgba(154, 140, 247, 0.12), transparent 70%), var(--bg); }
.auth-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); padding: 32px; box-shadow: var(--shadow); display: grid; gap: 6px; animation: rise 520ms var(--ease-out) backwards; }
.auth-card h1 { font: 600 2.3rem/1.02 var(--display); letter-spacing: -0.035em; margin: 22px 0 4px; }
.auth-card .sub { color: var(--muted); margin-bottom: 18px; }
.auth-card .btn { width: 100%; margin-top: 6px; }
.auth-alt { margin-top: 14px; text-align: center; font-size: 0.92rem; color: var(--muted); }
.auth-alt a { color: var(--accent); font-weight: 600; }

/* ---------- discover ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input { max-width: 420px; }
.seg { display: inline-flex; padding: 4px; border-radius: var(--r-pill); background: var(--surface); border: 1px solid var(--line); margin-bottom: 18px; }
.seg a, .seg button { border: 0; background: transparent; padding: 0.5rem 1.1rem !important; border-radius: var(--r-pill); color: var(--muted); font-weight: 600; font-size: 0.9rem !important; text-decoration: none; cursor: pointer; }
.seg .on { background: var(--text); color: var(--bg); }
.chips { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none; margin: 0 0 12px; padding: 2px 0; overscroll-behavior-x: contain; }
.chips::-webkit-scrollbar { display: none; }
.cbtn { flex: none; scroll-snap-align: start; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--muted); padding: 0.55rem 1.1rem; border-radius: var(--r-pill); font-size: 0.92rem; font-weight: 600; min-height: 42px; transition: background 160ms, color 160ms, transform 120ms var(--ease-spring); }
.cbtn:active { transform: scale(0.95); }
.cbtn.on { background: var(--text); color: var(--bg); border-color: transparent; }
.subtabs { display: flex; align-items: center; gap: 4px; margin-bottom: 16px; }
.subtabs .sub { border: 0; background: transparent; color: var(--faint); padding: 0.4rem 0.9rem; border-radius: var(--r-pill); cursor: pointer; font-size: 0.88rem; font-weight: 600; }
.subtabs .sub.on { background: var(--surface-2); color: var(--text); }
.subtabs .note { margin-left: auto; font-size: 0.76rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; }
.ccard { display: block; text-decoration: none; color: inherit; animation: rise 520ms var(--ease-out) backwards; animation-delay: calc(var(--i, 0) * 45ms); }
.ccard .cover { position: relative; aspect-ratio: 3 / 4; border-radius: var(--r-lg); overflow: hidden; background: var(--surface-2); transition: transform 300ms var(--ease-out), box-shadow 300ms; border: 1px solid var(--line); }
.ccard:hover .cover { transform: translateY(-3px); border-color: var(--line-2); }
.ccard:active .cover { transform: scale(0.97); }
.ccard .cover .av { --s: 100%; width: 100%; height: 100%; border-radius: 0; font-size: 3.6rem; transition: transform 700ms var(--ease-out); }
.ccard:hover .cover .av { transform: scale(1.05); }
.ccard .cover-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ccard .scrim, .ccard .cover-shade { position: absolute; inset: 0; background: linear-gradient(180deg, transparent 50%, rgba(10, 6, 12, 0.92)); pointer-events: none; }
.ccard .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px; color: #fff; display: grid; gap: 3px; }
.ccard .cap h3 { font: 600 1.05rem/1.15 var(--display); letter-spacing: -0.015em; color: #fff; }
.ccard .cap p { color: rgba(255, 255, 255, 0.8); font-size: 0.8rem; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ccard .count { position: absolute; top: 10px; right: 10px; z-index: 2; display: inline-flex; align-items: center; gap: 5px; padding: 0.25rem 0.6rem; border-radius: var(--r-pill); background: rgba(10, 6, 12, 0.6); backdrop-filter: blur(8px); color: #fff; font-size: 0.72rem; font-weight: 600; }
.ccard .count svg { width: 12px; height: 12px; }
.ccard .rank { position: absolute; left: 10px; bottom: 58px; z-index: 2; font: 600 3.4rem/1 var(--display); color: var(--gold); text-shadow: 0 4px 18px rgba(0,0,0,.45); letter-spacing: -0.05em; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tags-under { margin-top: 8px; min-height: 26px; }
/* story cards keep a text body under the cover */
.ccard .body { padding: 10px 2px 0; display: grid; gap: 3px; }
.ccard .body h3 { font: 600 1.15rem/1.15 var(--display); }
.ccard .body p { font-size: 0.84rem; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ccard .meta { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: 0.75rem; color: var(--faint); gap: 6px; }

.empty { border: 1.5px dashed var(--line-2); border-radius: var(--r-xl); padding: 44px 24px; text-align: center; color: var(--muted); display: grid; gap: 14px; justify-items: center; background: var(--grad-soft); }
.empty h3 { font: 600 1.6rem var(--display); color: var(--text); }
.install-card { display: flex; align-items: center; gap: 12px; padding: 14px 16px; margin-bottom: 18px; border-radius: var(--r-lg); background: var(--grad-soft); border: 1px solid var(--line); }
.install-card p { font-size: 0.85rem; color: var(--muted); }

/* ---------- character / story page ---------- */
.cpage { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 40px; max-width: 1040px; }
.cpage .big .av { --s: 100%; width: 100%; aspect-ratio: 3 / 4; height: auto; border-radius: var(--r-xl); font-size: 7rem; box-shadow: var(--shadow); }
.cpage h1 { font: 600 3rem/1 var(--display); letter-spacing: -0.04em; margin-bottom: 10px; }
.cpage .tag { color: var(--muted); font-size: 1.1rem; margin-bottom: 16px; }
.sect { margin-top: 24px; padding: 18px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); }
.sect h4 { font-size: 0.78rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--accent); margin-bottom: 8px; }
.sect p { white-space: pre-wrap; color: var(--text); line-height: 1.6; }
.row-btns { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 22px; }
.spage { max-width: 980px; }
.hero-img { position: relative; height: 320px; border-radius: var(--r-xl); overflow: hidden; background-size: cover; background-position: center; margin-bottom: 20px; display: flex; align-items: flex-end; }
.hero-img.none { background: radial-gradient(120% 90% at 28% 18%, hsl(var(--h) 85% 58%), transparent 62%), radial-gradient(110% 110% at 85% 95%, hsl(calc(var(--h) + 40) 70% 34%), hsl(var(--h) 50% 12%)); }
.hero-img .shade { position: absolute; inset: 0; background: linear-gradient(180deg, transparent 30%, rgba(8, 4, 10, 0.85)); }
.hero-txt { position: relative; padding: 28px; color: #fff; }
.hero-txt h1 { font: 600 3rem/1 var(--display); letter-spacing: -0.04em; margin-bottom: 6px; }
.hero-txt p { opacity: .85; }
.cast-row { display: flex; flex-wrap: wrap; gap: 10px; }
.cast-pill { display: inline-flex; align-items: center; gap: 10px; padding: 6px 16px 6px 6px; border-radius: var(--r-pill); background: var(--surface-2); text-decoration: none; font-weight: 600; font-size: 0.9rem; }
.cast-pill:hover { background: var(--surface-3); }

/* ---------- editor ---------- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 28px; align-items: start; max-width: 1120px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); padding: 22px; }
.panel h3 { font: 600 1.4rem var(--display); letter-spacing: -0.02em; margin-bottom: 4px; }
.panel .sub { font-size: 0.88rem; color: var(--muted); margin-bottom: 16px; }
.side-col { position: sticky; top: 24px; display: grid; gap: 16px; }
.side-col .panel { background: var(--surface); }
.av-pick { display: flex; gap: 16px; align-items: center; }
.av-pick .av { --s: 92px; border-radius: 22px; }
.starter-row { margin-bottom: 8px; }
.hue-bar { height: 8px; border-radius: 99px; background: linear-gradient(90deg, hsl(0 80% 60%), hsl(60 80% 55%), hsl(120 70% 50%), hsl(180 70% 50%), hsl(240 75% 62%), hsl(300 75% 58%), hsl(360 80% 60%)); }
.bg-prev { height: 130px; border-radius: var(--r-md); border: 1.5px dashed var(--line-2); background-size: cover; background-position: center; display: grid; place-items: center; color: var(--faint); font-size: 0.85rem; margin-bottom: 8px; }
.cast-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; max-height: 300px; overflow-y: auto; padding: 2px; }
.cast-opt { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-2); cursor: pointer; text-align: left; font-size: 0.88rem; font-weight: 550; transition: border-color 160ms, background 160ms; }
.cast-opt.on { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- chats list ---------- */
.chat-list { display: grid; gap: 8px; max-width: 780px; }
.chat-row { display: flex; gap: 14px; align-items: center; padding: 12px 14px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); text-decoration: none; transition: background 160ms, transform 160ms var(--ease-spring); }
.chat-row:hover { background: var(--surface-2); }
.chat-row:active { transform: scale(0.985); }
.chat-row .nm { font-weight: 700; }
.chat-row .last { color: var(--muted); font-size: 0.86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- chat ---------- */
@property --h1 { syntax: '<number>'; inherits: true; initial-value: 20; }
.chat-wrap { height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr); }
.chat-wrap > * { min-width: 0; }
.chat-wrap.ambient { background: radial-gradient(60% 30% at 12% 0%, hsl(var(--h1) 30% 40% / 0.13), transparent 70%), var(--bg); }
.chat-wrap.has-bg { position: relative; background: var(--chat-bg) center / cover no-repeat; }
.chat-wrap.has-bg::before { content: ''; position: absolute; inset: 0; background: color-mix(in srgb, var(--bg) 74%, transparent); pointer-events: none; }
.chat-wrap.has-bg > * { position: relative; }
.chat-top { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(14px); }
.chat-top .grow { min-width: 0; }
.chat-top .nm { font-weight: 700; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-top .sm { font-size: 0.78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stack { display: flex; } .stack .av { margin-left: -10px; box-shadow: 0 0 0 2px var(--bg); } .stack .av:first-child { margin-left: 0; }
.msgs { overflow-y: auto; padding: 24px 20px; overscroll-behavior: contain; }
.msgs-in { max-width: 760px; margin: 0 auto; display: grid; gap: 14px; min-width: 0; }
.turns { display: grid; gap: 8px; }
.turns.me { justify-items: stretch; }
.turn { display: grid; gap: 6px; }
.m { display: flex; gap: 10px; align-items: flex-start; animation: rise 280ms var(--ease-out) backwards; min-width: 0; }
.m.me { justify-content: flex-end; }
.m .bub { padding: 0.75rem 1rem; border-radius: 20px; max-width: min(620px, 86%); white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; font-size: 0.98rem; }
.m.ai .bub { background: var(--surface-2); border-top-left-radius: 6px; }
.m.me .bub { background: var(--bubble-me); color: var(--text); border-top-right-radius: 6px; }
.stack-v { display: grid; gap: 4px; min-width: 0; max-width: min(620px, 86%); }
.stack-v .bub { max-width: 100%; }
.who { font-size: 0.78rem; font-weight: 700; color: var(--muted); padding-left: 4px; }
.av-spacer { width: 34px; flex: none; }
.m-narr { color: var(--muted); font-size: 0.93rem; line-height: 1.6; padding: 2px 8px 2px 44px; white-space: pre-wrap; overflow-wrap: anywhere; animation: rise 280ms var(--ease-out) backwards; }
.turn.is-narr .m-narr { padding-left: 8px; }
.m-narr.me { padding: 2px 8px; text-align: right; }
.m em { color: var(--blush); }
.typing-dots { display: inline-flex; gap: 5px; padding: 4px 2px; }
.typing-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: bounce 1.1s infinite; }
.typing-dots i:nth-child(2) { animation-delay: .12s; } .typing-dots i:nth-child(3) { animation-delay: .24s; }
@keyframes bounce { 0%, 60%, 100% { transform: none; opacity: .45; } 30% { transform: translateY(-4px); opacity: 1; } }
.starters { display: flex; flex-wrap: wrap; gap: 8px; margin-left: 44px; }
.starters .chip { cursor: pointer; font-size: 0.85rem; padding: 0.45rem 0.9rem; color: var(--text); }
.starters .chip:hover { border-color: var(--accent); }
.composer { padding: 10px 20px 18px; background: linear-gradient(180deg, transparent, var(--bg) 40%); }
.mention-row { max-width: 760px; margin: 0 auto 10px; display: flex; align-items: center; gap: 8px; overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain; min-width: 0; }
.mention-row::-webkit-scrollbar { display: none; }
.mention-row > * { flex: none; }
.mention-row .chip { cursor: pointer; padding: 4px 12px 4px 4px; color: var(--text); font-size: 0.82rem; }
.mention-row .chip:hover { border-color: var(--accent); }
.composer-in { max-width: 760px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; padding: 6px 6px 6px 18px; border-radius: 26px; background: var(--surface); border: 1px solid var(--line); min-width: 0; transition: border-color 160ms, box-shadow 160ms; }
.composer-in:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.composer textarea { border: 0; background: transparent; box-shadow: none !important; min-height: 28px; max-height: 160px; resize: none; padding: 0.55rem 0; overflow-y: auto; }
.composer textarea:focus-visible { outline: none; }
.composer .meta { max-width: 760px; margin: 8px auto 0; display: flex; justify-content: space-between; font-size: 0.74rem; color: var(--faint); padding: 0 10px; }
.send-btn { flex: none; width: 46px; height: 46px; border-radius: 50%; border: 0; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); cursor: pointer; transition: transform 160ms var(--ease-spring), background 160ms; }
.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(0.9); }
.send-btn[disabled] { opacity: 0.5; }
.send-btn svg { width: 20px; height: 20px; }
.banner { max-width: 760px; margin: 0 auto 12px; padding: 12px 14px 12px 16px; border-radius: var(--r-lg); background: var(--grad-soft); border: 1px solid var(--line); font-size: 0.92rem; display: flex; gap: 12px; align-items: center; }
.banner .btn { margin-left: auto; }

/* ---------- billing / studio ---------- */
.plans-app { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 36px; }
.plan-a { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); padding: 22px; display: grid; gap: 8px; align-content: start; }
.plan-a.cur { border: 1px solid var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.plan-a .pr { font: 600 2.6rem/1 var(--display); letter-spacing: -0.04em; }
.plan-a .pr small { font: 500 0.82rem var(--sans); color: var(--faint); letter-spacing: 0; }
.plan-a ul { list-style: none; padding: 0; margin: 6px 0 12px; display: grid; gap: 7px; font-size: 0.9rem; color: var(--muted); }
.plan-a li::before { content: '✓  '; color: var(--accent); font-weight: 700; }
.studio-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.studio-out { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.job { border-radius: var(--r-lg); overflow: hidden; background: var(--surface); border: 1px solid var(--line); }
.job-media img, .job-media video { width: 100%; }
.job-wait { aspect-ratio: 1; display: grid; place-items: center; color: var(--muted); padding: 16px; text-align: center; font-size: 0.9rem; background: var(--grad-soft); }
.job.failed .job-wait { color: var(--danger); }
.job-p { padding: 10px 14px 14px; font-size: 0.82rem; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tbl { width: 100%; border-collapse: collapse; font-size: 0.9rem; max-width: 760px; }
.tbl th { text-align: left; font-size: 0.74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--faint); padding: 8px 0; border-bottom: 1px solid var(--line); }
.tbl td { padding: 11px 0; border-bottom: 1px solid var(--line); }

#toasts { position: fixed; bottom: 20px; right: 20px; z-index: 95; display: grid; gap: 10px; }
.toast { background: var(--surface-2); border: 1px solid var(--line-2); border-left: 4px solid var(--danger); padding: 0.8rem 1rem; border-radius: var(--r-md); box-shadow: var(--shadow); max-width: 360px; font-size: 0.9rem; animation: rise 260ms var(--ease-out) backwards; }
.toast.ok { border-left-color: var(--ok); }

/* ================= phones ================= */
@media (max-width: 900px) {
  .shell { display: block; }
  .side, .dtop { display: none; }
  .topbar { display: flex; position: sticky; top: 0; z-index: 20; align-items: center; gap: 10px; padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(16px); }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 10px; right: 10px; bottom: calc(env(safe-area-inset-bottom) + 10px); z-index: 30; padding: 6px; border-radius: 24px; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(16px); border: 1px solid var(--line); box-shadow: var(--shadow-pop); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 52px; border-radius: 18px; font-size: 0.66rem; font-weight: 650; color: var(--muted); text-decoration: none; transition: color 160ms, background 160ms; }
  .tabbar a svg { width: 22px; height: 22px; }
  .tabbar a.on { color: var(--accent); background: var(--accent-soft); }
  .tabbar a:active { transform: scale(0.94); }
  .main { padding: 6px 16px calc(100px + env(safe-area-inset-bottom)); }
  .home { grid-template-columns: minmax(0, 1fr); }
  .rail { display: none; }
  .hero-card { padding: 26px 22px; min-height: 0; margin-bottom: 20px; }
  .hero-card .star { width: 190px; height: 190px; right: -50px; }
  .shell.chat-mode .topbar, .shell.chat-mode .tabbar { display: none; }
  .main.chat-main { padding: 0; }
  .page-head { margin-bottom: 16px; }
  .page-head h1 { font-size: 1.7rem; }
  .page-head .btn { min-height: 40px; padding: 0.5rem 1rem; }
  .chips { margin: 0 -16px 10px; padding: 2px 16px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .ccard .cap { padding: 11px; }
  .ccard .cap h3 { font-size: 1.05rem; }
  .ccard .rank { font-size: 2.8rem; bottom: 50px; }
  .cpage, .editor { grid-template-columns: 1fr; gap: 22px; }
  .cpage .big { max-width: 260px; }
  .cpage h1, .hero-txt h1 { font-size: 2.2rem; }
  .hero-img { height: 230px; }
  .side-col { position: static; order: -1; }
  .plans-app, .studio-grid { grid-template-columns: 1fr; }
  .studio-out { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tbl { display: block; overflow-x: auto; overscroll-behavior-x: contain; }
  .chat-wrap { height: 100dvh; }
  .chat-top { padding: calc(env(safe-area-inset-top) + 8px) 10px 8px; gap: 8px; }
  .chat-top .sm { display: none; }
  .chat-top .dd.compact { display: none; }
  .msgs { padding: 14px 12px; }
  .m .bub, .stack-v { max-width: 88%; }
  .composer { padding: 8px 10px calc(env(safe-area-inset-bottom) + 10px); }
  .composer .meta { display: none; }
  .starters { margin-left: 0; }
  #toasts { left: 12px; right: 12px; bottom: calc(96px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }
}
@media (max-width: 360px) { .grid { grid-template-columns: 1fr; } }

.mature-tag { position: absolute; top: 10px; left: 10px; z-index: 2; font-size: 0.7rem; font-weight: 800; padding: 0.2rem 0.55rem; border-radius: var(--r-pill); background: var(--accent); color: var(--accent-ink); }
input[type='date'] { width: 100%; padding: 0.8rem 1rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); font-size: 16px; color-scheme: inherit; min-height: 48px; }
input[type='date']:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 4px var(--accent-soft); }

/* ---------- home: hero + right rail ---------- */
.home { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; align-items: start; }
.home-main { min-width: 0; }
@media (max-width: 1180px) { .home { grid-template-columns: minmax(0, 1fr); } .rail { display: none; } }
.hero-card { position: relative; overflow: hidden; border-radius: var(--r-xl); border: 1px solid var(--line); background: radial-gradient(55% 120% at 88% 50%, rgba(154, 140, 247, 0.12), transparent 65%), var(--surface); padding: 44px 44px 40px; margin-bottom: 26px; display: grid; gap: 10px; align-content: center; min-height: 240px; }
.hero-card h1 { position: relative; font: 500 clamp(2.4rem, 5vw, 3.7rem)/1 var(--display); letter-spacing: -0.045em; background: linear-gradient(180deg, var(--text) 30%, var(--muted)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero-card .lead { position: relative; font: 500 clamp(1.2rem, 2.4vw, 1.6rem)/1.2 var(--display); letter-spacing: -0.02em; color: var(--muted); }
.hero-card .sub { position: relative; color: var(--faint); font-size: 0.98rem; }
.hero-card .btn { position: relative; justify-self: start; margin-top: 12px; }
.hero-card .star { position: absolute; right: 24px; top: 50%; transform: translateY(-50%); width: 280px; height: 280px; color: var(--text); opacity: 0.09; pointer-events: none; }
.rail { display: grid; gap: 16px; position: sticky; top: 76px; }
.rcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); padding: 16px; }
.rhead { display: flex; justify-content: space-between; align-items: center; margin: 0 2px 12px; }
.rhead h3 { font: 600 1rem var(--display); letter-spacing: -0.01em; }
.rhead a { color: var(--accent); font-size: 0.8rem; font-weight: 550; text-decoration: none; }
.feat { position: relative; display: block; aspect-ratio: 16 / 11; border-radius: var(--r-lg); overflow: hidden; text-decoration: none; color: #fff; background: var(--surface-2); }
.feat .av { --s: 100%; width: 100%; height: 100%; border-radius: 0; font-size: 3.4rem; }
.feat .shade { position: absolute; inset: 0; background: linear-gradient(180deg, transparent 40%, rgba(8, 8, 12, 0.9)); }
.feat .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 12px 14px; display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; }
.feat b { font: 600 1rem/1.2 var(--display); display: block; }
.feat small { font-size: 0.78rem; opacity: 0.8; }
.feat .rate { font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.trend { display: grid; gap: 2px; }
.trend a { display: grid; grid-template-columns: 16px 40px minmax(0, 1fr) 18px; align-items: center; gap: 12px; padding: 8px 6px; border-radius: var(--r-md); text-decoration: none; color: inherit; transition: background 140ms; }
.trend a:hover { background: var(--surface-2); }
.trend .rk { font-size: 0.85rem; color: var(--faint); font-weight: 600; text-align: center; }
.trend .av { --s: 40px; border-radius: 10px; }
.trend .nm { font-weight: 600; font-size: 0.92rem; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trend .ct { font-size: 0.76rem; color: var(--muted); }
.trend svg { width: 15px; height: 15px; color: var(--faint); }
.qa { display: grid; gap: 8px; }
.qa a { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line); text-decoration: none; font-weight: 550; font-size: 0.9rem; transition: background 140ms, border-color 140ms; }
.qa a:hover { background: var(--surface-3); border-color: var(--line-2); }
.qa a svg { width: 18px; height: 18px; color: var(--accent); flex: none; }
.qa a svg:last-child { margin-left: auto; color: var(--faint); width: 15px; height: 15px; }

.feed-anchor { scroll-margin-top: 80px; }
.btn svg { width: 16px; height: 16px; }
@media (min-width: 901px) { .toolbar.m-only { display: none; } }
@media (max-width: 900px) { .hero-card h1 { font-size: 2.3rem; } }
@media (max-width: 1180px) { .home { grid-template-columns: minmax(0, 1fr); } .rail { display: none; } }

.m.me .av { margin-left: 0; }
.m.me .av-spacer { width: 34px; }
