:root {
  --bg: #f7efe1;
  --surface: #fffaf0;
  --surface-strong: #fff3cf;
  --ink: #243238;
  --muted: #5f6a64;
  --line: #decfb1;
  --accent: #2f7d6c;
  --accent-strong: #1d594c;
  --warm: #cc6b49;
  --shadow: 0 18px 45px rgba(68, 48, 22, 0.12);
  --reader-size: 1.3rem;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  scroll-behavior: smooth;
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(247, 239, 225, 0.92), rgba(242, 247, 238, 0.98)),
    radial-gradient(circle at 12% 6%, rgba(47, 125, 108, 0.13), transparent 32%),
    radial-gradient(circle at 88% 2%, rgba(204, 107, 73, 0.12), transparent 30%);
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  letter-spacing: 0;
}

body.dark {
  --bg: #172023;
  --surface: #202b2f;
  --surface-strong: #2d3a3d;
  --ink: #f4efe3;
  --muted: #c9d0c8;
  --line: #465356;
  --accent: #73c8af;
  --accent-strong: #a8e4d4;
  --warm: #f0a174;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
  background: #172023;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
.book-card:focus-visible {
  outline: 3px solid var(--warm);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  left: 1rem;
  top: -5rem;
  z-index: 20;
  padding: 0.75rem 1rem;
  background: var(--ink);
  color: var(--surface);
  border-radius: 6px;
}

.skip-link:focus {
  top: 1rem;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 1rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 76px;
  padding: 0.8rem 1rem;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 900;
  font-size: 1.25rem;
}

.eyebrow {
  margin: 0 0 0.15rem;
  color: var(--muted);
  font-size: 0.88rem;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.32rem, 2.2vw, 2rem);
  line-height: 1.18;
}

.top-actions {
  display: flex;
  gap: 0.45rem;
  flex: 0 0 auto;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: none;
}

.layout {
  display: grid;
  grid-template-columns: minmax(220px, 290px) minmax(0, 1fr) minmax(240px, 320px);
  gap: 1rem;
  align-items: start;
}

.shelf,
.reader,
.notebook {
  min-width: 0;
}

.shelf,
.notebook {
  position: sticky;
  top: 1rem;
}

.shelf-header,
.notebook-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 0.8rem;
  margin-bottom: 0.7rem;
}

.shelf-header h2,
.notebook-head h2 {
  margin-bottom: 0;
  font-size: 1.08rem;
}

.shelf-header p,
.notebook-head p,
.book-meta,
.source-note,
.save-state {
  color: var(--muted);
  font-size: 0.9rem;
}

.book-list {
  display: grid;
  gap: 0.75rem;
}

.book-card {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 0.75rem;
  width: 100%;
  min-height: 104px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  padding: 0.65rem;
  box-shadow: none;
}

.book-card.active {
  border-color: var(--accent);
  box-shadow: inset 4px 0 0 var(--accent), var(--shadow);
}

.book-thumb {
  width: 74px;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid var(--line);
  background-color: var(--surface-strong);
}

.book-thumb img,
.cover-strip img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.book-card h3 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
  line-height: 1.28;
}

.book-card p {
  margin: 0;
}

.done-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 4.5em;
  min-height: 1.7rem;
  margin-top: 0.45rem;
  padding: 0.18rem 0.45rem;
  border-radius: 999px;
  background: rgba(47, 125, 108, 0.12);
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 700;
}

.reader {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: clamp(0.9rem, 2vw, 1.35rem);
  box-shadow: var(--shadow);
}

.reader-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
}

.book-kicker {
  margin-bottom: 0.2rem;
  color: var(--accent-strong);
  font-size: 0.92rem;
  font-weight: 800;
}

#readerTitle {
  margin-bottom: 0.5rem;
  font-size: clamp(1.55rem, 2.4vw, 2.25rem);
  line-height: 1.18;
}

.page-pill {
  flex: 0 0 auto;
  min-width: 6.4rem;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  text-align: center;
  font-weight: 700;
}

.progress-track {
  height: 8px;
  margin: 0.3rem 0 1rem;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(95, 106, 100, 0.16);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--warm));
  transition: width 160ms ease;
}

.page-card {
  display: grid;
  grid-template-columns: minmax(260px, 42%) minmax(0, 1fr);
  gap: clamp(1rem, 2vw, 1.4rem);
  align-items: start;
}

.cover-strip {
  position: sticky;
  top: 1rem;
  aspect-ratio: 4 / 3;
  min-height: 0;
  margin: 0;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid var(--line);
  background-color: var(--surface-strong);
}

.page-body {
  min-height: 360px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding: clamp(1rem, 2.2vw, 1.6rem);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.48), rgba(255, 255, 255, 0)),
    var(--surface-strong);
}

body.dark .page-body {
  background: var(--surface-strong);
}

.page-body h3 {
  margin-bottom: 0.8rem;
  font-size: clamp(1.25rem, 2vw, 1.7rem);
  line-height: 1.25;
}

.page-body p,
.page-body li {
  font-size: var(--reader-size);
  line-height: 1.9;
}

.page-body p {
  margin-bottom: 0.9rem;
}

.page-body ul {
  margin: 0;
  padding-left: 1.45rem;
}

.source-note {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.source-note a {
  color: var(--accent-strong);
  font-weight: 800;
}

.audio-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 190px);
  gap: 0.75rem 1rem;
  align-items: center;
  margin: 0 0 1rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.audio-buttons {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
}

.audio-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 850;
}

.audio-button.primary,
.audio-button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.audio-button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.rate-control {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.65rem;
  align-items: center;
  margin: 0;
  color: var(--muted);
  white-space: nowrap;
}

.rate-control input {
  padding: 0;
  accent-color: var(--accent);
}

.speech-status {
  grid-column: 1 / -1;
  min-height: 1.35rem;
  margin: -0.25rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.reader-controls,
.note-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

.reader-controls {
  justify-content: space-between;
}

.nav-button,
.utility-button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 800;
}

.nav-button {
  width: min(48%, 220px);
}

.nav-button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.nav-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.notebook {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.notebook-head {
  align-items: start;
}

.notebook-head p {
  max-width: 9rem;
  margin-bottom: 0;
  text-align: right;
}

label {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 800;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  padding: 0.72rem 0.8rem;
  resize: vertical;
}

textarea {
  min-height: 5.9rem;
  line-height: 1.7;
}

.utility-button {
  flex: 1 1 0;
  min-width: 0;
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.utility-button + .utility-button {
  background: var(--surface-strong);
  color: var(--ink);
}

.save-state {
  min-height: 1.4rem;
  margin: 0.7rem 0 0;
}

@media (max-width: 1120px) {
  .layout {
    grid-template-columns: 230px minmax(0, 1fr);
  }

  .notebook {
    grid-column: 1 / -1;
    position: static;
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 0.65rem;
  }

  .topbar {
    align-items: start;
    padding: 0.6rem 0.2rem 0.8rem;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
  }

  .top-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
    max-width: 96px;
  }

  .icon-button {
    width: 42px;
    height: 42px;
  }

  .layout {
    display: block;
  }

  .shelf {
    position: static;
    margin-bottom: 0.85rem;
  }

  .book-list {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(225px, 78vw);
    overflow-x: auto;
    padding-bottom: 0.5rem;
    scroll-snap-type: x proximity;
  }

  .book-card {
    scroll-snap-align: start;
  }

  .reader,
  .notebook {
    margin-bottom: 0.85rem;
  }

  .reader-head {
    align-items: start;
  }

  .audio-panel {
    grid-template-columns: 1fr;
  }

  .audio-buttons {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .page-card {
    grid-template-columns: 1fr;
  }

  .cover-strip {
    position: static;
    min-height: auto;
    aspect-ratio: 4 / 3;
  }

  .page-body {
    min-height: 45vh;
  }

  .reader-controls {
    padding: 0.45rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
  }

  .nav-button {
    width: 50%;
  }
}

@media (max-width: 520px) {
  :root {
    --reader-size: 1.22rem;
  }

  .topbar {
    gap: 0.55rem;
  }

  .brand-block {
    gap: 0.6rem;
  }

  .eyebrow {
    font-size: 0.78rem;
  }

  .reader {
    padding: 0.75rem;
  }

  .reader-head {
    display: block;
  }

  .page-pill {
    display: inline-block;
    margin-bottom: 0.4rem;
  }

  .page-body {
    padding: 1rem;
  }

  .audio-buttons {
    grid-template-columns: 1fr 1fr;
  }

  .audio-button {
    min-height: 48px;
  }

  .page-body p,
  .page-body li {
    line-height: 1.82;
  }
}

@media print {
  body {
    background: white;
  }

  .top-actions,
  .shelf,
  .reader-controls,
  .cover-strip,
  .skip-link {
    display: none !important;
  }

  .app-shell {
    padding: 0;
  }

  .layout {
    display: block;
  }

  .reader,
  .notebook {
    border: 0;
    box-shadow: none;
    padding: 0;
  }

  .page-card {
    display: block;
  }

  .page-body {
    min-height: auto;
    background: white;
    padding: 0;
  }
}
