:root {
  --paper: #f8f5f0;
  --paper-deep: #eee8e0;
  --ink: #272321;
  --muted: #756e69;
  --line: #ddd4cb;
  --rose: #d8a99f;
  --rose-light: #f0d5cf;
  --rose-dark: #9a665d;
  --sidebar: #fbf9f6;
  --white: #fff;
  --shadow: 0 22px 60px rgba(70, 50, 42, .14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; overflow: hidden; }
button, input { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.login-screen {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at 18% 18%, rgba(216, 169, 159, .25), transparent 25%),
    radial-gradient(circle at 82% 82%, rgba(235, 213, 181, .42), transparent 27%),
    var(--paper);
  position: relative;
  overflow: hidden;
}

.login-art .letter {
  position: absolute;
  font: 400 clamp(110px, 18vw, 260px)/1 Georgia, serif;
  color: rgba(154, 102, 93, .07);
  user-select: none;
}
.letter-a { left: 5%; top: 7%; transform: rotate(-9deg); }
.letter-l { right: 7%; bottom: 2%; transform: rotate(12deg); }
.letter-z { right: 12%; top: 4%; font-size: clamp(80px, 12vw, 180px) !important; }

.login-card {
  position: relative;
  width: min(100%, 458px);
  padding: clamp(28px, 5vw, 48px);
  border: 1px solid rgba(154, 102, 93, .18);
  border-radius: 24px;
  background: rgba(255, 255, 255, .86);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.brand, .mini-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .18em;
  text-decoration: none;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--rose);
  color: white;
  font: 700 17px/1 Georgia, serif;
  letter-spacing: 0;
}

.login-heading { margin: 42px 0 30px; }
.eyebrow {
  display: block;
  margin-bottom: 10px;
  color: var(--rose-dark);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.login-heading h1 {
  margin: 0;
  font: 500 clamp(32px, 8vw, 43px)/1.08 Georgia, "Times New Roman", serif;
  letter-spacing: -.025em;
}
.login-heading p { margin: 16px 0 0; color: var(--muted); }

.field { display: grid; gap: 8px; margin-top: 18px; }
.field > span:first-child { font-size: 13px; font-weight: 720; }
.field input {
  width: 100%;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  padding: 0 15px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.field input:focus {
  border-color: var(--rose-dark);
  box-shadow: 0 0 0 4px rgba(216, 169, 159, .22);
}
.password-field { position: relative; display: block; }
.password-field input { padding-right: 50px; }
.reveal-button {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 38px;
  height: 38px;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.reveal-button svg { width: 21px; fill: none; stroke: var(--muted); stroke-width: 1.7; }
.login-error { min-height: 21px; margin: 10px 0 2px; color: #a13f3f; font-size: 13px; }
.login-card.shake { animation: shake .36s ease; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

.primary-button {
  width: 100%;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  border: 0;
  border-radius: 11px;
  background: var(--ink);
  color: white;
  font-weight: 750;
  cursor: pointer;
  transition: background .2s, transform .15s;
}
.primary-button:hover { background: #493d38; }
.primary-button:active { transform: translateY(1px); }
.copyright { margin: 24px 0 0; color: #9a928d; text-align: center; font-size: 11px; }

.app { height: 100svh; display: grid; grid-template-columns: 320px minmax(0, 1fr); background: var(--paper); }
.sidebar {
  min-width: 0;
  height: 100svh;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  z-index: 30;
}
.sidebar-head { height: 70px; display: flex; align-items: center; justify-content: space-between; padding: 0 22px; border-bottom: 1px solid var(--line); }
.sidebar-close { display: none !important; }
.sidebar-title { padding: 24px 22px 18px; }
.sidebar-title span { display: block; margin-bottom: 5px; color: var(--rose-dark); font-size: 11px; font-weight: 760; letter-spacing: .1em; text-transform: uppercase; }
.sidebar-title strong { font: 500 21px/1.18 Georgia, serif; }

.search { position: relative; margin: 0 16px 12px; }
.search > svg { position: absolute; left: 13px; top: 50%; width: 18px; transform: translateY(-50%); fill: none; stroke: var(--muted); stroke-width: 1.8; pointer-events: none; }
.search input {
  width: 100%;
  height: 44px;
  padding: 0 54px 0 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  outline: none;
}
.search input:focus { border-color: var(--rose-dark); box-shadow: 0 0 0 3px rgba(216, 169, 159, .18); }
.search kbd { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); padding: 3px 6px; border: 1px solid var(--line); border-radius: 5px; color: #8e8580; background: var(--paper); font-size: 10px; }
.search-status { padding: 0 20px; color: var(--muted); font-size: 12px; }
.search-results, .toc { min-height: 0; overflow: auto; padding: 0 10px 18px; scrollbar-width: thin; scrollbar-color: #cabeb5 transparent; }
.search-results { flex: 1; }
.toc { flex: 1; }

.toc-section { margin: 5px 0; }
.toc-heading {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 12px 8px;
  border: 0;
  background: none;
  color: #776e69;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .09em;
  text-align: left;
  text-transform: uppercase;
  cursor: pointer;
}
.toc-heading svg { width: 14px; fill: none; stroke: currentColor; stroke-width: 2; transition: transform .2s; }
.toc-section.collapsed .toc-heading svg { transform: rotate(-90deg); }
.toc-section.collapsed .toc-items { display: none; }
.toc-link {
  width: 100%;
  min-height: 38px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #4f4946;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.toc-link:hover { background: #f1ece7; }
.toc-link.active { background: var(--rose-light); color: #663f38; font-weight: 720; }
.toc-link span:last-child { color: #9b918b; font-size: 11px; }
.toc-link.active span:last-child { color: #805149; }

.result {
  width: 100%;
  padding: 13px 11px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.result:hover { background: #f2ece7; }
.result-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 6px; font-size: 12px; font-weight: 760; }
.result-head span:last-child { color: var(--rose-dark); white-space: nowrap; }
.result p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.result mark { padding: 0 2px; border-radius: 2px; background: #f6dda0; color: inherit; }
.empty-results { padding: 32px 14px; color: var(--muted); font-size: 13px; line-height: 1.5; text-align: center; }

.sidebar-footer { min-height: 58px; display: flex; align-items: center; justify-content: space-between; padding: 0 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.quiet-button { display: inline-flex; align-items: center; gap: 7px; border: 0; background: transparent; color: var(--muted); font-size: 12px; cursor: pointer; }
.quiet-button:hover { color: var(--ink); }
.quiet-button svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; }

.reader { min-width: 0; height: 100svh; display: grid; grid-template-rows: 70px minmax(0, 1fr) 66px; }
.reader-bar { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0 22px; border-bottom: 1px solid var(--line); background: rgba(248, 245, 240, .92); backdrop-filter: blur(12px); z-index: 5; }
.reader-context { min-width: 0; display: flex; align-items: center; gap: 12px; }
.reader-context > div { min-width: 0; }
.reader-context span { display: block; margin-bottom: 3px; color: var(--rose-dark); font-size: 10px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.reader-context strong { display: block; overflow: hidden; font: 500 16px/1.2 Georgia, serif; text-overflow: ellipsis; white-space: nowrap; }
.icon-button, .tool-button {
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.75);
  cursor: pointer;
}
.icon-button { width: 38px; height: 38px; }
.icon-button svg, .tool-button svg { width: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.menu-button { display: none; }
.reader-tools { display: flex; align-items: center; gap: 6px; }
.tool-button { min-width: 34px; height: 34px; padding: 0 9px; }
.tool-button:hover, .icon-button:hover { background: white; border-color: #c9bbb1; }
.tool-button-wide { font-size: 11px; }
.zoom-value { min-width: 45px; color: var(--muted); font-size: 11px; text-align: center; }
.tool-divider { width: 1px; height: 22px; margin: 0 4px; background: var(--line); }

.reader-stage { min-width: 0; min-height: 0; overflow: auto; display: flex; align-items: flex-start; justify-content: flex-start; padding: clamp(18px, 3vw, 38px); background: var(--paper-deep); scrollbar-color: #b9aaa0 transparent; }
.page-shell {
  --zoom: 1;
  position: relative;
  flex: 0 0 auto;
  width: min(100%, 960px);
  margin-inline: auto;
  min-height: 300px;
  background: white;
  box-shadow: 0 12px 38px rgba(62, 47, 40, .16);
}
.page-shell img { display: block; width: 100%; height: auto; opacity: 1; transition: opacity .15s; user-select: none; }
.page-shell.loading img { opacity: 0; }
.page-loading { position: absolute; inset: 0; display: grid; place-items: center; background: #fff; z-index: 2; }
.page-loading span { width: 30px; height: 30px; border: 3px solid var(--rose-light); border-top-color: var(--rose-dark); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.page-controls { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 clamp(14px, 3vw, 26px); border-top: 1px solid var(--line); background: var(--sidebar); }
.page-arrow { display: inline-flex; align-items: center; gap: 10px; border: 0; background: transparent; font-size: 13px; font-weight: 680; cursor: pointer; }
.page-arrow:last-child { justify-self: end; }
.page-arrow:disabled { opacity: .35; cursor: default; }
.page-arrow span[aria-hidden] { font-size: 18px; }
.page-count { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.page-count input { width: 54px; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: white; text-align: center; outline: none; appearance: textfield; }
.page-count input::-webkit-inner-spin-button { display: none; }
.page-count input:focus { border-color: var(--rose-dark); box-shadow: 0 0 0 3px rgba(216, 169, 159, .18); }

.scrim { position: fixed; inset: 0; background: rgba(32, 27, 24, .38); z-index: 20; }

@media (max-width: 920px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(88vw, 340px); transform: translateX(-102%); box-shadow: 12px 0 40px rgba(30, 20, 15, .18); transition: transform .22s ease; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close, .menu-button { display: inline-grid !important; }
  .reader-bar { padding: 0 14px; }
  .reader-context strong { max-width: 46vw; }
}

@media (max-width: 560px) {
  .login-screen { padding: 16px; }
  .login-card { padding: 27px 22px; border-radius: 18px; }
  .login-heading { margin: 34px 0 26px; }
  .reader { grid-template-rows: 62px minmax(0, 1fr) 58px; }
  .reader-tools .tool-button-wide, .reader-tools .tool-divider, .zoom-value { display: none; }
  .reader-stage { padding: 14px 10px 22px; }
  .page-arrow span:not([aria-hidden]) { display: none; }
  .page-arrow { width: 38px; height: 38px; justify-content: center; }
  .page-arrow:last-child { justify-content: center; }
  .reader-context span { display: none; }
  .reader-context strong { max-width: 48vw; }
}

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