:root {
  --ink: #292823;
  --muted: #777268;
  --paper: #f7f3eb;
  --paper-deep: #eee7dc;
  --card: #fffdf8;
  --terracotta: #a8583f;
  --terracotta-dark: #85432f;
  --sage: #6f806d;
  --line: rgba(41, 40, 35, 0.13);
  --shadow: 0 18px 45px rgba(63, 48, 38, 0.09);
}

* { box-sizing: border-box; }
html { background: var(--paper); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 80% 4%, rgba(168, 88, 63, .08), transparent 27rem), var(--paper); }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid rgba(168, 88, 63, .28); outline-offset: 2px; }

.topbar { min-height: calc(74px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) max(22px, calc((100vw - 1120px)/2)) 0; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: rgba(247,243,235,.82); backdrop-filter: blur(18px); position: sticky; top: 0; z-index: 5; }
.brand { color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: 11px; font-family: Georgia, serif; font-size: 19px; font-weight: 700; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 40px; border-radius: 4px 10px 10px 4px; color: #fff; background: var(--terracotta); font: 700 11px/1 Inter, sans-serif; box-shadow: inset 4px 0 rgba(0,0,0,.1); }
.icon-button, .close-button, .account-button { border: 1px solid var(--line); background: var(--card); color: var(--ink); width: 42px; height: 42px; border-radius: 50%; font-size: 24px; display: grid; place-items: center; }
.topbar .account-button { margin-left: 9px; background: var(--terracotta); color: white; font-size: 14px; font-weight: 800; }
.topbar { justify-content: flex-start; }
.topbar .icon-button { margin-left: auto; }

main { width: min(1120px, calc(100% - 44px)); margin: 0 auto; padding-bottom: 70px; }
.hero { padding: 68px 0 48px; display: flex; align-items: end; justify-content: space-between; gap: 24px; }
.eyebrow { margin: 0 0 11px; color: var(--terracotta); letter-spacing: .16em; font-size: 11px; font-weight: 800; }
h1, h2, h3 { font-family: Georgia, 'Times New Roman', serif; }
h1 { margin: 0; font-size: clamp(44px, 7vw, 78px); letter-spacing: -.04em; line-height: .98; }
h1 span { color: var(--terracotta); font-size: .55em; vertical-align: top; }
.hero-copy { color: var(--muted); font-family: Georgia, serif; font-style: italic; font-size: 18px; margin: 18px 0 0; }
.primary-button, .secondary-button, .danger-button { border-radius: 999px; padding: 13px 20px; font-weight: 750; border: 1px solid transparent; }
.primary-button { background: var(--terracotta); color: #fff; box-shadow: 0 8px 20px rgba(168,88,63,.18); }
.primary-button:hover { background: var(--terracotta-dark); }
.secondary-button { background: var(--card); border-color: var(--line); color: var(--ink); }
.danger-button { color: #9c3f33; background: #fff2ef; }
.ios-install { margin: -22px 0 30px; padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border-radius: 13px; background: #fff8e7; border: 1px solid rgba(192,138,64,.25); color: #6e552f; }
.ios-install[hidden] { display: none; }
.ios-install strong, .ios-install span { display: block; }
.ios-install strong { font-size: 13px; margin-bottom: 3px; }
.ios-install span { font-size: 12px; line-height: 1.4; }
.ios-install button { border: 0; background: transparent; color: inherit; font-size: 22px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); background: rgba(255,253,248,.55); border-radius: 17px; overflow: hidden; box-shadow: var(--shadow); }
.stats article { padding: 25px 30px; display: flex; align-items: baseline; gap: 11px; }
.stats article + article { border-left: 1px solid var(--line); }
.stats strong { font: 700 30px/1 Georgia, serif; color: var(--terracotta); }
.stats span { color: var(--muted); font-size: 13px; font-weight: 650; }

.tabs { margin-top: 34px; display: flex; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tab { border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); white-space: nowrap; padding: 15px 20px; font-weight: 700; }
.tab:first-child { padding-left: 2px; }
.tab.active { color: var(--terracotta); border-bottom-color: var(--terracotta); }
.tab span { display: inline-grid; place-items: center; margin-left: 5px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--paper-deep); font-size: 11px; }
.tab.active span { background: rgba(168,88,63,.12); }

.library-section { padding-top: 34px; }
.section-heading { display: flex; justify-content: space-between; align-items: end; margin-bottom: 24px; }
.section-heading h2, .sheet h2 { margin: 0; font-size: 30px; }
.section-heading select { color: var(--muted); background: transparent; border: 0; padding: 8px; }
.book-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 17px; }
.book-card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 17px; display: grid; grid-template-columns: 95px minmax(0,1fr); gap: 17px; box-shadow: 0 8px 30px rgba(63,48,38,.05); cursor: pointer; transition: transform .18s, box-shadow .18s; }
.book-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.cover { width: 95px; aspect-ratio: 2/3; border-radius: 7px; object-fit: cover; background: var(--paper-deep); box-shadow: 0 8px 15px rgba(30,25,21,.16); }
.cover-placeholder { display: grid; place-items: center; padding: 9px; color: rgba(255,255,255,.9); background: linear-gradient(145deg, var(--sage), #445442); text-align: center; font: 700 13px/1.2 Georgia, serif; }
.book-info { min-width: 0; display: flex; flex-direction: column; }
.status { align-self: flex-start; padding: 5px 8px; border-radius: 5px; color: var(--sage); background: rgba(111,128,109,.1); text-transform: uppercase; font-size: 9px; font-weight: 850; letter-spacing: .1em; }
.status.reading { color: var(--terracotta); background: rgba(168,88,63,.1); }
.status.read { color: #655584; background: rgba(101,85,132,.1); }
.book-card h3 { margin: 10px 0 4px; font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.author { margin: 0; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress-wrap { margin-top: auto; }
.progress-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-bottom: 6px; }
.progress-track { height: 5px; background: var(--paper-deep); border-radius: 5px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--terracotta); border-radius: 5px; }
.card-footer { margin-top: auto; padding-top: 10px; display: flex; justify-content: space-between; align-items: center; color: #c08a40; font-size: 13px; }
.comment-mark { color: var(--muted); font-size: 12px; }
.empty-state { padding: 65px 24px; text-align: center; border: 1px dashed rgba(41,40,35,.2); border-radius: 18px; }
.empty-state h3 { font-size: 25px; margin: 12px 0 6px; }
.empty-state p { color: var(--muted); margin: 0 auto 22px; max-width: 430px; }
.empty-icon { color: var(--terracotta); font-size: 38px; }

.sheet { width: min(680px, calc(100% - 28px)); max-height: min(86vh, 850px); border: 0; border-radius: 22px; padding: 28px; color: var(--ink); background: var(--paper); box-shadow: 0 30px 90px rgba(35,28,23,.3); }
.sheet::backdrop { background: rgba(35,31,27,.46); backdrop-filter: blur(4px); }
.sheet-header { display: flex; justify-content: space-between; gap: 20px; align-items: start; }
.search-box { display: flex; align-items: center; margin-top: 26px; padding: 6px 6px 6px 14px; border: 1px solid var(--line); border-radius: 13px; background: var(--card); }
.search-box input { flex: 1; min-width: 0; border: 0; outline: 0; padding: 10px; background: transparent; }
.search-box button { border: 0; border-radius: 9px; padding: 10px 13px; color: #fff; background: var(--terracotta); font-weight: 700; }
.search-help, .search-status { color: var(--muted); font-size: 12px; }
.search-results { margin-top: 15px; display: grid; gap: 9px; }
.result { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: var(--card); padding: 10px; display: grid; grid-template-columns: 45px 1fr auto; align-items: center; gap: 12px; text-align: left; color: var(--ink); }
.result img, .result-cover { width: 45px; height: 64px; border-radius: 4px; object-fit: cover; background: var(--paper-deep); }
.result strong, .result span { display: block; }
.result span { color: var(--muted); font-size: 12px; margin-top: 4px; }
.result b { color: var(--terracotta); font-size: 20px; }
.text-button { border: 0; color: var(--terracotta); background: transparent; padding: 18px 0 0; text-decoration: underline; }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 17px; margin-top: 25px; }
.form-grid label, fieldset { color: var(--muted); font-size: 12px; font-weight: 700; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; margin-top: 7px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); padding: 12px; }
.full-width, .rating-field { grid-column: 1/-1; }
.rating-field { border: 0; padding: 0; margin: 0; }
.rating { display: inline-flex; flex-direction: row-reverse; margin-top: 5px; }
.rating input { position: absolute; opacity: 0; pointer-events: none; }
.rating label { color: #cbc2b5; cursor: pointer; font-size: 29px; padding-right: 5px; }
.rating input:checked ~ label, .rating label:hover, .rating label:hover ~ label { color: #c08a40; }
.form-actions { margin-top: 24px; display: grid; grid-template-columns: auto 1fr auto auto; gap: 10px; align-items: center; }
.toast { position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translate(-50%, 30px); opacity: 0; padding: 12px 18px; border-radius: 999px; color: #fff; background: var(--ink); box-shadow: var(--shadow); transition: .25s; z-index: 20; pointer-events: none; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.auth-sheet { width: min(470px, calc(100% - 28px)); }
.auth-brand { display: flex; align-items: center; gap: 15px; }
.auth-brand h2 { font-size: 29px; }
.auth-copy, .account-copy { color: var(--muted); line-height: 1.55; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; margin: 24px 0 18px; border-bottom: 1px solid var(--line); }
.auth-tabs button { border: 0; border-bottom: 2px solid transparent; padding: 12px; background: transparent; color: var(--muted); font-weight: 750; }
.auth-tabs button.active { color: var(--terracotta); border-bottom-color: var(--terracotta); }
#authForm { display: grid; gap: 15px; }
#authForm label { color: var(--muted); font-size: 12px; font-weight: 700; }
#authForm input { width: 100%; margin-top: 7px; padding: 13px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
#authForm p { color: var(--muted); font-size: 11px; margin: -5px 0 0; }
.auth-error { min-height: 20px; color: #9c3f33; font-size: 13px; }
.auth-sheet .primary-button { width: 100%; }
.account-sheet { width: min(450px, calc(100% - 28px)); }
.account-email { padding: 14px; border-radius: 10px; background: var(--card); font-weight: 750; }

@media (max-width: 720px) {
  main { width: min(100% - 28px, 600px); }
  .topbar { min-height: calc(65px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 15px 0; }
  .hero { padding: 40px 0 30px; align-items: start; flex-direction: column; }
  .hero .primary-button { width: 100%; }
  .stats article { padding: 18px 10px; flex-direction: column; align-items: center; gap: 5px; }
  .stats article + article { border-left: 1px solid var(--line); }
  .book-grid { grid-template-columns: 1fr; }
  .book-card { grid-template-columns: 82px minmax(0,1fr); }
  .cover { width: 82px; }
  .section-heading { align-items: center; }
  .section-heading h2 { font-size: 25px; }
  .sheet { padding: 22px 18px calc(20px + env(safe-area-inset-bottom)); margin: auto auto 0; width: 100%; max-height: 92vh; border-radius: 22px 22px 0 0; }
  .form-grid { grid-template-columns: 1fr; }
  .full-width, .rating-field { grid-column: auto; }
  .form-actions { grid-template-columns: 1fr 1fr; }
  .form-actions span { display: none; }
  .form-actions .danger-button { grid-column: 1/-1; }
}
