/* Shared reference finish. Layout/gestures remain in their owning stylesheets. */
:root {
    --bg: #0d1114;
    --bg-2: #151a1e;
    --panel: #1b2025;
    --panel-solid: #12171b;
    --panel-strong: #252b30;
    --sidebar-bg: #101519;
    --text: #f3f1ee;
    --muted: #aaa8a6;
    --line: #43484e;
    --sidebar-line: #363c42;
    --accent: #ff6555;
    --accent-2: #e84538;
    --accent-soft: #fa59482b;
    --focus-ring: #ff8575;
    --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.76' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Cpath fill='%23fff' opacity='.035' filter='url(%23n)' d='M0 0h160v160H0z'/%3E%3C/svg%3E");
    --surface-gradient: var(--grain), linear-gradient(125deg, #23292e 0%, #11161a 48%, #1b2025 100%);
    --surface-shadow: inset 0 1px 1px #ffffff0c, inset 0 -1px 2px #0005, 0 8px 24px #0003;
    --selected-surface: var(--grain), radial-gradient(ellipse at 50% 0, #ff78622b, transparent 75%), linear-gradient(130deg, #542c2b, #301e20 55%, #4b2928);
}
html[data-theme="light"] {
    --bg: #eef0f2;
    --bg-2: #f8f9fa;
    --panel: #e8ebee;
    --panel-solid: #fafbfc;
    --panel-strong: #dce1e5;
    --sidebar-bg: #f1f3f5;
    --text: #282c30;
    --muted: #616970;
    --line: #b7bec5;
    --sidebar-line: #c5cbd1;
    --accent: #c83d2e;
    --accent-2: #a92c22;
    --accent-soft: #d44e3820;
    --focus-ring: #b83528;
    --surface-gradient: var(--grain), linear-gradient(125deg, #fff, #edf0f3 55%, #f8f9fa);
    --surface-shadow: inset 0 1px 1px #fff, inset 0 -1px 2px #23303d13, 0 8px 24px #23303d10;
    --selected-surface: var(--grain), linear-gradient(130deg, #f9d7cc, #f1e2da 55%, #f3cdc1);
}
html, html[data-theme="light"] { background: var(--bg); }
html body.app-page {
    background: var(--grain), radial-gradient(ellipse at 28% 12%, #ffffff05, transparent 65%), var(--bg);
    color: var(--text);
}
html body.app-page .app-frame, html body.app-page .content-frame { background: transparent; }
html body.app-page .site-sidebar {
    background: var(--surface-gradient);
    border-color: var(--sidebar-line);
    box-shadow: inset -1px 0 #ffffff05;
}
html body.app-page :is(.simple-card, .auth-card, .comments-panel, .full-height-card, .private-status-panel,
    .quota-inline-offer, .register-offer, .phase5g-panel, .phase5g-status-card, .phase5g-history-card,
    .phase5g-submit-bar, .detail-cover-card, .account-menu, .auth-dialog, .library-delete-dialog,
    .ui-dialog, .modal-card, .account-options, .library-guest-state) {
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface-gradient);
    color: var(--text);
    box-shadow: var(--surface-shadow);
}
html body.app-page :is(.home-drop-zone, .mangayaku-reference-drop, .phase5g-file-picker,
    .phase5g-file-order li, .phase5g-language-lock, .phase5g-stage-list > li, .phase5g-result-card,
    .detail-preview-frame, .detail-translation-panel.is-visible, .modal-placeholder-card) {
    border-color: var(--line);
    border-radius: 14px;
    background: var(--surface-gradient);
    box-shadow: var(--surface-shadow);
}
html body.app-page :is(.home-drop-zone, .mangayaku-reference-drop):is(:hover, .is-dragging, .dragging) {
    border-color: var(--accent);
    background: var(--selected-surface);
}
html body.app-page :is(.home-drop-zone, .mangayaku-reference-drop) :is(strong, span) { color: var(--text); }
html body.app-page :is(.home-drop-zone, .mangayaku-reference-drop) small { color: var(--muted); }
html body.app-page :is(.stack-form, .mangayaku-title-field, .phase5g-basics) :is(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]), textarea, select) {
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--surface-gradient);
    color: var(--text);
    box-shadow: inset 0 2px 5px #0002, 0 1px #ffffff08;
}
html body.app-page :is(input, textarea, select):focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}
html body.app-page .library-search input:focus-visible { outline: none; box-shadow: none; }
/* A search input has no surface of its own; the pill owns clipping and focus. */
html body.app-page .library-search { overflow: hidden; border-color: var(--line); }
html body.app-page .library-search input {
    appearance: none; -webkit-appearance: none;
    height: 100%; min-height: 0; border: 0; border-radius: 0;
    background: transparent; box-shadow: none;
}
html body.app-page .library-search:focus-within { border-color: var(--focus-ring); }
html body.app-page .instant-upload-form .home-drop-zone {
    border: 1px solid #f06b32;
    box-shadow: var(--surface-shadow), inset 0 0 0 1px #f06b321a;
}
html body.app-page .home-drop-zone:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 3px; }
html body.app-page :is(.button, .top-action, button.secondary, .account-menu-close, .auth-dialog-close, .modal-close) {
    border: 1px solid var(--line);
    background: var(--surface-gradient);
    color: var(--text);
    box-shadow: var(--surface-shadow);
}
html body.app-page :is(.button.primary, .top-action.primary, .stack-form button[type="submit"], .phase5g-submit-bar button[type="submit"]) {
    border-color: var(--accent);
    background: var(--grain), linear-gradient(135deg, color-mix(in srgb, var(--theme-button) 80%, white), var(--theme-button));
    color: var(--theme-button-text);
    box-shadow: inset 0 1px #ffffff45, 0 4px 18px color-mix(in srgb, var(--accent) 20%, transparent);
}
html body.app-page :is(.sidebar-link, .sidebar-account, .account-options .account-tab, .account-menu .account-tab, .auth-dialog-tabs button) {
    border: 1px solid transparent;
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
    box-shadow: none;
}
html body.app-page :is(.sidebar-link, .sidebar-account, .account-tab):hover { color: var(--text); border-color: var(--line); }
html body.app-page :is(.sidebar-link.active, .account-tab.active, .auth-dialog-tabs button.active),
html body.app-page :is(.account-options, .account-menu) .account-tab.active,
html body.app-page .mangayaku-profile-options .phase5g-profile-card input:checked + span {
    border-color: var(--accent);
    background: var(--selected-surface);
    color: var(--accent);
    box-shadow: inset 0 1px #ffffff1c, inset 0 0 12px #ff6c4e0c, 0 0 16px #ff5a3d12;
}
html body.app-page .mangayaku-profile-options .phase5g-profile-card > span {
    border-radius: 12px;
    background: var(--surface-gradient);
    color: var(--text);
}
html body.app-page :is(.account-menu-tabs, .auth-dialog-tabs, .auth-dialog-image) { background: var(--panel-solid); border-color: var(--line); }
html body.app-page .auth-dialog::after { background: var(--line); animation: none; }
html body.app-page .auth-dialog-atmosphere { background: radial-gradient(ellipse at 20% 15%, #ffffff08, transparent 65%); }
html body.app-page .auth-dialog-particle { opacity: .1; animation: none; box-shadow: none; }
html body.app-page :is(.phase5g-state, .status-pill) { background: var(--panel-solid); border-color: var(--line); color: var(--text); }
html body.app-page :is(.eyebrow, .phase5g-eyebrow, .auth-switch a) { color: var(--accent); }
html body.app-page :is(.account-panel button, .mangayaku-upload-actions button, .library-delete-actions button) {
    border: 1px solid var(--line); background: var(--surface-gradient); color: var(--text); box-shadow: var(--surface-shadow);
}
html body.app-page :is(.account-panel button[type="submit"], .mangayaku-upload-actions button[type="submit"], [data-library-delete-confirm]) {
    border-color: var(--accent); background: var(--selected-surface); color: var(--accent);
}
html body.app-page :is(.account-tab, .auth-dialog-tabs button, .stack-form button, .sidebar-link, .sidebar-account) { font-weight: 600; }
html body.app-page .header-theme .theme-switch {
    width: 76px; height: 40px;
    border: 1px solid var(--line);
    background: var(--surface-gradient);
    box-shadow: var(--surface-shadow);
    overflow: visible;
}
html body.app-page .header-theme .theme-switch-thumb {
    width: 32px; height: 32px; top: 3px; left: 3px;
    transform: translateX(36px);
    border: 1px solid #ff9c80;
    background: var(--grain), linear-gradient(140deg, #ff785b, #ec4435);
    box-shadow: inset 0 1px 2px #ffffff40, 0 0 14px #ff5d4255;
}
html[data-theme="light"] body.app-page .header-theme .theme-switch-thumb { transform: translateX(0); }
html body.app-page .header-theme .theme-icon { color: var(--muted); }
html:not([data-theme="light"]) body.app-page .header-theme .theme-icon-moon,
html[data-theme="light"] body.app-page .header-theme .theme-icon-sun { color: #fff; }
.nav-symbol { width: 25px; height: 25px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.reference-brand { display: none; }
html body.app-page.reader-page-body :is(.content-frame, .page-shell, .reader-viewer-stage, .result-viewer-stage) {
    background: var(--grain), radial-gradient(ellipse at 50% 0, #ffffff05, transparent 75%), var(--bg);
}
html body.app-page.reader-page-body :is(.reader-page-zone span, .result-viewer-zone span, .viewer-page-status, .reader-stream-status, .reader-sidebar-toggle span),
html body.app-page :is(.processing-reader-toolbar a, .processing-reader-title, .processing-reader-error) {
    border-color: var(--line); background: var(--surface-gradient); color: var(--text); box-shadow: var(--surface-shadow);
}
html body.app-page.reader-page-body :is(.reader-current-page img, .protected-page-image) { border-color: var(--line); box-shadow: 0 18px 48px #0005; }
@media (min-width: 1025px) {
    html body.app-page .sidebar-link { min-height: 52px; padding: 12px; }
}
@media (max-width: 1024px) {
    :root, html[data-theme="light"] { --mobile-header-h: 124px; --mobile-nav-h: 72px; }
    /* Text fields retain their border and caret without a lingering outer box. */
    html body.app-page :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]), textarea, select):focus-visible,
    html body.app-page .library-search:focus-within { outline: none; }
    html body.app-page:not(.reader-page-body) .site-sidebar { justify-content: flex-start; border: 0; background: transparent; box-shadow: none; padding-inline: 12px 104px; }
    html body.app-page:not(.reader-page-body) .sidebar-brand { width: 100%; height: 100%; min-height: 0; }
    html body.app-page:not(.reader-page-body) .sidebar-brand > .sidebar-logo { display: none; }
    .reference-brand { display: grid; grid-template-columns: 30% minmax(0, 1fr); align-items: center; gap: 14px; width: 100%; max-width: 420px; }
    html body.app-page.reader-page-body .reference-brand { display: none; }
    .reference-brand-mark { display: block; position: relative; aspect-ratio: 1; overflow: hidden; }
    .reference-brand-mark img { position: absolute; width: 145%; max-width: none; height: auto; left: 0; top: 0; transform: translate(-15%, -3%); }
    .reference-brand-type { display: grid; gap: 9px; }
    .reference-brand-wordmark { display: block; position: relative; aspect-ratio: 4.2; overflow: hidden; }
    .reference-brand-wordmark img { position: absolute; width: 121%; max-width: none; height: auto; left: -19%; top: 0; transform: translateY(-73%); }
    html body.app-page .top-actions { top: calc(env(safe-area-inset-top) + 42px); right: 12px; }
    html body.app-page.auth-dialog-open .top-actions .top-action { display: none; }
    html body.app-page .mobile-tab-bar { border: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; background: var(--surface-gradient); box-shadow: 0 -8px 30px #0002; padding: 0; gap: 0; }
    html body.app-page .mobile-tab { height: 100%; border: 0; border-radius: 0; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); font-size: 12px; font-weight: 600; grid-template-rows: 30px auto; gap: 3px; }
    html body.app-page .mobile-tab:first-child { border-top-left-radius: 16px; padding-left: max(4px, env(safe-area-inset-left)); }
    html body.app-page .mobile-tab:last-child { border-top-right-radius: 16px; padding-right: max(4px, env(safe-area-inset-right)); }
    html body.app-page .mobile-tab.active { background: var(--selected-surface); color: var(--accent); box-shadow: none; }
    html body.app-page .mobile-tab .nav-symbol { width: 27px; height: 27px; }
    html body.app-page .account-options { padding: 12px; min-height: 0; }
}
@media (max-width: 360px) {
    html body.app-page:not(.reader-page-body) .site-sidebar { padding-inline: 8px 100px; }
    html body.app-page .top-actions { right: 8px; }
    .reference-brand { gap: 12px; }
}
