:root {
  color-scheme: dark light;
  --bg: #141414;
  --surface: #1c1c1c;
  --raised: #272727;
  --line: #333333;
  --text: #f5f5f5;
  --muted: #9e9e9e;
  --accent: #fdce45;
  --accent-ink: var(--accent);
  --on-accent: #1a1a1a;
  --danger: #f0705a;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  --mini: 0px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f7f7;
    --surface: #ffffff;
    --raised: #ececec;
    --line: #dedede;
    --text: #1a1a1a;
    --muted: #6b6b6b;
    /* put.io yellow is unreadable as text on white, so text and outlines use a darker ink */
    --accent-ink: #7a5800;
    --danger: #b3412d;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
body.has-mini { --mini: 68px; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; touch-action: manipulation; }
a { color: var(--accent-ink); }
:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }

#app {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100%;
  padding: var(--top) 16px calc(var(--bottom) + var(--mini) + 24px);
}

/* ---------- shared bits ---------- */

.btn {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-weight: 600;
  white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--danger); }
a.btn { display: inline-flex; align-items: center; text-decoration: none; }
.btn.outline { background: none; border-color: var(--accent); color: var(--accent-ink); }
.btn:active, .chip:active, .book-open:active .cover { transform: scale(0.97); }

.icon-btn {
  width: 44px; height: 44px;
  display: inline-grid; place-items: center;
  border-radius: 50%;
  color: var(--text);
  flex: none;
}
.icon-btn:active { background: var(--raised); }

input[type="text"], input[type="password"], input[type="search"] {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  min-width: 0;
}
input::placeholder { color: var(--muted); }

.bar {
  display: flex; align-items: center; gap: 8px;
  height: 60px;
  position: sticky; top: 0; z-index: 2;
  margin: 0 -16px; padding: 0 12px 0 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.spacer { width: 44px; flex: none; }
.spacer.grow { flex: 1; width: auto; }
.wordmark { display: flex; align-items: center; gap: 8px; font: 700 22px/1 var(--sans); letter-spacing: -0.02em; }
.wordmark img { border-radius: 7px; }
.bar-title { flex: 1; min-width: 0; text-align: center; display: grid; }
.bar-title small { color: var(--muted); font-size: 12px; }
.bar-title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { color: var(--muted); text-align: center; padding: 48px 16px; display: grid; gap: 16px; justify-items: center; }

.bar-thin { display: block; height: 3px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar-thin i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--bottom) + var(--mini) + 20px);
  transform: translate(-50%, 20px);
  max-width: min(92vw, 420px);
  padding: 12px 18px; border-radius: 14px;
  background: var(--text); color: var(--bg);
  font-size: 14px; font-weight: 500; text-align: center;
  opacity: 0; pointer-events: none; z-index: 50;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- connect ---------- */

.connect { max-width: 440px; margin: 0 auto; padding: 12vh 4px 24px; display: grid; gap: 20px; }
.brand { display: flex; align-items: center; gap: 12px; font: 700 24px/1 var(--sans); letter-spacing: -0.02em; }
.brand img { border-radius: 14px; }
.connect .art { width: 100%; height: auto; }
.connect h1 { font: 600 clamp(30px, 8vw, 40px)/1.1 var(--sans); letter-spacing: -0.015em; text-wrap: balance; }
.lede { color: var(--muted); font-size: 17px; }
#cta { display: flex; flex-wrap: wrap; gap: 8px; }
/* tighter than .btn so both buttons fit on one line of the 440px column */
#cta > .btn { padding: 0 12px; }
.setup { display: grid; gap: 16px; flex: 1 0 100%; }
.steps { margin: 0; padding: 0 0 0 20px; display: grid; gap: 12px; color: var(--muted); }
.steps li::marker { color: var(--accent-ink); font-weight: 700; }
.copy {
  display: block; width: 100%; margin-top: 8px; padding: 10px 12px;
  border-radius: 10px; border: 1px dashed var(--line); background: var(--surface);
  font: 13px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text);
  text-align: left; word-break: break-all;
}
.row { display: flex; gap: 8px; }
.connect details { color: var(--muted); }
.connect summary { cursor: pointer; padding: 8px 0; font-size: 14px; }
.connect details .row { margin-top: 8px; }
.fine { color: var(--muted); font-size: 13px; }
/* boot.js marks signed-in visitors, so the landing page doesn't flash before their library */
.signed-in [data-view="boot"] .connect { display: none; }
.about { display: grid; gap: 12px; margin-top: 24px; color: var(--muted); }
.about h2 { margin-top: 12px; font: 600 20px/1.2 var(--sans); color: var(--text); }
.about ul { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.shots { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.shots img { width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--line); }
.zipped { text-align: center; }
.foot { display: flex; justify-content: center; align-items: center; gap: 20px; padding: 24px 16px; }
.foot .icon-btn { color: inherit; }
.foot img { border-radius: 6px; }
/* keeps the footer clear of the fixed "Use this folder" button */
[data-view="folders"] .foot { padding-bottom: 96px; }

/* ---------- folder picker ---------- */

.folder-list { display: grid; }
.folder {
  display: flex; align-items: center; gap: 14px;
  min-height: 56px; padding: 8px 4px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}
.folder-icon { color: var(--accent-ink); display: grid; }
.folder-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { color: var(--muted); display: grid; }
.pick {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 16px 16px calc(var(--bottom) + 16px);
  display: grid; justify-items: center;
  background: linear-gradient(transparent, var(--bg) 40%);
}
.pick .btn { width: min(100%, 420px); min-height: 52px; overflow: hidden; text-overflow: ellipsis; }

/* ---------- library ---------- */

.search { display: flex; align-items: center; gap: 10px; padding: 0 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); }
.search span { display: grid; }
.search svg { width: 20px; height: 20px; }
.search input { border: 0; background: none; padding: 0; color: var(--text); outline: none; }
.search:focus-within { border-color: var(--accent-ink); }

.section { font: 600 20px/1.2 var(--sans); margin: 28px 0 14px; }
.section small { font: 400 14px var(--sans); color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 22px 16px; }
.strip { display: grid; grid-auto-flow: column; grid-auto-columns: 132px; gap: 14px; overflow-x: auto; margin: 0 -16px; padding: 0 16px 4px; scrollbar-width: none; }
.strip::-webkit-scrollbar { display: none; }

.book { min-width: 0; }
.book.is-hidden .book-open { opacity: 0.4; }
.book-open { display: grid; gap: 6px; text-align: left; align-content: start; width: 100%; min-width: 0; }
.book-tools { display: flex; gap: 2px; margin: 2px 0 0 -8px; }
.mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; color: var(--muted); }
.mark:active { background: var(--raised); }
.mark svg { width: 19px; height: 19px; }
.mark-star.on { color: var(--accent-ink); }
.mark-star.on svg { fill: var(--accent); }
.cover-picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 14px 12px; min-height: 120px; align-content: start; }
.cover-picks button { display: grid; gap: 6px; text-align: left; min-width: 0; align-content: start; }
.cover-picks small { color: var(--muted); font-size: 12px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cover-picks p { grid-column: 1 / -1; }
.section .link { float: right; font: 500 14px/1.7 var(--sans); color: var(--muted); }
.section .link + .link { margin-right: 14px; }
.install { margin-top: 16px; padding: 12px 6px 12px 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.install .row { align-items: center; }
.install > a.btn { margin-right: 10px; flex: none; }
.filters { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 16px; padding: 0 16px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters .chip { flex: none; padding: 0 14px; white-space: nowrap; }
.book .bar-thin { margin-top: 2px; }
.book-title { font-weight: 600; font-size: 14px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-sub { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* List view: the same cards, laid out as rows. */
.list { grid-template-columns: 1fr; gap: 0; }
.list .book { display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--line); }
.list .book-open { flex: 1; grid-template-columns: 56px 1fr; gap: 3px 14px; align-content: center; padding: 10px 0; }
.list .cover { grid-area: 1 / 1 / 4 / 2; border-radius: 6px; box-shadow: none; }
.list .book-title { grid-area: 1 / 2; align-self: end; }
.list .book-sub { grid-area: 2 / 2; }
.list .bar-thin { grid-area: 3 / 2; align-self: start; }
.list .book-tools { flex: none; margin: 0; }

.cover {
  display: block; width: 100%; aspect-ratio: 1; object-fit: cover;
  border-radius: 8px; background: var(--raised);
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.28);
  transition: transform 0.12s;
}
/* A cloth-bound stand-in when a book has no artwork. */
.cover.made {
  container-type: inline-size;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 11% 10% 10% 15%;
  color: oklch(0.95 0.03 var(--hue));
  background:
    linear-gradient(90deg, rgb(0 0 0 / 0.28) 0 5%, rgb(255 255 255 / 0.08) 5% 6.5%, transparent 6.5%),
    linear-gradient(160deg, oklch(0.46 0.09 var(--hue)), oklch(0.3 0.07 var(--hue)));
  overflow: hidden;
}
.cover-title { font: 600 13cqw/1.12 var(--sans); letter-spacing: -0.01em; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.cover-author { font: 500 6.5cqw/1.2 var(--sans); letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- mini player ---------- */

#mini {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: grid; grid-template-columns: 1fr auto; align-items: center;
  padding: 2px max(8px, calc(50% - 372px)) var(--bottom) max(0px, calc(50% - 380px));
}
#mini .bar-thin { position: absolute; inset: 0 0 auto; border-radius: 0; height: 2px; }
.mini-open { display: flex; align-items: center; gap: 12px; padding: 9px 8px 9px 16px; text-align: left; min-width: 0; }
.mini-cover { width: 46px; flex: none; }
.mini-cover .cover { border-radius: 6px; box-shadow: none; }
.mini-text { display: grid; min-width: 0; }
.mini-text strong, .mini-text small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-text strong { font-size: 14.5px; }
.mini-text small { color: var(--muted); font-size: 13px; }

/* ---------- full player ---------- */

#player {
  position: fixed; inset: 0; z-index: 10;
  background: var(--bg);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto auto auto;
  gap: clamp(10px, 2.2vh, 22px);
  padding: calc(var(--top) + 6px) max(24px, calc(50vw - 230px)) calc(var(--bottom) + 18px);
  transform: translateY(100%);
  visibility: hidden;
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s 0.28s;
}
body.player-open #player { transform: none; visibility: visible; transition-delay: 0s; }
body.player-open { overflow: hidden; }

.p-top { display: flex; align-items: center; justify-content: space-between; margin: 0 -10px; }
.p-left { color: var(--muted); font-size: 13.5px; font-variant-numeric: tabular-nums; }
.p-cover { display: grid; place-items: center; min-height: 0; }
.p-cover .cover { width: auto; height: 100%; max-width: 100%; max-height: min(100%, 420px); border-radius: 12px; box-shadow: 0 18px 44px rgb(0 0 0 / 0.38); }
.p-cover .cover.made { width: min(100%, 420px); height: auto; }
@supports (height: 1cqh) {
  .p-cover { container-type: size; }
  .p-cover .cover, .p-cover .cover.made { width: min(100cqw, 100cqh, 420px); height: min(100cqw, 100cqh, 420px); }
}
.p-meta { text-align: center; display: grid; gap: 4px; }
.p-meta h2 { font: 600 clamp(22px, 5.6vw, 28px)/1.15 var(--sans); letter-spacing: -0.01em; text-wrap: balance; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.p-meta p { color: var(--muted); min-height: 1.45em; }

.p-chapter {
  justify-self: center; max-width: 100%;
  display: flex; align-items: baseline; gap: 10px;
  padding: 9px 16px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 14.5px; font-weight: 600;
}
.p-chapter span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-chapter small { color: var(--muted); font-weight: 400; white-space: nowrap; }
.p-chapter:disabled { color: var(--muted); cursor: default; }

.p-scrub { display: grid; gap: 4px; }
.p-times { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 28px; margin: 0; background: none; cursor: pointer;
  --fill: 0%;
}
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 6px; background: linear-gradient(90deg, var(--accent) var(--fill), var(--line) var(--fill)); }
input[type="range"]::-moz-range-track { height: 6px; border-radius: 6px; background: linear-gradient(90deg, var(--accent) var(--fill), var(--line) var(--fill)); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -6px; border-radius: 50%; background: var(--text); border: 0; box-shadow: 0 1px 4px rgb(0 0 0 / 0.4); }
input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--text); border: 0; }

.p-controls { display: flex; align-items: center; justify-content: space-between; }
.play {
  width: 76px; height: 76px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent);
  transition: transform 0.1s;
}
.play svg { width: 34px; height: 34px; }
.play:active { transform: scale(0.94); }
.skip { position: relative; width: 56px; height: 56px; display: grid; place-items: center; border-radius: 50%; }
.skip span { display: grid; }
.skip svg { width: 42px; height: 42px; stroke-width: 1.5; }
.skip b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; font-weight: 700; padding-top: 3px; }
.skip:active { background: var(--raised); }

.p-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tool {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 48px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line);
}
.tool b { display: grid; font-size: 15px; font-variant-numeric: tabular-nums; }
.tool b svg { width: 19px; height: 19px; }
.tool small { color: var(--muted); font-size: 13.5px; white-space: nowrap; }
.tool.on { border-color: var(--accent-ink); }
.tool.on b, .tool.on small { color: var(--accent-ink); }

/* ---------- sheets ---------- */

dialog.sheet {
  width: min(100%, 520px); max-width: 100%; max-height: 82dvh;
  margin: auto auto 0; padding: 0;
  border: 0; border-radius: 22px 22px 0 0;
  background: var(--surface); color: var(--text);
  overflow: hidden;
}
dialog.sheet[open] { display: flex; flex-direction: column; animation: rise 0.22s cubic-bezier(0.2, 0.8, 0.2, 1); }
dialog.sheet::backdrop { background: rgb(0 0 0 / 0.55); }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 10px 8px 22px; }
.sheet-head h3 { font: 600 21px/1.2 var(--sans); }
.sheet-body { overflow-y: auto; padding: 4px 22px calc(var(--bottom) + 24px); display: grid; gap: 16px; }

.chapters { list-style: none; margin: 0 -10px; padding: 0; }
.chapters button { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 50px; padding: 8px 10px; border-radius: 12px; text-align: left; }
.chapters .num { width: 26px; flex: none; text-align: center; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; display: grid; place-items: center; }
.chapters .num svg { width: 16px; height: 16px; }
.chapters .name { flex: 1; min-width: 0; }
.chapters .at { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.chapters .current { background: var(--raised); font-weight: 600; }
.chapters .current .num { color: var(--accent-ink); }

.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 10px; }
.chips.wide { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.chip { min-height: 48px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg); font-weight: 600; font-variant-numeric: tabular-nums; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.stepper { display: flex; align-items: center; justify-content: center; gap: 22px; }
.stepper output { font: 600 34px/1 var(--sans); min-width: 4.2ch; text-align: center; font-variant-numeric: tabular-nums; }
.stepper .btn { width: 52px; height: 52px; padding: 0; font-size: 24px; }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.setting div { display: grid; min-width: 0; }
.setting small { color: var(--muted); font-size: 13.5px; }
.switch { -webkit-appearance: none; appearance: none; flex: none; position: relative; width: 52px; height: 32px; margin: 6px 0; border-radius: 999px; background: var(--line); cursor: pointer; transition: background 0.15s; }
.switch::before { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 0.3); transition: transform 0.15s; }
.switch:checked { background: var(--accent); }
.switch:checked::before { transform: translateX(20px); background: var(--on-accent); }

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