:root {
  color-scheme: light;
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --text: #172033;
  --muted: #647089;
  --border: #d8e0eb;
  --accent: #3157d5;
  --accent-strong: #2446b4;
  --accent-soft: #e9eeff;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --shadow: 0 16px 42px rgba(15, 23, 42, .13);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1120;
  --surface: #151e2e;
  --surface-soft: #101827;
  --text: #edf2fb;
  --muted: #a6b2c8;
  --border: #2d3a51;
  --accent: #7896ff;
  --accent-strong: #91a9ff;
  --accent-soft: #202f5a;
  --danger: #ff9a90;
  --danger-soft: #3b2022;
  --shadow: 0 18px 44px rgba(0, 0, 0, .36);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body { font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
button, input { font: inherit; }
button { touch-action: manipulation; }
a { color: var(--accent); }
svg { width: 22px; height: 22px; fill: currentColor; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.app-shell { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; }
.topbar { min-height: 64px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 18px; padding: 9px 18px; background: var(--surface); border-bottom: 1px solid var(--border); z-index: 10; }
.brand { justify-self: start; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 0; border: 0; background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.brand > span { min-width: 0; display: flex; flex-direction: column; }
.brand strong { font-size: 15px; letter-spacing: -.01em; }
.brand small { margin-top: 3px; max-width: 260px; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.desktop-tabs { display: flex; align-items: center; gap: 4px; padding: 4px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface-soft); }
.section-tab { min-height: 36px; padding: 6px 14px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 750; cursor: pointer; }
.section-tab.active { background: var(--surface); color: var(--accent); box-shadow: 0 2px 8px rgba(15, 23, 42, .08); }
.top-actions, .tool-group { display: flex; align-items: center; gap: 6px; }
.top-actions { justify-self: end; }
.btn { min-height: 40px; padding: 8px 13px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); font-weight: 720; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.btn:hover { background: var(--surface-soft); }
.btn:disabled, .dock-button:disabled, .dock-page:disabled, .nav-item:disabled { opacity: .38; cursor: not-allowed; }
.btn:focus-visible, .brand:focus-visible, .section-tab:focus-visible, .nav-item:focus-visible, .dock-button:focus-visible, .dock-page:focus-visible, input:focus-visible, .text-link:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent), transparent 65%); outline-offset: 2px; }
.btn.icon { width: 42px; min-width: 42px; padding: 8px; }
.btn.text { font-size: 13px; }
.btn.primary { background: var(--accent); color: white; border-color: transparent; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.large { min-height: 48px; padding: 12px 22px; font-size: 16px; }
.btn.danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger), transparent 65%); }
.content { min-height: 0; overflow: hidden; }
.app-view { height: 100%; min-height: 0; }
.reader-view { display: grid; grid-template-rows: auto minmax(0, 1fr); }
.toolbar { min-height: 58px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; padding: 8px 14px; background: var(--surface-soft); border-bottom: 1px solid var(--border); z-index: 5; }
.reader-navigation { justify-self: start; }
.zoom-tools { justify-self: center; }
.advanced-tools { justify-self: end; }
.zoom-value { min-width: 64px; }
.page-control { display: flex; align-items: center; gap: 5px; color: var(--muted); white-space: nowrap; }
.page-control input { width: 58px; height: 40px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--text); text-align: center; font-weight: 760; }
.workspace { min-height: 0; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; position: relative; }
.viewer-area { min-width: 0; min-height: 0; position: relative; display: flex; align-items: stretch; justify-content: stretch; }
.welcome-card, .error-card { margin: auto; max-width: 720px; padding: 34px; text-align: center; }
.welcome-icon { margin-bottom: 6px; }
.eyebrow { margin: 0 0 8px !important; color: var(--accent) !important; font-size: 12px !important; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }
.welcome-card h1, .view-heading h1 { margin: 4px 0 12px; font-size: clamp(28px, 5vw, 44px); letter-spacing: -.035em; }
.welcome-card > p { color: var(--muted); font-size: 16px; line-height: 1.6; }
.feature-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 24px 0 14px; }
.feature-grid span { padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--muted); font-size: 13px; }
.feature-grid strong { display: block; color: var(--text); }
.text-link { padding: 8px; border: 0; background: transparent; color: var(--accent); font-weight: 750; cursor: pointer; }
.drop-hint { margin-top: 10px; font-size: 12px !important; }
.viewer { width: 100%; height: 100%; overflow: auto; background: linear-gradient(135deg, color-mix(in srgb, var(--bg), #000 3%), var(--bg)); overscroll-behavior: contain; scrollbar-color: var(--muted) transparent; scrollbar-width: thin; }
.canvas-stage { width: max-content; min-width: 100%; min-height: 100%; display: flex; justify-content: flex-start; align-items: flex-start; padding: 28px; touch-action: pan-x pan-y; }
.canvas-stage canvas { flex: 0 0 auto; max-width: none; margin-inline: auto; background: white; box-shadow: var(--shadow); transform: scale(1); transform-origin: center center; transition: transform 90ms ease-out; }
.canvas-stage canvas.pinching { transition: none; }
.loading { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); padding: 14px 20px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
.sidebar, .search-panel { width: 250px; display: none; overflow: auto; background: var(--surface); border-right: 1px solid var(--border); z-index: 4; }
.sidebar.open, .search-panel.open { display: block; }
.search-panel { width: 320px; border-right: 0; border-left: 1px solid var(--border); }
.panel-title { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; background: var(--surface); border-bottom: 1px solid var(--border); z-index: 2; }
.thumb-list { padding: 10px; }
.thumb-range { margin: 2px 0 10px; color: var(--muted); font-size: 12px; text-align: center; }
.thumb-batch { width: 100%; margin-bottom: 10px; }
.thumb { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 5px; margin-bottom: 9px; padding: 8px; border: 1px solid transparent; border-radius: 10px; background: transparent; color: var(--text); cursor: pointer; }
.thumb:hover, .thumb.active { background: var(--surface-soft); border-color: var(--border); }
.thumb canvas { max-width: 150px; background: white; box-shadow: 0 3px 10px rgba(0, 0, 0, .15); }
.thumb span { color: var(--muted); font-size: 12px; }
.search-form { display: flex; gap: 7px; padding: 12px; }
.search-form input { min-width: 0; flex: 1; padding: 10px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-soft); color: var(--text); }
.search-status { padding: 0 12px 8px; color: var(--muted); font-size: 13px; }
.search-results { padding: 0 10px 20px; }
.search-result { width: 100%; margin-bottom: 8px; padding: 10px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-soft); color: var(--text); text-align: left; cursor: pointer; }
.search-result small { display: block; margin-bottom: 3px; color: var(--muted); }
.search-result mark { padding: 0 2px; border-radius: 3px; background: #ffe58a; color: #242424; }
.error-card { display: flex; flex-direction: column; gap: 12px; }
.error-card span { color: var(--muted); }
.page-view { overflow: auto; padding: clamp(24px, 5vw, 54px); }
.view-heading { max-width: 760px; margin: 0 auto 24px; }
.view-heading > p:last-child { max-width: 680px; color: var(--muted); line-height: 1.6; }
.history-list, .about-grid { max-width: 960px; margin: auto; display: grid; gap: 14px; }
.history-item { display: grid; grid-template-columns: 1fr auto; gap: 14px; padding: 18px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); box-shadow: 0 8px 22px rgba(15, 23, 42, .05); }
.history-main { min-width: 0; }
.history-main h2 { margin: 0 0 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; }
.history-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; color: var(--muted); font-size: 12px; }
.history-actions, .card-actions { display: flex; align-items: center; gap: 7px; }
.empty-state { max-width: 960px; margin: auto; min-height: 230px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; border: 1px dashed var(--border); border-radius: 18px; color: var(--muted); text-align: center; }
.empty-state strong { color: var(--text); font-size: 18px; }
.history-footer { max-width: 960px; margin: 18px auto 0; display: flex; align-items: center; justify-content: space-between; gap: 14px; color: var(--muted); font-size: 12px; }
.about-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.info-card { padding: 22px; border: 1px solid var(--border); border-radius: 17px; background: var(--surface); line-height: 1.65; }
.info-card h2 { margin: 0 0 10px; font-size: 18px; }
.info-card p { margin: 0; color: var(--muted); }
.product-card { display: flex; gap: 16px; }
.product-card > div { flex: 1; }
.product-card dl { margin: 0; }
.product-card dl div { display: flex; justify-content: space-between; gap: 16px; padding: 5px 0; border-bottom: 1px solid var(--border); }
.product-card dt { color: var(--muted); }
.product-card dd { margin: 0; font-weight: 760; }
.card-actions { margin-top: 16px; flex-wrap: wrap; }
.reader-dock, .bottom-nav { display: none; }
.statusbar { min-height: 34px; display: flex; align-items: center; gap: 12px; padding: 6px 12px; background: var(--surface); border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; }
.statusbar #fileStatus { overflow: hidden; text-overflow: ellipsis; }
.statusbar #viewStatus { margin-left: auto; }
.badge { padding: 3px 7px; border: 1px solid #b8e7c9; border-radius: 999px; background: #dff7e8; color: #146c43; font-size: 10px; font-weight: 850; }
.toast { position: fixed; left: 50%; bottom: 52px; z-index: 30; max-width: min(90vw, 480px); transform: translateX(-50%); padding: 11px 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--text); color: var(--surface); box-shadow: var(--shadow); font-size: 13px; text-align: center; }
.default-dialog { width: min(90vw, 470px); padding: 26px; border: 1px solid var(--border); border-radius: 20px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); text-align: center; }
.default-dialog::backdrop { background: rgba(7, 12, 24, .62); backdrop-filter: blur(3px); }
.default-dialog h2 { margin: 7px 0 10px; font-size: 24px; letter-spacing: -.025em; }
.default-dialog > p:not(.eyebrow) { color: var(--muted); line-height: 1.6; }
.dialog-icon { margin-bottom: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.about-page { min-height: 100%; overflow: auto; padding: 32px; }
.about-card { max-width: 800px; margin: auto; padding: 32px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); line-height: 1.65; }

@media (max-width: 900px) {
  .topbar { grid-template-columns: 1fr auto; }
  .desktop-tabs { display: none; }
  .toolbar { display: flex; justify-content: space-between; gap: 6px; padding: 7px 10px; }
  .zoom-tools { display: none; }
  .desktop-page, .desktop-only { display: none !important; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .sidebar, .search-panel { position: absolute; inset: 0 auto 0 0; width: min(84vw, 330px); height: 100%; box-shadow: var(--shadow); }
  .search-panel { inset: 0 0 0 auto; }
  .statusbar { display: none; }
  .app-shell { grid-template-rows: auto minmax(0, 1fr) auto auto; }
  .reader-dock { min-height: 62px; display: grid; grid-template-columns: 1fr 1fr auto 1fr 1fr; align-items: stretch; padding: 5px max(6px, env(safe-area-inset-right)) 5px max(6px, env(safe-area-inset-left)); border-top: 1px solid var(--border); background: var(--surface); }
  body:not([data-view="reader"]) .reader-dock { display: none; }
  .dock-button, .dock-page { min-width: 0; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
  .dock-button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: 10px; font-weight: 720; }
  .dock-button svg { width: 22px; height: 22px; }
  .dock-page { align-self: center; min-width: 60px; min-height: 44px; height: 44px; padding: 0 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-soft); color: var(--text); font-size: 11px; font-weight: 820; }
  .bottom-nav { min-height: 66px; display: grid; grid-template-columns: repeat(4, 1fr); padding: 4px max(5px, env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom)) max(5px, env(safe-area-inset-left)); border-top: 1px solid var(--border); background: var(--surface); }
  .nav-item { min-width: 0; min-height: 44px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: 10px; font-weight: 760; cursor: pointer; }
  .nav-item svg { width: 22px; height: 22px; }
  .nav-item.active { background: var(--accent-soft); color: var(--accent); }
  .canvas-stage { padding: 14px 8px; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
  .about-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .topbar { min-height: 58px; gap: 8px; padding: 8px 10px; }
  .brand { gap: 7px; }
  .brand img { width: 32px; height: 32px; }
  .brand small { max-width: 145px; }
  .top-actions { gap: 5px; }
  .top-actions .btn.primary { min-height: 44px; padding: 8px 11px; font-size: 13px; }
  .toolbar { min-height: 54px; }
  .toolbar .btn.icon { width: 44px; min-width: 44px; min-height: 44px; }
  .page-control input { width: 48px; }
  .welcome-card { padding: 22px 18px; }
  .welcome-card h1 { font-size: 30px; }
  .welcome-card > p { font-size: 15px; }
  .feature-grid { grid-template-columns: 1fr; margin-top: 18px; }
  .feature-grid span { padding: 9px 12px; }
  .feature-grid strong { display: inline; }
  .page-view { padding: 24px 16px; }
  .view-heading h1 { font-size: 32px; }
  .history-item { grid-template-columns: 1fr; padding: 15px; }
  .history-actions { justify-content: flex-end; }
  .history-footer { align-items: stretch; flex-direction: column; }
  .product-card { align-items: flex-start; }
}

@media (max-width: 370px) {
  .brand small { display: none; }
  .advanced-tools #rotateBtn { display: none; }
  .reader-dock { grid-template-columns: 1fr 1fr auto 1fr 1fr; }
  .dock-page { min-width: 52px; padding: 0 5px; }
}
