:root {
    --bg: #f1f3ee;
    --panel: #fffef9;
    --panel-strong: #ffffff;
    --ink: #151515;
    --muted: #62665e;
    --line: #151515;
    --soft-line: #d8dbd1;
    --accent: #0a6b54;
    --accent-strong: #084c3d;
    --accent-soft: #dff2ec;
    --danger: #b42318;
    --warning: #8a5a00;
    --shadow: 0 18px 42px rgba(21, 21, 21, 0.09);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        linear-gradient(135deg, rgba(10, 107, 84, 0.08), transparent 34%),
        linear-gradient(315deg, rgba(32, 81, 113, 0.1), transparent 38%),
        var(--bg);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
}

button,
input,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

.app-shell {
    width: min(1260px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 46px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 16px;
}

.topbar h1,
.section-heading h2,
.modal-header h3 {
    margin: 0;
    line-height: 1.08;
    letter-spacing: 0;
}

.topbar h1 {
    font-size: 44px;
}

.section-heading h2 {
    font-size: 28px;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--accent);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.topbar-actions,
.modal-actions,
.section-heading {
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-heading {
    justify-content: space-between;
    margin: 34px 0 14px;
}

.primary-button,
.secondary-button,
.icon-button {
    min-height: 42px;
    border-radius: 8px;
    border: 2px solid var(--line);
    font-weight: 800;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.primary-button {
    padding: 0 18px;
    background: var(--ink);
    color: #ffffff;
}

.secondary-button {
    padding: 0 16px;
    background: var(--panel);
    color: var(--ink);
}

.icon-button {
    width: 44px;
    padding: 0;
    background: var(--panel);
    color: var(--ink);
    font-size: 24px;
    line-height: 1;
}

.primary-button:hover,
.secondary-button:hover,
.icon-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 18px rgba(21, 21, 21, 0.12);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.52;
    transform: none;
    box-shadow: none;
}

.settings-panel,
.status-bar {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
    padding: 14px 16px;
    border: 2px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 254, 249, 0.88);
    backdrop-filter: blur(10px);
}

.settings-panel label {
    display: grid;
    flex: 1 1 280px;
    gap: 6px;
}

.settings-panel span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.settings-panel input {
    width: 100%;
    min-height: 42px;
    border: 2px solid var(--line);
    border-radius: 8px;
    padding: 0 12px;
    background: #ffffff;
    outline: none;
}

.status-bar {
    align-items: center;
    margin-bottom: 24px;
}

.status-bar strong,
.status-bar span {
    display: block;
}

.status-bar span {
    margin-top: 3px;
    color: var(--muted);
    font-size: 14px;
}

.model-pill {
    flex: 0 0 auto;
    padding: 8px 10px;
    border: 1px solid var(--soft-line);
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: 13px;
    font-weight: 800;
}

.sources-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 22px;
    align-items: start;
}

.source-card {
    min-width: 0;
    border: 4px solid var(--line);
    background: var(--panel-strong);
    box-shadow: var(--shadow);
}

.source-url {
    display: flex;
    border-bottom: 4px solid var(--line);
}

.source-url input {
    width: 100%;
    min-width: 0;
    height: 50px;
    border: 0;
    padding: 0 14px;
    outline: none;
    font-weight: 800;
    text-align: center;
}

.source-paste {
    display: block;
    width: 100%;
    min-height: 86px;
    max-height: 160px;
    resize: vertical;
    border: 0;
    border-bottom: 2px solid var(--line);
    padding: 10px 12px;
    background: #fbfbf7;
    color: var(--ink);
    outline: none;
    line-height: 1.45;
}

.source-body {
    min-height: 260px;
    max-height: 360px;
    overflow: auto;
    padding: 12px 14px;
}

.source-footer {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 8px;
    align-items: center;
    min-height: 48px;
    padding: 8px;
    border-top: 4px solid var(--line);
}

.text-toggle {
    min-height: 34px;
    border: 0;
    border-radius: 6px;
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-weight: 900;
}

.mini-button {
    min-height: 34px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #ffffff;
    font-size: 12px;
    font-weight: 800;
}

.word-count {
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

.empty-state,
.error-state,
.warning-state {
    display: grid;
    min-height: 170px;
    place-items: center;
    color: var(--muted);
    text-align: center;
    line-height: 1.4;
}

.error-state {
    color: var(--danger);
    font-weight: 800;
}

.warning-state {
    color: var(--warning);
    font-weight: 800;
}

.heading-list,
.ideal-list,
.recommendations {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.heading-item,
.ideal-item,
.recommendations li {
    position: relative;
    padding: 9px 10px;
    border: 1px solid var(--soft-line);
    border-left: 5px solid var(--line);
    border-radius: 6px;
    background: #ffffff;
}

.heading-item .level,
.ideal-item .level {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    min-height: 24px;
    margin-right: 8px;
    border-radius: 5px;
    background: var(--ink);
    color: #ffffff;
    font-size: 12px;
    font-weight: 900;
}

.heading-item .text,
.ideal-item .text {
    font-weight: 800;
}

.heading-item.h2,
.ideal-item.h2 {
    margin-left: 18px;
}

.heading-item.h3,
.ideal-item.h3 {
    margin-left: 36px;
}

.heading-item.h4,
.ideal-item.h4 {
    margin-left: 54px;
}

.heading-item.h5,
.ideal-item.h5 {
    margin-left: 72px;
}

.heading-item.h6,
.ideal-item.h6 {
    margin-left: 90px;
}

.ideal-panel {
    min-height: 330px;
    border: 4px solid var(--line);
    background: var(--panel-strong);
    box-shadow: var(--shadow);
}

.ideal-content {
    padding: 18px;
}

.ideal-summary {
    margin: 0 0 16px;
    color: var(--muted);
    line-height: 1.5;
}

.recommendations {
    margin-bottom: 18px;
}

.recommendations li {
    border-left-color: var(--accent);
    color: var(--accent-strong);
    font-weight: 700;
}

.ideal-item .reason {
    display: block;
    margin-top: 6px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.4;
}

.prompt-box {
    width: 100%;
    min-height: 210px;
    resize: vertical;
    border: 2px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: #ffffff;
    line-height: 1.5;
}

.text-modal {
    width: min(900px, calc(100% - 28px));
    height: min(780px, calc(100% - 28px));
    border: 4px solid var(--line);
    border-radius: 8px;
    padding: 0;
    background: var(--panel);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.28);
}

.text-modal::backdrop {
    background: rgba(0, 0, 0, 0.38);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 16px;
    border-bottom: 2px solid var(--line);
}

.text-modal textarea {
    display: block;
    width: calc(100% - 32px);
    height: calc(100% - 158px);
    margin: 16px;
    resize: none;
    border: 2px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    background: #ffffff;
    line-height: 1.55;
    outline: none;
}

.modal-actions {
    justify-content: flex-end;
    padding: 0 16px 16px;
}

.loading {
    min-height: 170px;
    display: grid;
    place-items: center;
    color: var(--accent-strong);
    font-weight: 900;
}

@media (max-width: 1020px) {
    .sources-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    .app-shell {
        width: min(100% - 20px, 1260px);
        padding-top: 18px;
    }

    .topbar,
    .status-bar,
    .settings-panel,
    .section-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .topbar h1 {
        font-size: 32px;
    }

    .topbar-actions {
        display: grid;
        grid-template-columns: 44px 1fr 1fr;
    }

    #copyAllTextsBtn {
        grid-column: 1 / -1;
    }

    .sources-grid {
        grid-template-columns: 1fr;
    }

    .source-body {
        max-height: 320px;
    }

    .source-footer {
        grid-template-columns: 1fr 1fr;
    }

    .word-count {
        grid-column: 1 / -1;
    }

    .heading-item.h4,
    .ideal-item.h4,
    .heading-item.h5,
    .ideal-item.h5,
    .heading-item.h6,
    .ideal-item.h6 {
        margin-left: 36px;
    }
}
