:root {
  color-scheme: light;
  --ink: #1f1f1f;
  --muted: #6f7478;
  --line: rgba(0, 0, 0, 0.12);
  --surface: #ffffff;
  --canvas: #ffffff;
  --soft: #f5f7f9;
  --accent: #03a9f4;
  --accent-dark: #0288d1;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

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

body {
  overflow-y: scroll;
}

a {
  color: inherit;
}

button,
input {
  font: inherit;
}

.shell {
  min-height: 100vh;
  background: var(--canvas);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 10px max(16px, calc((100vw - 760px) / 2));
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
}

.brand-copy {
  display: grid;
  min-width: 0;
  gap: 1px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.1;
}

.brand-copy small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.nav {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
  gap: 10px;
  font-size: 14px;
}

.nav a,
.nav button,
.primary,
.auth-actions button,
.back-link {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
  text-decoration: none;
}

.nav a,
.back-link {
  display: inline-flex;
  align-items: center;
  color: var(--ink);
}

.nav button,
.auth-actions button {
  background: var(--soft);
  color: var(--ink);
}

.nav-muted {
  overflow: hidden;
  max-width: 190px;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

.primary:hover {
  background: var(--accent-dark);
}

.app-main {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 16px 16px 48px;
}

.detail-main {
  padding-top: 14px;
}

.page-heading {
  display: grid;
  gap: 16px;
  padding: 8px 0 12px;
}

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

.page-heading h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
}

.search-field {
  display: grid;
  grid-template-columns: 40px 1fr;
  align-items: center;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.search-icon {
  display: grid;
  height: 100%;
  place-items: center;
  color: var(--muted);
  font-size: 22px;
}

.search-field input {
  width: 100%;
  min-width: 0;
  height: 50px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.content-stack {
  display: grid;
  gap: 18px;
  padding-top: 8px;
}

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

.section-title h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
}

.count-pill {
  min-width: 28px;
  border-radius: 999px;
  padding: 4px 9px;
  background: #e1f5fe;
  color: #01579b;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.link-list,
.chapter-list {
  display: grid;
  gap: 8px;
  padding-top: 12px;
}

.link-tile,
.chapter-row,
.auth-panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.link-tile {
  display: grid;
  grid-template-columns: 54px 1fr 24px;
  align-items: center;
  min-height: 76px;
  gap: 12px;
  padding: 8px 10px 8px 8px;
  color: var(--ink);
  text-decoration: none;
}

.tile-cover {
  width: 48px;
  height: 56px;
  border-radius: 4px;
  background: #e0e0e0;
  object-fit: cover;
}

.tile-cover-empty {
  display: grid;
  place-items: center;
  color: var(--accent);
}

.tile-body {
  min-width: 0;
}

.tile-body h3,
.chapter-copy h3 {
  display: -webkit-box;
  overflow: hidden;
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.25;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.tile-subtitle {
  display: -webkit-box;
  overflow: hidden;
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.tile-meta {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 0;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 500;
}

.meta-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--accent);
}

.chevron {
  color: #7b7b7b;
  font-size: 30px;
  line-height: 1;
}

.auth-panel {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.auth-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.auth-panel h3 {
  margin: 0;
  font-size: 16px;
}

.auth-panel input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  outline-color: var(--accent);
}

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

.back-link {
  width: fit-content;
  margin-bottom: 12px;
  background: var(--soft);
  color: var(--ink);
}

.book-detail {
  display: grid;
  grid-template-columns: 150px 1fr;
  align-items: start;
  gap: 18px;
  padding-bottom: 24px;
}

.book-detail img,
.book-cover-placeholder {
  width: 150px;
  aspect-ratio: 2 / 3;
  border-radius: 8px;
  background: #e0e0e0;
  object-fit: cover;
}

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

.book-detail h1 {
  margin-bottom: 12px;
  font-size: 24px;
  line-height: 1.15;
}

.book-description {
  margin: 0;
  color: #3f3f3f;
  font-size: 15px;
  line-height: 1.55;
}

.chapter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 66px;
  padding: 12px 14px;
  color: var(--ink);
  text-decoration: none;
}

.chapter-copy {
  min-width: 0;
}

.chapter-trailing {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.chapter-index {
  color: var(--muted);
  font-size: 13px;
}

.reader-page {
  min-height: 100vh;
  background: #050505;
}

.reader-appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  min-height: 58px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.96);
}

.reader-back,
.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 24px;
  text-decoration: none;
}

.icon-button {
  opacity: 0.55;
  cursor: default;
}

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

.reader-title h1 {
  overflow: hidden;
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-title span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-image {
  display: block;
  width: min(100vw, 900px);
  height: auto;
  margin: 0 auto;
}

.status,
.empty-state {
  padding: 42px 0;
  color: var(--muted);
  text-align: center;
}

.error {
  border-radius: 8px;
  padding: 12px 14px;
  background: #fef3f2;
  color: var(--danger);
}

@media (max-width: 620px) {
  .topbar {
    padding-inline: 16px;
  }

  .nav a,
  .nav-muted {
    display: none;
  }

  .book-detail {
    grid-template-columns: 112px 1fr;
    gap: 14px;
  }

  .book-detail img,
  .book-cover-placeholder {
    width: 112px;
  }

  .auth-actions {
    grid-template-columns: 1fr;
  }
}
