/* ============================================================
   listen v1.2 — stylesheet (no frameworks, no CDN)
   Warm dark theme by default; light theme via [data-theme="light"]
   ============================================================ */

:root,
html[data-theme="dark"] {
  --bg:        #171310;
  --bg-soft:   #1f1a15;
  --surface:   #241e18;
  --surface-2: #2d261e;
  --border:    #3a3128;
  --text:      #ece5da;
  --muted:     #a3947f;
  --accent:    #e8a33d;
  --accent-ink:#171310;
  --danger:    #e06c5a;
  --shadow:    0 18px 40px rgba(0,0,0,.55);
}

html[data-theme="light"] {
  --bg:        #faf5ec;
  --bg-soft:   #f3ecdf;
  --surface:   #ffffff;
  --surface-2: #f6efe3;
  --border:    #e2d7c4;
  --text:      #2a2218;
  --muted:     #8a7c66;
  --accent:    #b06f10;
  --accent-ink:#ffffff;
  --danger:    #b9432f;
  --shadow:    0 18px 40px rgba(80,60,20,.18);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100vh;
}

.mono  { font-variant-numeric: tabular-nums; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.small { font-size: 13px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

.wrap { max-width: 980px; margin: 0 auto; padding: 0 18px; }

button { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------------- header ---------------- */

.top {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.top-row { height: 60px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo { width: 30px; height: 30px; display: block; }
.brand-name {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 26px;
  letter-spacing: -0.5px;
}

.top-actions { display: flex; align-items: center; gap: 8px; }

.btn {
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 12px;
  padding: 9px 14px;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  min-height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s ease, border-color .15s ease;
}
.btn:hover { background: var(--surface); }
.btn.subtle { border-color: transparent; color: var(--muted); }
.btn.subtle:hover { color: var(--text); }
.btn.icon { width: 40px; padding: 0; font-size: 16px; }
.btn.primary {
  background: var(--accent); color: var(--accent-ink);
  border-color: var(--accent); font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }

/* ---------------- main / sections ---------------- */

.main { padding: 26px 18px 140px; }

.section-title {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 400;
  font-size: 20px;
  margin: 0 0 14px;
}
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.section-head .section-title { margin: 0; }

#continue-section { margin-bottom: 30px; }

.continue-row {
  display: flex; gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.continue-row .card {
  min-width: 240px; max-width: 280px;
  scroll-snap-align: start;
  flex: 0 0 auto;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px 16px 14px;
  cursor: pointer;
  text-align: left;
  transition: transform .15s ease, border-color .15s ease;
}
.card:hover { transform: translateY(-2px); border-color: var(--muted); }
.card:active { transform: translateY(0); }

.book-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
  line-height: 1.25;
  margin-bottom: 5px;
  overflow-wrap: anywhere;
}
.card-meta { margin-bottom: 10px; }

.badge {
  display: inline-block;
  font-size: 11px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink);
}

.card-bar {
  height: 5px; border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  margin-bottom: 7px;
}
.card-bar > div { height: 100%; background: var(--accent); border-radius: 999px; }

.empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 56px 18px;
  border: 1px dashed var(--border);
  border-radius: 18px;
}
.empty code {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2px 7px; border-radius: 7px;
  font-size: 13px;
}

/* ---------------- player sheet ---------------- */

.backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,.55);
}

.player {
  position: fixed; z-index: 70;
  left: 0; right: 0; bottom: 0;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow);
  padding: 10px 20px calc(20px + env(safe-area-inset-bottom));
  max-height: 92vh;
  overflow-y: auto;
  animation: sheet-up .22s ease;
}
@keyframes sheet-up {
  from { transform: translateY(24px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

@media (min-width: 720px) {
  .player {
    left: 50%; right: auto; bottom: 50%;
    transform: translate(-50%, 50%);
    width: 560px;
    border-radius: 22px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 22px;
  }
  @keyframes sheet-up {
    from { transform: translate(-50%, 52%); opacity: 0; }
    to   { transform: translate(-50%, 50%); opacity: 1; }
  }
}

.sheet-close {
  display: block; margin: 0 auto 2px;
  background: none; border: none;
  color: var(--muted); font-size: 22px;
  cursor: pointer; padding: 2px 26px;
}

.player-head { text-align: center; margin-bottom: 18px; }
.player-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px; line-height: 1.2;
  overflow-wrap: anywhere;
}

/* signature: whole-book progress with chapter tick marks */
.bar-wrap { position: relative; padding: 6px 0 2px; }

.ticks { position: absolute; left: 0; right: 0; top: 50%; height: 0; pointer-events: none; }
.ticks i {
  position: absolute; top: -4px;
  width: 2px; height: 8px;
  background: color-mix(in srgb, var(--muted) 55%, transparent);
  border-radius: 1px;
}

input[type="range"] {
  width: 100%; margin: 0;
  -webkit-appearance: none; appearance: none;
  background: transparent;
  height: 28px;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 999px;
  background: var(--surface-2);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent);
  border: none;
  margin-top: -6px;
}
input[type="range"]::-moz-range-track {
  height: 6px; border-radius: 999px;
  background: var(--surface-2);
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); border: none;
}

.times { display: flex; justify-content: space-between; align-items: center; margin: 2px 2px 16px; }

.controls {
  display: flex; align-items: center; justify-content: center;
  gap: 14px; margin-bottom: 18px;
}

.ctl {
  border: none; background: var(--surface);
  border-radius: 16px;
  width: 52px; height: 52px;
  font-size: 19px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .15s ease;
}
.ctl:hover { background: var(--surface-2); }
.ctl small { font-size: 10px; font-weight: 700; margin: 0 1px; }
.ctl.main {
  background: var(--accent); color: var(--accent-ink);
  width: 64px; height: 64px;
  border-radius: 20px;
  font-size: 24px;
}
.ctl.main:hover { filter: brightness(1.06); background: var(--accent); }
.ctl.sm { width: 42px; height: 42px; font-size: 15px; border-radius: 13px; }
.ctl.sm.main { width: 46px; height: 46px; font-size: 17px; }

.row2 {
  display: flex; flex-wrap: wrap;
  align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px;
}
.speed, .sleep { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.chip {
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 999px;
  min-width: 38px; min-height: 34px;
  padding: 4px 11px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
}
.chip:hover { background: var(--surface); }
.chip.val { min-width: 58px; font-weight: 600; }
.chip.active {
  background: var(--accent); color: var(--accent-ink);
  border-color: var(--accent); font-weight: 600;
}

.chapters-block { border-top: 1px solid var(--border); padding-top: 12px; }
.chapters-toggle {
  background: none; border: none;
  color: var(--muted); font-size: 14px;
  cursor: pointer; padding: 6px 2px;
  display: flex; align-items: center; gap: 8px;
}
.chapters-toggle:hover { color: var(--text); }
.pill {
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 11px;
  padding: 1px 8px; border-radius: 999px;
}

.chapter-list { margin-top: 8px; max-height: 240px; overflow-y: auto; }
.chapter-item {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: none; background: none;
  border-radius: 11px;
  font-size: 14px;
  cursor: pointer; text-align: left;
}
.chapter-item:hover { background: var(--surface); }
.chapter-item.active { background: var(--surface-2); }
.chapter-item.active .ch-name { color: var(--accent); font-weight: 600; }
.ch-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-dur  { flex: 0 0 auto; }

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

.mini {
  position: fixed; z-index: 50;
  left: 0; right: 0; bottom: 0;
  background: var(--bg-soft);
  border-top: 1px solid var(--border);
  box-shadow: 0 -10px 24px rgba(0,0,0,.25);
  padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 10px;
}
.mini-info {
  flex: 1; min-width: 0;
  background: none; border: none;
  text-align: left; cursor: pointer;
  display: flex; flex-direction: column; gap: 1px;
  padding: 4px 2px;
}
.mini-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mini-ctls { display: flex; align-items: center; gap: 8px; }

/* ---------------- toasts ---------------- */

.toasts {
  position: fixed; z-index: 90;
  left: 50%; transform: translateX(-50%);
  bottom: calc(86px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
  width: max-content; max-width: 92vw;
}
.toast {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 14px;
  box-shadow: var(--shadow);
  animation: toast-in .18s ease;
  max-width: 92vw;
}
@keyframes toast-in {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0);   opacity: 1; }
}

/* ---------------- login ---------------- */

.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 18px; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 44px 36px;
  width: 100%; max-width: 350px;
  text-align: center;
  box-shadow: var(--shadow);
}
.login-logo { width: 52px; height: 52px; margin-bottom: 12px; }
.login-brand {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 34px; letter-spacing: -0.5px;
}
.login-tag { color: var(--muted); font-size: 14px; margin: 4px 0 30px; }
.pin-input {
  width: 100%;
  font-size: 26px; text-align: center; letter-spacing: 10px;
  padding: 14px;
  border: 2px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 13px;
  outline: none;
  margin-bottom: 14px;
}
.pin-input:focus { border-color: var(--accent); }
.login-error { color: var(--danger); margin-top: 14px; font-size: 14px; }

/* ---------------- misc ---------------- */

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