:root {
  color-scheme: light;
  --bg: #f4f6f2;
  --panel: #ffffff;
  --panel-soft: #edf5f4;
  --text: #20242a;
  --muted: #707780;
  --line: #dfe4df;
  --accent: #2f7276;
  --accent-soft: #dfeeee;
  --warm: #c46d4f;
  --accent-text: #ffffff;
  --shadow: 0 10px 26px rgba(37, 45, 48, 0.08);
  --reader-font-size: 20px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151515;
  --panel: #202020;
  --panel-soft: #242a2b;
  --text: #e7e0d4;
  --muted: #9d9487;
  --line: #33302d;
  --accent: #7ab7bd;
  --accent-soft: #213538;
  --warm: #d08363;
  --accent-text: #111111;
  --shadow: none;
}

a {
  color: inherit;
  text-decoration: none;
}

code {
  overflow-wrap: anywhere;
}

.page {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 16px 32px;
}

.page-home {
  padding-bottom: calc(92px + env(safe-area-inset-bottom));
}

.topbar,
.book-header {
  padding: calc(14px + env(safe-area-inset-top)) 2px 18px;
}

.home-hero {
  display: flex;
  align-items: flex-end;
  min-height: 150px;
  margin: -18px -16px 18px;
  padding: calc(28px + env(safe-area-inset-top)) 20px 24px;
  background:
    radial-gradient(circle at 80% 20%, rgba(196, 109, 79, 0.16), transparent 34%),
    linear-gradient(135deg, #edf5f4 0%, #f8faf6 58%, #f4f6f2 100%);
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar h1,
.book-header h1,
.empty-state h1,
.empty-state h2 {
  margin: 0;
  font-size: 30px;
  line-height: 1.25;
  letter-spacing: 0;
}

.topbar p,
.book-header p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.home-panel {
  display: none;
}

.home-panel.is-active {
  display: block;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 12px;
}

.section-title h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.3;
  letter-spacing: 0;
}

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

.book-list,
.chapter-list,
.recent-list {
  display: grid;
  gap: 12px;
}

.book-item,
.chapter-item,
.recent-item {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.book-item {
  grid-template-columns: 58px 1fr;
  align-items: center;
}

.book-cover,
.recent-cover {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 74px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 24px;
  font-weight: 850;
  line-height: 1;
  box-shadow: inset 0 -18px 0 rgba(0, 0, 0, 0.08);
}

.book-info,
.recent-info {
  display: grid;
  min-width: 0;
  gap: 6px;
}

.book-title,
.chapter-item span,
.recent-info strong {
  overflow: hidden;
  color: var(--text);
  font-size: 17px;
  font-weight: 650;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-meta,
.book-progress,
.chapter-item small,
.back-link,
.recent-info span,
.recent-info small {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}

.book-progress {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-track {
  display: block;
  width: 100%;
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7ebe6;
}

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

.back-link {
  display: inline-block;
  margin-bottom: 14px;
}

.primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  margin-top: 18px;
  padding: 0 18px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 15px;
  font-weight: 700;
}

.chapter-item {
  grid-template-columns: 1fr auto;
  align-items: center;
  min-height: 70px;
}

.chapter-item.is-current {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.recent-item {
  grid-template-columns: 50px 1fr;
  align-items: center;
}

.recent-cover {
  width: 50px;
  height: 62px;
  background: var(--warm);
  font-size: 22px;
}

.empty-state {
  padding: 48px 4px;
}

.empty-state.compact {
  padding: 34px 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.52);
}

.empty-state p {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.7;
}

.bottom-tabs {
  position: fixed;
  right: 12px;
  bottom: 10px;
  left: 12px;
  z-index: 8;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: min(calc(100% - 24px), 736px);
  margin: 0 auto;
  padding: 8px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  border: 1px solid rgba(210, 217, 211, 0.86);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 14px 34px rgba(28, 34, 36, 0.18);
  backdrop-filter: blur(18px);
}

.bottom-tabs button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 750;
}

.bottom-tabs button.is-active {
  background: var(--accent);
  color: var(--accent-text);
}

.tab-icon {
  display: inline-flex;
  width: 18px;
  height: 18px;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  line-height: 1;
}

.reader {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 18px 86px;
  background: var(--bg);
}

.reader-head {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: calc(48px + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  backdrop-filter: blur(14px);
}

.reader-content {
  padding: 18px 0 20px;
}

.reader-content h1 {
  margin: 0 0 28px;
  font-size: 24px;
  line-height: 1.35;
  letter-spacing: 0;
}

.reader-content p {
  margin: 0 0 1.08em;
  color: var(--text);
  font-size: var(--reader-font-size);
  line-height: 1.88;
  letter-spacing: 0;
  text-align: left;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.reader-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr 48px 48px 48px 1fr;
  gap: 1px;
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.reader-nav a,
.reader-nav span,
.reader-nav button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 42px;
  padding: 0 8px;
  border: 0;
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

.reader-nav span {
  color: var(--muted);
}

@supports not (color: color-mix(in srgb, white, black)) {
  .reader-head,
  .reader-nav {
    background: var(--bg);
  }
}
