:root {
  color-scheme: dark;
  font: 15px/1.5 "Segoe UI", system-ui, sans-serif;
  color: #ecebe4;
  background: #191b1a;
  --surface: #202321;
  --line: #383c36;
  --text: #ecebe4;
  --muted: #a8afa6;
  --accent: #c8d9bd;
  --serif: Georgia, "Times New Roman", serif;
  --gutter: clamp(18px, 4vw, 40px);
  overflow-anchor: none;
  scrollbar-gutter: stable;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 280px; }
h1, h2, p { margin: 0; }
a { color: inherit; }
button, input, select { font: inherit; }
button { color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.site-header {
  position: sticky;
  z-index: 2;
  top: 0;
  border-bottom: 1px solid #333732;
  background: #1c1f1d;
}

.header-inner {
  width: min(100%, 1140px);
  min-height: 62px;
  margin-inline: auto;
  padding-inline: var(--gutter);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: .01em;
}

.brand-mark {
  width: 29px;
  height: 29px;
  display: grid;
  place-content: center;
  grid-auto-flow: column;
  border-radius: 7px;
  background: #c0d2b5;
}

.brand-mark::before, .brand-mark::after {
  content: "";
  display: block;
  width: 8px;
  height: 11px;
  border: 1.4px solid #2e3c30;
}

.brand-mark::before { border-radius: 2px 1px 1px 2px; transform: skewY(7deg); }
.brand-mark::after { border-radius: 1px 2px 2px 1px; transform: skewY(-7deg); }

.library {
  width: min(100%, 1140px);
  margin-inline: auto;
  padding: clamp(30px, 4.5vw, 44px) var(--gutter) 65px;
}

.library h1 {
  margin-bottom: clamp(20px, 3vw, 28px);
  font: 400 clamp(28px, 3.8vw, 34px)/1.12 var(--serif);
  letter-spacing: -.035em;
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.book-card {
  position: relative;
  display: grid;
  grid-template-columns: clamp(116px, 14vw, 172px) minmax(0, 1fr);
  min-height: 252px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.book-cover {
  position: relative;
  display: grid;
  overflow: hidden;
  place-items: center;
  border-radius: 11px 0 0 11px;
  background: #364239;
  color: var(--accent);
  font: 48px var(--serif);
}

.book-cover img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-summary {
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: flex-start;
  padding: 20px 22px 17px;
}

.book-summary h2 {
  overflow-wrap: anywhere;
  font: 400 27px/1.15 var(--serif);
  letter-spacing: -.025em;
}

.book-author { margin-top: 4px; color: #c1c5bc; }
.book-chapters { margin-top: 10px; color: var(--muted); font-size: 13px; }
.book-progress {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  margin-top: auto;
  padding-block: 15px 11px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.book-progress progress {
  appearance: none;
  flex: 1;
  height: 4px;
  min-width: 0;
  overflow: hidden;
  border: 0;
  border-radius: 4px;
  background: #3d453d;
  color: #b8cea9;
}

.book-progress progress::-webkit-progress-bar { background: #3d453d; }
.book-progress progress::-webkit-progress-value { border-radius: 4px; background: #b8cea9; }
.book-progress progress::-moz-progress-bar { border-radius: 4px; background: #b8cea9; }

.read-link {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border: 1px solid #4d5b49;
  border-radius: 6px;
  background: #303b30;
  color: #dfebd8;
  text-decoration: none;
  font-weight: 600;
  font-size: 13px;
}

.read-link:hover { background: #3c4c3b; }
.read-link::after { position: absolute; inset: 0; border-radius: 12px; content: ""; }
.source-link, .source-path {
  max-width: 100%;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
  text-decoration: none;
}

.source-link, .source-path { position: relative; z-index: 1; }
.source-link:hover { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.empty { color: var(--muted); }

.tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px; }
.tool-button, .panel-close {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 0;
  border-radius: 6px;
  padding: 5px 10px;
  background: transparent;
  color: #d1d8ce;
  cursor: pointer;
  font-size: 13px;
}

.tool-symbol { color: var(--accent); font-size: 16px; font-weight: 600; line-height: 1; }
.tool-button:hover, .panel-close:hover { background: #303831; color: white; }
.tools a { text-decoration: none; }
.tools a[aria-current] { color: var(--accent); background: #303831; }

.account-page {
  width: min(100%, 820px);
  margin-inline: auto;
  padding: 32px var(--gutter) 65px;
}

.account-page h1 { margin-bottom: 18px; font-size: 20px; font-weight: 600; }
.auth-page { width: min(100%, 450px); }
.auth-form {
  padding: clamp(16px, 4vw, 24px);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.auth-form label { display: grid; gap: 5px; margin-bottom: 12px; font-size: 14px; }
.auth-form input {
  min-width: 0;
  min-height: 40px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #191b1a;
  color: var(--text);
}

.auth-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 16px; }
.auth-submit {
  min-height: 38px;
  padding: 5px 12px;
  border: 1px solid #4d5b49;
  border-radius: 6px;
  background: #303b30;
  color: #dfebd8;
  cursor: pointer;
}

.auth-submit:hover { background: #3c4c3b; }
.auth-hint, .auth-message, .account-status, .opening-details, .user-role { font-size: 13px; color: var(--muted); }
.auth-message:not(:empty) { margin-top: 10px; }
.account-status:empty { display: none; }
.account-status { display: block; padding: 0 var(--gutter) 8px; text-align: center; }
.user-entry { border-top: 1px solid var(--line); }
.user-entry:last-child { border-bottom: 1px solid var(--line); }
.user-entry summary { padding: 12px 0; cursor: pointer; overflow-wrap: anywhere; }
.user-role, .user-entry summary .opening-details { margin-inline-start: 10px; }
.user-books { margin: 0 0 14px; padding-inline-start: 22px; overflow-wrap: anywhere; }
.user-books ul { margin-block: 5px 12px; padding-inline-start: 22px; }
.user-books .opening-details { display: block; }

.reading {
  --measure: 700px;
  --reading-font: var(--serif);
  --reading-size: 20px;
  --reading-gutter: clamp(23px, 5.5vw, 50px);
  --line-height: 1.72;
  --paragraph-gap: .9em;
}

.reading[data-font="sans"] { --reading-font: "Segoe UI", system-ui, sans-serif; }
.reading[data-size="18"] { --reading-size: 18px; }
.reading[data-size="22"] { --reading-size: 22px; }
.reading[data-size="24"] { --reading-size: 24px; }
.reading[data-size="26"] { --reading-size: 26px; }

.reading-page {
  width: min(calc(100% - 2 * var(--reading-gutter)), var(--measure));
  margin-inline: auto;
  padding-block: clamp(32px, 4.5vw, 44px) 60px;
}

.chapter-heading { margin-bottom: clamp(22px, 3vw, 32px); }
.chapter-heading h1 {
  font: 400 clamp(28px, 4.2vw, 34px)/1.12 var(--serif);
  overflow-wrap: anywhere;
  letter-spacing: -.035em;
}

.chapter-book { margin-bottom: 8px; color: var(--accent); font-size: 14px; }
.chapter-author { margin-top: 9px; color: var(--muted); }
.chapter-text {
  color: #dedfd6;
  font: var(--reading-size)/var(--line-height) var(--reading-font);
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.chapter-text p + p { margin-top: var(--paragraph-gap); }

.chapter-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 13px;
  margin-top: 31px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.chapter-nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chapter-nav a, .mark-read {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 6px 11px;
  border-radius: 6px;
  text-decoration: none;
}

.chapter-nav a { color: var(--accent); }
.chapter-nav a:hover { background: var(--surface); }
.mark-read {
  margin-left: auto;
  border: 1px solid var(--line);
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 13px;
}

.mark-read:hover:enabled { background: var(--surface); color: var(--text); }
.mark-read:disabled { border-color: transparent; color: var(--accent); cursor: default; }

.panel {
  position: fixed;
  inset: 0;
  width: min(calc(100% - 36px), 370px);
  max-height: calc(100dvh - 90px);
  margin: 74px max(18px, calc((100vw - 1060px) / 2)) auto auto;
  padding: 0;
  border: 1px solid #434a41;
  border-radius: 11px;
  background: #232823;
  color: var(--text);
  box-shadow: 0 20px 70px #0006;
}

.panel::backdrop { background: #0a0d0bb0; }
.panel-inner { padding: 16px 16px 17px; }
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
  padding-left: 4px;
}

.panel-header h2 { font: 400 23px/1.2 var(--serif); }
.panel-close { min-width: 38px; padding: 0; font-size: 24px; line-height: 1; }
.chapter-list { list-style: none; margin: 0; padding: 0; }
.chapter-list a {
  display: flex;
  min-height: 40px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 5px;
  text-decoration: none;
}

.chapter-list a:hover, .chapter-list a[aria-current="page"] { background: #354035; }
.chapter-list a[aria-current="page"], .check { color: var(--accent); }
.setting-list { display: grid; gap: 8px; padding-inline: 4px; }
.setting {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(128px, 1fr);
  align-items: center;
  gap: 10px;
}

.setting select {
  min-height: 40px;
  min-width: 0;
  border: 1px solid #495349;
  border-radius: 5px;
  padding: 5px 7px;
  color: var(--text);
  background: #2b322b;
}

.range-setting {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 10px;
  padding-top: 6px;
}

.range-setting output { color: var(--accent); font-size: 13px; font-variant-numeric: tabular-nums; }
.range-setting input {
  grid-column: 1 / -1;
  width: 100%;
  min-height: 32px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

@media (max-width: 780px) {
  .books-grid { grid-template-columns: minmax(0, 1fr); gap: 15px; }
  .book-card { grid-template-columns: clamp(105px, 26vw, 155px) minmax(0, 1fr); min-height: 215px; }
  .book-summary { padding: 16px 18px 14px; }
}

@media (max-width: 420px) {
  :root { scrollbar-gutter: auto; }
  .header-inner { min-height: 57px; gap: 5px; padding-inline: 12px; }
  .brand { gap: 6px; font-size: 14px; }
  .brand-mark { width: 25px; height: 25px; }
  .tools { gap: 2px; }
  .tool-button { min-height: 44px; gap: 4px; padding-inline: 6px; }
  .tool-symbol { font-size: 14px; }
  .book-summary h2 { font-size: 23px; }
  .book-summary { padding-inline: 14px; }
  .panel { margin: 65px auto auto; }
  .chapter-footer { gap: 3px; }
  .chapter-nav { gap: 2px; }
  .chapter-nav a, .mark-read { min-height: 44px; padding-inline: 7px; }
}
