/* Paper Podcast — mobile-first, no framework. */

:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-2: #eeece7;
  --text: #1b1d22;
  --text-dim: #5f636d;
  --text-faint: #8b8f99;
  --border: #dedbd4;
  --accent: #b8791a;
  --accent-soft: #f3e3c4;
  --highlight: #fdf3dd;
  --shadow: 0 1px 2px rgba(20, 23, 31, .06), 0 4px 14px rgba(20, 23, 31, .05);
  --radius: 12px;
  --maxw: 46rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171f;
    --surface: #1c202a;
    --surface-2: #262b37;
    --text: #e9e9ec;
    --text-dim: #a3a8b4;
    --text-faint: #767c8a;
    --border: #2e3442;
    --accent: #e8b64c;
    --accent-soft: #3a3320;
    --highlight: #262436;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN",
        "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", Meiryo, Roboto, sans-serif;
  overflow-wrap: break-word;
}

h1, h2, h3 { line-height: 1.35; margin: 0; font-weight: 650; }

button { font: inherit; color: inherit; cursor: pointer; }

a { color: var(--accent); }

/* ------------------------------- topbar ------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: max(.6rem, env(safe-area-inset-top)) 1rem .6rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { font-size: 1rem; letter-spacing: .01em; }
.brand a { color: var(--text); text-decoration: none; }
.spacer { flex: 1; }

.back {
  background: none;
  border: 0;
  font-size: 1.35rem;
  line-height: 1;
  padding: .25rem .4rem;
  margin-left: -.4rem;
  border-radius: 8px;
}
.back:hover { background: var(--surface-2); }

.offline-flag {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .1rem .5rem;
}

main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1rem 1rem calc(3rem + env(safe-area-inset-bottom));
}

.view[hidden] { display: none; }

/* ------------------------------- search ------------------------------- */

.search-row { position: relative; margin-bottom: .75rem; }

#search {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .7rem 2.4rem .7rem .9rem;
  -webkit-appearance: none;
}
#search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
#search::-webkit-search-cancel-button { display: none; }

#search-clear {
  position: absolute;
  right: .35rem;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: none;
  color: var(--text-faint);
  padding: .5rem;
  line-height: 1;
}

.ghost { background: none; border: 1px solid var(--border); border-radius: 999px; }
.ghost.small { font-size: .78rem; padding: .2rem .7rem; color: var(--text-dim); }

/* -------------------------------- tags -------------------------------- */

.tags { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .9rem; }

.tag {
  font-size: .78rem;
  padding: .22rem .7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  white-space: nowrap;
}
.tag[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #14171f;
  font-weight: 600;
}

.result-count { font-size: .82rem; color: var(--text-faint); margin: 0 0 .6rem; }

/* ---------------------------- episode cards --------------------------- */

.episode-list { display: flex; flex-direction: column; gap: .7rem; }

.card {
  display: block;
  text-align: left;
  width: 100%;
  color: var(--text);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .9rem 1rem;
}
.card:hover { border-color: var(--accent); }

.card-title { font-size: 1.02rem; font-weight: 650; margin-bottom: .25rem; }
.card-desc {
  font-size: .89rem;
  color: var(--text-dim);
  margin: 0 0 .5rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .4rem;
  font-size: .76rem;
  color: var(--text-faint);
}

.badge {
  border-radius: 4px;
  padding: .05rem .4rem;
  background: var(--surface-2);
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .05em;
  font-size: .68rem;
}
.badge.mock { background: var(--accent-soft); color: var(--accent); }

.card-tags { margin-top: .5rem; display: flex; flex-wrap: wrap; gap: .3rem; }
.card-tags span {
  font-size: .72rem;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .05rem .55rem;
}

.progress {
  margin-top: .6rem;
  height: 3px;
  border-radius: 2px;
  background: var(--surface-2);
  overflow: hidden;
}
.progress div { height: 100%; background: var(--accent); }

.empty, .error {
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  text-align: center;
}
.error { color: #c0392b; border-color: #c0392b55; }
@media (prefers-color-scheme: dark) { .error { color: #ff8a7a; } }

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

.episode-head { margin-bottom: .9rem; }
#ep-title { font-size: 1.3rem; }
.meta { font-size: .8rem; color: var(--text-faint); margin: .35rem 0 0; }
.ep-description { font-size: .92rem; color: var(--text-dim); margin: .5rem 0 0; }

.parts { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .9rem; }
.parts button {
  font-size: .82rem;
  padding: .3rem .85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
}
.parts button[aria-selected="true"] {
  background: var(--accent); border-color: var(--accent); color: #14171f; font-weight: 600;
}

.player {
  position: sticky;
  top: calc(env(safe-area-inset-top) + 2.9rem);
  z-index: 10;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .85rem 1rem 1rem;
  margin-bottom: 1rem;
}

.seek { position: relative; height: 26px; display: flex; align-items: center; }

.seek-track {
  position: absolute;
  left: 0; right: 0;
  height: 5px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}
.seek-buffered { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--border); }
.seek-played { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent); }

.seek-input {
  position: relative;
  width: 100%;
  margin: 0;
  background: none;
  -webkit-appearance: none;
  appearance: none;
  height: 26px;
}
.seek-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.seek-input::-webkit-slider-runnable-track { height: 26px; background: none; }
.seek-input::-moz-range-track { height: 26px; background: none; }
.seek-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px; margin-top: 5px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.seek-input::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
}

.times {
  display: flex;
  justify-content: space-between;
  font-size: .75rem;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  margin-top: .1rem;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.4rem;
  margin-top: .5rem;
}

.control {
  min-width: 48px;
  min-height: 48px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  display: grid;
  place-items: center;
  position: relative;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-dim);
}
.control:hover { border-color: var(--accent); color: var(--accent); }
.control.primary {
  min-width: 60px;
  min-height: 60px;
  background: var(--accent);
  border-color: var(--accent);
  color: #14171f;
  font-size: 1.2rem;
}
.control.primary:hover { color: #14171f; filter: brightness(1.05); }

.rewind-num {
  position: absolute;
  font-size: .55rem;
  font-weight: 700;
  top: 56%;
  left: 50%;
  transform: translate(-50%, -50%);
  letter-spacing: -.02em;
}

/* ------------------------------ downloads ----------------------------- */

.download-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  margin-top: .9rem;
}

.pill {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  border-radius: 999px;
  padding: .35rem .9rem;
  font-size: .82rem;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
}
.pill:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.pill:disabled { cursor: default; opacity: .9; }
.pill.done { border-color: var(--accent); color: var(--accent); }
.pill.busy { cursor: progress; }

.download-note { font-size: .76rem; color: var(--text-faint); }

.badge.offline { background: var(--accent-soft); color: var(--accent); }

/* ------------------------------- papers -------------------------------
   Compact chips live inside the sticky player, so the PDF is one tap away at
   the moment the narration reaches that paper. Full citations sit in the
   episode header above, where they are read once rather than acted on. */

.citations {
  list-style: none;
  margin: .7rem 0 0;
  padding: 0;
  font-size: .82rem;
  color: var(--text-faint);
}
.citations li { padding-left: 1rem; text-indent: -1rem; }
.citations li + li { margin-top: .2rem; }

.papers {
  display: flex;
  gap: .4rem;
  margin-top: .8rem;
  padding-top: .8rem;
  border-top: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.papers::-webkit-scrollbar { display: none; }
.papers:empty { display: none; }

.paper-link {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  flex: none;
  max-width: 100%;
  text-decoration: none;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: .3rem .8rem;
  font-size: .8rem;
  white-space: nowrap;
  transition: border-color .15s, background .15s, color .15s;
}
.paper-link:hover { border-color: var(--accent); color: var(--text); }
.paper-link.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #14171f;
  font-weight: 600;
}
.paper-link .pdf-tag {
  font-size: .6rem;
  letter-spacing: .06em;
  font-weight: 700;
  opacity: .75;
  flex: none;
}
.paper-link .paper-cite { overflow: hidden; text-overflow: ellipsis; }

/* ----------------------------- transcript ----------------------------- */

.transcript-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .5rem;
}
.transcript-head h3 { font-size: .95rem; color: var(--text-dim); font-weight: 600; }
#follow-toggle[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

.transcript { display: flex; flex-direction: column; gap: .3rem; }

.seg {
  text-align: left;
  width: 100%;
  background: none;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: 0 8px 8px 0;
  padding: .55rem .8rem;
  color: var(--text-dim);
  font-size: .95rem;
  line-height: 1.85;
  transition: background .2s, color .2s, border-color .2s;
}
.seg:hover { background: var(--surface); }
.seg.active {
  background: var(--highlight);
  border-left-color: var(--accent);
  color: var(--text);
}
.seg.done { color: var(--text-faint); }

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

@media (min-width: 40rem) {
  main { padding: 1.5rem 1.5rem 4rem; }
  #ep-title { font-size: 1.55rem; }
  .papers { flex-direction: row; flex-wrap: wrap; }
  .paper-link { flex: 1 1 18rem; }
}
