:root {
  color-scheme: light dark;
  --ground: #f2f2f7; --page: #fbfbfd; --ink: #1d1d1f; --ink-2: #6e6e73; --hair: rgb(0 0 0 / .08);
  --accent: #0a84ff; --accent-wash: rgb(10 132 255 / .09); --danger: #d70015;
  --glass: rgb(255 255 255 / .62); --glass-edge: rgb(255 255 255 / .75);
  --glass-lift: inset 0 1px 0 rgb(255 255 255 / .9), inset 0 -1px 1px rgb(0 0 0 / .04),
                0 12px 32px rgb(0 0 0 / .12), 0 2px 6px rgb(0 0 0 / .06);
  --glow-a: rgb(120 170 255 / .45); --glow-b: rgb(255 160 200 / .35); --glow-c: rgb(140 230 210 / .35);
  --ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  --read: ui-serif, "New York", "Iowan Old Style", Charter, Georgia, serif;
  --spring: cubic-bezier(.2, .9, .3, 1.4);
  --settle: cubic-bezier(.16, 1, .3, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --ground: #000; --page: #000; --ink: #e8e8ed; --ink-2: #98989d; --hair: rgb(255 255 255 / .1);
    --accent-wash: rgb(10 132 255 / .16); --danger: #ff6961;
    --glass: rgb(36 36 40 / .58); --glass-edge: rgb(255 255 255 / .14);
    --glass-lift: inset 0 1px 0 rgb(255 255 255 / .14), inset 0 -1px 1px rgb(0 0 0 / .3),
                  0 12px 32px rgb(0 0 0 / .5), 0 2px 6px rgb(0 0 0 / .3);
    --glow-a: rgb(40 90 220 / .45); --glow-b: rgb(170 60 140 / .3); --glow-c: rgb(30 140 130 / .3);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--ground); touch-action: manipulation; } /* no double-tap zoom; pinch still works */
body { margin: 0; min-height: 100dvh; color: var(--ink); font: 17px/1.4 var(--ui); background: var(--ground); }
::selection { background: rgb(10 132 255 / .3); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
svg { display: block; }
[hidden] { display: none !important; }

/* Liquid glass: frosted, saturated, lit from the top edge. Only on controls that float over content. */
.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(24px) saturate(180%); backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--glass-edge); box-shadow: var(--glass-lift);
}
/* Round icon buttons; --size per button. */
.round { flex: none; width: var(--size, 44px); height: var(--size, 44px); display: grid; place-items: center;
         padding: 0; border-radius: 50%; transition: transform .2s var(--spring); }
.round:active, #drop:active, .speeds button:active { transform: scale(.92); }
.track { flex: 1; max-width: 9rem; height: 4px; border-radius: 2px; background: var(--hair); overflow: hidden; }
.track i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }

/* Library */
body:not(.reading) { background:
  radial-gradient(60% 40% at 15% 0%, var(--glow-a), transparent 70%),
  radial-gradient(50% 35% at 100% 20%, var(--glow-b), transparent 70%),
  radial-gradient(60% 40% at 50% 100%, var(--glow-c), transparent 70%) fixed, var(--ground); }
main { max-width: 40rem; margin: 0 auto; padding: calc(2.5rem + env(safe-area-inset-top)) 1rem calc(3rem + env(safe-area-inset-bottom)); }
header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
h1 { margin: 0; font-size: 34px; font-weight: 700; letter-spacing: -.02em; }
#drop { display: inline-flex; align-items: center; gap: .4rem; padding: .55rem 1rem .55rem .8rem; border-radius: 999px;
        font-size: 15px; font-weight: 600; color: var(--accent); cursor: pointer; transition: transform .2s var(--spring); }
#error { margin: 0 0 1rem; color: var(--danger); font-size: 15px; }
#error:empty, #bookList:empty, #bookList:not(:empty) + #empty { display: none; }
#bookList { list-style: none; margin: 0; padding: 0; border-radius: 22px; overflow: hidden; }
#bookList li { display: flex; align-items: center; gap: .9rem; padding: .8rem .9rem; cursor: pointer; }
#bookList li + li { border-top: 1px solid var(--hair); }
#bookList li:active { background: var(--accent-wash); }
.cover { flex: none; width: 44px; height: 62px; border-radius: 6px; display: grid; place-items: center;
         color: #fff; font: 600 20px var(--read); box-shadow: 0 2px 6px rgb(0 0 0 / .18), inset 0 0 0 .5px rgb(255 255 255 / .2); }
.info { flex: 1; min-width: 0; }
.title { font-weight: 600; font-size: 16px; line-height: 1.3; overflow-wrap: anywhere;
         display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meta { margin-top: .35rem; display: flex; align-items: center; gap: .6rem; color: var(--ink-2); font-size: 13px; font-variant-numeric: tabular-nums; }
.remove { --size: 36px; color: var(--ink-2); }
.remove:active, #back:active { background: var(--hair); }
#empty { margin: 4rem 0; text-align: center; color: var(--ink-2); line-height: 1.5; }
body.over::after { content: "Drop to add"; position: fixed; inset: 12px; display: grid; place-items: center; border-radius: 28px;
                   font: 600 22px var(--ui); color: var(--accent); background: var(--accent-wash);
                   border: 2px dashed var(--accent); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }

/* Reader */
body.reading { background: var(--page); }
body.reading main, body:not(.reading) :is(#bar, #text, #topglass, .panel) { display: none; }
#topglass { position: fixed; top: 0; left: 0; right: 0; height: env(safe-area-inset-top); z-index: 2;
            background: color-mix(in srgb, var(--page) 70%, transparent); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
#text { max-width: 36em; margin: 0 auto; padding: calc(2rem + env(safe-area-inset-top)) 1.25rem 60vh;
        font: 20px/1.65 var(--read); white-space: pre-wrap; hyphens: auto; -webkit-hyphens: auto; }
#text p { margin: 0 -.3rem 1em; padding: 0 .3rem; border-radius: 6px; transition: background-color .3s; }
#text .speaking { background: var(--accent-wash); }
::highlight(word) { background-color: var(--accent); color: #fff; }

/* Floating player bar and the drawers above it. Drags on them must never scroll the text behind. */
#bar, .panel { position: fixed; left: 50%; z-index: 3; transform: translateX(-50%); touch-action: none; overscroll-behavior: contain; }
#bar { bottom: calc(14px + env(safe-area-inset-bottom)); width: min(30rem, calc(100% - 24px)); display: flex; align-items: center;
       gap: .35rem; padding: 6px; border-radius: 999px; animation: rise .5s var(--settle); }
@keyframes rise { from { transform: translate(-50%, 24px); opacity: 0; filter: blur(6px); } }
.progress { flex: 1; min-width: 0; padding: 0 .3rem; }
.progress .track { max-width: none; margin-top: 6px; }
#pct { display: block; font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#rate { background: var(--hair); font-size: 13px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
#music { --size: 40px; color: var(--ink-2); }
#music[aria-pressed="true"] { color: var(--accent); background: var(--accent-wash); }
#listen { --size: 52px; background: var(--accent); color: #fff; box-shadow: 0 4px 12px rgb(0 0 0 / .22), inset 0 1px 0 rgb(255 255 255 / .35); }
.panel { bottom: calc(86px + env(safe-area-inset-bottom)); width: min(22rem, calc(100% - 24px));
         padding: 14px 16px; border-radius: 24px; animation: pop .35s var(--settle); }
@keyframes pop { from { opacity: 0; transform: translate(-50%, 10px) scale(.96); filter: blur(4px); } }
.panel h2 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
.speeds { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.speeds button { height: 44px; border-radius: 14px; background: var(--hair); font-size: 15px; font-weight: 600;
                 font-variant-numeric: tabular-nums; transition: transform .2s var(--spring); }
.speeds button[aria-checked="true"] { background: var(--accent); color: #fff; }
.mixrow { display: flex; align-items: center; justify-content: space-between; font-weight: 600; font-size: 15px; }
.volrow { display: flex; align-items: center; gap: .6rem; margin-top: 14px; font-size: 13px; color: var(--ink-2); }
.volrow b { font-weight: 600; color: var(--ink); }
#voicelvl { width: 3rem; text-align: right; font-variant-numeric: tabular-nums; }
input[type="range"] { flex: 1; accent-color: var(--accent); touch-action: pan-x; }
input[role="switch"] { -webkit-appearance: none; appearance: none; position: relative; width: 51px; height: 31px; margin: 0;
                       border-radius: 999px; background: var(--hair); transition: background .25s; cursor: pointer; }
input[role="switch"]::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
                              background: #fff; box-shadow: 0 2px 6px rgb(0 0 0 / .25); transition: transform .3s var(--spring); }
input[role="switch"]:checked { background: #34c759; }
input[role="switch"]:checked::after { transform: translateX(20px); }

/* Loading pill */
#loading { position: fixed; top: calc(10px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 4;
           display: flex; align-items: center; gap: .6rem; margin: 0; padding: .45rem 1rem .45rem .6rem;
           border-radius: 999px; font-size: 14px; max-width: calc(100% - 24px); }
#loading span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#orb { flex: none; width: 20px; height: 20px; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
