/* ============================================================
   AI Text Humanizer — Dark Neumorphism
   Complete redesign with generous spacing
   ============================================================ */

:root {
    /* Surface */
    --surface:        #242426;
    --surface-raised: #2a2a2d;
    --surface-sunken: #1f1f21;

    /* Shadows */
    --shadow-dark:  #171718;
    --shadow-light: #313135;

    /* Text */
    --text-strong:  #f0f1ec;
    --text-body:    #c8cabf;
    --text-muted:   #8a8c82;

    /* Accent — muted olive */
    --accent:        #879963;
    --accent-strong: #9aad74;
    --accent-soft:   rgba(135, 153, 99, 0.14);
    --on-accent:     #1b1c18;

    /* Feedback */
    --positive: #879963;
    --danger:   #d1495b;

    /* Elevation */
    --elev-1: 6px 6px 12px var(--shadow-dark), -6px -6px 12px var(--shadow-light);
    --elev-2: 9px 9px 18px var(--shadow-dark), -9px -9px 18px var(--shadow-light);
    --elev-3: 14px 14px 28px var(--shadow-dark), -14px -14px 28px var(--shadow-light);
    --inset-1: inset 4px 4px 8px var(--shadow-dark), inset -4px -4px 8px var(--shadow-light);
    --inset-2: inset 6px 6px 12px var(--shadow-dark), inset -6px -6px 12px var(--shadow-light);

    /* Radius */
    --r-lg: 20px;
    --r-md: 16px;
    --r-sm: 14px;
    --r-xs: 10px;
    --r-pill: 999px;

    /* Fonts */
    --font-display: 'Poppins', system-ui, sans-serif;
    --font-body:    'Inter', system-ui, sans-serif;

    /* Motion */
    --ease-soft: cubic-bezier(0.4, 0, 0.2, 1);
    --dur-fast: 120ms;
    --dur-base: 200ms;
    --dur-slow: 360ms;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-body);
    background: var(--surface);
    min-height: 100%;
    padding: 32px 24px 64px;
}

.sr-only {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0,0,0,0); border: 0;
}

/* ============================================================
   Utility: neumorphic layers
   ============================================================ */
.neu-raised {
    background: var(--surface);
    border-radius: var(--r-lg);
    box-shadow: var(--elev-2);
}
.neu-inset {
    background: var(--surface-sunken);
    border-radius: var(--r-md);
    box-shadow: var(--inset-1);
}

/* ============================================================
   Error banner
   ============================================================ */
.error-banner {
    position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
    z-index: 900;
    background: var(--surface-raised);
    box-shadow: var(--elev-3);
    border-radius: var(--r-sm);
    color: var(--danger);
    font-family: var(--font-body);
    font-size: .875rem;
    font-weight: 500;
    padding: 14px 24px;
    display: flex; align-items: center; gap: 16px;
    max-width: 560px; width: calc(100% - 48px);
}
.error-banner[hidden] { display: none; }
.error-banner button {
    background: none; border: none; color: var(--text-muted);
    font-size: 1.2rem; cursor: pointer; padding: 4px;
    border-radius: var(--r-xs);
}
.error-banner button:hover { color: var(--danger); }
.error-banner button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ============================================================
   App frame
   ============================================================ */
.app-frame {
    max-width: 1360px;
    margin: 0 auto;
    background: var(--surface);
    border-radius: var(--r-lg);
    box-shadow: var(--elev-3);
    padding: 40px 48px;
}

/* ============================================================
   Header
   ============================================================ */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 32px;
}
.header-left {
    display: flex;
    align-items: baseline;
    gap: 16px;
}
.logo {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-strong);
    letter-spacing: -0.01em;
}
.logo-subtitle {
    font-family: var(--font-body);
    font-size: .8125rem;
    color: var(--text-muted);
    font-weight: 400;
}

/* Badge / LM status */
.badge {
    font-family: var(--font-body);
    font-size: .8125rem;
    font-weight: 500;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-raised);
    border-radius: var(--r-pill);
    padding: 8px 16px;
    box-shadow: var(--elev-1);
}
.badge-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    display: inline-block;
    background: var(--text-muted);
}
.badge.online { color: var(--accent); }
.badge.online .badge-dot { background: var(--accent); }
.badge.offline .badge-dot {
    background: none;
    border: 2px solid var(--text-muted);
}

/* Header actions */
.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}
.header-divider {
    width: 1px;
    height: 28px;
    background: var(--surface-sunken);
    margin: 0 4px;
}

/* Icon button */
.icon-btn {
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border: none;
    border-radius: var(--r-sm);
    box-shadow: var(--elev-1);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.15rem;
    transition: all var(--dur-base) var(--ease-soft);
    flex-shrink: 0;
}
.icon-btn:hover {
    color: var(--accent);
    box-shadow: var(--elev-2);
    transform: translateY(-1px);
}
.icon-btn:active {
    box-shadow: var(--inset-1);
    transform: translateY(0);
}
.icon-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.icon-btn.active {
    color: var(--accent);
    box-shadow: var(--inset-1);
}

/* Small icon button (inline use) */
.icon-btn-sm {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border: none;
    border-radius: var(--r-xs);
    box-shadow: var(--elev-1);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    transition: all var(--dur-base) var(--ease-soft);
    flex-shrink: 0;
}
.icon-btn-sm:hover {
    color: var(--accent);
    box-shadow: var(--elev-2);
}
.icon-btn-sm:active {
    box-shadow: var(--inset-1);
}
.icon-btn-sm:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ============================================================
   Mode row (toggle + profile)
   ============================================================ */
.mode-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
}
.mode-pill {
    display: inline-flex;
    background: var(--surface-sunken);
    border-radius: var(--r-pill);
    box-shadow: var(--inset-1);
    padding: 4px;
}
.mode-btn {
    font-family: var(--font-body);
    font-size: .875rem;
    font-weight: 600;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: var(--r-pill);
    padding: 10px 28px;
    cursor: pointer;
    transition: all var(--dur-base) var(--ease-soft);
}
.mode-btn:hover { color: var(--text-body); }
.mode-btn.active {
    background: var(--surface);
    color: var(--accent);
    box-shadow: var(--elev-1);
}
.mode-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.panel-section[hidden] { display: none; }

/* ============================================================
   Editors
   ============================================================ */
.editors {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 28px;
    margin-bottom: 28px;
}
.editor-card {
    padding: 28px;
    display: flex;
    flex-direction: column;
    min-height: 420px;
}
.editor-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    min-height: 32px;
}
.editor-top-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.editor-top-right {
    display: flex;
    align-items: center;
    gap: 10px;
}
.eyebrow {
    font-family: var(--font-display);
    font-size: .75rem;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--accent);
}

/* Text stats */
.text-stats {
    font-family: var(--font-body);
    font-size: .75rem;
    color: var(--text-muted);
    font-weight: 400;
}

/* Score pill */
.score-pill {
    font-family: var(--font-display);
    font-size: .8125rem;
    font-weight: 600;
    letter-spacing: .04em;
    border-radius: var(--r-pill);
    padding: 4px 14px;
}
.score-pill--before {
    color: var(--danger);
    background: rgba(209, 73, 91, 0.12);
}
.score-pill--after {
    color: var(--positive);
    background: var(--accent-soft);
}

/* Rhythm strip */
.rhythm-strip {
    width: 100%;
    height: 48px;
    margin-bottom: 14px;
    overflow: visible;
}
.rhythm-strip path {
    fill: none;
    stroke: var(--text-muted);
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.rhythm-strip--animated path {
    animation: draw-line .6s ease forwards;
}
@media (prefers-reduced-motion: reduce) {
    .rhythm-strip--animated path { animation: none; }
}
@keyframes draw-line {
    from { stroke-dashoffset: var(--dash-length); }
    to   { stroke-dashoffset: 0; }
}

/* Input textarea */
.textarea-wrap {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--surface-sunken);
    border-radius: var(--r-md);
    box-shadow: var(--inset-1);
    padding: 4px;
}
.textarea-wrap:focus-within {
    box-shadow: var(--inset-1), 0 0 0 2px var(--accent);
}

#input-text {
    font-family: var(--font-body);
    font-size: .9375rem;
    line-height: 1.7;
    color: var(--text-strong);
    background: transparent;
    border: none;
    border-radius: var(--r-sm);
    padding: 14px 18px;
    resize: vertical;
    flex: 1;
    min-height: 0;
    width: 100%;
    outline: none;
}
#input-text::placeholder {
    color: var(--text-muted);
}

.upload-fab {
    position: absolute;
    top: 14px;
    right: 14px;
}
.upload-fab span {
    font-family: var(--font-body);
    font-size: .75rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--surface);
    border-radius: var(--r-xs);
    box-shadow: var(--elev-1);
    padding: 7px 14px;
    cursor: pointer;
    transition: color var(--dur-fast), box-shadow var(--dur-fast);
    display: inline-block;
}
.upload-fab span:hover {
    color: var(--accent);
    box-shadow: var(--elev-2);
}
.file-tag {
    font-family: var(--font-body);
    font-size: .75rem;
    font-weight: 500;
    color: var(--accent);
    padding: 4px 18px 0;
}
.file-tag[hidden] { display: none; }

.textarea-wrap.dragover {
    box-shadow: var(--inset-1), 0 0 0 2px var(--accent);
}

/* Output */
.output-box {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 4px;
}
.output-text {
    font-family: var(--font-body);
    font-size: .9375rem;
    line-height: 1.7;
    color: var(--text-muted);
    padding: 14px 18px;
    flex: 1;
    min-height: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-y: auto;
}
.output-text.populated {
    color: var(--text-strong);
}
.output-placeholder {
    font-style: italic;
    color: var(--text-muted);
}

/* Edit marks */
.diff-del {
    color: var(--danger);
    text-decoration: line-through;
    text-decoration-color: var(--danger);
}
.diff-ins {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-color: var(--accent-strong);
    text-underline-offset: 3px;
}

/* Output footer */
.output-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 14px;
}
.output-footer[hidden] { display: none; }
.output-actions { display: flex; gap: 12px; align-items: center; }

/* ============================================================
   Export dropdown
   ============================================================ */
.export-dropdown {
    position: relative;
}
.export-toggle {
    cursor: pointer;
}
.export-menu {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 8px;
    background: var(--surface);
    border-radius: var(--r-md);
    box-shadow: var(--elev-3);
    padding: 6px;
    min-width: 180px;
    opacity: 0;
    pointer-events: none;
    transform: translateY(4px);
    transition: all var(--dur-base) var(--ease-soft);
    z-index: 100;
}
.export-dropdown.open .export-menu {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}
.export-option {
    display: block;
    width: 100%;
    text-align: left;
    font-family: var(--font-body);
    font-size: .8125rem;
    font-weight: 500;
    color: var(--text-body);
    background: none;
    border: none;
    border-radius: var(--r-xs);
    padding: 10px 14px;
    cursor: pointer;
    transition: all var(--dur-fast);
}
.export-option:hover {
    color: var(--accent);
    background: var(--accent-soft);
}
.export-option:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

/* ============================================================
   Text buttons (link-style)
   ============================================================ */
.text-btn {
    font-family: var(--font-body);
    font-size: .8125rem;
    font-weight: 600;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px 4px;
    transition: color var(--dur-fast);
}
.text-btn:hover { color: var(--accent); }
.text-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.text-btn[aria-pressed="true"] {
    color: var(--accent);
}

/* ============================================================
   Comparison stats
   ============================================================ */
.comparison-stats {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 16px;
    margin-bottom: 28px;
}
.comparison-stats[hidden] { display: none; }
.stat-card {
    padding: 20px 16px;
    text-align: center;
}
.stat-label {
    font-family: var(--font-body);
    font-size: .6875rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-muted);
    display: block;
    margin-bottom: 10px;
}
.stat-values {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.stat-before {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-muted);
}
.stat-arrow {
    color: var(--text-muted);
    font-size: .875rem;
}
.stat-after {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--accent);
}
.stat-delta-value {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 700;
}
.stat-delta-value.positive { color: var(--positive); }
.stat-delta-value.negative { color: var(--danger); }

/* ============================================================
   Controls section
   ============================================================ */
.controls-section {
    padding: 28px 32px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.controls-top {
    display: flex;
    align-items: flex-end;
    gap: 24px;
    flex-wrap: wrap;
}
.controls-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}
.controls-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.controls-label {
    font-family: var(--font-body);
    font-size: .6875rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.controls-options {
    display: flex;
    align-items: center;
    gap: 20px;
}

/* Segmented control (intensity, format) */
.intensity-group,
.format-group {
    display: inline-flex;
    background: var(--surface-sunken);
    border-radius: var(--r-pill);
    box-shadow: var(--inset-1);
    padding: 4px;
    border: none;
}
.seg-btn {
    font-family: var(--font-body);
    font-size: .8125rem;
    font-weight: 500;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: var(--r-pill);
    padding: 9px 20px;
    cursor: pointer;
    transition: all var(--dur-base) var(--ease-soft);
}
.seg-btn:hover { color: var(--text-body); }
.seg-btn.active {
    background: var(--surface);
    color: var(--accent);
    box-shadow: var(--elev-1);
}
.seg-btn:focus { outline: none; }
.seg-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Checkbox */
.check-label {
    font-family: var(--font-body);
    font-size: .8125rem;
    font-weight: 500;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}
.check-label input {
    accent-color: var(--accent);
    width: 16px; height: 16px;
}
.check-label input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Selects (shared) */
.tone-select,
.lang-select,
.profile-select {
    font-family: var(--font-body);
    font-size: .8125rem;
    font-weight: 500;
    color: var(--text-body);
    background: var(--surface-sunken);
    border: none;
    border-radius: var(--r-pill);
    box-shadow: var(--inset-1);
    padding: 10px 18px;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238a8c82' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
    min-width: 140px;
}
.tone-select:hover,
.lang-select:hover,
.profile-select:hover { color: var(--text-strong); }
.tone-select:focus,
.lang-select:focus,
.profile-select:focus {
    outline: none;
    box-shadow: var(--inset-1), 0 0 0 2px var(--accent);
}
.tone-select:focus-visible,
.lang-select:focus-visible,
.profile-select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.tone-select option,
.lang-select option,
.profile-select option {
    background: var(--surface);
    color: var(--text-body);
}

.lang-hint {
    font-family: var(--font-body);
    font-size: .6875rem;
    color: var(--danger);
    display: none;
    align-items: center;
    gap: 6px;
}
.lang-hint.visible { display: inline-flex; }

/* CTA button */
.cta-btn {
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 600;
    color: var(--on-accent);
    background: var(--accent);
    border: none;
    border-radius: var(--r-sm);
    padding: 14px 40px;
    cursor: pointer;
    box-shadow: var(--elev-1);
    transition: all var(--dur-base) var(--ease-soft);
    min-height: 52px;
}
.cta-btn:hover:not(:disabled) {
    background: var(--accent-strong);
    box-shadow: var(--elev-2);
    transform: translateY(-1px);
}
.cta-btn:active:not(:disabled) {
    box-shadow: var(--inset-1);
    transform: translateY(0);
}
.cta-btn:disabled {
    opacity: .4;
    cursor: not-allowed;
    box-shadow: none;
}
.cta-btn:focus-visible {
    outline: 2px solid var(--accent-strong);
    outline-offset: 3px;
}
.cta-working { display: none; }
.cta-btn.working .cta-label { display: none; }
.cta-btn.working .cta-working { display: inline; }

.shortcut-hint {
    font-family: var(--font-body);
    font-size: .6875rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 8px;
}

/* ============================================================
   Quick presets
   ============================================================ */
.quick-presets {
    display: flex;
    align-items: center;
    gap: 6px;
}
.preset-btn {
    font-family: var(--font-body);
    font-size: .75rem;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--surface);
    border: none;
    border-radius: var(--r-pill);
    box-shadow: var(--elev-1);
    padding: 6px 14px;
    cursor: pointer;
    transition: all var(--dur-base) var(--ease-soft);
}
.preset-btn:hover {
    color: var(--accent);
    box-shadow: var(--elev-2);
}
.preset-btn:active {
    box-shadow: var(--inset-1);
}
.preset-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.preset-btn.active {
    color: var(--accent);
    box-shadow: var(--inset-1);
}

/* ============================================================
   Profile dropdown
   ============================================================ */
.profile-group {
    display: flex;
    align-items: center;
    gap: 8px;
}
.profile-save-btn {
    font-family: var(--font-body);
    font-size: .75rem;
    font-weight: 600;
    color: var(--accent);
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--r-xs);
    transition: color var(--dur-fast);
}
.profile-save-btn:hover { color: var(--accent-strong); }
.profile-save-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ============================================================
   Batch mode
   ============================================================ */
.batch-drop {
    padding: 56px 32px;
    text-align: center;
    cursor: pointer;
    transition: box-shadow var(--dur-base);
    margin-bottom: 20px;
}
.batch-drop:hover {
    box-shadow: var(--inset-2);
}
.batch-drop.dragover {
    box-shadow: var(--inset-2), 0 0 0 2px var(--accent);
}
.batch-drop-icon {
    font-size: 2rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}
.batch-drop-text {
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-body);
    margin-bottom: 6px;
}
.batch-drop-hint {
    font-size: .8125rem;
    color: var(--text-muted);
}

.batch-file-list { margin-bottom: 20px; }
.batch-file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-family: var(--font-body);
    font-size: .875rem;
    color: var(--text-strong);
    background: var(--surface);
    border-radius: var(--r-sm);
    box-shadow: var(--elev-1);
    padding: 14px 20px;
    margin-bottom: 10px;
}
.batch-file-item .bf-name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.batch-file-item .bf-size {
    font-size: .75rem;
    color: var(--text-muted);
    margin: 0 16px;
    flex-shrink: 0;
}
.batch-file-item .bf-remove {
    font-family: var(--font-body);
    font-size: .875rem;
    font-weight: 600;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: var(--r-xs);
    transition: color var(--dur-fast);
    flex-shrink: 0;
}
.batch-file-item .bf-remove:hover { color: var(--danger); }
.batch-file-item .bf-remove:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ============================================================
   Batch progress bar
   ============================================================ */
.batch-progress {
    margin-bottom: 20px;
    display: none;
}
.batch-progress.active { display: block; }
.batch-progress-bar-wrap {
    background: var(--surface-sunken);
    border-radius: var(--r-pill);
    box-shadow: var(--inset-1);
    height: 32px;
    overflow: hidden;
    position: relative;
}
.batch-progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: var(--r-pill);
    transition: width var(--dur-base) var(--ease-soft);
    min-width: 0;
}
.batch-progress-label {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-body);
    font-size: .75rem;
    font-weight: 600;
    color: var(--text-strong);
    z-index: 1;
}
.batch-progress-file {
    font-family: var(--font-body);
    font-size: .8125rem;
    color: var(--text-muted);
    margin-top: 10px;
    text-align: center;
}

/* ============================================================
   Auto-preview badge
   ============================================================ */
.auto-preview-badge {
    font-family: var(--font-body);
    font-size: .6875rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--accent);
    background: var(--accent-soft);
    border-radius: var(--r-pill);
    padding: 3px 10px;
    display: none;
}
.auto-preview-badge.visible { display: inline-flex; }

/* ============================================================
   History panel (slide-in from right)
   ============================================================ */
.history-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    z-index: 800;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur-base) var(--ease-soft);
}
.history-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.history-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 400px;
    max-width: 90vw;
    background: var(--surface);
    box-shadow: var(--elev-3);
    z-index: 850;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform var(--dur-slow) var(--ease-soft);
    overflow: hidden;
}
.history-panel.open {
    transform: translateX(0);
}
.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 28px 28px 20px;
    border-bottom: 1px solid var(--surface-sunken);
}
.history-title {
    font-family: var(--font-display);
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-strong);
}
.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 20px 28px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.history-item {
    background: var(--surface);
    border-radius: var(--r-md);
    box-shadow: var(--elev-1);
    padding: 18px;
    cursor: pointer;
    transition: all var(--dur-base) var(--ease-soft);
}
.history-item:hover {
    box-shadow: var(--elev-2);
    transform: translateY(-1px);
}
.history-item-preview {
    font-family: var(--font-body);
    font-size: .8125rem;
    color: var(--text-body);
    line-height: 1.5;
    margin-bottom: 10px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.history-item-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: .75rem;
    color: var(--text-muted);
}
.history-item-scores {
    display: flex;
    gap: 8px;
}
.history-empty {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
    font-size: .875rem;
    font-style: italic;
}
.history-footer {
    padding: 20px 28px;
    border-top: 1px solid var(--surface-sunken);
}

/* ============================================================
   Modal (shared for custom rules, shortcuts help, profiles)
   ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur-base) var(--ease-soft);
}
.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}
.modal-content {
    background: var(--surface);
    border-radius: var(--r-lg);
    box-shadow: var(--elev-3);
    padding: 36px;
    max-width: 640px;
    width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
    transform: scale(0.95) translateY(8px);
    transition: transform var(--dur-slow) var(--ease-soft);
}
.modal-content.modal-wide {
    max-width: 860px;
}
.modal-overlay.open .modal-content {
    transform: scale(1) translateY(0);
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
}
.modal-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.modal-title {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-strong);
}
.modal-close {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.25rem;
    cursor: pointer;
    border-radius: var(--r-xs);
    transition: color var(--dur-fast);
}
.modal-close:hover { color: var(--danger); }
.modal-close:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ============================================================
   Custom rules editor
   ============================================================ */
.rules-tabs {
    display: inline-flex;
    background: var(--surface-sunken);
    border-radius: var(--r-pill);
    box-shadow: var(--inset-1);
    padding: 4px;
    margin-bottom: 24px;
}
.rules-tab {
    font-family: var(--font-body);
    font-size: .8125rem;
    font-weight: 600;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: var(--r-pill);
    padding: 10px 24px;
    cursor: pointer;
    transition: all var(--dur-base) var(--ease-soft);
}
.rules-tab:hover { color: var(--text-body); }
.rules-tab.active {
    background: var(--surface);
    color: var(--accent);
    box-shadow: var(--elev-1);
}
.rules-tab:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.rules-panel { display: none; }
.rules-panel.active { display: block; }

.rules-count {
    font-size: .6875rem;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--surface-sunken);
    border-radius: var(--r-pill);
    padding: 1px 8px;
    margin-left: 6px;
}

.rules-toolbar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}
.rules-search {
    flex: 1;
}
.rules-filter {
    min-width: 150px;
}

.rules-list {
    max-height: 320px;
    overflow-y: auto;
    margin-bottom: 8px;
}

.rules-divider {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 20px 0 16px;
    font-family: var(--font-body);
    font-size: .6875rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.rules-divider::before,
.rules-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--surface-sunken);
}

.rule-entry {
    background: var(--surface);
    border-radius: var(--r-sm);
    box-shadow: var(--elev-1);
    padding: 12px 16px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: opacity var(--dur-fast);
}
.rule-entry.rule-disabled {
    opacity: .45;
}
.rule-entry.rule-custom {
    border-left: 3px solid var(--accent);
}
.rule-toggle {
    flex-shrink: 0;
    cursor: pointer;
}
.rule-toggle input {
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
}
.rule-entry-text {
    flex: 1;
    font-family: var(--font-body);
    font-size: .8125rem;
    color: var(--text-strong);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.rule-entry-action {
    font-size: .6875rem;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--accent-soft);
    border-radius: var(--r-pill);
    padding: 2px 10px;
    flex-shrink: 0;
}
.rule-entry-type {
    font-size: .6875rem;
    font-weight: 500;
    color: var(--text-muted);
    flex-shrink: 0;
}
.rule-entry-remove {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--r-xs);
    font-size: 1rem;
    flex-shrink: 0;
    transition: color var(--dur-fast);
}
.rule-entry-remove:hover { color: var(--danger); }
.rule-entry-remove:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.rule-entry-edit {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--r-xs);
    font-size: .875rem;
    flex-shrink: 0;
    transition: color var(--dur-fast);
}
.rule-entry-edit:hover { color: var(--accent); }
.rule-entry-edit:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.rule-add-row {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}
.rule-input {
    flex: 1;
    font-family: var(--font-body);
    font-size: .875rem;
    color: var(--text-strong);
    background: var(--surface-sunken);
    border: none;
    border-radius: var(--r-sm);
    box-shadow: var(--inset-1);
    padding: 12px 16px;
    outline: none;
}
.rule-input::placeholder { color: var(--text-muted); }
.rule-input:focus {
    box-shadow: var(--inset-1), 0 0 0 2px var(--accent);
}
.rule-select {
    font-family: var(--font-body);
    font-size: .8125rem;
    color: var(--text-body);
    background: var(--surface-sunken);
    border: none;
    border-radius: var(--r-sm);
    box-shadow: var(--inset-1);
    padding: 12px 16px;
    cursor: pointer;
    appearance: none;
}
.rule-select:focus {
    box-shadow: var(--inset-1), 0 0 0 2px var(--accent);
    outline: none;
}

/* ============================================================
   Keyboard shortcuts help
   ============================================================ */
.shortcut-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.shortcut-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
}
.shortcut-label {
    font-family: var(--font-body);
    font-size: .875rem;
    color: var(--text-body);
}
.shortcut-keys {
    display: flex;
    gap: 6px;
}
.kbd {
    font-family: var(--font-body);
    font-size: .75rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--surface-sunken);
    border-radius: var(--r-xs);
    box-shadow: var(--inset-1);
    padding: 5px 12px;
    min-width: 32px;
    text-align: center;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1024px) {
    .comparison-stats {
        grid-template-columns: repeat(3, 1fr);
    }
}
@media (max-width: 768px) {
    body { padding: 16px 12px 40px; }
    .app-frame { padding: 24px 20px; }
    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }
    .header-left {
        flex-direction: column;
        gap: 4px;
    }
    .logo { font-size: 1.35rem; }
    .editors { grid-template-columns: 1fr; }
    .mode-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }
    .controls-section { padding: 20px; }
    .controls-top {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
    }
    .controls-bottom {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
    }
    .controls-options {
        justify-content: center;
    }
    .cta-btn { width: 100%; text-align: center; }
    .comparison-stats { grid-template-columns: 1fr 1fr; }
    .header-actions { gap: 8px; }
    .history-panel { width: 100%; right: 0; }
    .modal-content { max-width: 95vw; padding: 24px; }
}

/* ============================================================
   Light theme overrides
   ============================================================ */
[data-theme="light"] {
    --surface:        #e4e4e6;
    --surface-raised: #eaeaed;
    --surface-sunken: #d8d8da;
    --shadow-dark:    #c0c0c2;
    --shadow-light:   #ffffff;
    --text-strong:    #1a1a1c;
    --text-body:      #4a4a4e;
    --text-muted:     #8a8a8e;
    --accent:         #6b7f4e;
    --accent-strong:  #5a6c40;
    --accent-soft:    rgba(107, 127, 78, 0.14);
    --on-accent:      #f0f1ec;
    --positive:       #6b7f4e;
}

/* ============================================================
   Reduced motion guard
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    .history-panel,
    .modal-content,
    .batch-progress-fill,
    .icon-btn,
    .icon-btn-sm,
    .history-item,
    .mode-btn,
    .seg-btn,
    .cta-btn,
    .export-menu,
    .export-option {
        transition: none !important;
    }
}
