:root {
  --bg: #16130f;
  --bg2: #1e1a15;
  --card: #241f19;
  --card2: #2d2720;
  --line: #3a3229;
  --text: #f3ece2;
  --muted: #a99d8c;
  --accent: #f0a04b;
  --accent2: #ffbf73;
  --danger: #ef6a5a;
  --radius: 16px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 20% -10%, #2a2118 0%, transparent 60%), var(--bg);
  color: var(--text); font: 15px/1.45 var(--sans); -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.sprite { position: absolute; }
svg { width: 1.2em; height: 1.2em; flex: none; }
a { color: var(--accent2); }
button, input, select { font: inherit; color: inherit; }
kbd { font: 12px var(--sans); background: var(--card2); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; }
code { background: var(--card2); padding: 2px 6px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.error { color: var(--danger); margin: 8px 0 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--card2); border-radius: 999px;
  padding: 10px 18px; cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap;
  transition: background .15s, transform .1s, border-color .15s;
}
.btn:hover { border-color: #5a4d3e; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1c1309; font-weight: 600; }
.btn.primary:hover { background: var(--accent2); }
.btn.big { padding: 14px 26px; font-size: 16px; }
.btn.danger { color: #ffb4a8; border-color: #6a3a32; }
.btn.danger:hover { background: #4a2a24; border-color: var(--danger); }
.btn.sm { padding: 7px 14px; font-size: 14px; }
.icon-btn { background: none; border: 0; padding: 6px; border-radius: 10px; cursor: pointer; display: inline-flex; color: var(--muted); }
.icon-btn:hover { color: var(--text); background: var(--card2); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
input:not([type=range]), select {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 11px 14px; outline: none; min-width: 0;
}
input:not([type=range]):focus { border-color: var(--accent); }

/* Home */
.home-wrap { max-width: 560px; margin: 0 auto; padding: 72px 16px 40px; }
.home-wrap.center { text-align: center; }
.home-wrap.center .row { justify-content: center; }
.brand-lg { display: flex; align-items: center; gap: 10px; color: var(--accent); font-weight: 600; letter-spacing: .02em; }
.center .brand-lg { justify-content: center; }
.brand-lg svg { width: 26px; height: 26px; }
h1 { font: 600 clamp(34px, 7vw, 52px)/1.05 var(--serif); margin: 22px 0 14px; letter-spacing: -.01em; }
h2 { font: 600 20px/1.2 var(--serif); margin: 0 0 8px; }
.lede { color: var(--muted); font-size: 17px; margin: 0 0 28px; }
.create { padding: 20px; display: grid; gap: 14px; }
.home-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#browse { margin-top: 28px; }
.browse-head { display: flex; align-items: center; justify-content: space-between; }
.browse-head h2 { margin: 0; }
#browse-list { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 8px; }
#browse-list a { display: flex; align-items: center; gap: 14px; padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; color: var(--text); text-decoration: none; }
#browse-list a:hover { border-color: #5a4d3e; }
#browse-list a.full { opacity: .6; }
.room-main { display: grid; min-width: 0; flex: 1; }
.room-main strong, .room-main span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-main span, .room-side > span { font-size: 13px; }
.room-side { display: grid; justify-items: end; gap: 4px; flex: none; }
.dots { display: flex; }
.mini { width: 24px; height: 24px; border-radius: 50%; background: var(--c); color: #1a120a; font: 600 10px/24px var(--sans); text-align: center; margin-left: -6px; box-shadow: 0 0 0 2px var(--card); }
.mini:first-child { margin-left: 0; }
.mini.away { filter: grayscale(.8) brightness(.6); }
.field { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.join { display: flex; gap: 10px; margin-top: 16px; }
.join input { flex: 1; }
#recent { margin-top: 36px; }
#recent h2 { font: 600 13px var(--sans); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
#recent-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
#recent-list a { display: flex; justify-content: space-between; gap: 12px; padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; color: var(--text); text-decoration: none; }
#recent-list a:hover { border-color: #5a4d3e; }
#recent-list .muted { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Room */
#room { max-width: 1180px; margin: 0 auto; padding: 0 16px 32px; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 0; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--accent); text-decoration: none; font-weight: 600; }
.brand svg { width: 22px; height: 22px; }
.conn { background: #4a2a1f; color: #ffc2a8; border-radius: 999px; padding: 4px 12px; font-size: 13px; }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; cursor: pointer; max-width: 180px; }
.chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--me, var(--accent)); flex: none; }

.seats { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 10px; margin: 4px 0 18px; }
.seat { display: grid; justify-items: center; gap: 6px; min-width: 0; position: relative; }
.avatar {
  width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center;
  font: 600 18px var(--sans); color: #1a120a; background: var(--c); position: relative;
  box-shadow: 0 0 0 3px var(--bg), 0 0 0 4px color-mix(in srgb, var(--c) 50%, transparent);
  transition: transform .2s;
}
.seat.me .avatar { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--c); }
.seat.away .avatar { filter: grayscale(.8) brightness(.6); }
.seat.buffering .avatar::after {
  content: ""; position: absolute; inset: -7px; border-radius: 50%;
  border: 2px solid transparent; border-top-color: var(--c); animation: spin 0.9s linear infinite;
}
.seat.open .avatar { background: transparent; border: 2px dashed var(--line); box-shadow: none; color: var(--muted); font-weight: 400; font-size: 13px; }
.crown { position: absolute; top: -9px; left: 50%; transform: translateX(-50%); color: #ffcf5a; filter: drop-shadow(0 1px 2px #000a); display: flex; }
.crown svg { width: 16px; height: 16px; }
.mod {
  position: absolute; top: -4px; width: 20px; height: 20px; border-radius: 50%; padding: 0;
  display: grid; place-items: center; cursor: pointer; border: 2px solid var(--bg);
  background: var(--card2); color: var(--muted); opacity: .75; transition: opacity .15s, background .15s, color .15s;
}
.mod svg { width: 11px; height: 11px; }
.kick { right: -4px; }
.ban { left: -4px; }
.seat:hover .mod, .mod:focus-visible { opacity: 1; }
.mod:hover { background: var(--danger); color: #fff; }
.seat .name { font-size: 12.5px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.seat.me .name { color: var(--text); }
.seat .status { position: absolute; top: -4px; right: calc(50% - 34px); font-size: 11px; background: var(--card2); border: 1px solid var(--line); border-radius: 999px; padding: 0 6px; color: var(--muted); }
@keyframes spin { to { transform: rotate(360deg); } }

.room-body { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: stretch; }
.player { padding: 28px; }
.empty { text-align: center; padding: 48px 12px; }
.empty-art { width: 84px; height: 84px; margin: 0 auto 18px; border-radius: 24px; display: grid; place-items: center; background: var(--card2); color: var(--accent); }
.empty-art svg { width: 40px; height: 40px; }
.empty p { color: var(--muted); margin: 0 0 22px; }

.now { display: grid; gap: 14px; }
.cover-wrap { width: min(280px, 70%); aspect-ratio: 1; margin: 0 auto 6px; position: relative; border-radius: 14px; overflow: hidden; box-shadow: 0 20px 50px #0008; background: var(--card2); }
.cover-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; position: relative; z-index: 1; }
.cover-fallback { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; text-align: center; font: 600 22px/1.2 var(--serif); color: #fff; }
.meta { text-align: center; }
.meta h2 { font-size: clamp(22px, 3.2vw, 30px); margin: 4px 0 4px; }
.author { color: var(--muted); }
.chapter-line { color: var(--accent2); font-size: 13px; letter-spacing: .04em; text-transform: uppercase; min-height: 1.2em; }

.scrub { position: relative; height: 26px; cursor: pointer; touch-action: none; margin-top: 6px; }
.scrub-track { position: absolute; left: 0; right: 0; top: 11px; height: 4px; background: var(--line); border-radius: 4px; }
.scrub:hover .scrub-track, .scrub.drag .scrub-track { height: 6px; top: 10px; }
.scrub-fill { height: 100%; background: var(--accent); border-radius: 4px; width: 0; }
.scrub-ticks i { position: absolute; top: -1px; bottom: -1px; width: 2px; background: var(--bg); }
.scrub-knob { position: absolute; top: 6px; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; background: var(--text); box-shadow: 0 2px 6px #0006; pointer-events: none; }
.scrub-tip { position: absolute; bottom: 28px; transform: translateX(-50%); background: var(--card2); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; font-size: 12px; white-space: nowrap; pointer-events: none; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.times { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); gap: 8px; }
.times .muted { text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.controls { display: flex; justify-content: center; align-items: center; gap: clamp(6px, 2vw, 18px); margin: 4px 0; }
.ctl { background: none; border: 0; color: var(--text); width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; position: relative; }
.ctl:hover { background: var(--card2); }
.ctl svg { width: 26px; height: 26px; }
.ctl.skip span { position: absolute; font-size: 9.5px; font-weight: 700; top: 50%; left: 50%; transform: translate(-50%, -38%); }
.ctl.play { width: 72px; height: 72px; background: var(--accent); color: #1c1309; box-shadow: 0 8px 24px #f0a04b40; }
.ctl.play:hover { background: var(--accent2); }
.ctl.play svg { width: 32px; height: 32px; }
.ctl:active { transform: scale(.94); }
.subcontrols { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 6px; background: var(--card2); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 13.5px; cursor: pointer; color: var(--text); }
.pill:hover { border-color: #5a4d3e; }
.pill select { background: transparent; border: 0; padding: 0; font-size: 13.5px; cursor: pointer; }
.pill select option { background: var(--card); }
.pill.active { border-color: var(--accent); color: var(--accent2); }
.pill.vol { padding: 2px 12px 2px 4px; }
.pill.vol input { width: 90px; accent-color: var(--accent); }
.ends { text-align: center; font-size: 13px; min-height: 1.2em; }

/* Side panel */
/* contain: size keeps chat history from growing the row: the player sets the
   row height and the side panel stretches to match it exactly. */
.side { display: flex; flex-direction: column; min-height: 420px; overflow: hidden; contain: size; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; background: none; border: 0; padding: 13px 6px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font-size: 14px; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.count { font-size: 11px; background: var(--card2); border-radius: 999px; padding: 1px 6px; }
.count:empty { display: none; }
.tab-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat, .list { list-style: none; margin: 0; padding: 10px 12px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.chat li { font-size: 16px; line-height: 1.4; overflow-wrap: anywhere; }
.chat li.event { color: var(--muted); font-size: 14px; text-align: center; padding: 2px 0; }
.chat .who { font-weight: 600; color: var(--c); margin-right: 6px; }
.chat li.react { display: flex; align-items: center; gap: 2px; }
.chat li.react .emoji { font-size: 30px; line-height: 1.1; }
.chat li.react .at { margin-left: 8px; }
.chat .at { font-size: 12px; color: var(--muted); margin-left: 6px; font-variant-numeric: tabular-nums; }
/* Eight equal columns that always fit the panel; the emoji size follows the
   bar's width (cqi) so wide color-emoji fonts can't push it past the edge. */
.reactions {
  display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 2px;
  padding: 6px 8px; border-top: 1px solid var(--line); container-type: inline-size;
}
.reactions button {
  background: none; border: 0; min-width: 0; width: 100%; padding: 6px 0; overflow: hidden;
  font-size: min(26px, 7.2cqi); line-height: 1.15; text-align: center;
  cursor: pointer; border-radius: 10px; transition: transform .12s, background .12s;
}
.reactions button:hover { transform: scale(1.12); background: var(--card2); }
.reactions button:active { transform: scale(.9); }
.chat-form { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; font-size: 16px; }
.list li { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; cursor: pointer; font-size: 14px; }
.list li:hover { background: var(--card2); }
.list li.current { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent2); }
.list .t { margin-left: auto; color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; flex: none; }
.list .lbl { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.list .by { display: block; font-size: 12px; color: var(--muted); }
.list .icon-btn { flex: none; }
.list li.ban-row { cursor: default; }
.list li.ban-row:hover { background: none; }
.ban-row .btn { margin-left: auto; flex: none; }

/* Overlays & dialogs */
.overlay { position: fixed; inset: 0; background: #0b0907d0; backdrop-filter: blur(6px); display: grid; place-items: center; z-index: 50; padding: 16px; }
.unlock { background: var(--card); border: 1px solid var(--line); border-radius: 24px; padding: 34px 30px; display: grid; justify-items: center; gap: 10px; cursor: pointer; color: var(--text); max-width: 360px; text-align: center; }
.unlock svg { width: 54px; height: 54px; color: var(--accent); animation: pulse 2s ease-in-out infinite; }
.unlock strong { font: 600 22px var(--serif); }
.unlock span { color: var(--muted); font-size: 14px; }
@keyframes pulse { 50% { transform: scale(1.08); } }
.dlg { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 20px; padding: 24px; width: min(440px, calc(100vw - 32px)); box-shadow: 0 30px 80px #000a; }
.dlg::backdrop { background: #0b0907c0; backdrop-filter: blur(4px); }
.dlg form { display: grid; gap: 14px; position: relative; }
.dlg h2 { margin: 0; }
.dlg p { margin: 0; }
.dlg .close { position: absolute; right: -8px; top: -8px; }
.dlg.wide { width: min(980px, calc(100vw - 32px)); height: min(760px, calc(100vh - 48px)); padding: 0; }
.dlg.wide[open] { display: flex; flex-direction: column; }
.invite-url { display: flex; gap: 8px; }
.invite-url input { flex: 1; font-size: 14px; }
.lib-head { display: flex; align-items: center; gap: 10px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.lib-head h2 { margin: 0 8px 0 0; }
.search { flex: 1; position: relative; display: flex; align-items: center; }
.search svg { position: absolute; left: 12px; color: var(--muted); width: 18px; }
.search input { width: 100%; padding-left: 38px; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px; padding: 20px; overflow-y: auto; align-content: start; }
.book { background: none; border: 0; padding: 0; text-align: left; cursor: pointer; display: grid; gap: 8px; color: var(--text); }
.book .art { aspect-ratio: 1; border-radius: 10px; overflow: hidden; position: relative; background: var(--card2); box-shadow: 0 8px 20px #0006; transition: transform .15s; }
.book:hover .art { transform: translateY(-3px); }
.book.current .art { outline: 3px solid var(--accent); outline-offset: 2px; }
.book.shelf.current .art { outline: none; }
.book.shelf.current .cover { outline: 3px solid var(--accent); outline-offset: 2px; }
.book img { width: 100%; height: 100%; object-fit: cover; display: block; position: relative; }
.book .fb { position: absolute; inset: 0; display: grid; place-items: center; padding: 12px; text-align: center; font: 600 15px/1.2 var(--serif); color: #fff; }
.book .bt { font-weight: 600; font-size: 14px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book .ba { font-size: 12.5px; color: var(--muted); }
/* Series folders: the cover sits in its own clipped box so two offset
   "pages" can peek out behind it without stretching the card. */
.book.shelf .art { overflow: visible; background: none; box-shadow: none; }
.book.shelf .art::before, .book.shelf .art::after {
  content: ""; position: absolute; inset: 0; border-radius: 10px; border: 1px solid #6a5b4a;
}
.book.shelf .art::before { transform: translate(12px, -12px); background: #3a3129; }
.book.shelf .art::after { transform: translate(6px, -6px); background: #4a3f34; }
.book.shelf .cover { position: absolute; inset: 0; border-radius: 10px; overflow: hidden; background: var(--card2); box-shadow: 0 8px 20px #0008; z-index: 1; }
.book.shelf .cover img { position: absolute; inset: 0; }
.book.shelf:hover .art { transform: translateY(-3px); }
.shelf-count { position: absolute; right: 8px; bottom: 8px; background: #000b; color: #fff; font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px; z-index: 2; }
.lib-grid { padding-top: 30px; column-gap: 26px; }
.book .prog { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: #0008; }
.book .prog i { display: block; height: 100%; background: var(--accent); }

.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 40; width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--card2); border: 1px solid var(--line); border-left: 4px solid var(--c, var(--accent)); border-radius: 12px; padding: 10px 14px; display: flex; align-items: center; gap: 12px; box-shadow: 0 10px 30px #0008; animation: rise .2s ease-out; font-size: 14px; }
.toast button { margin-left: auto; background: none; border: 0; color: var(--accent2); cursor: pointer; font-weight: 600; padding: 0; }
@keyframes rise { from { transform: translateY(10px); opacity: 0; } }
.floaters { position: fixed; inset: 0; pointer-events: none; z-index: 30; overflow: hidden; }
.floater {
  position: absolute; display: grid; justify-items: center; gap: 4px;
  animation: rise var(--dur, 4s) cubic-bezier(.25, .6, .4, 1) forwards; will-change: transform, opacity;
}
.floater .fe { font-size: 64px; line-height: 1; filter: drop-shadow(0 6px 14px #000a); }
.floater .fn { font-size: 13px; font-weight: 600; color: #1a120a; background: var(--c); padding: 2px 10px; border-radius: 999px; white-space: nowrap; box-shadow: 0 3px 10px #0008; }
@keyframes rise {
  0%   { transform: translate(0, 0) scale(.4); opacity: 0; }
  10%  { transform: translate(0, calc(var(--rise) * -.12)) scale(1.1); opacity: 1; }
  30%  { transform: translate(var(--sway), calc(var(--rise) * -.34)) scale(1); }
  52%  { transform: translate(calc(var(--sway) * -1), calc(var(--rise) * -.58)) scale(1); }
  75%  { transform: translate(var(--sway), calc(var(--rise) * -.8)) scale(1); opacity: 1; }
  100% { transform: translate(0, calc(var(--rise) * -1)) scale(.9); opacity: 0; }
}
.avatar.bump { animation: bump .5s ease-out; }
@keyframes bump { 30% { transform: scale(1.18); } 60% { transform: scale(.95); } }
@media (prefers-reduced-motion: reduce) { .floater { animation-duration: 1.5s; } .avatar.bump { animation: none; } }
@media (max-width: 600px) { .floater .fe { font-size: 52px; } }
@keyframes float { to { transform: translateY(-260px) scale(1.4); opacity: 0; } }

@media (max-width: 900px) {
  .room-body { grid-template-columns: 1fr; }
  .side { height: 460px; }
}
@media (max-width: 600px) {
  .seats { grid-template-columns: repeat(4, minmax(0, 1fr)); row-gap: 14px; }
  .avatar { width: 44px; height: 44px; font-size: 16px; }
  .player { padding: 20px 14px; }
  .brand span { display: none; }
  .top-actions .btn.sm span { display: none; }
  .top-actions .btn.sm { padding: 8px 10px; }
  .ctl { width: 46px; height: 46px; }
  .ctl.play { width: 66px; height: 66px; }
  .join { flex-direction: column; }
  .home-actions { grid-template-columns: 1fr; }
  .lib-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 14px; padding: 14px; }
  .lib-head { flex-wrap: wrap; padding: 14px; }
  .search { order: 5; flex-basis: 100%; }
  .lib-head h2 { margin-right: auto; }
}
