:root {
    color-scheme: dark;
    --bg: #101316;
    --panel: #1a2020;
    --panel-strong: #232927;
    --text: #f4f7f2;
    --muted: #b7c2bc;
    --line: #38413d;
    --accent: #28c7d8;
    --accent-strong: #9ee66e;
    --warn: #f3b562;
    --danger: #ff7a7a;
    --shadow: 0 20px 70px rgba(0, 0, 0, .32);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        linear-gradient(135deg, rgba(40, 199, 216, .10), transparent 35%),
        linear-gradient(315deg, rgba(158, 230, 110, .10), transparent 28%),
        var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
    color: inherit;
}

button,
input {
    font: inherit;
}

button,
.button-link {
    min-height: 46px;
    border: 0;
    border-radius: 8px;
    padding: 0 18px;
    background: var(--accent);
    color: #061013;
    font-weight: 800;
    cursor: pointer;
}

select {
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 12px;
    background: #0b0f10;
    color: var(--text);
    font: inherit;
}

button:hover,
.button-link:hover {
    filter: brightness(1.08);
}

button:disabled {
    cursor: wait;
    opacity: .72;
}

:focus-visible {
    outline: 3px solid var(--accent-strong);
    outline-offset: 4px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

.skip-link {
    position: absolute;
    left: 16px;
    top: 12px;
    transform: translateY(-150%);
    background: var(--accent-strong);
    color: #101316;
    padding: 10px 14px;
    border-radius: 8px;
    z-index: 10;
}

.skip-link:focus {
    transform: translateY(0);
}

.app-header,
.app-footer,
.workspace {
    width: min(1120px, calc(100% - 32px));
    margin: 0 auto;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 28px 0 20px;
}

.app-header h1 {
    margin: 0;
    font-size: clamp(2rem, 6vw, 4.5rem);
    line-height: .95;
    letter-spacing: 0;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--accent-strong);
    font-size: .78rem;
    font-weight: 900;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.top-nav {
    display: flex;
    align-items: center;
    gap: 0;
    padding: 4px 4px 0;
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 8px 8px 0 0;
    background: rgba(26, 32, 32, .84);
}

.top-nav a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    border: 1px solid transparent;
    border-bottom-color: var(--line);
    border-radius: 8px 8px 0 0;
    padding: 0 14px;
    color: var(--muted);
    text-decoration: none;
    font-weight: 700;
}

.top-nav a[aria-current="page"] {
    background: var(--panel-strong);
    border-color: var(--line);
    border-bottom-color: var(--panel-strong);
    color: var(--text);
    transform: translateY(1px);
}

.workspace {
    display: grid;
    gap: 18px;
    padding: 18px 0 36px;
}

.flow-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 520px);
    gap: 28px;
    align-items: end;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: clamp(20px, 5vw, 34px);
    background: rgba(26, 32, 32, .88);
    box-shadow: var(--shadow);
}

.panel-copy h2 {
    max-width: 720px;
    margin: 0;
    font-size: clamp(2rem, 5vw, 4rem);
    line-height: 1;
    letter-spacing: 0;
}

.panel-copy p:last-child {
    max-width: 680px;
    margin: 16px 0 0;
    color: var(--muted);
    font-size: 1.05rem;
    line-height: 1.6;
}

.download-form {
    display: grid;
    gap: 10px;
}

.download-form label {
    color: var(--text);
    font-weight: 800;
}

.input-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
}

input {
    width: 100%;
    min-height: 52px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 14px;
    background: #0b0f10;
    color: var(--text);
}

textarea {
    width: 100%;
    min-height: 76px;
    resize: vertical;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    background: #0b0f10;
    color: var(--text);
    font: inherit;
}

.hint {
    margin: 0;
    color: var(--muted);
    font-size: .92rem;
    line-height: 1.5;
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.status-grid.two-column {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.status-card {
    min-height: 188px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    background: rgba(35, 41, 39, .84);
}

.status-card h2 {
    margin: 0 0 12px;
    font-size: 1.1rem;
    letter-spacing: 0;
}

.status-card p {
    margin: 0;
    color: var(--muted);
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.status-card.is-ok {
    border-color: rgba(158, 230, 110, .65);
}

.status-card.is-error {
    border-color: rgba(255, 122, 122, .75);
}

.progress-shell {
    height: 12px;
    overflow: hidden;
    border-radius: 999px;
    background: #0b0f10;
    margin-bottom: 14px;
}

.progress-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-strong));
    transition: width .25s ease;
}

.result-card a,
.button-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 14px;
    color: #061013;
    text-decoration: none;
}

.button-link.secondary {
    margin-left: 8px;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--line);
}

.meta-list {
    display: grid;
    gap: 8px;
    margin: 12px 0 0;
    padding: 0;
    list-style: none;
}

.meta-list span {
    color: var(--text);
    font-weight: 800;
}

.notice {
    margin: 10px 0 0;
    color: var(--warn);
    font-weight: 800;
    overflow-wrap: anywhere;
}

.app-footer {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    padding: 22px 0 30px;
    border-top: 1px solid var(--line);
    color: var(--muted);
}

.history-form {
    display: grid;
    gap: 12px;
}

.history-form label {
    display: grid;
    gap: 7px;
    color: var(--text);
    font-weight: 800;
}

.filter-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.saved-filter-bar,
.checkbox-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.inline-check {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-weight: 800;
}

.inline-check input {
    width: auto;
    min-height: auto;
}

.stacked-tools {
    display: grid;
    gap: 18px;
}

.saved-filter-bar input,
.saved-filter-bar select {
    flex: 1 1 180px;
}

.checkbox-row label {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 12px;
    background: #0b0f10;
    font-weight: 800;
}

.checkbox-row input {
    width: auto;
    min-height: auto;
}

.history-results {
    display: grid;
    gap: 14px;
}

.history-results h2 {
    margin: 0;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.compact-form {
    padding: 12px 0;
}

.history-list {
    display: grid;
    gap: 12px;
}

.history-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 16px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
    background: rgba(35, 41, 39, .84);
}

.history-main {
    display: grid;
    grid-template-columns: 94px minmax(0, 1fr);
    gap: 14px;
    align-items: center;
}

.history-main img,
.thumb-placeholder {
    width: 94px;
    aspect-ratio: 1;
    object-fit: cover;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(40, 199, 216, .35), rgba(158, 230, 110, .20));
}

.history-main h3 {
    margin: 0;
    font-size: 1.25rem;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.history-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.note-field {
    display: grid;
    gap: 8px;
    margin-top: 12px;
    color: var(--text);
    font-weight: 800;
}

.inspector-hero {
    grid-template-columns: minmax(0, 1fr) 180px;
    align-items: center;
}

.inspector-thumb img,
.thumb-placeholder.large {
    width: 180px;
    aspect-ratio: 1;
    object-fit: cover;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(40, 199, 216, .35), rgba(158, 230, 110, .20));
}

.export-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}

.export-actions button {
    flex: 1 1 148px;
}

.export-actions .is-default-choice {
    box-shadow: inset 0 0 0 3px var(--accent-strong);
}

.export-result {
    display: grid;
    gap: 8px;
    margin-top: 12px;
}

.badge {
    display: inline-flex;
    min-height: 38px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 12px;
    color: var(--muted);
    font-weight: 800;
}

.tag-button {
    min-height: 30px;
    border: 1px solid rgba(243, 181, 98, .6);
    padding: 0 8px;
    background: transparent;
    color: var(--warn);
    font-size: .9rem;
}

.empty-state {
    min-height: 120px;
    align-items: center;
}

.a11y-toolbar {
    position: fixed;
    right: 14px;
    bottom: 14px;
    z-index: 30;
    display: grid;
    justify-items: end;
    gap: 8px;
}

.a11y-toolbar > button {
    min-width: 190px;
}

.a11y-toolbar > button,
.a11y-menu {
    box-shadow: var(--shadow);
}

.a11y-menu {
    width: min(320px, calc(100vw - 28px));
    display: grid;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: #0b0f10;
}

.a11y-menu label {
    min-height: 42px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-weight: 800;
}

.a11y-menu input {
    width: auto;
    min-height: auto;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(0, 0, 0, .68);
}

.shortcut-dialog,
.saveflow-dialog {
    width: min(560px, 100%);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.result-drawer {
    width: min(680px, 100%);
    max-height: min(720px, calc(100vh - 36px));
    overflow: auto;
}

.action-sheet,
.confirm-dialog {
    width: min(420px, 100%);
}

.dialog-body {
    margin-top: 14px;
}

.dialog-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}

.action-sheet-trigger {
    display: none;
}

.reading-content {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
    background: rgba(35, 41, 39, .84);
}

.reading-list {
    display: grid;
    gap: 12px;
    margin: 0;
}

.reading-list div {
    display: grid;
    gap: 4px;
}

.reading-list dt {
    color: var(--accent-strong);
    font-weight: 900;
}

.reading-list dd {
    margin: 0;
    overflow-wrap: anywhere;
    color: var(--text);
}

.shortcut-dialog h2 {
    margin: 0;
}

.mobile-action-bar {
    display: none;
}

body.a11y-mode {
    --accent-strong: #c8ff7a;
}

body.a11y-mode :focus-visible {
    outline-width: 5px;
    outline-offset: 5px;
}

body.a11y-mode button,
body.a11y-mode .button-link,
body.a11y-mode input,
body.a11y-mode select {
    min-height: 54px;
}

body.simple-mode {
    background: var(--bg);
}

body.simple-mode .flow-panel,
body.simple-mode .status-card,
body.simple-mode .history-card,
body.simple-mode .shortcut-dialog,
body.simple-mode .saveflow-dialog {
    box-shadow: none;
}

body.large-text-mode {
    font-size: 1.08rem;
}

body.text-first-mode .history-main {
    grid-template-columns: 1fr;
}

body.text-first-mode .history-main img,
body.text-first-mode .thumb-placeholder,
body.text-first-mode .inspector-thumb {
    display: none;
}

@media (max-width: 820px) {
    .app-header,
    .flow-panel,
    .inspector-hero,
    .input-row,
    .status-grid,
    .status-grid.two-column,
    .filter-row,
    .history-card,
    .history-main {
        grid-template-columns: 1fr;
    }

    .app-header {
        display: grid;
    }

    .top-nav {
        width: 100%;
    }

    .top-nav a {
        flex: 1;
        justify-content: center;
    }

    .history-actions {
        justify-content: stretch;
    }

    .history-actions button,
    .history-actions .button-link,
    .saved-filter-bar button,
    .saved-filter-bar select,
    .saved-filter-bar input {
        flex: 1;
    }

    .section-head {
        align-items: stretch;
        flex-direction: column;
    }

    .mobile-action-bar {
        position: sticky;
        bottom: 10px;
        z-index: 20;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        border: 1px solid var(--line);
        border-radius: 8px;
        padding: 8px;
        background: rgba(11, 15, 16, .94);
        box-shadow: var(--shadow);
    }

    .action-direct {
        display: none !important;
    }

    .action-sheet-trigger {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .dialog-actions {
        display: grid;
        grid-template-columns: 1fr;
    }
}

@media (max-width: 520px) {
    .app-header,
    .app-footer,
    .workspace {
        width: min(100% - 20px, 1120px);
    }

    .app-header h1,
    .panel-copy h2 {
        font-size: 2.25rem;
    }

    .flow-panel {
        padding: 18px;
    }

    .top-nav {
        overflow-x: auto;
        justify-content: flex-start;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: .01ms !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
    }
}
