:root {
  --bg: #f6f6f3;
  --surface: #fff;
  --text: #20211f;
  --muted: #6d7069;
  --border: #dedfd9;
  --accent: #335eea;
  --danger: #b3342a;
  --success: #237a45;
  --warning: #a25b09;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
a { color: var(--accent); text-decoration: none; }
button, input, select { font: inherit; }
button, .file-button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }

.topbar { height: 58px; padding: 0 max(20px, calc((100vw - 980px) / 2)); display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); background: var(--surface); }
.brand { color: var(--text); font-size: 18px; font-weight: 750; }
.topbar nav { display: flex; align-items: center; gap: 18px; }
.topbar form { margin: 0; }
.sync-button { min-height: 34px; padding: 6px 10px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 7px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.sync-button.sync-tone-neutral { border-color: var(--border); background: #f4f4f1; color: var(--muted); }
.sync-button.sync-tone-success { border-color: #badbc5; background: #e9f5ed; color: var(--success); }
.sync-button.sync-tone-progress { background: var(--accent); color: white; }
.sync-button.sync-tone-action { border-color: #ead3ad; background: #fff2df; color: var(--warning); }
.sync-button.sync-tone-error { background: var(--danger); color: white; }
.page { width: min(980px, calc(100% - 32px)); margin: 36px auto 80px; }
.page h1 { margin: 0; font-size: 32px; line-height: 1.2; }
.page h2 { margin: 38px 0 14px; font-size: 20px; }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; }
.page-heading p, .reader-heading p { margin: 7px 0 0; color: var(--muted); }
.primary, .secondary, .file-button { min-height: 40px; padding: 9px 15px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 7px; font-weight: 650; }
.primary, .file-button { background: var(--accent); color: white; }
.secondary { border-color: var(--border); background: var(--surface); color: var(--text); }
.full { width: 100%; }
.file-button input { display: none; }
.link-button { padding: 0; border: 0; background: none; color: var(--accent); }
.link-button.danger { color: var(--danger); }
.notice { margin-bottom: 18px; padding: 11px 13px; border: 1px solid #bdd5bf; border-radius: 7px; background: #eef8ef; }
.notice.error { border-color: #e1b9b5; background: #fff0ee; color: #7b2922; }
.summary { margin-top: 28px; display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--border); border-radius: 9px; background: var(--surface); }
.summary div { padding: 17px; display: grid; border-right: 1px solid var(--border); }
.summary div:last-child { border-right: 0; }
.summary strong { font-size: 23px; }
.summary span { color: var(--muted); font-size: 12px; }
.article-list, .card-list { border: 1px solid var(--border); border-radius: 9px; overflow: hidden; background: var(--surface); }
.article-row { position: relative; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border); color: var(--text); }
.article-row:last-child { border-bottom: 0; }
.article-row.is-read { background: #f8f8f6; }
.article-open { min-width: 0; padding: 15px 8px 15px 17px; display: flex; flex: 1; align-items: center; color: var(--text); }
.article-open::after { content: ""; position: absolute; inset: 0; }
.article-title { min-width: 0; display: grid; gap: 3px; }
.article-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.article-title small { color: var(--muted); font-size: 12px; }
.article-row.is-read .article-title strong { color: var(--muted); }
.article-progress { width: min(280px, 100%); margin-top: 5px; display: grid; gap: 3px; }
.article-progress-track { width: 100%; height: 5px; overflow: hidden; appearance: none; border: 0; border-radius: 999px; background: #e7e8e3; }
.article-progress-track::-webkit-progress-bar { background: #e7e8e3; }
.article-progress-track::-webkit-progress-value { background: var(--accent); }
.article-progress-track::-moz-progress-bar { background: var(--accent); }
.article-icon-actions { position: relative; z-index: 1; padding-right: 13px; display: flex; gap: 7px; }
.round-icon-button { width: 36px; height: 36px; padding: 0; display: inline-grid; flex: 0 0 36px; place-items: center; border: 1px solid var(--border); border-radius: 50%; background: white; color: var(--text); }
.round-icon-button:hover { border-color: #bfc1ba; background: #f5f5f2; }
.round-icon-button.danger { color: var(--danger); }
.round-icon-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
.empty { padding: 28px; border: 1px dashed #c8cac3; border-radius: 9px; color: var(--muted); text-align: center; }
.exports { margin-top: 40px; }
.export-box { min-height: 68px; margin-bottom: 10px; padding: 13px 15px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); }
.export-box > div { display: grid; gap: 3px; }
.export-box span { color: var(--muted); font-size: 12px; }
.apkg-form { display: flex; gap: 8px; }
.apkg-form select { max-width: 220px; padding: 8px; border: 1px solid var(--border); border-radius: 7px; background: white; }
.small-upload { margin-top: 8px; color: var(--muted); font-size: 12px; }
.small-upload input { margin-left: 8px; }
.saved-card { padding: 14px 16px; display: grid; grid-template-columns: 160px 1fr auto auto; align-items: center; gap: 14px; border-bottom: 1px solid var(--border); }
.saved-card:last-child { border-bottom: 0; }
.saved-card > div { display: grid; gap: 2px; }
.saved-card > div span { color: var(--muted); font-size: 11px; }
.saved-card p { margin: 0; color: #555850; font-size: 13px; }
.card-list.is-collapsed .saved-card:nth-child(n+6) { display: none; }
.cards-toggle { margin: 10px auto 0; padding: 5px 10px; display: block; border: 0; background: none; color: var(--accent); font-size: 13px; }
.card-sync-badge { padding: 4px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.card-sync-badge.is-synced { background: #e9f5ed; color: var(--success); }
.card-sync-badge.is-pending { background: #fff2df; color: #865018; }

.confirm-dialog { width: min(430px, calc(100% - 28px)); padding: 0; border: 1px solid var(--border); border-radius: 11px; background: var(--surface); color: var(--text); box-shadow: 0 18px 70px rgba(0,0,0,.28); }
.confirm-dialog::backdrop { background: rgba(20,20,20,.48); backdrop-filter: blur(2px); }
.confirm-dialog-content { padding: 22px; }
.confirm-dialog h2 { margin: 0 0 12px; font-size: 21px; }
.confirm-dialog p { margin: 7px 0; color: var(--muted); }
.confirm-dialog p strong { display: block; overflow: hidden; color: var(--text); text-overflow: ellipsis; white-space: nowrap; }
.confirm-dialog-actions { margin-top: 22px; display: flex; justify-content: flex-end; gap: 9px; }
.confirm-dialog-actions form { margin: 0; }
.danger-button { background: var(--danger); }

.auth-page { min-height: calc(100vh - 72px); display: grid; place-items: center; }
.auth-card { width: min(380px, 100%); padding: 28px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.auth-card h1 { font-size: 27px; }
.auth-card > p { margin: 8px 0 24px; color: var(--muted); }
.auth-card label { margin-bottom: 14px; display: grid; gap: 6px; font-size: 13px; font-weight: 650; }
.auth-card input { width: 100%; height: 42px; padding: 0 11px; border: 1px solid var(--border); border-radius: 7px; background: white; }
.auth-card > a { display: block; margin-top: 18px; text-align: center; }

.pdf-body { background: #252525; }
.reader-page { width: 100%; margin: 0; }
.pdf-workspace { min-height: 100dvh; background: #252525; }
.pdf-viewer { min-height: 100dvh; padding: 12px; display: grid; justify-items: center; gap: 18px; }
.reader-completion { min-height: 52dvh; padding: 64px 20px 84px; display: grid; justify-items: center; align-content: center; gap: 10px; color: white; text-align: center; }
.reader-completion p { margin: 0; color: #b7b7b4; font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.reader-completion h1 { margin: 0; color: white; font-size: clamp(34px, 6vw, 58px); line-height: 1; }
.read-switch { min-width: min(100%, 330px); margin-top: 22px; padding: 17px 21px; display: inline-flex; align-items: center; justify-content: center; gap: 13px; border: 1px solid rgba(255,255,255,.23); border-radius: 14px; background: rgba(255,255,255,.08); color: white; font-size: 18px; font-weight: 750; cursor: pointer; }
.read-switch input { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.read-switch-track { width: 52px; height: 30px; padding: 3px; display: flex; align-items: center; border-radius: 999px; background: #757570; box-shadow: inset 0 1px 2px rgba(0,0,0,.35); transition: background .18s ease; }
.read-switch-knob { width: 24px; height: 24px; display: block; border-radius: 50%; background: white; box-shadow: 0 1px 3px rgba(0,0,0,.35); transition: transform .18s ease; }
.read-switch input:checked + .read-switch-track { background: var(--success); }
.read-switch input:checked + .read-switch-track .read-switch-knob { transform: translateX(22px); }
.read-switch input:focus-visible + .read-switch-track { outline: 3px solid #9db6ff; outline-offset: 3px; }
.read-switch input:disabled + .read-switch-track { opacity: .6; }
.pdf-page { position: relative; overflow: hidden; background: white; box-shadow: 0 2px 12px rgba(0,0,0,.38); }
.pdf-page canvas { position: absolute; inset: 0; display: block; }
.pdf-page.loading::after { content: ""; position: absolute; inset: 0; background: linear-gradient(110deg, #fff 25%, #f1f1f1 40%, #fff 55%); background-size: 220% 100%; animation: loading 1.2s linear infinite; }
.pdf-page.ready::after { display: none; }
.pdf-page.failed::after { content: "Страница не загрузилась"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
@keyframes loading { to { background-position-x: -220%; } }
.viewer-back { --reader-control-scale: 1; position: fixed; top: 11px; left: 11px; z-index: 20; padding: calc(8px * var(--reader-control-scale)) calc(11px * var(--reader-control-scale)); border: 1px solid rgba(255,255,255,.25); border-radius: calc(7px * var(--reader-control-scale)); background: rgba(25,25,25,.86); color: white; font-size: calc(13px * var(--reader-control-scale)); backdrop-filter: blur(8px); }
.pdf-status { position: fixed; top: 50%; left: 50%; z-index: 20; padding: 10px 13px; border-radius: 7px; background: #171717; color: white; transform: translate(-50%, -50%); }
.page-number { position: absolute; right: 8px; bottom: 5px; z-index: 5; color: #777; font-size: 10px; pointer-events: none; user-select: none; }
.highlight-layer { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.word-highlight { position: absolute; min-width: 2px; min-height: 2px; padding: 0; border: 0; border-radius: 2px; background: rgba(255, 224, 75, .56); box-shadow: inset 0 -1px rgba(192, 145, 0, .18); mix-blend-mode: multiply; pointer-events: auto; }
.word-highlight.is-pending { animation: highlight-pulse 1.15s ease-in-out infinite alternate; }
.word-highlight.is-failed { outline: 1px dotted rgba(133, 84, 0, .65); }
@keyframes highlight-pulse { to { background-color: rgba(255, 224, 75, .78); } }
.selection-popover, .highlight-popover { --reader-control-scale: 1; position: fixed; z-index: 40; width: max-content; max-width: calc(100vw - 20px); padding: calc(9px * var(--reader-control-scale)) calc(11px * var(--reader-control-scale)); display: grid; gap: calc(3px * var(--reader-control-scale)); border: 1px solid rgba(255,255,255,.18); border-radius: calc(7px * var(--reader-control-scale)); background: rgba(25,25,25,.94); color: white; box-shadow: 0 6px 24px rgba(0,0,0,.35); backdrop-filter: blur(8px); }
.selection-popover { z-index: 35; }
.selection-popover[hidden], .highlight-popover[hidden] { display: none; }
.selection-action { max-width: 100%; padding: calc(8px * var(--reader-control-scale)) calc(11px * var(--reader-control-scale)); overflow: hidden; border: 0; border-radius: calc(6px * var(--reader-control-scale)); background: #335eea; color: white; font-size: calc(13px * var(--reader-control-scale)); font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.highlight-popover[hidden] { display: none; }
.selection-popover span, .highlight-popover span { overflow-wrap: anywhere; color: #e8e8e8; font-size: calc(13px * var(--reader-control-scale)); }
.highlight-popover strong { font-size: calc(14px * var(--reader-control-scale)); }
.highlight-delete { margin-top: calc(5px * var(--reader-control-scale)); padding: calc(5px * var(--reader-control-scale)) 0 0; border: 0; border-top: 1px solid rgba(255,255,255,.16); background: none; color: #ffaaa3; font-size: calc(12px * var(--reader-control-scale)); text-align: left; }

.textLayer { color-scheme: only light; position: absolute; inset: 0; z-index: 3; overflow: clip; opacity: 1; line-height: 1; letter-spacing: normal; word-spacing: normal; text-align: initial; text-size-adjust: none; forced-color-adjust: none; transform-origin: 0 0; caret-color: CanvasText; }
.textLayer :is(span, br) { position: absolute; color: transparent; white-space: pre; cursor: text; transform-origin: 0% 0%; user-select: text; }
.textLayer { --min-font-size: 1; --text-scale-factor: calc(var(--total-scale-factor) * var(--min-font-size)); --min-font-size-inv: calc(1 / var(--min-font-size)); }
.textLayer > :not(.markedContent), .textLayer .markedContent span:not(.markedContent) { z-index: 1; --font-height: 0; --scale-x: 1; --rotate: 0deg; font-size: calc(var(--text-scale-factor) * var(--font-height)); transform: rotate(var(--rotate)) scaleX(var(--scale-x)) scale(var(--min-font-size-inv)); }
.textLayer .markedContent { display: contents; }
.textLayer span[role="img"] { cursor: default; user-select: none; }
.textLayer ::selection { background: rgba(45, 98, 235, .3); color: transparent; }
.textLayer br::selection { background: transparent; }
@media (max-width: 700px) {
  .page { width: min(100% - 22px, 980px); margin-top: 22px; }
  .topbar { padding: 0 12px; }
  .topbar nav { gap: 10px; }
  .sync-button { padding: 6px 8px; font-size: 12px; }
  .page-heading { align-items: start; }
  .page h1 { font-size: 27px; }
  .summary div { padding: 12px; text-align: center; }
  .summary strong { font-size: 19px; }
  .export-box { align-items: stretch; flex-direction: column; }
  .apkg-form { flex-direction: column; }
  .apkg-form select { max-width: none; }
  .saved-card { grid-template-columns: 1fr auto auto; }
  .saved-card p { grid-column: 1 / -1; grid-row: 2; }
  .article-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: stretch; gap: 0; }
  .article-open { grid-column: 1; grid-row: 1; padding: 12px 8px 7px 12px; }
  .article-icon-actions { grid-column: 2; grid-row: 1 / 3; padding: 8px; flex-direction: column; justify-content: center; }
  .reader-page { width: 100%; margin: 0; }
  .pdf-viewer { padding: 8px 0; gap: 10px; }
  .viewer-back { top: 7px; left: 7px; }
  .reader-completion { min-height: 46dvh; padding: 48px 16px 68px; }
}
.auth-links { display: flex; gap: 1rem; flex-wrap: wrap; }
.settings-section { margin: 2rem 0; }
.settings-profile { margin: 0; color: var(--muted); font-size: 13px; }
.settings-form { display: grid; gap: 1rem; max-width: 36rem; }
.settings-form label, .deck-action-form label { display: grid; gap: .4rem; font-size: 13px; font-weight: 680; }
.settings-form input, .settings-form select, .deck-action-form select { width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid #c8cac3; border-radius: 7px; background: var(--surface); color: var(--text); }
.field-help { color: var(--muted); font-size: 11px; font-weight: 450; }
.eyebrow { display: block; color: var(--muted); font-size: 11px; font-weight: 750; letter-spacing: .07em; text-transform: uppercase; }
.section-heading { margin: 36px 0 14px; display: flex; align-items: end; justify-content: space-between; gap: 16px; }
.section-heading h2, .page .section-heading h2 { margin: 2px 0 0; }
.section-heading p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.sync-overview { --sync-color: var(--muted); margin: 28px 0 36px; padding: 22px; display: flex; align-items: center; justify-content: space-between; gap: 28px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); box-shadow: 0 1px 0 rgba(32,33,31,.03); }
.sync-overview-full { margin: 0 0 16px; align-items: stretch; }
.sync-overview-main { min-width: 0; flex: 1; }
.sync-status-heading { display: flex; align-items: center; gap: 11px; }
.sync-status-heading h2, .sync-status-heading h3, .page .sync-status-heading h2, .page .sync-status-heading h3 { margin: 1px 0 0; font-size: 20px; line-height: 1.25; }
.sync-status-dot { width: 11px; height: 11px; flex: 0 0 11px; border: 3px solid color-mix(in srgb, var(--sync-color) 22%, white); border-radius: 50%; background: var(--sync-color); box-sizing: content-box; }
.sync-overview-main > p { max-width: 680px; margin: 12px 0 0; color: #555850; }
.sync-error-detail { padding: 9px 11px; border-radius: 7px; background: #fff0ee; color: #7b2922 !important; font-size: 13px; }
.sync-tone-success { --sync-color: var(--success); border-color: #badbc5; background: linear-gradient(135deg, #fbfffc, #fff 48%); }
.sync-tone-progress { --sync-color: var(--accent); border-color: #cbd6fb; background: linear-gradient(135deg, #f7f9ff, #fff 48%); }
.sync-tone-action { --sync-color: var(--warning); border-color: #ead3ad; background: linear-gradient(135deg, #fffaf1, #fff 48%); }
.sync-tone-error { --sync-color: var(--danger); border-color: #e4beb9; background: linear-gradient(135deg, #fff7f5, #fff 48%); }
.sync-progress-label { margin-top: 18px; display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 11px; }
.sync-progress-label span:first-child { color: var(--text); font-weight: 700; }
.sync-progress-track { width: 100%; height: 7px; margin-top: 6px; display: block; overflow: hidden; appearance: none; border: 0; border-radius: 999px; background: #e7e8e3; }
.sync-progress-track::-webkit-progress-bar { border-radius: 999px; background: #e7e8e3; }
.sync-progress-track::-webkit-progress-value { border-radius: 999px; background: var(--sync-color); transition: width .35s ease; }
.sync-progress-track::-moz-progress-bar { border-radius: 999px; background: var(--sync-color); transition: width .35s ease; }
.sync-meta { margin: 17px 0 0; display: flex; flex-wrap: wrap; gap: 9px 24px; }
.sync-meta div { display: grid; gap: 1px; }
.sync-meta dt { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .04em; }
.sync-meta dd { margin: 0; font-size: 13px; font-weight: 680; }
.sync-overview-action { flex: 0 0 auto; }

.setup-card, .next-action-card { padding: 22px; display: grid; grid-template-columns: minmax(0, .85fr) minmax(320px, 1.15fr); gap: 32px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.setup-card h3, .next-action-card h3 { margin: 0; font-size: 20px; }
.setup-card p, .next-action-card p, .disclosure-content > p { margin: 8px 0 0; color: var(--muted); }
.connect-form { max-width: none; }
.deck-action-form { display: grid; grid-template-columns: minmax(220px, 1fr) auto; align-items: end; gap: 10px; }
.primary-sync-action { padding: 12px 0 4px; display: flex; align-items: center; gap: 14px; }
.primary-sync-action span { color: var(--muted); font-size: 12px; }

.settings-disclosure { margin-top: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.settings-disclosure > summary { padding: 14px 16px; cursor: pointer; font-weight: 700; list-style-position: inside; }
.settings-disclosure[open] > summary { border-bottom: 1px solid var(--border); }
.disclosure-content { padding: 16px; }
.disclosure-content > p:first-child { margin-top: 0; }
.danger-disclosure > summary { color: #7b2922; }
.danger { color: var(--danger); }
.security-settings { margin-top: 34px; }

.sync-event-list { background: #fbfbf9; }
.sync-event { padding: 13px 16px; display: grid; grid-template-columns: 98px 1fr; gap: 12px; border-bottom: 1px solid var(--border); }
.sync-event:last-child { border-bottom: 0; }
.sync-event > div { display: grid; gap: 2px; }
.sync-event > div > span { color: var(--muted); font-size: 11px; }
.sync-event p { margin: 5px 0 0; color: #6f342e; font-size: 12px; }
.event-state { width: fit-content; height: fit-content; padding: 3px 7px; border-radius: 999px; background: #ecece8; color: #555850; font-size: 10px; font-weight: 750; }
.sync-event-succeeded .event-state { background: #e5f3e9; color: var(--success); }
.sync-event-failed .event-state { background: #f9e5e2; color: var(--danger); }
.sync-event-running .event-state, .sync-event-queued .event-state { background: #e8edff; color: var(--accent); }

.rebuild-job-panel { margin-bottom: 14px; padding: 14px 16px; display: grid; gap: 2px; border: 1px solid #cbd6fb; border-radius: 10px; background: linear-gradient(135deg, #f7f9ff, #fff 48%); }
.rebuild-job-panel p { margin: 0; color: var(--text); }
.rebuild-job-panel p .field-help { display: block; }
.rebuild-job-panel .sync-progress-label { margin-top: 9px; }
.rebuild-job-panel .sync-progress-track { margin-top: 5px; background-color: #dde2f2; }
.rebuild-job-panel a.primary { width: fit-content; margin-top: 10px; }
.rebuild-job-panel .sync-error-detail { margin-top: 4px; }

@media (max-width: 700px) {
  .sync-overview { padding: 17px; align-items: stretch; flex-direction: column; gap: 18px; }
  .sync-overview-action .primary, .sync-overview-action .secondary { width: 100%; }
  .sync-progress-label span:last-child { display: none; }
  .setup-card, .next-action-card { padding: 17px; grid-template-columns: 1fr; gap: 20px; }
  .deck-action-form { grid-template-columns: 1fr; }
  .primary-sync-action { align-items: stretch; flex-direction: column; }
  .sync-meta { display: grid; grid-template-columns: 1fr 1fr; }
  .sync-event { grid-template-columns: 86px 1fr; }
}
