/* BumbleReader – app styles */

:root {
  --accent: #FFC800;
  --ink: #1B1B18;
  --selection: rgba(255, 200, 0, .38);
  --font-ui: "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --ease: cubic-bezier(.2, .8, .2, 1);

  /* Reader settings; overwritten from JS. Custom properties inherit into the shadow root. */
  --r-font: var(--font-serif);
  --r-size: 19px;
  --r-lh: 1.6;
  --r-width: 680px;

  --bg: #FAFAF7; --fg: #1B1B18; --muted: #8A8A82; --line: #E8E7E1; --surface: #FFFFFF;
  --shadow: rgba(27, 27, 24, .16);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #121211; --fg: #E6E4DC; --muted: #77756D; --line: #2A2A27; --surface: #1C1C1A;
    --shadow: rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="sepia"] {
  --bg: #F4ECD8; --fg: #3B3226; --muted: #9A8B72; --line: #E4D9BE; --surface: #FBF5E6;
  --shadow: rgba(59, 50, 38, .18);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #121211; --fg: #E6E4DC; --muted: #77756D; --line: #2A2A27; --surface: #1C1C1A;
  --shadow: rgba(0, 0, 0, .5);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body { margin: 0; min-height: 100dvh; background: var(--bg); transition: background-color .3s, color .3s; }
html.reading, html.reading body { overflow: hidden; overscroll-behavior: none; height: 100%; }

[hidden] { display: none !important; }
::selection { background: var(--selection); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
svg { fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 18px 0 14px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -.005em;
  white-space: nowrap;
  transition: transform .15s var(--ease), box-shadow .2s var(--ease);
}
.btn-primary svg { width: 18px; height: 18px; stroke-width: 2.2; }
.btn-primary:hover { box-shadow: 0 6px 18px -6px rgba(255, 200, 0, .7); }
.btn-primary:active { transform: scale(.97); }
.btn-primary:focus-visible { outline-color: var(--fg); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  color: var(--fg);
  transition: background-color .15s;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover { background: color-mix(in srgb, var(--fg) 7%, transparent); }

/* ── Library ───────────────────────────────────────────────────────── */

.library { min-height: 100dvh; }
.lib-head, .lib-main {
  padding-left: max(clamp(20px, 5vw, 56px), env(safe-area-inset-left));
  padding-right: max(clamp(20px, 5vw, 56px), env(safe-area-inset-right));
}
.lib-head {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: calc(env(safe-area-inset-top) + 20px);
  padding-bottom: 20px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -.015em;
}
.brand img { border-radius: 8px; }
.library.is-empty .lib-head .btn-primary { visibility: hidden; }

.lib-main { padding-bottom: calc(env(safe-area-inset-bottom) + 64px); }

.grid {
  list-style: none;
  margin: 0;
  padding: 12px 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 44px 32px;
}
@media (max-width: 520px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 32px 18px; }
}

.card { position: relative; min-width: 0; }
.card-link { display: block; color: inherit; text-decoration: none; border-radius: 6px; }
.card-link:focus-visible { outline-offset: 6px; }

.cover {
  aspect-ratio: 2 / 3;
  border-radius: 4px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 1px 2px var(--shadow), 0 12px 28px -14px var(--shadow);
  transition: transform .3s var(--ease), box-shadow .3s var(--ease);
}
.card-link:hover .cover {
  transform: translateY(-4px);
  box-shadow: 0 2px 4px var(--shadow), 0 22px 36px -18px var(--shadow);
}
.cover img { display: block; width: 100%; height: 100%; object-fit: cover; }

.cover-fallback {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px 14px 14px;
  border: 1px solid var(--line);
  border-radius: inherit;
  border-top: 3px solid var(--accent);
  font-family: var(--font-serif);
}
.cover-fallback .fb-title {
  font-size: 17px;
  line-height: 1.2;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 6;
  line-clamp: 6;
  overflow: hidden;
}
.cover-fallback .fb-author { font-family: var(--font-ui); font-size: 11px; color: var(--muted); letter-spacing: .02em; }

.card-meta { padding-top: 14px; }
.card-title, .card-author {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -.005em;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}
.card-author { margin-top: 3px; font-size: 13px; color: var(--muted); white-space: nowrap; }

.card-progress { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.card-progress .bar { flex: 1; height: 2px; background: var(--line); border-radius: 2px; overflow: hidden; }
.card-progress .bar span { display: block; height: 100%; background: var(--accent); }
.card-progress .pct { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

.card-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(27, 27, 24, .62);
  color: #fff;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity .2s, background-color .15s;
}
.card-remove svg { width: 16px; height: 16px; stroke-width: 2; }
.card-remove:hover { background: rgba(27, 27, 24, .85); }
.card:hover .card-remove, .card-remove:focus-visible { opacity: 1; }
@media (hover: none) { .card-remove { opacity: 1; } }

.empty {
  min-height: calc(100dvh - 200px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 0;
}
.empty img { border-radius: 26px; box-shadow: 0 20px 40px -20px rgba(255, 200, 0, .8); margin-bottom: 36px; }
.empty h1 { margin: 0; font-size: clamp(22px, 4vw, 28px); font-weight: 600; letter-spacing: -.02em; }
.empty p { margin: 8px 0 28px; color: var(--muted); }

/* Drop overlay */
.drop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.drop::before {
  content: "";
  position: absolute;
  inset: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  border: 2px dashed var(--accent);
  border-radius: 20px;
}
.drop.active { opacity: 1; }
.drop-inner { text-align: center; font-size: 17px; font-weight: 600; }
.drop-inner img { border-radius: 16px; }
.drop-inner p { margin: 16px 0 0; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 28px);
  z-index: 110;
  max-width: min(440px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--fg);
  color: var(--bg);
  font-size: 14px;
  box-shadow: 0 12px 32px -12px var(--shadow);
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s var(--ease), transform .25s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── Reader ────────────────────────────────────────────────────────── */

.reader { position: fixed; inset: 0; background: var(--bg); overflow: hidden; }

.r-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  height: calc(56px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  transition: opacity .25s var(--ease), transform .25s var(--ease);
}
.r-bar.hidden { opacity: 0; transform: translateY(-6px); pointer-events: none; }
.r-title {
  flex: 1;
  min-width: 0;
  margin: 0 8px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn.aa { font-family: var(--font-serif); font-size: 18px; letter-spacing: -.02em; }

.r-stage {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  padding: calc(env(safe-area-inset-top) + 64px) max(24px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 48px) max(24px, env(safe-area-inset-left));
  touch-action: pinch-zoom;
  cursor: default;
}
#r-viewport {
  display: block;
  width: min(var(--r-width), 100%);
  height: 100%;
  overflow: hidden;
  overflow: clip;
  color: var(--fg);
}

.r-foot {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 14px);
  transform: translateX(-50%);
  width: min(var(--r-width), calc(100% - 48px));
  display: flex;
  justify-content: space-between;
  gap: 24px;
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.r-chapter { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; pointer-events: none; }
.r-progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s var(--ease); }

/* Panels */
.scrim {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(10, 10, 8, .28);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s var(--ease);
}
.scrim.open { opacity: 1; pointer-events: auto; }
:root[data-theme="dark"] .scrim { background: rgba(0, 0, 0, .5); }

.sheet {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 30;
  width: min(360px, 88vw);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  box-shadow: 0 0 48px -12px var(--shadow);
  visibility: hidden;
  transition: transform .32s var(--ease), visibility 0s linear .32s;
}
.sheet.open { transform: none; visibility: visible; transition: transform .32s var(--ease); }
.sheet-left {
  left: 0;
  border-right: 1px solid var(--line);
  transform: translateX(-100%);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.sheet-right {
  right: 0;
  border-left: 1px solid var(--line);
  transform: translateX(100%);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) 0;
  overflow-y: auto;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: none;
  height: 56px;
  padding: 0 8px 0 24px;
}
.sheet-head h2 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -.01em; }

.toc, .sheet-right {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--fg) 22%, transparent) transparent;
}
.toc { list-style: none; margin: 0; padding: 4px 0 24px; overflow-y: auto; flex: 1; overscroll-behavior: contain; }
.toc button {
  position: relative;
  display: block;
  width: 100%;
  padding: 10px 24px 10px calc(24px + var(--depth, 0) * 16px);
  text-align: left;
  font-size: 14px;
  line-height: 1.35;
  color: var(--fg);
  transition: background-color .15s;
}
.toc button.sub { color: var(--muted); font-size: 13px; }
.toc button:hover { background: color-mix(in srgb, var(--fg) 5%, transparent); }
.toc button[aria-current="true"] { font-weight: 600; color: var(--fg); }
.toc button[aria-current="true"]::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.toc button:focus-visible { outline-offset: -2px; }

.setting { padding: 18px 24px; border-top: 1px solid var(--line); }
.setting-label { display: block; margin-bottom: 12px; font-size: 12px; color: var(--muted); letter-spacing: .02em; }

.swatches { display: flex; gap: 12px; }
.swatch {
  flex: 1;
  height: 52px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-family: var(--font-serif);
  font-size: 18px;
  transition: box-shadow .15s;
}
.swatch-light { background: #FAFAF7; color: #1B1B18; }
.swatch-sepia { background: #F4ECD8; color: #3B3226; }
.swatch-dark { background: #121211; color: #E6E4DC; border-color: #2A2A27; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }

.stepper {
  display: flex;
  align-items: center;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.stepper button { flex: 1; height: 100%; border-radius: 9px; }
.stepper button:hover:not(:disabled) { background: color-mix(in srgb, var(--fg) 5%, transparent); }
.stepper button:disabled { opacity: .3; cursor: default; }
.stepper output { min-width: 56px; text-align: center; font-size: 14px; font-variant-numeric: tabular-nums; }
.small-a { font-family: var(--font-serif); font-size: 14px; }
.big-a { font-family: var(--font-serif); font-size: 22px; }

.segmented {
  display: flex;
  padding: 3px;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.segmented button {
  flex: 1;
  height: 36px;
  border-radius: 7px;
  font-size: 13px;
  color: var(--muted);
  transition: background-color .15s, color .15s;
}
.segmented button:hover { color: var(--fg); }
.segmented button[aria-pressed="true"] { background: color-mix(in srgb, var(--fg) 8%, transparent); color: var(--fg); font-weight: 600; }
.font-serif { font-family: var(--font-serif); font-size: 15px !important; }
/* On a phone the column already fills the screen; the width setting would do nothing. */
@media (max-width: 600px) { .setting-width { display: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
  }
}
