:root {
  --page: #e9e2c8;
  --paper: #fffdfa;
  --cream: #f4efd8;
  --ink: #222;
  --muted: #555;
  --line: #cfc7a8;
  --brand: #0077b6;
  --brand-dark: #005f91;
  --teal: #0aa6b5;
  --gold: #f4b400;
  --coral: #ef5b5b;
  --violet: #6b5bd6;
  --danger: #b3261e;
  --success: #218838;
  --radius: 4px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(rgba(71, 46, 25, .05), rgba(71, 46, 25, .05)),
    repeating-linear-gradient(
      90deg,
      #7a5634 0 96px,
      #694729 96px 102px,
      #855f3a 102px 198px,
      #6e4b2c 198px 204px
    ),
    linear-gradient(180deg, #f4e8cc 0%, #e7d5ad 100%);
  color: var(--ink);
  font-family: Arial, "Noto Sans Khmer", "Khmer OS Battambang", "Leelawadee UI", sans-serif;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2; }
.hidden { display: none !important; }

.auth-screen {
  display: grid;
  min-height: 100vh;
  grid-template-columns: minmax(300px, 560px) minmax(320px, 430px);
  gap: 42px;
  align-items: center;
  justify-content: center;
  padding: 36px 20px;
  background: var(--page);
}

body.app-open .auth-screen { display: none; }
.app-shell { display: none; min-height: 100vh; }
body.app-open .app-shell { display: block; }

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #111;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 28px;
  letter-spacing: 0.04em;
  text-decoration: none;
}

.brand-lockup strong { color: var(--brand); }
.brand-lockup.large { display: grid; justify-items: start; gap: 12px; font-size: 34px; }
.brand-logo { width: 48px; height: 48px; object-fit: contain; object-position: center; border-radius: 50%; background: #fff; }
.brand-logo.large { width: 170px; height: 170px; border-radius: 50%; object-fit: contain; object-position: center; background: #fff; padding: 6px; }

.auth-copy h1 { margin: 18px 0 10px; font-size: 40px; line-height: 1.2; }
.auth-copy p { margin: 0 0 18px; color: var(--muted); font-size: 18px; }
.auth-panel, .panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.auth-panel { padding: 16px; }
.stack-form { display: grid; gap: 10px; }
.stack-form.compact { gap: 8px; }
.stack-form h2, .reset-panel h3 { margin: 0; }

input, textarea, select {
  width: 100%;
  border: 1px solid #bbb;
  border-radius: 3px;
  background: #fff;
  color: var(--ink);
}
input, select { min-height: 38px; padding: 7px 10px; }
textarea { padding: 9px 10px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--brand); outline: 2px solid rgba(0, 119, 182, .18); }

.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.three-col { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.gender-field { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0; padding: 0; border: 0; }
.gender-field legend { grid-column: 1 / -1; color: var(--muted); font-size: 13px; font-weight: 700; }
.gender-field label { display: flex; min-height: 38px; align-items: center; justify-content: space-between; padding: 7px 9px; border: 1px solid #bbb; border-radius: 3px; }
.gender-field input { width: auto; min-height: auto; }
.remember-row { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.remember-row input { width: auto; min-height: auto; }

.primary-button, .success-button, .tool-button, .ghost-button, .download-button, .read-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 7px 12px;
  border: 0;
  border-radius: 3px;
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 3px 0 rgba(0,0,0,.18);
  transition: background .16s ease, box-shadow .16s ease;
}
.primary-button:hover, .success-button:hover, .tool-button:hover, .ghost-button:hover, .download-button:hover, .read-button:hover { box-shadow: 0 5px 10px rgba(0,0,0,.12); }
.primary-button:active, .success-button:active, .tool-button:active, .ghost-button:active, .download-button:active, .read-button:active { box-shadow: 0 2px 6px rgba(0,0,0,.12); }
.primary-button, .download-button { background: var(--brand); }
.primary-button:hover, .download-button:hover { background: var(--brand-dark); }
.read-button { background: linear-gradient(180deg, #2ec4b6, #087f8c); }
.read-button:hover { background: linear-gradient(180deg, #35d2c4, #066c77); }
.success-button { background: var(--success); }
.tool-button, .ghost-button { background: #e6eef5; color: #111; border: 1px solid #b8c5ce; }
.link-button, .archive-link { border: 0; background: transparent; color: var(--brand); font-weight: 700; }
.link-button:hover, .archive-link:hover { text-decoration: underline; }

.auth-divider { height: 1px; margin: 15px 0; background: var(--line); }
.reset-panel { display: grid; gap: 9px; margin-top: 10px; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--cream); }
.form-message { min-height: 18px; margin: 0; color: var(--danger); font-size: 13px; }
.security-list { display: grid; gap: 4px; margin: 0; padding-left: 20px; color: var(--muted); font-size: 12px; }
.password-strength { min-height: 18px; margin: 0; color: var(--muted); font-size: 12px; font-weight: 700; }
.password-strength[data-strength="0"], .password-strength[data-strength="1"], .password-strength[data-strength="2"] { color: var(--danger); }
.password-strength[data-strength="3"] { color: #a86f00; }
.password-strength[data-strength="4"], .password-strength[data-strength="5"] { color: var(--success); }

.archive-bar {
  display: flex;
  min-height: 30px;
  align-items: center;
  justify-content: space-between;
  padding: 4px max(14px, calc((100vw - 1120px) / 2));
  background: #222;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}
.archive-bar div { display: flex; gap: 14px; }
.archive-link { color: #fff; }

.topbar {
  display: grid;
  grid-template-columns: 220px minmax(260px, 1fr) auto;
  gap: 16px;
  align-items: center;
  width: min(1120px, calc(100% - 24px));
  margin: 0 auto;
  padding: 14px 0;
}

.topbar > * {
  min-width: 0;
}

.search-box {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  border: 1px solid #bdb7a0;
  border-radius: 3px;
  background: #fff;
  color: #666;
}
.search-box svg { margin-left: 9px; }
.search-box::after { content: "Search"; padding: 0 10px; color: #888; font-size: 12px; border-left: 1px solid #ddd; }
.search-box input { min-height: 38px; border: 0; outline: 0; }

.menu-wrap {
  position: relative;
  justify-self: end;
}
.menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid #0a5f94;
  border-radius: 10px;
  background: linear-gradient(180deg, #2aa3df, #0a6ca4);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0;
  box-shadow: 0 8px 18px rgba(10, 54, 84, .2);
}
.menu-toggle:active,
.menu-toggle[aria-expanded="true"] { box-shadow: 0 8px 18px rgba(10, 54, 84, .2); }
.menu-panel {
  position: absolute;
  top: calc(100% + 16px);
  right: 0;
  z-index: 30;
  display: grid;
  gap: 10px;
  width: min(320px, calc(100vw - 32px));
  padding: 14px;
  border: 1px solid #b7cfe0;
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 14px 30px rgba(25, 41, 60, .16);
}
.menu-item {
  display: grid;
  grid-template-columns: 24px 1fr;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 0 14px;
  border: 1px solid #cae0ed;
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff, #e6f4fc);
  color: #173041;
  font-size: 14px;
  font-weight: 700;
  text-align: left;
  box-shadow: 0 6px 14px rgba(42, 74, 97, .08);
}
.menu-item:hover,
.menu-item.active {
  background: linear-gradient(180deg, #ffffff, #d7effc);
}
.menu-item svg { width: 20px; height: 20px; }

.avatar { display: grid; width: 32px; height: 32px; place-items: center; border-radius: 3px; background: var(--brand); color: #fff; font-weight: 800; }
.user-pill { display: inline-flex; max-width: 170px; align-items: center; gap: 7px; overflow: hidden; font-weight: 700; }
.current-user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main-layout {
  width: min(1120px, calc(100% - 24px));
  margin: 0 auto 0;
  border: 1px solid #bfb795;
  background:
    linear-gradient(180deg, rgba(255,255,255,.97), rgba(255,252,244,.98)),
    linear-gradient(180deg, #f6ecd1, #ead8ad);
  box-shadow: 0 14px 32px rgba(38, 32, 12, .12);
}

.hero-band {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 20px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(135deg, #ffffff 0%, #e8f7ff 45%, #fff5d6 100%);
  color: var(--ink);
}
.hero-band h1, .hero-band p { margin: 0; }
.hero-band h1 { max-width: 780px; font-size: 24px; font-weight: 500; }
.hero-band p { color: var(--muted); }
.eyebrow { margin: 0; color: var(--brand); font-size: 13px; font-weight: 700; }

.stats-row {
  display: none;
}

.view { display: none; }
.view.active { display: block; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; padding: 18px 22px 6px; }
.section-heading h2, .section-heading p { margin: 0; }
.section-heading h2 { font-size: 18px; font-weight: 500; text-decoration: underline; }
.section-lead { margin-top: 8px !important; color: var(--muted); font-size: 14px; line-height: 1.6; text-decoration: none; }
.section-heading select { max-width: 220px; }

.document-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 22px 14px;
}

.document-filter-button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid #c6dbe9;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffffff, #edf7fd);
  color: #17405b;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 4px 10px rgba(24, 58, 86, .08);
}

.document-filter-button:hover,
.document-filter-button.active {
  border-color: #70b7dc;
  background: linear-gradient(180deg, #fefefe, #dff2ff);
  color: #0a5f94;
}

.welcome-panel {
  padding: 18px 22px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fcf7ea, #f7efd9);
}
.welcome-hero {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 20px;
  align-items: center;
  padding: 16px 18px;
  border: 1px solid rgba(255,255,255,.7);
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.92), rgba(247,243,230,.94)),
    repeating-linear-gradient(90deg, rgba(139, 104, 64, .06) 0 58px, rgba(255,255,255,0) 58px 62px);
  box-shadow: 0 10px 24px rgba(63, 53, 24, .12);
}
.welcome-portrait-frame {
  position: relative;
  padding: 10px;
  border-radius: 16px;
  background: linear-gradient(180deg, #1478b0, #0c577c);
  box-shadow: 0 8px 20px rgba(10, 52, 78, .22);
}
.welcome-portrait {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 18px;
  box-shadow: 0 12px 22px rgba(0,0,0,.22);
}
.welcome-copy {
  display: grid;
  gap: 10px;
  color: #173041;
}
.welcome-copy h2 {
  margin: 0;
  color: #0b5f91;
  font-size: 28px;
  font-weight: 800;
  line-height: 1.2;
}
.welcome-copy p {
  margin: 0;
  font-size: 15px;
  line-height: 1.7;
}
.welcome-library-meta {
  display: grid;
  gap: 8px;
  margin-top: 4px;
  padding: 14px 16px;
  border: 1px solid #d8e8f2;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255,255,255,.92), rgba(224,244,255,.9));
  box-shadow: 0 6px 16px rgba(17, 66, 96, .1);
}
.welcome-library-meta h3 {
  margin: 0;
  color: #0a4e77;
  font-size: 20px;
  font-weight: 800;
  line-height: 1.35;
}

.home-shortcuts {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 0 22px 14px;
}
.home-mode-button {
  display: grid;
  grid-template-columns: 36px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 0 14px;
  border: 1px solid #c7d7e5;
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff, #e6f3fb);
  color: #153042;
  font-size: 13px;
  font-weight: 800;
  text-align: left;
  box-shadow: 0 5px 14px rgba(26, 52, 77, .08);
}
.home-mode-button:hover,
.home-mode-button.active {
  background: linear-gradient(180deg, #ffffff, #d7effc);
}
.home-mode-icon {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(180deg, #0f91d0, #0a5f94);
  color: #fff;
  font-size: 16px;
  font-weight: 900;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.4), 0 5px 10px rgba(8, 68, 105, .2);
}
.home-mode-button:nth-child(2) .home-mode-icon { background: linear-gradient(180deg, #8d66ff, #5640bb); }
.home-mode-button:nth-child(3) .home-mode-icon { background: linear-gradient(180deg, #0bb389, #0a7f66); }
.home-mode-button:nth-child(4) .home-mode-icon { background: linear-gradient(180deg, #f3b439, #bf7d08); }

.book-shelves { display: grid; }
.book-shelf {
  padding: 12px 22px 20px;
  border-top: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255,252,246,.98), rgba(251,243,219,.94)),
    repeating-linear-gradient(90deg, rgba(166, 124, 72, .08) 0 64px, rgba(255,255,255,0) 64px 68px);
}
.book-shelf:nth-child(even) {
  background:
    linear-gradient(180deg, rgba(247,251,255,.98), rgba(247,240,218,.94)),
    repeating-linear-gradient(90deg, rgba(166, 124, 72, .08) 0 64px, rgba(255,255,255,0) 64px 68px);
}
.book-shelf h3 { margin: 0 0 10px; color: #0b5f91; font-size: 16px; font-weight: 700; text-decoration: underline; }
.shelf-track {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(122px, 1fr));
  gap: 14px;
  align-items: end;
  padding: 2px 8px 12px;
  border-bottom: 8px solid #a97542;
  box-shadow: inset 0 -2px 0 rgba(76, 47, 20, .22);
}

.media-group {
  padding: 18px 22px 24px;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, #f8f1da, #fff9e8);
}
.media-group:nth-child(even) {
  background: linear-gradient(180deg, #f3fbff, #fff);
}
.media-group h3 {
  margin: 0 0 14px;
  color: #0b5f91;
  font-size: 16px;
  font-weight: 700;
  text-decoration: underline;
}
.media-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
}
.media-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: 18px;
  border: 1px solid #d6e4ee;
  background: #ffffff;
  box-shadow: 0 8px 20px rgba(24, 42, 61, .08);
}
.media-preview {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 14px;
  background: linear-gradient(135deg, #163047, #355f86);
  color: #fff;
  font-size: 24px;
  font-weight: 900;
  box-shadow: 0 8px 18px rgba(19, 37, 55, .12);
}
.media-preview.image {
  background-position: center;
  background-size: cover;
}
.media-preview.video::after {
  content: "▶";
  position: absolute;
  inset: auto auto 12px 12px;
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 999px;
  background: rgba(0,0,0,.45);
  font-size: 18px;
}
.media-card strong,
.media-card span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.media-card span {
  color: var(--muted);
  font-size: 13px;
}
.media-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.book-card {
  display: grid;
  gap: 8px;
  justify-items: center;
  min-width: 0;
  padding: 10px 10px 12px;
  border: 1px solid rgba(184, 201, 214, .9);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255,255,255,.96), rgba(248,251,253,.94));
  box-shadow: 0 8px 18px rgba(20, 45, 65, .08);
}
.book-cover {
  position: relative;
  display: grid;
  width: 82px;
  height: 122px;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  background: linear-gradient(145deg, var(--book-a, #0f426b), var(--book-b, #0aa6b5));
  color: #fff;
  background-position: center;
  background-size: cover;
  border: 1px solid rgba(18, 54, 78, .12);
  box-shadow: 0 4px 10px rgba(0,0,0,.12);
}
.book-cover-text { padding: 7px; text-align: center; font-size: 17px; font-weight: 900; }
.book-body {
  display: grid;
  gap: 5px;
  width: 100%;
  justify-items: center;
}
.book-category, .book-description, .download-stat { display: none; }
.book-title {
  width: 100%;
  min-height: 34px;
  margin: 0;
  overflow: hidden;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}
.book-meta {
  display: block;
  width: 100%;
  min-height: 18px;
  margin: 0;
  overflow: hidden;
  color: #627789;
  text-align: center;
  font-size: 11px;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.book-actions { display: grid; width: 100%; gap: 4px; justify-items: center; }
.download-button, .read-button { width: 100%; min-height: 32px; padding: 6px 8px; font-size: 11px; }

.shelf-heading { background: linear-gradient(180deg, #fff, #f5fbff); border-bottom: 1px solid var(--line); }
.library-shelf-room {
  display: grid;
  gap: 28px;
  padding: 26px 22px 34px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255,255,255,.45), rgba(255,255,255,0) 16%),
    repeating-linear-gradient(90deg, rgba(109,74,42,.18) 0 80px, rgba(83,54,30,.12) 80px 84px),
    linear-gradient(180deg, #f1e1ba, #dec18a);
  background-size: auto, 84px 100%, auto;
}
.library-shelf-row {
  position: relative;
  padding: 0 18px 28px;
}
.shelf-books {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 18px;
  align-items: end;
}
.wood-shelf {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 26px;
  border-radius: 3px;
  background: linear-gradient(180deg, #b07a42, #84552c);
  box-shadow: 0 6px 16px rgba(55, 31, 9, .2);
}
.shelf-book {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 8px;
  justify-items: center;
  min-width: 0;
}
.shelf-book-cover {
  position: relative;
  display: grid;
  width: 74px;
  height: 128px;
  place-items: center;
  overflow: hidden;
  border: 0;
  border-radius: 6px;
  background: linear-gradient(145deg, var(--book-a), var(--book-b));
  color: #fff;
  background-position: center;
  background-size: cover;
  border: 1px solid rgba(18, 54, 78, .12);
  box-shadow: 0 8px 18px rgba(0,0,0,.14);
}
.shelf-book-cover span {
  position: relative;
  z-index: 1;
  padding: 8px;
  overflow: hidden;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
}
.shelf-book-info {
  display: grid;
  width: min(170px, 100%);
  gap: 6px;
  padding: 9px;
  border: 1px solid rgba(120, 83, 34, .22);
  border-radius: 7px;
  background: rgba(255,255,255,.82);
  box-shadow: 0 8px 18px rgba(69, 43, 12, .16);
}
.shelf-book-info strong,
.shelf-book-info span {
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.shelf-book-info strong { font-size: 12px; }
.shelf-book-info span { color: var(--muted); font-size: 11px; }
.shelf-book-info div { display: grid; gap: 5px; }

.reading-heading { background: linear-gradient(180deg, #fff, #fff7da); border-bottom: 1px solid var(--line); }
.reading-dashboard {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
  gap: 18px;
  padding: 22px;
  background:
    linear-gradient(135deg, rgba(244,180,0,.12), transparent 38%),
    linear-gradient(315deg, rgba(0,119,182,.12), transparent 34%),
    #fffdf2;
}
.reading-card {
  padding: 18px;
  border: 1px solid #d8c57a;
  border-radius: 8px;
  background: rgba(255,255,255,.92);
  box-shadow: 0 10px 0 #e2cf83, 0 18px 28px rgba(65, 52, 15, .16);
}
.reading-card h3 { margin: 0 0 14px; color: #6c4b00; font-size: 17px; }
.reading-form { display: grid; gap: 14px; }
.reading-history-list { display: grid; gap: 12px; }
.reading-history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: start;
  padding: 14px;
  border: 1px solid #d8e3ea;
  border-radius: 8px;
  background: linear-gradient(145deg, #fff, #eef9ff);
  box-shadow: 0 8px 16px rgba(28, 63, 82, .12);
}
.reading-history-main { display: grid; gap: 7px; min-width: 0; }
.reading-history-main strong,
.reading-history-main span,
.reading-history-main small,
.reading-history-main p { margin: 0; }
.reading-history-main span,
.reading-history-main small { color: var(--muted); }
.reading-history-main p { padding: 8px 10px; border-left: 4px solid var(--gold); background: #fff8df; }
.reading-history-main ul { display: grid; gap: 4px; margin: 0; padding-left: 18px; color: var(--muted); font-size: 12px; }
.reading-history-actions { display: grid; gap: 7px; min-width: 110px; }
.progress-bar {
  overflow: hidden;
  height: 10px;
  border-radius: 999px;
  background: #dfe8ee;
  box-shadow: inset 0 1px 2px rgba(0,0,0,.16);
}
.progress-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--gold));
}

.favorites-heading { background: linear-gradient(180deg, #fff, #effcf4); border-bottom: 1px solid var(--line); }
.favorites-dashboard {
  display: grid;
  gap: 18px;
  padding: 22px;
  background:
    linear-gradient(135deg, rgba(35,165,111,.12), transparent 34%),
    linear-gradient(315deg, rgba(0,119,182,.1), transparent 30%),
    #fbfff9;
}
.favorite-control {
  display: grid;
  gap: 12px;
  padding: 18px;
  border: 1px solid #b5d9bb;
  border-radius: 8px;
  background: rgba(255,255,255,.94);
  box-shadow: 0 10px 0 #9ed6b8, 0 18px 28px rgba(18, 88, 56, .14);
}
.favorite-control > div { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; }
.favorite-control label { display: grid; gap: 6px; color: var(--muted); font-size: 14px; font-weight: 700; }
.favorite-list { display: grid; gap: 22px; }
.favorite-folder {
  padding: 16px;
  border: 1px solid rgba(35,165,111,.28);
  border-radius: 10px;
  background: linear-gradient(180deg, #ffffff, #eefbf3);
  box-shadow: 0 12px 24px rgba(20, 82, 52, .12);
}
.favorite-folder h3 { margin: 0 0 14px; color: #0d724a; text-decoration: underline; }
.favorite-folder > div { display: grid; grid-template-columns: repeat(auto-fill, minmax(245px, 1fr)); gap: 14px; }
.favorite-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: start;
  padding: 13px;
  border: 1px solid #d8e7dd;
  border-left: 6px solid #23a56f;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 18px rgba(30, 84, 56, .12);
}
.favorite-item.priority-high { border-left-color: var(--coral); }
.favorite-item.priority-low { border-left-color: var(--brand); }
.favorite-book-cover {
  display: grid;
  width: 62px;
  height: 92px;
  place-items: center;
  overflow: hidden;
  border: 0;
  border-radius: 6px;
  background: linear-gradient(145deg, var(--book-a), var(--book-b));
  color: #fff;
  background-position: center;
  background-size: cover;
  border: 1px solid rgba(18, 54, 78, .12);
  box-shadow: 0 6px 14px rgba(0,0,0,.12);
}
.favorite-book-cover span { padding: 6px; overflow: hidden; text-align: center; font-size: 10px; font-weight: 800; line-height: 1.2; }
.favorite-item-body { display: grid; gap: 6px; min-width: 0; }
.favorite-item-body strong,
.favorite-item-body span,
.favorite-item-body p { margin: 0; }
.favorite-item-body strong,
.favorite-item-body span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.favorite-item-body span { color: var(--muted); font-size: 12px; }
.favorite-item-body p { padding: 8px; border-radius: 5px; background: #f4fbf7; color: #314138; font-size: 12px; }
.favorite-item-body div { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }

.book-form { margin: 0 22px 22px; padding: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid label { display: grid; gap: 6px; color: var(--muted); font-size: 14px; font-weight: 700; }
.form-grid .wide { grid-column: 1 / -1; }
.hint { color: var(--muted); font-size: 13px; }

.manage-list { display: grid; gap: 10px; padding: 0 22px 22px; }
.manage-item { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.manage-item h3, .manage-item p { margin: 0; }
.manage-actions { display: flex; gap: 8px; }
.admin-panel { margin: 0 22px 22px; border: 1px solid #d7c36f; border-radius: 8px; background: linear-gradient(180deg, #fff9dc, #fff); box-shadow: 0 10px 20px rgba(60, 45, 0, .12); }
.admin-users { display: grid; gap: 10px; padding: 0 16px 16px; }
.admin-user { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 11px 12px; border: 1px solid #e1d391; border-radius: 6px; background: #fff; }
.admin-user strong, .admin-user span { display: block; }
.admin-user span { color: var(--muted); font-size: 12px; }
.telegram-sync-panel {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: start;
  margin: 0 16px 16px;
  padding: 14px;
  border: 1px solid #b8dff5;
  border-radius: 8px;
  background: linear-gradient(145deg, #fff, #eaf8ff);
}
.telegram-sync-panel.visible {
  margin: 0 22px 16px;
  border-color: #2bb8d8;
  background: linear-gradient(145deg, #ffffff, #dff8ff 52%, #f4fffb);
  box-shadow: 0 12px 26px rgba(0, 118, 160, .12);
}
.telegram-sync-panel.disabled-panel {
  border-color: #d3d7dc;
  background: linear-gradient(145deg, #fff, #f5f7f9);
}
.telegram-sync-panel h3,
.telegram-sync-panel p { margin: 0; }
.telegram-sync-panel p:not(.eyebrow) { color: var(--muted); font-size: 13px; }
.telegram-sync-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}
.telegram-sync-toast {
  position: absolute;
  top: 12px;
  right: 14px;
  max-width: min(320px, calc(100% - 28px));
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(16, 30, 55, .94);
  color: #fff;
  font-size: 12px;
  line-height: 1.35;
  box-shadow: 0 10px 24px rgba(9, 27, 52, .22);
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s ease;
  z-index: 3;
}
.telegram-sync-toast.show {
  opacity: 1;
}
.telegram-sync-toast.tone-success { background: rgba(20, 117, 68, .96); }
.telegram-sync-toast.tone-warn { background: rgba(164, 95, 12, .96); }
.telegram-sync-toast.tone-error { background: rgba(163, 34, 34, .96); }
.telegram-sync-result {
  grid-column: 1 / -1;
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}
.telegram-sync-result ul { margin: 0; padding-left: 18px; }
.telegram-sync-result li { display: grid; gap: 2px; margin-bottom: 6px; }
.telegram-sync-result code { color: var(--ink); font-weight: 700; }
.danger-button { min-height: 36px; padding: 7px 12px; border: 0; border-radius: 3px; background: #f7d7d7; color: var(--danger); font-weight: 700; }
.danger-button:disabled { cursor: not-allowed; opacity: .55; }
.empty-state { padding: 24px; color: var(--muted); text-align: center; }

.summary-report {
  width: min(1120px, calc(100% - 24px));
  margin: 14px auto 0;
}
.summary-report-inner {
  border: 1px solid #bfb795;
  background: linear-gradient(180deg, #fffef8, #f4ecd2);
  box-shadow: 0 10px 20px rgba(46, 38, 16, .08);
}
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 6px 16px 14px;
}
.summary-card {
  display: grid;
  gap: 4px;
  padding: 10px 8px;
  border-radius: 10px;
  border: 1px solid #d6ddc4;
  background: linear-gradient(180deg, #ffffff, #ebf7ff);
  box-shadow: 0 5px 12px rgba(33, 51, 68, .08);
  text-align: center;
}
.summary-card:nth-child(2) { background: linear-gradient(180deg, #ffffff, #eef9eb); }
.summary-card:nth-child(3) { background: linear-gradient(180deg, #ffffff, #f5ecff); }
.summary-card:nth-child(4) { background: linear-gradient(180deg, #ffffff, #fff0e5); }
.summary-card strong {
  color: #0a5f94;
  font-size: 20px;
  font-weight: 900;
}
.summary-card span {
  color: #3b4b59;
  font-size: 12px;
  font-weight: 700;
}

.support-panel {
  padding: 8px 22px 24px;
}
.support-panel-grid {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 24px;
  align-items: center;
  padding: 22px;
  border-radius: 20px;
  background: linear-gradient(135deg, #fffef9 0%, #edf8ff 48%, #fff5dd 100%);
  box-shadow: 0 16px 0 #dccf9f, 0 28px 38px rgba(69, 52, 18, .17);
}
.support-qr-card {
  padding: 14px;
  border-radius: 18px;
  background: linear-gradient(180deg, #ffffff, #eef7ff);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.95), 0 12px 22px rgba(11, 62, 98, .14);
}
.support-qr-image {
  display: block;
  width: 100%;
  border-radius: 14px;
}
.support-copy {
  display: grid;
  gap: 14px;
}
.support-copy h3,
.support-copy p {
  margin: 0;
}
.support-copy h3 {
  color: #0a4e77;
  font-size: 28px;
  font-weight: 800;
  line-height: 1.3;
}
.support-copy p {
  color: #273742;
  font-size: 15px;
  line-height: 1.8;
}

.site-footer {
  width: min(1120px, calc(100% - 24px));
  margin: 0 auto 24px;
  padding: 14px 18px;
  border: 1px solid #bfb795;
  border-top: 0;
  background: #ded6b9;
  color: #333;
  text-align: center;
  font-size: 13px;
}

.reader-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.58);
}

.reader-window {
  display: grid;
  grid-template-rows: auto minmax(300px, 1fr) auto;
  width: min(980px, 100%);
  height: min(860px, 92vh);
  border: 1px solid #111;
  background: #fff;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}

.reader-window header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--cream);
}

.reader-window h2,
.reader-window p {
  margin: 0;
}

.reader-stage {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  overflow: auto;
  background: #f6f8fb;
  padding: 16px;
}

.reader-book-shell {
  display: grid;
  align-items: center;
  justify-items: center;
  width: min(860px, 100%);
  min-height: 320px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #dbe2ea;
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(18, 31, 46, .12);
}

.reader-window iframe,
.reader-stage img,
.reader-stage video,
.reader-stage canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(72vh, 760px);
  border: 0;
  background: #fff;
}
.reader-window iframe {
  width: 100%;
  min-height: min(72vh, 760px);
}
.reader-stage canvas {
  box-shadow: 0 2px 10px rgba(0,0,0,.08);
}
.reader-stage img {
  object-fit: contain;
  background: #f8fbff;
}
.reader-stage video {
  background: #000;
}

.reader-pdf-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px 18px;
  border-top: 1px solid #d8e2ea;
  background: #f7fafc;
}
.reader-progress {
  display: grid;
  justify-items: center;
  gap: 4px;
  text-align: center;
}
.reader-progress strong {
  color: #0a4e77;
  font-size: 16px;
}
.reader-progress span {
  color: #5a6470;
  font-size: 13px;
}
.reader-media-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

@media (max-width: 960px) {
  .auth-screen, .topbar { grid-template-columns: 1fr; }
  .topbar { gap: 10px; }
  .brand-lockup { font-size: 24px; }
  .search-box { width: 100%; }
  .shelf-track { grid-template-columns: repeat(3, minmax(92px, 1fr)); }
  .menu-wrap { justify-self: stretch; }
  .menu-toggle { width: 100%; justify-content: center; }
  .menu-panel { left: 0; right: 0; width: auto; }
  .welcome-hero { grid-template-columns: 1fr; }
  .welcome-panel { padding: 16px 14px 18px; }
  .welcome-hero { gap: 14px; padding: 14px; }
  .welcome-portrait-frame { max-width: 280px; margin: 0 auto; }
  .welcome-copy h2 { font-size: 24px; }
  .welcome-library-meta h3 { font-size: 19px; }
  .home-shortcuts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .document-filter-bar { padding: 0 16px 12px; }
  .support-panel-grid { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .media-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .reading-dashboard { grid-template-columns: 1fr; }
  .favorite-control > div { grid-template-columns: 1fr; }
  .hero-band { padding: 16px 18px; }
  .hero-band h1 { font-size: 22px; }
  .section-heading { padding: 16px 16px 8px; }
  .book-shelf { padding: 14px 16px 18px; }
  .media-group { padding: 16px; }
  .manage-list { padding: 0 16px 18px; }
  .book-form { margin: 0 16px 18px; padding: 16px; }
  .reader-window {
    width: min(100%, 100vw);
    height: 100vh;
    border-radius: 0;
    border: 0;
  }
  .reader-window header {
    position: sticky;
    top: 0;
    z-index: 2;
  }
  .reader-pdf-controls { padding: 12px 14px 14px; }
}

@media (max-width: 640px) {
  body { line-height: 1.5; }
  .auth-screen { padding: 20px 12px; }
  .auth-copy h1 { font-size: 30px; }
  .two-col, .three-col, .gender-field, .form-grid { grid-template-columns: 1fr; }
  .hero-band, .section-heading, .manage-item { align-items: start; flex-direction: column; grid-template-columns: 1fr; }
  .topbar { width: calc(100% - 16px); gap: 8px; padding: 12px 0; }
  .brand-lockup { gap: 8px; font-size: 20px; }
  .brand-logo { width: 40px; height: 40px; }
  .user-pill { max-width: 100%; }
  .search-box { grid-template-columns: auto 1fr; }
  .search-box::after { display: none; }
  .search-box input { font-size: 16px; }
  .main-layout, .summary-report { width: calc(100% - 12px); }
  .hero-band { gap: 10px; padding: 14px 12px; }
  .hero-band h1 { font-size: 20px; }
  .hero-band p, .section-lead, .welcome-copy p { font-size: 14px; }
  .welcome-panel { padding: 12px 10px 16px; }
  .welcome-hero { gap: 12px; padding: 12px; border-radius: 12px; }
  .welcome-portrait-frame { max-width: 220px; padding: 10px; border-radius: 16px; }
  .welcome-portrait { border-radius: 12px; }
  .welcome-copy h2 { font-size: 20px; line-height: 1.3; }
  .welcome-library-meta { padding: 12px; }
  .welcome-library-meta h3 { font-size: 17px; }
  .home-shortcuts { gap: 10px; padding: 0 10px 14px; }
  .home-mode-button {
    grid-template-columns: 36px 1fr;
    gap: 10px;
    min-height: 56px;
    padding: 0 12px;
    font-size: 13px;
  }
  .home-mode-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    font-size: 16px;
  }
  .section-heading { gap: 10px; padding: 14px 12px 8px; }
  .section-heading select { width: 100%; max-width: none; }
  .document-filter-bar {
    gap: 6px;
    padding: 0 12px 12px;
  }
  .document-filter-button {
    flex: 1 1 calc(50% - 6px);
    min-height: 36px;
    padding: 0 10px;
    font-size: 12px;
  }
  .shelf-track {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 10px;
      padding-bottom: 10px;
      border-bottom-width: 6px;
    }
  .book-shelf { padding: 12px 10px 16px; }
  .book-cover { width: 74px; height: 110px; }
  .book-card { padding: 8px 8px 10px; }
  .book-title { min-height: 32px; font-size: 11px; }
  .book-meta { min-height: 16px; font-size: 10px; }
  .book-actions { width: 100%; }
  .download-button, .read-button { min-height: 34px; font-size: 11px; }
  .media-group { padding: 14px 10px 16px; }
  .media-card { padding: 10px; border-radius: 12px; }
  .media-preview { border-radius: 10px; }
  .reading-history-item { grid-template-columns: 1fr; }
  .reading-history-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .favorite-item { grid-template-columns: 1fr; justify-items: center; }
  .favorite-item-body { width: 100%; }
  .menu-panel { padding: 12px; }
  .home-shortcuts { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: 1fr; }
  .reader-pdf-controls { flex-direction: column; }
  .reader-progress strong { font-size: 15px; }
  .reader-progress span { font-size: 12px; }
  .reader-media-actions { width: 100%; justify-content: stretch; }
  .reader-media-actions .download-button,
  .reader-media-actions .primary-button { flex: 1; }
  .media-grid { grid-template-columns: 1fr; }
  .reader-window { height: 92vh; }
  .reader-stage { padding: 12px; }
  .reader-window iframe,
  .reader-stage img,
  .reader-stage video,
  .reader-stage canvas {
    max-height: min(66vh, 620px);
  }
  .reader-window header { padding: 10px 12px; }
  .reader-window h2 { font-size: 18px; }
  .summary-report { margin-top: 10px; }
  .summary-grid { gap: 8px; padding: 4px 10px 10px; }
  .summary-card { padding: 8px 6px; }
}

@media (max-width: 420px) {
  .topbar { width: calc(100% - 10px); }
  .main-layout, .summary-report { width: calc(100% - 10px); }
  .hero-band h1 { font-size: 18px; }
  .welcome-copy h2 { font-size: 19px; }
  .shelf-track { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .book-cover { width: 72px; height: 110px; }
    .book-title, .book-actions { width: 78px; }
  .reader-window { height: 100vh; }
  .reader-stage { padding: 8px; }
  .reader-window iframe,
  .reader-stage img,
  .reader-stage video,
  .reader-stage canvas {
    max-height: min(62vh, 560px);
  }
}
