:root {
  color-scheme: light dark;
  --bg: #f5f2ea;
  --panel: #fbf8f1;
  --panel-strong: #fffdf7;
  --text: #2b2b2b;
  --muted: #81796d;
  --line: rgba(43, 43, 43, 0.12);
  --accent: #2c6e6b;
  --accent-2: #d9793a;
  --shadow: 0 24px 70px rgba(70, 52, 32, 0.14);
  --reader-bg: #f5f2ea;
  --reader-text: #2b2b2b;
  --cover-end: #214f64;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
  background: radial-gradient(circle at 18% 0%, rgba(217, 121, 58, 0.1), transparent 32%),
    linear-gradient(135deg, var(--bg) 0%, #fffaf0 46%, color-mix(in srgb, var(--bg), var(--accent) 8%) 100%);
  color: var(--text);
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px;
}

.library-view,
.reader-view {
  min-height: calc(100vh - 56px);
  border: 1px solid var(--line);
  border-radius: 28px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.brand-heading {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  column-gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border: 1px solid color-mix(in srgb, var(--accent-2), transparent 58%);
  border-radius: 18px;
  background: color-mix(in srgb, var(--panel-strong), var(--accent-2) 5%);
  box-shadow: 0 14px 34px rgba(77, 48, 22, 0.12);
}

.brand-mark img {
  display: block;
  width: 44px;
  height: 44px;
  border-radius: 12px;
}

.top-bar,
.reader-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 30px;
}

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

h1 {
  margin-bottom: 0;
  font-size: 42px;
  font-weight: 850;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel-strong);
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(70, 52, 32, 0.1);
}

.import-button input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.import-button span {
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
}

.import-button svg {
  width: 25px;
  height: 25px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin: 0 30px 24px;
  padding: 10px 14px 10px 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel-strong);
}

.search-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  color: var(--accent);
}

.search-icon svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.search-row input {
  min-width: 0;
  height: 34px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.shelf-section {
  padding: 0 30px 30px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  color: var(--muted);
}

.section-heading h2 {
  margin-bottom: 3px;
}

.section-heading span {
  font-size: 13px;
}

.view-toggle {
  display: flex;
  gap: 8px;
}

.view-toggle button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel-strong);
  color: var(--muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.view-toggle .active {
  border-color: transparent;
  background: var(--accent);
  color: white;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 360px;
  text-align: center;
  color: var(--muted);
}

.empty-state h3 {
  margin-bottom: 8px;
  color: var(--text);
  font-size: 24px;
}

.empty-illustration {
  width: 158px;
  height: 158px;
  margin-bottom: 22px;
}

.empty-illustration img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

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

.book-grid[data-view="list"] {
  grid-template-columns: 1fr;
}

.book-card {
  position: relative;
  min-height: 104px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel-strong);
  overflow: hidden;
}

.book-open {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  width: 100%;
  min-height: 102px;
  border: 0;
  border-radius: 18px;
  padding: 14px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.book-grid[data-view="grid"] .book-open {
  grid-template-columns: 1fr;
  grid-template-rows: auto minmax(0, 1fr);
  justify-items: center;
  min-height: 184px;
  height: 100%;
  text-align: center;
}

.book-grid[data-view="grid"] .cover {
  width: 82px;
  height: 112px;
}

.book-grid[data-view="grid"] .book-info {
  display: grid;
  gap: 6px;
  align-content: start;
  width: 100%;
  min-width: 0;
}

.book-card-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
}

.manage-dot {
  display: grid;
  place-items: center;
  width: 24px;
  height: 18px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
}

.book-grid[data-view="grid"] .book-card strong {
  padding-right: 0;
}

.book-open:hover {
  background: color-mix(in srgb, var(--accent), transparent 92%);
}

.cover {
  display: grid;
  place-items: end start;
  width: 58px;
  height: 78px;
  padding: 8px;
  border-radius: 12px;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--cover-end));
  overflow: hidden;
}

.cover.pdf {
  background: linear-gradient(135deg, var(--accent-2), #743021);
}

.cover.epub {
  background: linear-gradient(135deg, #6868ac, #2f315d);
}

.image-cover {
  padding: 0;
  background: #d8dee8;
}

.image-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-manage {
  position: absolute;
  right: 10px;
  bottom: 12px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 26px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  z-index: 2;
}

.book-manage:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--accent), transparent 90%);
}

.book-card strong {
  display: -webkit-box;
  padding-right: 28px;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-height: 1.22;
}

.book-card p {
  margin: 5px 0 8px;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-progress {
  height: 5px;
  border-radius: 999px;
  background: rgba(15, 139, 141, 0.14);
  overflow: hidden;
}

.mini-progress span {
  display: block;
  height: 100%;
  width: var(--value);
  background: var(--accent);
}

.reader-view {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: block;
  background: var(--reader-bg);
  border: 0;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
  touch-action: manipulation;
}

.reader-title {
  min-width: 0;
  text-align: center;
}

.reader-title strong,
.reader-title span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.reader-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  padding: 18px 26px;
  background: color-mix(in srgb, var(--reader-bg) 84%, transparent);
  backdrop-filter: blur(18px);
  box-shadow: 0 12px 38px rgba(18, 24, 20, 0.08);
  opacity: 0;
  transform: translateY(-16px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.reader-view.controls-visible .reader-bar,
.reader-view.controls-visible .reader-progress,
.reader-view.controls-visible .reader-tools {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.page-surface {
  position: relative;
  width: 100%;
  height: 100%;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: color-mix(in srgb, var(--reader-bg) 88%, white);
  box-shadow: none;
  overflow: hidden;
  perspective: 1400px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.page-content {
  position: relative;
  z-index: 1;
  width: min(760px, 100%);
  height: 100%;
  margin: 0 auto;
  padding: 34px 34px 58px;
  background: color-mix(in srgb, var(--reader-bg) 88%, white);
  transition: transform 220ms ease, opacity 220ms ease;
}

.chapter-title {
  color: color-mix(in srgb, var(--reader-text), transparent 48%);
  font-size: 13px;
}

.page-text {
  color: var(--reader-text);
  font-size: var(--font-size, 19px);
  line-height: var(--line-height, 1.75);
  white-space: pre-wrap;
}

.reader-tools {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 5;
  display: grid;
  gap: 12px;
  padding: 12px 34px;
  background: color-mix(in srgb, var(--reader-bg) 92%, transparent);
  backdrop-filter: blur(20px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.reader-tools {
  bottom: 0;
  transform: translateY(16px);
  border-top: 1px solid rgba(60, 66, 55, 0.12);
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

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

.reader-progress {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.reader-progress input {
  flex: 1;
  min-width: 0;
}

.reader-adjustments {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  width: min(720px, 100%);
  justify-self: center;
}

.reader-stepper {
  display: grid;
  grid-template-columns: auto 34px minmax(34px, auto) 34px;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 14px;
}

.reader-stepper strong {
  min-width: 34px;
  color: var(--reader-text);
  text-align: center;
  font-size: 14px;
  font-weight: 650;
}

.step-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: color-mix(in srgb, var(--panel-strong), var(--reader-bg) 12%);
  color: var(--reader-text);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.reader-action-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  width: min(620px, 100%);
  justify-self: center;
}

.reader-tool-button {
  display: grid;
  justify-items: center;
  gap: 6px;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--reader-text);
  cursor: pointer;
  font-size: 12px;
}

.tool-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: color-mix(in srgb, var(--panel-strong), var(--reader-bg) 12%);
  color: var(--accent);
  box-shadow: 0 8px 20px rgba(32, 36, 25, 0.07);
}

.tool-icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.reader-tool-button.active .tool-icon {
  border-color: transparent;
  background: var(--accent);
  color: white;
}

.reader-tool-button.active > span:last-child {
  color: var(--accent);
  font-weight: 700;
}

.page-slide {
  position: absolute;
  inset: 0;
  z-index: 3;
  overflow: hidden;
  background: color-mix(in srgb, var(--reader-bg) 88%, white);
  transition: transform 260ms cubic-bezier(0.2, 0.72, 0.16, 1), opacity 260ms ease;
}

.page-slide.turn-next.is-turning {
  transform: translateX(-22%);
  opacity: 0;
}

.page-slide.turn-prev.is-turning {
  transform: translateX(22%);
  opacity: 0;
}

.chapter-drawer {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 8;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(390px, 88vw);
  height: 100%;
  border-left: 1px solid var(--line);
  background: var(--panel-strong);
  box-shadow: -24px 0 70px rgba(18, 24, 20, 0.2);
}

.chapter-drawer header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.chapter-drawer h2 {
  margin: 0;
}

.chapter-list {
  overflow-y: auto;
  padding: 10px;
}

.chapter-list button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 0;
  border-radius: 10px;
  padding: 13px 12px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.chapter-list button:hover,
.chapter-list .active {
  background: rgba(15, 139, 141, 0.1);
}

.chapter-list span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-list small {
  color: var(--muted);
}

.empty-list {
  margin: 0;
  padding: 22px 12px;
  color: var(--muted);
  text-align: center;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(16, 20, 24, 0.42);
}

.book-editor {
  width: min(520px, 100%);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  background: var(--panel-strong);
  box-shadow: 0 32px 80px rgba(16, 20, 24, 0.24);
}

.book-editor header,
.book-editor footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.book-editor footer {
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  margin-top: 18px;
}

.book-editor h2 {
  margin: 0;
}

.book-editor label {
  display: grid;
  gap: 8px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 14px;
}

.book-editor input[type="text"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--panel);
  color: var(--text);
  outline: 0;
}

.compact {
  width: 38px;
  height: 38px;
}

.cover-editor {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr);
  align-items: center;
  gap: 16px;
  margin-top: 18px;
}

.cover-preview {
  display: grid;
  place-items: end start;
  width: 104px;
  height: 142px;
  border-radius: 14px;
  padding: 12px;
  overflow: hidden;
  background: linear-gradient(135deg, var(--accent), var(--cover-end));
  color: white;
  font-size: 15px;
  font-weight: 800;
}

.cover-preview.has-image {
  padding: 0;
  background: #d8dee8;
}

.cover-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cover-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.secondary-button,
.danger-button,
.book-editor footer button[type="submit"] {
  display: inline-grid;
  place-items: center;
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 16px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.secondary-button input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.danger-button {
  border-color: color-mix(in srgb, var(--accent-2), transparent 62%);
  color: #b14121;
}

.book-editor footer button[type="submit"] {
  border-color: transparent;
  background: var(--accent);
  color: white;
}

[data-theme="day"] {
  --bg: #eef1f4;
  --panel: #f8fafb;
  --panel-strong: #ffffff;
  --text: #151719;
  --muted: #747a84;
  --line: rgba(20, 25, 32, 0.12);
  --accent: #0f8b8d;
  --accent-2: #d9793a;
  --cover-end: #234b68;
  --reader-bg: #f6f7f9;
  --reader-text: #151719;
  --shadow: 0 24px 70px rgba(26, 31, 39, 0.16);
}

[data-theme="night"] {
  --bg: #111315;
  --panel-strong: #1c2024;
  --panel: #171a1d;
  --text: #f2f3f4;
  --muted: #9ba1a8;
  --accent: #2c6e6b;
  --accent-2: #d9793a;
  --cover-end: #102f3c;
  --reader-bg: #111315;
  --reader-text: #dad6c8;
  --line: rgba(255, 255, 255, 0.14);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

[data-theme="paper"] {
  --bg: #f5f2ea;
  --panel: #fbf8f1;
  --panel-strong: #fffdf7;
  --text: #2b2b2b;
  --muted: #81796d;
  --line: rgba(43, 43, 43, 0.12);
  --accent: #2c6e6b;
  --accent-2: #d9793a;
  --cover-end: #174a50;
  --reader-bg: #f5f2ea;
  --reader-text: #2b2b2b;
  --shadow: 0 24px 70px rgba(70, 52, 32, 0.14);
}

@media (max-width: 720px) {
  .app-shell {
    padding: 0;
  }

  .library-view,
  .reader-view {
    min-height: 100vh;
    border: 0;
    border-radius: 0;
  }

  .top-bar,
  .reader-bar {
    padding: 22px;
  }

  h1 {
    font-size: 34px;
  }

  .search-row,
  .shelf-section {
    margin-left: 18px;
    margin-right: 18px;
    padding-left: 0;
    padding-right: 0;
  }

  .book-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 9px;
  }

  .book-grid[data-view="list"] {
    grid-template-columns: 1fr;
  }

  .book-grid[data-view="grid"] .book-open {
    min-height: 160px;
    padding: 10px 8px;
  }

  .book-grid[data-view="grid"] .cover {
    width: 58px;
    height: 78px;
    border-radius: 10px;
    font-size: 11px;
  }

  .book-grid[data-view="grid"] .book-card strong {
    font-size: 14px;
    min-height: 2.44em;
  }

  .book-grid[data-view="grid"] .book-card p {
    font-size: 11px;
    margin: 0 0 6px;
  }

  .book-manage {
    right: 7px;
    bottom: 12px;
    width: 30px;
    height: 24px;
  }

  .cover-editor,
  .book-editor footer {
    grid-template-columns: 1fr;
  }

  .book-editor footer span {
    display: none;
  }

  .page-content {
    padding: 28px 24px 72px;
  }

  .reader-view.controls-visible .page-content {
    padding-bottom: 170px;
  }

  .reader-tools {
    padding-left: 18px;
    padding-right: 18px;
  }

  .reader-progress {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .reader-tools {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    padding-top: 9px;
    font-size: 14px;
  }

  .reader-adjustments {
    gap: 8px;
  }

  .reader-stepper {
    grid-template-columns: auto 30px minmax(28px, auto) 30px;
    gap: 6px;
    font-size: 13px;
  }

  .step-button {
    width: 30px;
    height: 30px;
  }

  .reader-action-row {
    gap: 6px;
  }

  .tool-icon {
    width: 38px;
    height: 38px;
  }

  .reader-tool-button {
    font-size: 11px;
  }

  .reader-progress {
    gap: 10px;
  }

  .reader-progress input[type="range"] {
    height: 20px;
  }
}
