:root {
  --bg: #0b0b0d;
  --panel: #131317;
  --panel2: #1a1a20;
  --line: #26262e;
  --text: #ececf1;
  --muted: #8b8b98;
  --accent: #e8a33d;
  --accent-dim: #3a2c14;
  --green: #4cc38a;
  --red: #e5584f;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sab: env(safe-area-inset-bottom, 0px);
  --sat: env(safe-area-inset-top, 0px);
  --tabs-h: 0px;
  --bar-h: 84px;
  --bars: calc(var(--bar-h) + var(--tabs-h));
}
* { box-sizing: border-box; border-radius: 0 !important; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body {
  margin: 0; color: var(--text); background: var(--bg);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100dvh; padding-bottom: calc(var(--bars) + var(--sab) + 12px);
  overscroll-behavior-y: none;
}
.muted { color: var(--muted); }
.empty { padding: 32px 0; }
h1 { font: 600 30px/1.1 var(--serif); margin: 0; }
h2 { font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); margin: 28px 0 12px; font-weight: 700; }

button, select, input {
  font: inherit; color: var(--text); background: var(--panel2);
  border: 1px solid var(--line); padding: 10px 14px; outline: none; min-height: 40px;
}
button { cursor: pointer; touch-action: manipulation; }
@media (hover: hover) { button:hover { border-color: #494953; background: #22222a; } }
button:active { background: #2a2a33; }
button:focus-visible, input:focus-visible, select:focus-visible { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #141414; font-weight: 700; }
@media (hover: hover) { button.primary:hover { background: #f3b45a; } }
button.danger { color: var(--red); }
button:disabled { opacity: .5; }
input[type=search], input[type=text] { -webkit-appearance: none; appearance: none; }

/* ── header ─────────────────────────────── */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 20px;
  padding: calc(var(--sat) + 0px) 24px 0; height: calc(60px + var(--sat));
  background: rgba(11,11,13,.92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font: 700 18px var(--serif); letter-spacing: .02em; white-space: nowrap; }
.brand img { width: 28px; height: 28px; display: block; }
.tabs-desktop { display: flex; height: 100%; }
.tabs-desktop .tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 0 18px; color: var(--muted); min-height: 0; height: 100%; }
.tabs-desktop .tab.active { color: var(--text); border-bottom-color: var(--accent); }
#searchForm { display: flex; flex: 1; max-width: 560px; margin-left: auto; }
#searchForm input { flex: 1; min-width: 0; border-right: 0; }

main { padding: 8px 24px 24px; }

/* ── hero ───────────────────────────────── */
.hero {
  display: grid; grid-template-columns: 220px 1fr; gap: 28px; margin-top: 24px; padding: 24px;
  background: linear-gradient(100deg, var(--accent-dim), var(--panel) 60%); border: 1px solid var(--line);
}
.hero .cover { width: 220px; height: 220px; cursor: pointer; }
.hero .kicker { font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
.hero h1 { font-size: 38px; margin-top: 6px; cursor: pointer; }
.hero .author { color: var(--muted); font-size: 16px; margin-top: 4px; }
.hero .where { margin-top: 18px; color: var(--text); }
.hero .bar { max-width: 460px; }
.hero .btn-row { margin-top: 18px; }

/* ── sections / grids ───────────────────── */
.sec-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.sec-head h2 { margin-bottom: 12px; }
.toolbar { display: flex; gap: 6px; margin-bottom: 12px; }
.toolbar input { width: 200px; }
.toolbar button { min-width: 40px; padding: 0 12px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 20px 16px; }
.row-scroll { display: flex; gap: 16px; overflow-x: auto; scroll-snap-type: x proximity; padding-bottom: 6px; scrollbar-width: none; }
.row-scroll::-webkit-scrollbar { display: none; }
.row-scroll .card { width: 160px; flex: none; scroll-snap-align: start; }

.card { cursor: pointer; display: flex; flex-direction: column; min-width: 0; }
.card .cover { width: 100%; aspect-ratio: 1; border: 1px solid var(--line); }
@media (hover: hover) { .card:hover .cover { border-color: var(--accent); } }
.card .t { font: 600 15px/1.25 var(--serif); margin-top: 10px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card .a { color: var(--muted); font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 3px; background: var(--line); margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.pill { display: inline-block; font-size: 10px; letter-spacing: .1em; padding: 2px 7px; border: 1px solid var(--line); text-transform: uppercase; font-weight: 700; white-space: nowrap; }
.pill.ok { color: var(--green); border-color: var(--green); }
.pill.own { color: var(--accent); border-color: var(--accent); }
.pill.no { color: var(--muted); }

.cover { background: var(--panel2); position: relative; overflow: hidden; flex: none; }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover .ph { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 12px; text-align: center; font: 700 15px/1.2 var(--serif); color: #fff; }
.cover.big { width: 220px; height: 220px; }
.cover.small { width: 56px; height: 56px; }
.cover.small .ph { font-size: 8px; padding: 3px; }

/* ── search results ─────────────────────── */
.result { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center; padding: 14px 16px; background: var(--panel); border: 1px solid var(--line); margin-bottom: 8px; }
.result .t { font: 600 16px/1.25 var(--serif); }
.result .raw { color: var(--muted); font-size: 12px; margin-top: 3px; word-break: break-word; }
.result .meta { display: flex; gap: 12px; align-items: center; margin-top: 8px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.result button { min-width: 84px; }

/* ── sheets ─────────────────────────────── */
.sheet-back { position: fixed; left: 0; right: 0; top: 0; bottom: calc(var(--bars) + var(--sab)); background: rgba(0,0,0,.7); z-index: 20; overflow-y: auto; overscroll-behavior: contain; }
.detail-sheet { background: var(--bg); border-left: 1px solid var(--line); min-height: 100%; margin-left: auto; width: min(100%, 880px); padding: 28px; position: relative; }
.close { position: absolute; top: 12px; right: 12px; width: 44px; height: 44px; z-index: 2; }
.detail-head { display: flex; gap: 24px; }
.detail-info { display: flex; flex-direction: column; gap: 6px; padding-right: 50px; min-width: 0; }
.detail-info .author { color: var(--muted); font-size: 16px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.btn-row .primary { min-width: 120px; }
.chapters { border-top: 1px solid var(--line); }
.chap { display: grid; grid-template-columns: 36px 1fr auto; gap: 10px; padding: 13px 8px; border-bottom: 1px solid var(--line); cursor: pointer; align-items: center; min-height: 48px; }
@media (hover: hover) { .chap:hover { background: var(--panel); } }
.chap.now { background: var(--panel); box-shadow: inset 3px 0 var(--accent); }
.chap .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.chap .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chap .s { color: var(--muted); font-size: 12px; white-space: nowrap; }
.chap.done .nm { color: var(--muted); }

/* ── now playing ────────────────────────── */
.np { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; flex-direction: column; padding: calc(var(--sat) + 8px) 20px calc(var(--sab) + 16px); overflow-y: auto; }
.np-top { display: flex; align-items: center; justify-content: space-between; max-width: 560px; width: 100%; margin: 0 auto; }
.np-top button { width: 44px; height: 44px; padding: 0; font-size: 20px; background: none; border: 0; }
.np-label { font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.np-body { max-width: 560px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; flex: 1; justify-content: center; }
.np-cover { width: min(100%, 44vh, 420px); aspect-ratio: 1; margin: 4px auto 0; border: 1px solid var(--line); }
.np-cover .ph { font-size: 22px; }
.np-title { font: 600 24px/1.2 var(--serif); }
.np-chap { color: var(--muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seek-times { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; margin-top: 6px; }
.np-controls { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.np-controls button { flex: 1; height: 56px; font-size: 20px; padding: 0; background: none; border: 1px solid var(--line); }
.np-controls button.big { flex: 1.5; height: 64px; font-size: 26px; background: var(--accent); }
.np-controls .skip b { font-size: 14px; }
.chips-block { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.chips-label { font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin-top: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { padding: 0 14px; min-height: 40px; background: var(--panel); }
.chips button.on { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

/* ── mini player ────────────────────────── */
.player {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabs-h) + var(--sab)); height: var(--bar-h); z-index: 30;
  background: var(--panel); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: minmax(180px, 1fr) minmax(300px, 2.2fr) auto; align-items: center; gap: 16px; padding-right: 16px;
}
.bar-progress { position: absolute; left: 0; right: 0; top: -1px; height: 2px; background: transparent; }
.bar-progress i { display: block; height: 100%; width: 0; background: var(--accent); }
.p-open { display: flex; align-items: center; gap: 12px; min-width: 0; height: 100%; cursor: pointer; }
.p-open .cover { width: var(--bar-h); height: var(--bar-h); border: 0; }
.p-open .cover .ph { font-size: 9px; }
.p-text { min-width: 0; }
.p-title { font: 600 15px var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-chap { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-desk { display: flex; align-items: center; gap: 8px; }
.p-desk button { min-width: 44px; padding: 0 10px; }
.p-desk input[type=range] { flex: 1; }
.tm { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; min-width: 40px; text-align: center; }
button.round { width: 48px; height: 48px; padding: 0; font-size: 18px; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; border: 0; padding: 0; margin: 0; cursor: pointer; min-height: 0; touch-action: none; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; background: var(--seek-bg, linear-gradient(to right, var(--accent) var(--pct, 0%), var(--line) var(--pct, 0%))); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 18px; margin-top: -7px; background: var(--accent); border: 0; }
input[type=range]::-moz-range-track { height: 4px; background: var(--line); }
input[type=range]::-moz-range-progress { height: 4px; background: var(--accent); }
input[type=range]::-moz-range-thumb { width: 14px; height: 18px; background: var(--accent); border: 0; }

.tabs-mobile { display: none; }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--bars) + var(--sab) + 16px); background: var(--panel2); border: 1px solid var(--accent); padding: 10px 18px; z-index: 60; max-width: 90vw; text-align: center; }

/* ── phone ──────────────────────────────── */
@media (max-width: 820px) {
  :root { --tabs-h: 58px; --bar-h: 68px; }
  .top { flex-wrap: wrap; height: auto; padding: calc(var(--sat) + 10px) 14px 10px; gap: 10px; }
  .tabs-desktop { display: none; }
  .brand { font-size: 17px; }
  #searchForm { order: 3; width: 100%; max-width: none; margin: 0; flex-basis: 100%; }
  #searchForm input { min-height: 44px; }
  #searchForm button { min-height: 44px; }
  main { padding: 4px 14px 16px; }
  .hero { grid-template-columns: 112px 1fr; gap: 16px; padding: 16px; margin-top: 16px; }
  .hero .cover { width: 112px; height: 112px; }
  .hero h1 { font-size: 22px; }
  .hero .author { font-size: 14px; }
  .hero .where { margin-top: 10px; font-size: 13px; }
  .hero .btn-row { margin-top: 12px; grid-column: 1 / -1; }
  .hero .btn-row .primary { width: 100%; min-height: 48px; }
  .hero-body { grid-column: 2; }
  .toolbar { width: 100%; }
  .toolbar input { flex: 1; width: auto; min-height: 44px; }
  .toolbar select, .toolbar button { min-height: 44px; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 18px 12px; }
  .row-scroll .card { width: 138px; }

  .result { gap: 12px; padding: 14px; }
  .result button { min-height: 44px; min-width: 76px; }

  .sheet-back { background: var(--bg); }
  .detail-sheet { width: 100%; border: 0; padding: calc(var(--sat) + 56px) 16px 24px; }
  .detail-head { flex-direction: column; gap: 16px; align-items: center; text-align: center; }
  .cover.big { width: min(64vw, 260px); height: min(64vw, 260px); }
  .detail-info { padding: 0; align-items: center; }
  .btn-row { justify-content: center; width: 100%; }
  .btn-row .primary { flex: 1 1 100%; min-height: 50px; }
  .btn-row button { min-height: 46px; }
  .close { top: calc(var(--sat) + 8px); }

  /* mini player becomes a compact bar above the tab bar */
  .player { grid-template-columns: 1fr auto; padding-right: 10px; gap: 8px; }
  .p-desk { display: none; }
  .p-open .cover { width: var(--bar-h); height: var(--bar-h); }
  button.round { width: 52px; height: 52px; }

  .tabs-mobile {
    display: grid; grid-template-columns: 1fr 1fr; position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
    height: calc(var(--tabs-h) + var(--sab)); padding-bottom: var(--sab);
    background: var(--panel); border-top: 1px solid var(--line);
  }
  .tabs-mobile .tab { background: none; border: 0; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: 11px; letter-spacing: .06em; min-height: 0; }
  .tabs-mobile .tab .ic { font-size: 20px; line-height: 1; }
  .tabs-mobile .tab.active { color: var(--accent); }
  #toast { bottom: calc(var(--bars) + var(--sab) + 12px); }
}
@media (max-width: 380px) { .grid { gap: 14px 10px; } .np-title { font-size: 21px; } }
@media (max-height: 640px) { .np-cover { width: min(100%, 34vh); } .np-controls button { height: 48px; } .np-controls button.big { height: 54px; } }
