:root {
  color-scheme: light;
  --background: #eef1f4;
  --surface: #fff;
  --surface-soft: #f5f7f9;
  --text: #222b36;
  --muted: #5f6c7b;
  --border: #d4dce4;
  --accent: #1768aa;
  --accent-hover: #10558e;
  --accent-soft: #e8f1f9;
  --accent-text: #fff;
  --focus: #1883d8;
  --error: #9b2932;
  --error-soft: #fff0f1;
  --success: #247554;
  --shadow: 0 3px 16px rgb(24 42 60 / 4%);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --background: #171c23;
  --surface: #212831;
  --surface-soft: #29323d;
  --text: #e7edf3;
  --muted: #abb8c7;
  --border: #3e4958;
  --accent: #77bfff;
  --accent-hover: #9cd0ff;
  --accent-soft: #263d53;
  --accent-text: #142333;
  --focus: #77bfff;
  --error: #ffb4bc;
  --error-soft: #422a31;
  --success: #7bd7ac;
  --shadow: none;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    color-scheme: dark;
    --background: #171c23;
    --surface: #212831;
    --surface-soft: #29323d;
    --text: #e7edf3;
    --muted: #abb8c7;
    --border: #3e4958;
    --accent: #77bfff;
    --accent-hover: #9cd0ff;
    --accent-soft: #263d53;
    --accent-text: #142333;
    --focus: #77bfff;
    --error: #ffb4bc;
    --error-soft: #422a31;
    --success: #7bd7ac;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--background); color: var(--text); font: 15px/1.6 "Segoe UI Variable", "Segoe UI", "Microsoft YaHei UI", system-ui, sans-serif; }
button, input, select { font: inherit; }
button, select, input[type="checkbox"] { cursor: pointer; }
button, input, select, a { -webkit-tap-highlight-color: transparent; }
button, input, select { max-width: 100%; }
button:disabled, input:disabled, select:disabled { cursor: not-allowed; opacity: .55; }
button, a, input, select, summary { outline-offset: 3px; }
:focus-visible { outline: 2px solid var(--focus); }
a { color: var(--accent); text-underline-offset: .18em; }
a:hover { color: var(--accent-hover); }
h1, h2, h3, p { margin: 0; }
svg { display: block; }
.app-shell { width: min(1120px, calc(100% - 48px)); margin: 0 auto; }
.app-header { min-height: 98px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 13px; min-width: 0; }
.brand-mark { width: 43px; height: 43px; display: grid; place-items: center; background: var(--accent-soft); border: 1px solid var(--border); border-radius: 11px; color: var(--accent); }
.brand-mark svg { width: 27px; height: 27px; }
h1 { font-size: 24px; line-height: 1.25; letter-spacing: -.6px; font-weight: 650; }
.edition { margin-top: 4px; font-size: 12px; color: var(--muted); }
.theme-control { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 13px; flex-shrink: 0; }
.theme-control select { min-height: 36px; padding: 5px 29px 5px 10px; }
.intro { padding: 29px 0 23px; }
.intro h2 { font-size: clamp(21px, 2.8vw, 27px); line-height: 1.45; font-weight: 650; }
.intro p { margin-top: 7px; color: var(--muted); }
.engine-bar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 17px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 20px; }
.engine-copy { display: flex; align-items: flex-start; gap: 12px; min-width: 0; }
.engine-copy > div { min-width: 0; }
.engine-copy strong { font-size: 14px; font-weight: 600; }
.engine-copy p { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.status-dot { flex: 0 0 8px; width: 8px; height: 8px; background: var(--muted); border-radius: 50%; margin-top: 8px; }
.status-dot[data-state="ready"], .status-dot[data-state="done"] { background: var(--success); }
.status-dot[data-state="loading"], .status-dot[data-state="converting"] { background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); animation: pulse 1.4s ease-in-out infinite; }
.status-dot[data-state="error"] { background: var(--error); }
.workspace { display: grid; grid-template-columns: minmax(290px, 350px) minmax(0, 1fr); gap: 20px; align-items: start; }
.panel { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.panel-heading { display: flex; align-items: center; gap: 10px; padding: 19px 21px 17px; border-bottom: 1px solid var(--border); }
.panel-heading h2 { font-size: 16px; font-weight: 650; }
.step-number { width: 23px; height: 23px; line-height: 23px; background: var(--surface-soft); border: 1px solid var(--border); color: var(--muted); font-size: 12px; font-weight: 600; text-align: center; border-radius: 6px; }
form { padding: 20px; }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.field-group { margin-bottom: 20px; min-width: 0; }
.field-title { display: block; font-size: 13px; font-weight: 600; margin-bottom: 7px; }
.optional { margin-left: 5px; color: var(--muted); font-size: 12px; font-weight: 400; }
input[type="text"], input[type="number"], select { width: 100%; min-height: 40px; border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px; background: var(--surface); color: var(--text); }
.theme-control select { width: auto; }
input[type="file"] { display: block; width: 100%; min-height: 39px; min-width: 0; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-soft); font-size: 12px; overflow: hidden; color: var(--muted); }
input[type="file"]::file-selector-button { min-height: 37px; margin-right: 9px; padding: 6px 11px; color: var(--text); background: var(--surface); border: 0; border-right: 1px solid var(--border); font: inherit; cursor: pointer; }
.file-description, .field-help { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.file-description { margin: 7px 0 10px; }
.file-limit { margin: -4px 0 10px; }
.field-help { margin-top: 5px; }
.font-group > .field-help { margin: -1px 0 9px; }
.font-group { padding-top: 17px; border-top: 1px solid var(--border); }
.font-selection { display: flex; align-items: start; gap: 8px; }
.font-selection .file-description { flex: 1; min-width: 0; margin-bottom: 0; }
.font-selection .text-button { margin-top: 1px; flex-shrink: 0; padding-right: 0; font-size: 12px; }
.options-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.checkbox-field { display: flex; align-items: flex-start; gap: 8px; margin: 2px 0 20px; font-size: 13px; }
.checkbox-field input { width: 16px; height: 16px; margin: 3px 0 0; accent-color: var(--accent); flex-shrink: 0; }
.action-row { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }
.button { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 14px; border: 1px solid transparent; border-radius: 6px; font-size: 13px; font-weight: 600; line-height: 1.4; text-decoration: none; text-align: center; transition: background .12s ease, border-color .12s ease; }
.button.primary { background: var(--accent); color: var(--accent-text); }
.button.primary:hover:not(:disabled) { background: var(--accent-hover); color: var(--accent-text); }
.button.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.button.secondary:hover:not(:disabled) { background: var(--surface-soft); border-color: var(--muted); color: var(--text); }
.button.small { min-height: 33px; font-size: 12px; padding: 6px 10px; }
.text-button { min-height: 36px; padding: 6px 7px; background: none; border: 0; color: var(--muted); font-size: 13px; }
.text-button:hover:not(:disabled) { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.action-hint { margin-top: 10px; font-size: 12px; color: var(--muted); }
.scope-details { margin: 0 20px 19px; padding-top: 13px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; }
.scope-details summary { cursor: pointer; font-weight: 600; }
.scope-details p { margin-top: 8px; }
.results-panel { overflow: hidden; }
.result-count { margin-left: auto; font-size: 12px; color: var(--muted); }
.results-list { min-height: 330px; }
.empty-state { min-height: 365px; padding: 55px 24px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--muted); }
.empty-state svg { width: 54px; height: 54px; margin-bottom: 20px; color: var(--muted); opacity: .65; }
.empty-state h3 { margin-bottom: 8px; color: var(--text); font-size: 16px; font-weight: 600; }
.empty-state p { font-size: 13px; max-width: 310px; }
.results-note { padding: 13px 20px; border-top: 1px solid var(--border); background: var(--surface-soft); font-size: 12px; color: var(--muted); }
.page-result { padding: 20px; min-width: 0; }
.page-result + .page-result { border-top: 1px solid var(--border); }
.page-result-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-result-header h3 { font-size: 15px; font-weight: 650; }
.page-stats { font-size: 12px; color: var(--muted); margin-top: 3px; }
.download-links { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.report-link { font-size: 12px; }
.preview-section { margin-top: 17px; }
.preview-tabs { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--surface-soft); border: 1px solid var(--border); border-radius: 7px; width: fit-content; max-width: 100%; }
.preview-tab { min-height: 32px; padding: 5px 12px; border: 1px solid transparent; border-radius: 4px; background: transparent; color: var(--muted); font-size: 12px; }
.preview-tab[aria-pressed="true"] { background: var(--surface); color: var(--accent); border-color: var(--border); font-weight: 600; }
.preview-figure { margin: 12px 0 0; }
.preview-image-wrap { display: grid; place-items: center; min-height: 160px; max-height: 560px; overflow: auto; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.preview-image-wrap img { display: block; max-width: 100%; width: auto; height: auto; max-height: 540px; object-fit: contain; }
.preview-figure figcaption { display: flex; align-items: start; justify-content: space-between; gap: 12px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.preview-figure figcaption a { flex-shrink: 0; }
.preview-unavailable { margin-top: 16px; padding: 15px; border-radius: 6px; background: var(--surface-soft); color: var(--muted); font-size: 13px; }
.warnings { margin-top: 16px; padding: 12px 14px; border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 5px; background: var(--surface-soft); }
.warnings h4 { margin: 0 0 7px; font-size: 13px; font-weight: 600; }
.warnings ul { margin: 0; padding-left: 18px; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.warnings li + li { margin-top: 6px; }
.error-message { margin: -6px 0 20px; padding: 12px 16px; border: 1px solid var(--error); border-radius: 7px; color: var(--error); background: var(--error-soft); font-size: 13px; overflow-wrap: anywhere; }
.app-footer { display: flex; justify-content: space-between; gap: 14px; padding: 23px 0 30px; font-size: 12px; color: var(--muted); }
.skip-link { position: absolute; z-index: 10; top: 0; left: 12px; padding: 8px 12px; transform: translateY(-110%); background: var(--surface); border: 1px solid var(--accent); }
.skip-link:focus { transform: translateY(0); }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.noscript { margin: 20px; color: var(--error); }
@keyframes pulse { 50% { opacity: .45; } }

@media (max-width: 820px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .results-list { min-height: 240px; }
  .empty-state { min-height: 240px; padding: 35px 20px; }
}

@media (max-width: 480px) {
  body { font-size: 14px; }
  .app-shell { width: calc(100% - 28px); }
  .app-header { min-height: 86px; gap: 10px; }
  .brand { gap: 9px; }
  .brand-mark { width: 35px; height: 35px; border-radius: 8px; }
  .brand-mark svg { width: 24px; height: 24px; }
  h1 { font-size: 21px; }
  .edition { font-size: 11px; }
  .theme-control > span { display: none; }
  .theme-control select { width: 99px; font-size: 12px; padding-right: 17px; }
  .intro { padding: 23px 0 19px; }
  .intro p { font-size: 13px; }
  .engine-bar { flex-wrap: wrap; padding: 12px 14px; }
  .engine-bar > .button { margin-left: 20px; min-height: 34px; padding: 6px 10px; }
  .panel-heading { padding: 16px; }
  form, .page-result { padding: 16px; }
  .scope-details { margin-right: 16px; margin-left: 16px; }
  .results-note { padding: 12px 16px; }
  .page-result-header { align-items: flex-start; }
  .preview-tab { padding-right: 10px; padding-left: 10px; }
  .app-footer { flex-direction: column; gap: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
