:root {
  --bg: #2b2240;
  --bg2: #362b52;
  --panel: #fffaf3;
  --panel2: #f6eee2;
  --ink: #3b2f2a;
  --muted: #8d7f74;
  --line: #eadccb;
  --accent: #ff8a5c;
  --accent2: #ffb36b;
  --wito: #4f7cff;
  --wita: #e8559a;
  --good: #3fb37f;
  --radius: 16px;
  --shadow: 0 10px 40px rgba(20, 10, 40, .35);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); overflow: hidden; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.err { color: #d23c3c; min-height: 1.2em; margin: 6px 0 0; font-size: .9rem; }

/* ---------- Botones ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 10px 16px; font-weight: 700;
  background: var(--panel2); color: var(--ink); display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  transition: transform .08s, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: #fde3e3; color: #c0392b; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 10px; font-size: .88rem; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  border: 0; background: rgba(255,255,255,.12); color: #fff; width: 40px; height: 40px; border-radius: 12px; font-size: 1.15rem;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn.sm { width: 32px; height: 32px; font-size: .95rem; }
.icon-btn:hover { background: rgba(255,255,255,.22); }

/* ---------- Login ---------- */
#login { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(circle at 30% 20%, #4a3a78, var(--bg) 60%); }
.login-card { background: var(--panel); border-radius: 24px; padding: 28px; width: min(440px, 100%); text-align: center; box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 4px; font-size: 1.9rem; }
.amp { color: var(--accent); }
.who { display: flex; gap: 14px; justify-content: center; margin: 14px 0; }
.who-btn { border: 3px solid transparent; background: var(--panel2); border-radius: 18px; padding: 10px 10px 8px; display: flex; flex-direction: column; align-items: center; gap: 4px; font-weight: 800; font-size: 1.1rem; flex: 1; max-width: 170px; }
.who-btn canvas { width: 100px; height: 116px; }
.who-btn.sel[data-user="wito"] { border-color: var(--wito); }
.who-btn.sel[data-user="wita"] { border-color: var(--wita); }
#loginForm { display: flex; flex-direction: column; gap: 10px; }
#loginForm input { border: 2px solid var(--line); border-radius: 12px; padding: 12px; font-size: 1rem; background: #fff; }

/* ---------- App ---------- */
#app { position: fixed; inset: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr); }
#topbar { display: flex; align-items: center; gap: 12px; padding: calc(8px + var(--safe-t)) 12px 8px; color: #fff; min-height: 56px; }
.brand { font-size: 1.1rem; white-space: nowrap; }
#presence { flex: 1; display: flex; gap: 8px; justify-content: center; min-width: 0; }
.pchip { display: inline-flex; align-items: center; gap: 6px; background: rgba(255,255,255,.1); padding: 5px 12px; border-radius: 999px; font-size: .88rem; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pchip .dot { width: 9px; height: 9px; border-radius: 50%; background: #888; flex: none; }
.pchip.on .dot { background: #52e08f; box-shadow: 0 0 6px #52e08f; }
.top-actions { display: flex; gap: 6px; }

#main { display: flex; min-height: 0; min-width: 0; }
#stage { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 0; padding: 4px 8px; overflow: hidden; }
#room { display: block; border-radius: 14px; box-shadow: 0 14px 50px rgba(0,0,0,.45); touch-action: none; cursor: pointer; }
#roomTip { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); background: rgba(0,0,0,.65); color: #fff; padding: 7px 14px; border-radius: 999px; font-size: .9rem; pointer-events: none; max-width: 92%; text-align: center; }
#connBanner { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: #ffcc66; color: #523; padding: 6px 14px; border-radius: 999px; font-weight: 700; font-size: .85rem; }

/* ---------- Chat ---------- */
#chat { width: 340px; display: flex; flex-direction: column; background: var(--panel); border-radius: 18px 0 0 18px; margin: 4px 0 4px; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.chat-head .icon-btn { background: var(--panel2); color: var(--ink); margin-left: auto; }
#chatClose { display: none; }
#typing { font-size: .82rem; }
#chatList { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 3px; overscroll-behavior: contain; }
.day-sep { text-align: center; font-size: .75rem; color: var(--muted); margin: 10px 0 4px; }
.msg { max-width: 82%; display: flex; flex-direction: column; }
.msg.me { align-self: flex-end; align-items: flex-end; }
.msg .who-name { font-size: .72rem; font-weight: 800; margin: 6px 6px 1px; }
.msg .bubble { padding: 8px 12px; border-radius: 16px; background: var(--panel2); white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; line-height: 1.35; }
.msg.me .bubble { background: #ffe1cf; }
.msg .bubble a { color: #c55a1e; }
.msg .t { font-size: .68rem; color: var(--muted); margin: 1px 6px; }
.msg .yt-btn { margin-top: 4px; }
#chatForm { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); padding-bottom: calc(10px + var(--safe-b)); }
#chatInput { flex: 1; resize: none; border: 2px solid var(--line); border-radius: 14px; padding: 9px 12px; max-height: 120px; background: #fff; outline: none; }
#chatInput:focus { border-color: var(--accent2); }
.load-older { align-self: center; margin-bottom: 6px; }

/* ---------- Barra de herramientas ---------- */
#toolbar { display: flex; justify-content: center; gap: 6px; padding: 6px 8px calc(8px + var(--safe-b)); }
.tool { position: relative; border: 0; background: rgba(255,255,255,.1); color: #fff; border-radius: 16px; padding: 7px 14px 5px; display: flex; flex-direction: column; align-items: center; min-width: 74px; }
.tool span { font-size: 1.45rem; line-height: 1.1; }
.tool small { font-size: .74rem; font-weight: 700; opacity: .9; }
.tool:hover { background: rgba(255,255,255,.2); }
.tool i { position: absolute; top: 2px; right: 8px; background: var(--accent); color: #fff; font-style: normal; font-size: .72rem; font-weight: 800; border-radius: 999px; padding: 1px 6px; }
.tool-wrap { position: relative; }
#emotes { position: absolute; bottom: 110%; right: 0; background: var(--panel); border-radius: 16px; padding: 8px; display: grid; grid-template-columns: repeat(4, 44px); gap: 4px; box-shadow: var(--shadow); z-index: 40; }
#emotes button { border: 0; background: var(--panel2); border-radius: 12px; font-size: 1.5rem; height: 44px; }
.tool[data-act="chat"] { display: none; }

/* ---------- Hojas / paneles ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(15, 8, 30, .5); z-index: 50; display: grid; place-items: center; padding: 16px; animation: fade .15s; }
.sheet { background: var(--panel); border-radius: 22px; width: min(820px, 100%); max-height: min(88dvh, 900px); display: flex; flex-direction: column; box-shadow: var(--shadow); overflow: hidden; animation: pop .18s; }
.sheet.wide { width: min(1180px, 100%); height: min(88dvh, 900px); }
.sheet.small { width: min(440px, 100%); }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: 1.2rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-head .close { border: 0; background: var(--panel2); width: 38px; height: 38px; border-radius: 12px; font-size: 1.1rem; flex: none; }
.sheet-body { padding: 16px; overflow-y: auto; flex: 1; min-height: 0; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(14px) scale(.98); opacity: 0; } }

/* ---------- Librero ---------- */
.lib-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.lib-tools input[type=search] { flex: 1; min-width: 160px; border: 2px solid var(--line); border-radius: 12px; padding: 9px 12px; background: #fff; }
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 16px; }
.book { display: flex; flex-direction: column; gap: 6px; cursor: pointer; }
.cover { aspect-ratio: 2/3; border-radius: 6px 10px 10px 6px; overflow: hidden; position: relative; box-shadow: 0 6px 16px rgba(60,30,20,.25), inset 4px 0 0 rgba(0,0,0,.12); background: #ccc; transition: transform .15s; }
.book:hover .cover { transform: translateY(-3px) rotate(-.5deg); }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover .ph { position: absolute; inset: 0; padding: 14px 10px; color: #fff; display: flex; flex-direction: column; justify-content: space-between; font-weight: 800; line-height: 1.15; text-shadow: 0 1px 2px rgba(0,0,0,.3); word-break: break-word; }
.cover .fmt { position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,.55); color: #fff; font-size: .62rem; font-weight: 800; padding: 2px 6px; border-radius: 6px; }
.book .b-title { font-weight: 800; font-size: .92rem; line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book .b-meta { font-size: .76rem; color: var(--muted); }
.pbar { height: 5px; background: var(--line); border-radius: 9px; overflow: hidden; }
.pbar i { display: block; height: 100%; border-radius: 9px; }
.prog-row { display: flex; align-items: center; gap: 6px; font-size: .72rem; color: var(--muted); }
.prog-row .pbar { flex: 1; }
.empty { text-align: center; padding: 40px 10px; color: var(--muted); }
.empty .big { font-size: 3rem; }
.upload-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.upload-item { background: var(--panel2); border-radius: 10px; padding: 8px 12px; font-size: .85rem; }
.upload-item .pbar { margin-top: 5px; }
.drop-hint { border: 2px dashed var(--accent2); border-radius: 16px; padding: 18px; text-align: center; color: var(--muted); margin-bottom: 14px; display: none; }
.dragging .drop-hint { display: block; background: #fff4ea; }

.book-detail { display: grid; grid-template-columns: 160px 1fr; gap: 18px; }
.book-detail .cover { width: 160px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-size: .8rem; font-weight: 700; color: var(--muted); }
.field input, .field textarea { border: 2px solid var(--line); border-radius: 10px; padding: 9px 11px; background: #fff; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Lector ---------- */
#reader { position: fixed; inset: 0; z-index: 70; display: flex; flex-direction: column; background: var(--r-bg); color: var(--r-fg); }
#reader.light { --r-bg: #fbfaf7; --r-fg: #2a2522; --r-bar: #f1ede6; --r-line: #e4ddd2; }
#reader.sepia { --r-bg: #f4ecd8; --r-fg: #4b3a29; --r-bar: #eadfc6; --r-line: #dccfb2; }
#reader.dark { --r-bg: #1b1a1f; --r-fg: #d9d4cc; --r-bar: #26252c; --r-line: #34323b; }
.r-bar { display: flex; align-items: center; gap: 6px; padding: calc(6px + var(--safe-t)) 8px 6px; background: var(--r-bar); border-bottom: 1px solid var(--r-line); min-height: 52px; }
.r-bar.bottom { border-top: 1px solid var(--r-line); border-bottom: 0; padding: 6px 8px calc(6px + var(--safe-b)); }
.r-title { flex: 1; min-width: 0; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .95rem; }
.r-btn { border: 0; background: transparent; color: var(--r-fg); min-width: 38px; height: 38px; border-radius: 10px; font-size: 1.05rem; padding: 0 8px; white-space: nowrap; }
.r-btn:hover { background: var(--r-line); }
.r-btn.txt { font-size: .85rem; font-weight: 700; }
.r-mid { flex: 1; text-align: center; font-size: .82rem; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-body { flex: 1; position: relative; min-height: 0; }
#reader.zen .r-bar { display: none; }
.r-body iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: var(--r-bg); }
.r-pdf { position: absolute; inset: 0; overflow: auto; padding: 14px 0 40px; -webkit-overflow-scrolling: touch; }
.r-pdf .pg { margin: 0 auto 14px; background: #fff; box-shadow: 0 2px 12px rgba(0,0,0,.18); position: relative; }
.r-pdf .pg canvas { display: block; width: 100%; height: 100%; }
.r-pdf .pg .num { position: absolute; bottom: -18px; right: 0; font-size: .7rem; opacity: .5; }
#reader.dark .r-pdf .pg canvas { filter: invert(.9) hue-rotate(180deg); }
#reader.sepia .r-pdf .pg canvas { filter: sepia(.35) brightness(.97); }
.r-loading { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1rem; opacity: .7; }
.r-progress { height: 3px; background: var(--r-line); }
.r-progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .3s; }
.together { display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 999px; padding: 5px 12px; font-size: .8rem; font-weight: 700; background: rgba(232, 85, 154, .14); color: inherit; white-space: nowrap; max-width: min(44vw, 340px); overflow: hidden; text-overflow: ellipsis; }
.together.wito { background: rgba(79, 124, 255, .16); }
.r-pop { position: absolute; right: 8px; top: 8px; z-index: 5; background: var(--r-bar); color: var(--r-fg); border: 1px solid var(--r-line); border-radius: 14px; padding: 12px; box-shadow: var(--shadow); width: min(340px, calc(100vw - 16px)); max-height: 75%; overflow: auto; }
.r-pop h4 { margin: 0 0 8px; }
.r-pop .opts { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.r-pop .opts button { border: 1px solid var(--r-line); background: transparent; color: var(--r-fg); border-radius: 10px; padding: 6px 10px; }
.r-pop .opts button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.toc a { display: block; padding: 7px 6px; color: inherit; text-decoration: none; border-radius: 8px; font-size: .9rem; }
.toc a:hover, .toc a.cur { background: var(--r-line); }
.note-pop textarea { width: 100%; min-height: 130px; border-radius: 10px; border: 1px solid var(--r-line); padding: 10px; background: var(--r-bg); color: var(--r-fg); font-family: 'Patrick Hand', 'Nunito', cursive; font-size: 1.15rem; }

/* ---------- Libreta ---------- */
.nb { display: grid; grid-template-columns: 260px 1fr; height: 100%; min-height: 0; }
.nb-side { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--panel2); }
.nb-tabs { display: flex; gap: 6px; padding: 10px; }
.nb-tabs button { flex: 1; border: 0; border-radius: 10px; padding: 8px; font-weight: 800; background: transparent; }
.nb-tabs button.on.wito { background: var(--wito); color: #fff; }
.nb-tabs button.on.wita { background: var(--wita); color: #fff; }
.nb-list { flex: 1; overflow-y: auto; padding: 0 8px 10px; }
.nb-item { display: block; width: 100%; text-align: left; border: 0; background: transparent; border-radius: 10px; padding: 9px 10px; margin-bottom: 2px; }
.nb-item:hover { background: rgba(0,0,0,.04); }
.nb-item.on { background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.nb-item b { display: block; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nb-item span { font-size: .74rem; color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nb-new { margin: 0 10px 10px; }
.nb-page { display: flex; flex-direction: column; min-height: 0; min-width: 0; position: relative; background: #fffdf6; }
.nb-pagehead { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid #f0e6d2; flex-wrap: wrap; }
.nb-pagehead .saved { font-size: .78rem; color: var(--muted); margin-left: auto; white-space: nowrap; }
.nb-paper { flex: 1; overflow-y: auto; padding: 8px 18px 40px 64px; position: relative; min-height: 0;
  background-color: #fffdf6;
  background-image: linear-gradient(90deg, transparent 50px, #f3b5b5 50px, #f3b5b5 52px, transparent 52px),
                    repeating-linear-gradient(transparent 0 33px, #cfe0f2 33px 34px);
  background-attachment: local; background-position: 0 6px; }
.nb-paper .date { font-family: 'Patrick Hand', cursive; color: #b08a6a; font-size: 1.05rem; height: 34px; line-height: 34px; }
.nb-title { width: 100%; border: 0; background: transparent; outline: none; font-family: 'Patrick Hand', 'Comic Sans MS', cursive; font-size: 1.7rem; line-height: 34px; height: 34px; color: #2c3e70; padding: 0; margin-bottom: 34px; }
.nb-text { width: 100%; border: 0; background: transparent; outline: none; resize: none; font-family: 'Patrick Hand', 'Comic Sans MS', cursive; font-size: 1.32rem; line-height: 34px; color: #2c3e70; padding: 0; min-height: 60vh; overflow: hidden; display: block; }
.nb.normal .nb-title, .nb.normal .nb-text { font-family: 'Nunito', sans-serif; }
.nb.normal .nb-text { font-size: 1.08rem; }
.nb-ro { font-size: .8rem; background: #fff3d6; color: #8a6420; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.nb-empty { margin: auto; text-align: center; color: var(--muted); padding: 30px; }
.nb-back { display: none; }

/* ---------- Tele ---------- */
.tv-layout { display: grid; grid-template-columns: 1fr 360px; height: 100%; min-height: 0; }
.tv-main { padding: 14px; display: flex; flex-direction: column; gap: 10px; min-width: 0; min-height: 0; background: #17131f; }
.tv-slot { width: 100%; aspect-ratio: 16/9; background: #000; border-radius: 12px; max-height: calc(100% - 60px); position: relative; }
.tv-slot .off { position: absolute; inset: 0; display: grid; place-items: center; color: #aaa; text-align: center; padding: 20px; }
.tv-now { color: #eee; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tv-now .ttl { flex: 1; min-width: 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tv-side { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--line); }
.tv-search { display: flex; gap: 8px; padding: 12px; }
.tv-search input { flex: 1; min-width: 0; border: 2px solid var(--line); border-radius: 12px; padding: 9px 12px; background: #fff; }
.tv-tabs { display: flex; gap: 4px; padding: 0 12px 8px; }
.tv-tabs button { border: 0; background: transparent; padding: 6px 10px; border-radius: 9px; font-weight: 700; color: var(--muted); }
.tv-tabs button.on { background: var(--panel2); color: var(--ink); }
.tv-results { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.vid { display: flex; gap: 10px; width: 100%; border: 0; background: transparent; text-align: left; padding: 6px; border-radius: 12px; }
.vid:hover { background: var(--panel2); }
.vid .th { width: 130px; flex: none; aspect-ratio: 16/9; border-radius: 8px; background: #ddd center/cover; position: relative; }
.vid .th em { position: absolute; right: 4px; bottom: 4px; background: rgba(0,0,0,.75); color: #fff; font-style: normal; font-size: .7rem; padding: 1px 5px; border-radius: 4px; }
.vid .info { min-width: 0; }
.vid .info b { font-size: .86rem; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.vid .info span { font-size: .75rem; color: var(--muted); display: block; margin-top: 3px; }
.sheet.tv-sheet .sheet-body { padding: 0; }

#tvBox { position: fixed; z-index: 5; background: #000; overflow: hidden; border-radius: 4px; }
#tvBox #ytPlayer, #tvBox iframe { width: 100%; height: 100%; display: block; border: 0; }
#tvBox.hidden-tv { left: -9999px !important; top: 0 !important; width: 320px !important; height: 180px !important; }
#tvBox.room { pointer-events: none; border-radius: 2px; }
#tvBox.big { z-index: 60; border-radius: 12px; }
#tvBox.mini { z-index: 80; border-radius: 12px; box-shadow: var(--shadow); right: 12px; bottom: calc(12px + var(--safe-b)); width: min(300px, 55vw); aspect-ratio: 16/9; }
.tv-mini-bar { display: none; position: absolute; top: 4px; right: 4px; gap: 4px; }
#tvBox.mini .tv-mini-bar { display: flex; }
.tv-mini-bar button { border: 0; background: rgba(0,0,0,.6); color: #fff; width: 30px; height: 30px; border-radius: 8px; }
#tvJoin { position: absolute; inset: 0; border: 0; background: rgba(0,0,0,.6); color: #fff; font-weight: 800; font-size: 1rem; pointer-events: auto; }
#tvBox.room #tvJoin { font-size: .6rem; }

/* ---------- Avatar ---------- */
.av-layout { display: grid; grid-template-columns: 200px 1fr; gap: 18px; }
.av-preview { background: linear-gradient(#f3e5d3, #e7d2b9); border-radius: 18px; display: grid; place-items: center; padding: 10px; }
.av-group { margin-bottom: 12px; }
.av-group h4 { margin: 0 0 6px; font-size: .85rem; color: var(--muted); }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.sw { width: 32px; height: 32px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.sw.on { box-shadow: 0 0 0 3px var(--accent); }
.chip { border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px; font-weight: 700; font-size: .85rem; }
.chip.on { border-color: var(--accent); background: #fff1e8; }

/* ---------- Toasts / diálogo ---------- */
#toasts { position: fixed; top: calc(12px + var(--safe-t)); left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 24px); }
.toast { background: #2a2235; color: #fff; padding: 10px 16px; border-radius: 14px; box-shadow: var(--shadow); font-size: .92rem; animation: pop .2s; pointer-events: auto; }
.toast.err { background: #b93a3a; }
.dialog p { margin: 0 0 16px; line-height: 1.4; }

/* ---------- Responsivo ---------- */
@media (max-width: 999px) {
  #chat { position: fixed; left: 0; right: 0; bottom: 0; width: auto; height: min(75dvh, 640px); z-index: 45; border-radius: 22px 22px 0 0; margin: 0; box-shadow: var(--shadow); transform: translateY(110%); transition: transform .22s ease; }
  #chat.open { transform: none; }
  #chatClose { display: inline-flex; }
  .tool[data-act="chat"] { display: flex; }
}
@media (max-width: 760px) {
  #topbar { padding-left: 10px; padding-right: 10px; gap: 8px; min-height: 50px; }
  .brand { display: none; }
  #presence { justify-content: flex-start; }
  .tool { min-width: 0; flex: 1; padding: 6px 4px 4px; }
  .tool-wrap { flex: 1; display: flex; }
  #toolbar { gap: 4px; }
  .sheet-backdrop { padding: 0; place-items: end stretch; }
  .sheet, .sheet.wide { width: 100%; max-height: none; height: calc(100dvh - var(--safe-t) - 10px); border-radius: 22px 22px 0 0; }
  .sheet.small { height: auto; max-height: 90dvh; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 12px; }
  .book-detail { grid-template-columns: 110px 1fr; }
  .book-detail .cover { width: 110px; }
  .nb { grid-template-columns: 1fr; }
  .nb.show-page .nb-side { display: none; }
  .nb:not(.show-page) .nb-page { display: none; }
  .nb-back { display: inline-flex; }
  .nb-paper { padding-left: 46px; padding-right: 12px; background-image: linear-gradient(90deg, transparent 34px, #f3b5b5 34px, #f3b5b5 36px, transparent 36px), repeating-linear-gradient(transparent 0 33px, #cfe0f2 33px 34px); }
  .tv-layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .tv-main { padding: 8px; }
  .tv-side { border-left: 0; border-top: 1px solid var(--line); min-height: 0; }
  .av-layout { grid-template-columns: 1fr; }
  .av-preview { height: 170px; }
  .r-btn.hide-sm { display: none; }
}
