:root {
  color-scheme: light;
  --app-bg: #f3f5f2;
  --surface: #ffffff;
  --surface-soft: #eef2ef;
  --ink: #172522;
  --muted: #687571;
  --line: #dce3df;
  --accent: #246b57;
  --accent-strong: #185240;
  --accent-soft: #dcebe5;
  --danger: #a63c35;
  --shadow: 0 12px 36px rgba(24, 48, 41, 0.12);
  --sidebar-width: 232px;
  --reader-header-height: 64px;
  --player-height: 0px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  background: var(--app-bg);
  color: var(--ink);
  font-size: 15px;
  letter-spacing: 0;
}

button,
input,
select {
  color: inherit;
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid rgba(36, 107, 87, 0.28);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px 16px;
  background: #e9eeeb;
  border-right: 1px solid var(--line);
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 8px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-family: "Songti SC", "STSong", serif;
  font-size: 19px;
  font-weight: 700;
}

.brand div {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand strong {
  font-size: 18px;
}

.brand span:last-child {
  color: var(--muted);
  font-size: 12px;
}

.library-nav {
  min-height: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
  overflow: auto;
}

.nav-label {
  padding: 20px 10px 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.category-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #41504c;
  text-align: left;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.62);
}

.nav-item.is-active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 650;
  box-shadow: 0 1px 4px rgba(24, 48, 41, 0.06);
}

.nav-count {
  min-width: 24px;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: 6px;
  font-weight: 650;
}

.primary-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.secondary-button:hover {
  background: var(--surface-soft);
}

.danger-button {
  border: 1px solid #e7c8c5;
  background: #fff7f6;
  color: var(--danger);
}

.sidebar-import {
  width: 100%;
}

.account-button {
  width: 100%;
  min-height: 52px;
  justify-content: flex-start;
  padding: 8px 10px;
  text-align: left;
}

.account-symbol {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 18px;
}

.account-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.account-copy strong,
.account-copy small {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-copy small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.library-view {
  min-width: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.library-header {
  min-height: 112px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px clamp(24px, 4vw, 56px);
  border-bottom: 1px solid var(--line);
  background: rgba(243, 245, 242, 0.94);
}

.library-header h1 {
  margin: 0 0 5px;
  font-size: 28px;
  line-height: 1.2;
}

.library-header p {
  margin: 0;
  color: var(--muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-box {
  width: min(34vw, 340px);
  height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
}

.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 107, 87, 0.1);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
}

.library-content {
  flex: 1;
  padding: 32px clamp(24px, 4vw, 56px) 64px;
}

.loading-state {
  min-height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.empty-state {
  min-height: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.empty-state img {
  width: 270px;
  max-width: 72vw;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.empty-state h2 {
  margin: 24px 0 8px;
  font-size: 21px;
}

.empty-state p {
  margin: 0 0 20px;
  color: var(--muted);
}

.empty-state.compact {
  min-height: 320px;
}

.empty-symbol {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  font-size: 28px;
}

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

.book-card {
  min-width: 0;
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 15px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  transition: border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.book-card:hover {
  border-color: #bdcac4;
  box-shadow: 0 8px 24px rgba(24, 48, 41, 0.08);
  transform: translateY(-1px);
}

.book-cover {
  position: relative;
  width: 88px;
  aspect-ratio: 2 / 3;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  padding: 11px 9px;
  border-radius: 4px 7px 7px 4px;
  background: var(--cover-bg, #355f55);
  color: var(--cover-ink, #fff);
  box-shadow: inset 5px 0 rgba(0, 0, 0, 0.09), 0 5px 12px rgba(23, 37, 34, 0.15);
}

.book-cover::after {
  content: "";
  position: absolute;
  right: -18px;
  bottom: -24px;
  width: 54px;
  height: 72px;
  border: 10px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
}

.book-cover strong {
  position: relative;
  z-index: 1;
  display: -webkit-box;
  overflow: hidden;
  font-family: "Songti SC", "STSong", serif;
  font-size: 14px;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
}

.book-cover span {
  position: relative;
  z-index: 1;
  font-size: 10px;
  opacity: 0.76;
}

.book-details {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.book-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 4px;
}

.book-title-button {
  min-width: 0;
  padding: 2px 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.book-title-button strong {
  display: -webkit-box;
  overflow: hidden;
  font-size: 16px;
  line-height: 1.4;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.book-author {
  min-height: 20px;
  margin: 4px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  line-height: 1;
}

.icon-button:hover {
  border-color: var(--line);
  background: var(--surface-soft);
}

.book-menu {
  width: 30px;
  height: 30px;
  color: var(--muted);
  font-weight: 700;
}

.book-category {
  max-width: 100%;
  align-self: flex-start;
  margin-top: 10px;
  overflow: hidden;
  padding: 3px 7px;
  border-radius: 4px;
  background: var(--surface-soft);
  color: #4e605a;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-storage {
  align-self: flex-start;
  margin-top: 6px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 650;
}

.book-progress {
  margin-top: auto;
  padding-top: 12px;
}

.book-progress-track {
  height: 4px;
  overflow: hidden;
  border-radius: 2px;
  background: #e6ebe8;
}

.book-progress-track span {
  display: block;
  width: var(--progress, 0%);
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.book-progress-label {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
}

.reader-view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  z-index: 20;
  overflow: hidden;
  background: #f8f8f6;
  color: #202724;
}

.reader-view[data-theme="mist"] {
  background: #e7efea;
  color: #20312b;
}

.reader-view[data-theme="night"] {
  color-scheme: dark;
  background: #1d2422;
  color: #e5ebe7;
  --surface: #252e2b;
  --surface-soft: #303b37;
  --line: #3c4844;
  --muted: #a7b2ad;
}

.reader-header {
  height: var(--reader-header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
}

.reader-header-start,
.reader-actions {
  display: flex;
  align-items: center;
}

.reader-header-start {
  min-width: 0;
  gap: 4px;
}

.reader-book-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  margin-left: 8px;
}

.reader-book-meta strong,
.reader-book-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-book-meta strong {
  max-width: 34vw;
  font-size: 14px;
}

.reader-book-meta span {
  max-width: 34vw;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.reader-layout {
  position: relative;
  height: calc(100vh - var(--reader-header-height) - var(--player-height));
  height: calc(100dvh - var(--reader-header-height) - var(--player-height));
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.toc-panel,
.bookmark-panel {
  min-height: 0;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
}

.bookmark-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 320px;
  z-index: 4;
  border-right: 0;
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 30px rgba(22, 39, 34, 0.08);
}

.panel-heading {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px 0 18px;
  border-bottom: 1px solid var(--line);
}

.panel-heading strong {
  font-size: 14px;
}

.panel-close {
  display: none;
}

.toc-list,
.bookmark-list {
  height: calc(100% - 52px);
  overflow: auto;
  padding: 10px;
}

.toc-item {
  width: 100%;
  display: block;
  padding: 10px 9px;
  overflow: hidden;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toc-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  align-items: center;
}

.toc-download {
  width: 30px;
  height: 30px;
  color: var(--muted);
}

.toc-item:hover,
.toc-item.is-active {
  background: var(--surface-soft);
  color: inherit;
}

.toc-item.is-active {
  box-shadow: inset 3px 0 var(--accent);
  font-weight: 650;
}

.reader-scroll {
  min-width: 0;
  overflow: auto;
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
}

.reader-content {
  width: min(100% - 48px, 760px);
  min-height: calc(100% - 100px);
  margin: 0 auto;
  padding: 64px 0 100px;
  font-family: "Songti SC", "STSong", "SimSun", serif;
  font-size: var(--reader-font-size, 19px);
  line-height: 1.95;
  word-break: break-word;
}

.reader-paragraph {
  margin: 0 0 1.35em;
  padding: 1px 5px;
  border-radius: 3px;
  white-space: pre-wrap;
  transition: background 120ms ease;
}

.reader-paragraph:hover {
  background: rgba(36, 107, 87, 0.06);
}

.reader-position-block.is-speaking {
  background: rgba(36, 107, 87, 0.14);
  box-shadow: inset 3px 0 var(--accent);
}

.reader-content.has-rich-content {
  width: min(100% - 48px, 860px);
  line-height: 1.8;
}

.reader-content.has-rich-content .book-chapter + .book-chapter {
  margin-top: 3em;
  padding-top: 2em;
  border-top: 1px solid var(--line);
}

.reader-content.has-rich-content :is(h1, h2, h3, h4, h5, h6) {
  margin: 1.7em 0 0.75em;
  font-family: inherit;
  line-height: 1.4;
}

.reader-content.has-rich-content h1 {
  font-size: 1.7em;
}

.reader-content.has-rich-content h2 {
  font-size: 1.45em;
}

.reader-content.has-rich-content h3 {
  font-size: 1.25em;
}

.reader-content.has-rich-content p {
  margin: 0 0 1.25em;
}

.reader-content.has-rich-content :is(ul, ol) {
  margin: 1em 0 1.4em;
  padding-left: 2em;
}

.reader-content.has-rich-content li + li {
  margin-top: 0.45em;
}

.reader-content.has-rich-content blockquote {
  margin: 1.5em 0;
  padding: 0.25em 0 0.25em 1.25em;
  border-left: 3px solid color-mix(in srgb, var(--accent) 65%, var(--line));
  color: var(--muted);
}

.reader-content.has-rich-content pre {
  max-width: 100%;
  overflow: auto;
  padding: 1em;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface-soft);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.86em;
  line-height: 1.65;
  white-space: pre-wrap;
}

.reader-content.has-rich-content :is(figure, img) {
  max-width: 100%;
}

.reader-content.has-rich-content figure {
  margin: 1.8em auto;
}

.reader-content.has-rich-content img {
  display: block;
  height: auto;
  margin: 1.6em auto;
  object-fit: contain;
}

.reader-content.has-rich-content figcaption {
  margin-top: -0.8em;
  color: var(--muted);
  font-size: 0.85em;
  text-align: center;
}

.reader-content.has-rich-content table {
  width: 100%;
  display: block;
  margin: 1.6em 0;
  overflow-x: auto;
  border-collapse: collapse;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.86em;
  line-height: 1.5;
}

.reader-content.has-rich-content :is(th, td) {
  min-width: 7em;
  padding: 0.65em 0.75em;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.reader-content.has-rich-content th {
  background: var(--surface-soft);
  font-weight: 700;
}

.reader-content.has-rich-content a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

.reader-content.has-rich-content .doc-tab {
  display: inline-block;
  width: 2em;
}

.reader-content.has-rich-content .doc-list-item {
  position: relative;
  padding-left: 1.4em;
}

.reader-content.has-rich-content .doc-list-item::before {
  position: absolute;
  left: 0.25em;
  content: "•";
}

.reader-content.has-pdf-content {
  width: min(100% - 48px, 940px);
}

.pdf-document {
  width: 100%;
  display: grid;
  gap: 56px;
}

.pdf-extracted-page {
  scroll-margin-top: 24px;
}

.pdf-page-visual {
  margin: 0 !important;
}

.reader-content.has-rich-content .pdf-page-visual img,
.shared-content.has-rich-content .pdf-page-visual img {
  width: 100%;
  height: auto;
  margin: 0;
  border: 1px solid color-mix(in srgb, var(--line) 82%, #7f8985);
  background: #fff;
  box-shadow: 0 5px 20px rgba(25, 33, 30, 0.14);
}

.pdf-page-copy {
  width: min(100% - 32px, 760px);
  margin: 22px auto 0;
  padding: 0 0 0 18px;
  border-left: 2px solid var(--line);
}

.pdf-page-number {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 12px;
  font-weight: 700;
}

.pdf-page-copy p {
  margin: 0 !important;
  white-space: pre-wrap;
}

.pdf-page-copy.is-empty {
  padding: 12px 0 0;
  border-left: 0;
  text-align: center;
}

.pdf-page-copy.is-empty .pdf-page-number {
  margin: 0;
  font-weight: 500;
}

.rich-text-fallback {
  margin-top: 3em;
}

.reader-end {
  padding: 0 0 72px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.site-record {
  padding: 18px 24px calc(18px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  color: var(--muted);
  font: 12px/1.5 system-ui, -apple-system, sans-serif;
  text-align: center;
}

.site-record a {
  color: inherit;
  text-decoration: none;
}

.site-record a:hover,
.site-record a:focus-visible {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.reader-record {
  width: min(100% - 48px, 940px);
  margin: 0 auto;
}

.shared-record {
  margin-top: 72px;
}

.appearance-panel {
  position: absolute;
  top: 10px;
  right: 18px;
  width: 300px;
  z-index: 6;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.setting-row + .setting-row {
  margin-top: 18px;
}

.setting-row > label,
.setting-row > span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
}

.voice-setting {
  align-items: flex-start;
}

.voice-setting select {
  width: min(190px, 100%);
  min-width: 0;
  min-height: 34px;
  padding: 6px 28px 6px 9px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
}

.stepper {
  min-width: 0;
  display: grid;
  grid-template-columns: 30px minmax(100px, 1fr) 30px;
  align-items: center;
  gap: 5px;
}

.stepper button {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface-soft);
}

input[type="range"] {
  accent-color: var(--accent);
}

.theme-swatches {
  display: flex;
  gap: 9px;
}

.theme-swatch {
  width: 31px;
  height: 31px;
  border: 1px solid #c8d0cc;
  border-radius: 50%;
  box-shadow: inset 0 0 0 3px var(--surface);
}

.theme-swatch.is-active {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.theme-swatch.paper {
  background: #f8f8f6;
}

.theme-swatch.mist {
  background: #d9e7de;
}

.theme-swatch.night {
  background: #232b29;
}

.bookmark-item {
  position: relative;
  padding: 12px 38px 12px 10px;
  border-bottom: 1px solid var(--line);
}

.bookmark-jump {
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.bookmark-jump strong {
  display: block;
  margin-bottom: 5px;
  font-size: 13px;
}

.bookmark-jump span {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-family: "Songti SC", "STSong", serif;
  font-size: 12px;
  line-height: 1.55;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.bookmark-delete {
  position: absolute;
  top: 9px;
  right: 3px;
  color: var(--muted);
}

.bookmark-actions {
  position: absolute;
  top: 8px;
  right: 3px;
  display: flex;
}

.bookmark-actions .icon-button {
  width: 30px;
  height: 30px;
  color: var(--muted);
}

.bookmark-actions .bookmark-delete {
  position: static;
}

.bookmark-item:has(.bookmark-actions) {
  padding-right: 68px;
}

.bookmark-empty {
  padding: 40px 12px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.play-button {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  padding: 0 0 0 2px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
}

.play-button:hover {
  background: var(--accent-strong);
}

.speech-fab {
  position: fixed;
  right: max(22px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  width: 60px;
  height: 60px;
  z-index: 12;
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 8px 24px rgba(15, 48, 39, 0.26);
  font-size: 21px;
  touch-action: manipulation;
}

.reader-overlay {
  position: absolute;
  inset: var(--reader-header-height) 0 0;
  z-index: 7;
  border: 0;
  background: rgba(15, 27, 23, 0.28);
}

.share-view {
  grid-column: 1 / -1;
  min-height: 100vh;
  min-height: 100dvh;
  background: #f5f6f3;
}

.share-header {
  height: 68px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.share-header .brand {
  width: min(100% - 40px, 820px);
  margin: 0 auto;
  padding: 0;
}

.share-brand .brand-mark {
  width: 34px;
  height: 34px;
  font-size: 17px;
}

.shared-main {
  width: min(100% - 40px, 760px);
  margin: 0 auto;
  padding: 64px 0 150px;
}

.shared-meta {
  margin-bottom: 46px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.shared-meta span {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.shared-meta h1 {
  margin: 9px 0 0;
  font-family: "Songti SC", "STSong", serif;
  font-size: 30px;
  line-height: 1.35;
}

.shared-content {
  font-family: "Songti SC", "STSong", serif;
  font-size: 19px;
  line-height: 1.95;
  white-space: pre-wrap;
}

.shared-content.has-rich-content {
  white-space: normal;
}

.shared-content.has-rich-content img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5em auto;
}

.shared-content.has-rich-content table {
  width: 100%;
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
}

.shared-content.has-rich-content :is(th, td) {
  min-width: 7em;
  padding: 0.6em 0.7em;
  border: 1px solid var(--line);
}

.shared-content.has-rich-content .pdf-document {
  display: grid;
  gap: 48px;
}

.app-dialog {
  width: min(92vw, 540px);
  max-height: min(88vh, 720px);
  overflow: auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.app-dialog::backdrop {
  background: rgba(17, 30, 26, 0.45);
  backdrop-filter: blur(2px);
}

.app-dialog form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
}

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
}

.dialog-body form {
  gap: 16px;
  padding: 0;
}

.compact-dialog {
  width: min(92vw, 480px);
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.dialog-header h2 {
  margin: 0;
  font-size: 20px;
}

.dialog-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.translation-dialog {
  width: min(92vw, 620px);
}

.translation-languages {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 24px minmax(0, 1fr);
  align-items: end;
  gap: 10px;
}

.translation-arrow {
  padding-bottom: 11px;
  color: var(--muted);
  text-align: center;
}

.field select {
  width: 100%;
  height: 42px;
  padding: 0 34px 0 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.translation-result {
  min-height: 112px;
  max-height: 220px;
  overflow: auto;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.segmented-control {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
}

.segmented-control button {
  min-height: 34px;
  padding: 5px 12px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
}

.segmented-control button.is-active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 650;
  box-shadow: 0 1px 4px rgba(24, 48, 41, 0.1);
}

.file-dropzone {
  position: relative;
  min-height: 188px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 24px;
  border: 1px dashed #aab9b2;
  border-radius: 8px;
  background: #f7f9f7;
  text-align: center;
  cursor: pointer;
}

.file-dropzone.is-dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.file-dropzone input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.001;
  cursor: pointer;
}

.file-dropzone > span:last-child {
  color: var(--muted);
  font-size: 12px;
}

.drop-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  margin-bottom: 4px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 24px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field > span {
  font-size: 13px;
  font-weight: 650;
}

.field input,
.field textarea,
.share-result input {
  width: 100%;
  height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.field textarea {
  min-height: 92px;
  resize: vertical;
  padding: 10px 11px;
  line-height: 1.55;
}

.field input:focus,
.field textarea:focus,
.field select:focus,
.share-result input:focus {
  border-color: var(--accent);
}

.metadata-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}

.account-signed-in {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.account-summary {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 16px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.account-summary strong {
  font-size: 18px;
}

.account-summary span {
  color: var(--muted);
  font-size: 13px;
}

.account-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.account-cancel-form {
  padding-top: 18px !important;
  border-top: 1px solid var(--line);
}

#encrypted-import-fields {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8faf8;
}

.recovery-key-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.vault-book-actions {
  display: flex;
  gap: 8px;
}

.form-error {
  padding: 10px 12px;
  border-left: 3px solid var(--danger);
  background: #fff4f3;
  color: #7c2f2a;
  font-size: 13px;
}

.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 2px;
}

.dialog-actions.spread {
  justify-content: space-between;
}

.dialog-actions.spread > div {
  display: flex;
  gap: 9px;
}

.share-result {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.toast-region {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  max-width: min(360px, calc(100vw - 40px));
  padding: 11px 14px;
  border: 1px solid #374842;
  border-radius: 6px;
  background: #22322d;
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: toast-in 180ms ease;
}

.toast.is-error {
  border-color: #7e3531;
  background: #642e2a;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@media (max-width: 760px) {
  :root {
    --reader-header-height: calc(58px + env(safe-area-inset-top));
    --player-height: 0px;
  }

  .app-shell {
    display: block;
  }

  .sidebar {
    position: relative;
    width: 100%;
    height: auto;
    gap: 14px;
    padding: 14px 16px 10px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand {
    padding: 0;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    font-size: 17px;
  }

  .brand strong {
    font-size: 17px;
  }

  .library-nav {
    flex: none;
    flex-direction: row;
    gap: 6px;
    margin: 0 -16px;
    padding: 0 16px 2px;
    overflow-x: auto;
  }

  .nav-label,
  .sidebar-import {
    display: none;
  }

  .category-nav {
    display: contents;
  }

  .nav-item {
    width: auto;
    min-height: 34px;
    flex: 0 0 auto;
    justify-content: center;
    padding: 7px 11px;
    border: 1px solid transparent;
  }

  .nav-count {
    display: none;
  }

  .account-button {
    position: absolute;
    top: 14px;
    right: 16px;
    width: auto;
    min-height: 34px;
    padding: 6px 10px;
  }

  .account-symbol,
  .account-copy small {
    display: none;
  }

  .account-copy strong {
    max-width: 112px;
    font-size: 13px;
  }

  .library-header {
    position: relative;
    min-height: 132px;
    align-items: flex-start;
    padding: 18px 16px;
  }

  .library-header h1 {
    font-size: 23px;
  }

  .library-header p {
    display: none;
  }

  .header-actions {
    flex: 1;
    justify-content: flex-end;
  }

  .search-box {
    position: absolute;
    top: auto;
    right: 16px;
    bottom: 18px;
    left: 16px;
    width: auto;
  }

  .library-content {
    padding: 22px 16px 48px;
  }

  .book-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .book-card {
    grid-template-columns: 76px minmax(0, 1fr);
  }

  .book-cover {
    width: 76px;
  }

  .empty-state {
    min-height: 420px;
  }

  .reader-header {
    gap: 8px;
    padding: env(safe-area-inset-top) 8px 0;
  }

  .reader-actions {
    max-width: calc(100vw - 118px);
    flex: 0 1 auto;
    gap: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .reader-actions::-webkit-scrollbar {
    display: none;
  }

  .reader-actions .icon-button {
    width: 30px;
    flex: 0 0 30px;
  }

  .reader-header-start {
    min-width: 0;
    flex: 1 1 0;
    overflow: hidden;
  }

  .reader-header-start > .icon-button {
    width: 34px;
    flex: 0 0 34px;
  }

  .reader-book-meta {
    min-width: 0;
    flex: 1 1 0;
    margin-left: 3px;
  }

  .reader-book-meta strong,
  .reader-book-meta span {
    width: 100%;
    max-width: none;
  }

  .reader-layout {
    display: block;
  }

  .toc-panel,
  .bookmark-panel {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(86vw, 320px);
    z-index: 8;
    border-right: 1px solid var(--line);
    border-left: 0;
    box-shadow: 12px 0 30px rgba(22, 39, 34, 0.16);
    transform: translateX(-105%);
    transition: transform 180ms ease;
  }

  .toc-panel.is-open,
  .bookmark-panel.is-open {
    transform: translateX(0);
  }

  .bookmark-panel {
    right: auto;
  }

  .panel-close {
    display: grid;
  }

  .reader-scroll {
    height: 100%;
  }

  .reader-content {
    width: calc(100% - 34px);
    padding: 38px 0 80px;
    line-height: 1.85;
  }

  .reader-content.has-pdf-content {
    width: calc(100% - 24px);
    padding-top: 24px;
  }

  .pdf-document {
    gap: 38px;
  }

  .pdf-page-copy {
    width: calc(100% - 12px);
    margin-top: 16px;
    padding-left: 13px;
  }

  .shared-content.has-rich-content .pdf-document {
    gap: 38px;
  }

  .appearance-panel {
    top: 8px;
    right: 8px;
    width: min(310px, calc(100vw - 16px));
  }

  .speech-fab {
    right: calc(16px + env(safe-area-inset-right));
    bottom: calc(16px + env(safe-area-inset-bottom));
    width: 58px;
    height: 58px;
  }

  .shared-main {
    width: calc(100% - 34px);
    padding: 42px 0 150px;
  }

  .shared-meta {
    margin-bottom: 30px;
  }

  .shared-meta h1 {
    font-size: 25px;
  }

  .shared-content {
    font-size: 18px;
    line-height: 1.85;
  }

  .translation-languages {
    grid-template-columns: 1fr;
  }

  .translation-arrow {
    display: none;
  }

  .app-dialog {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
  }

  .app-dialog form {
    gap: 16px;
    padding: 18px;
  }

  .metadata-grid {
    grid-template-columns: 1fr;
  }

  .account-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .dialog-actions.spread {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .dialog-actions.spread > div {
    justify-content: flex-end;
  }

  .toast-region {
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    left: 12px;
    align-items: center;
  }
}

@supports (height: 100dvh) {
  body.immersive-mobile {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
  }

  body.immersive-mobile .share-view {
    position: fixed;
    inset: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

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