:root {
    --background: #f7f5f2;
    --surface: #ffffff;
    --surface-soft: #eef7f4;
    --border: #d9e7e2;

    --text: #2f2622;
    --text-muted: #6f6964;

    --primary: #a8dccb;
    --primary-dark: #2e5c57;
    --accent: #f36c21;

    --success: #2e5c57;
    --error: #b91c1c;

    --shadow: 0 16px 40px rgba(46, 92, 87, 0.1);

    --radius-large: 18px;
    --radius-medium: 12px;
    --radius-small: 8px;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    overflow-wrap: anywhere;
    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    background:
    radial-gradient(
        circle at top left,
        rgba(168, 220, 203, 0.45) 0,
        transparent 34%
    ),
    linear-gradient(
        180deg,
        #ffffff 0%,
        var(--background) 100%
    );
}

main {
    width: min(1100px, calc(100% - 32px));
    min-width: 0;
    margin: 0 auto;
    padding: 64px 0 96px;
}

header {
    margin-bottom: 36px;
    text-align: center;
}

header h1 {
    margin: 0;
    font-size: clamp(2.3rem, 5vw, 4rem);
    line-height: 1.05;
    letter-spacing: -0.045em;
}

header p {
    max-width: 680px;
    margin: 18px auto 0;
    color: var(--text-muted);
    font-size: 1.08rem;
}

.mode-selector {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    width: min(100%, 440px);
    margin: 0 auto 32px;
    padding: 6px;
    background: rgba(255, 255, 255, 0.86);
    border: 1px solid var(--border);
    border-radius: var(--radius-medium);
    box-shadow: 0 8px 22px rgba(46, 92, 87, 0.1);
}

.mode-button {
    padding: 12px 18px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--primary-dark);
    box-shadow: none;
}

.mode-button:hover {
    transform: none;
    background: var(--surface-soft);
    border-color: var(--border);
    color: var(--primary-dark);
    box-shadow: none;
}

.mode-button[aria-pressed="true"] {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    color: #ffffff;
    box-shadow: 0 6px 14px rgba(46, 92, 87, 0.22);
}

.mode-button[aria-pressed="true"]::before {
    content: "✓ ";
}

.mode-button:focus-visible {
    outline: 3px solid rgba(243, 108, 33, 0.55);
    outline-offset: 3px;
}

form {
    display: grid;
    gap: 24px;
    min-width: 0;
}

form section {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px 22px;
    min-width: 0;
    padding: 28px;
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid rgba(217, 231, 226, 0.95);
    border-radius: var(--radius-large);
    box-shadow: var(--shadow);
    backdrop-filter: blur(8px);
}

form section h2 {
    grid-column: 1 / -1;
    margin: 0 0 4px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
    font-size: 1.25rem;
    letter-spacing: -0.02em;
}

label {
    display: flex;
    flex-direction: column;
    gap: 8px;
    color: var(--primary-dark);
    font-size: 0.92rem;
    font-weight: 700;
}

.field-guidance {
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 500;
    line-height: 1.45;
}

input,
textarea,
select {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    padding: 13px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    background: var(--surface-soft);
    color: var(--text);
    font: inherit;
    font-weight: 400;
    outline: none;
    transition:
        border-color 160ms ease,
        box-shadow 160ms ease,
        background-color 160ms ease,
        transform 160ms ease;
}

input:hover,
textarea:hover,
select:hover {
    border-color: #a8cfc3;
    background: #ffffff;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--primary-dark);
    background: #ffffff;
    box-shadow: 0 0 0 4px rgba(168, 220, 203, 0.35);
}

textarea {
    min-height: 120px;
    resize: vertical;
}

label:has(textarea) {
    grid-column: 1 / -1;
}

button {
    width: 100%;
    min-height: 44px;
    padding: 16px 24px;
    border: 0;
    border-radius: var(--radius-medium);
    background: linear-gradient(
        135deg,
        var(--primary-dark) 0%,
        #214844 100%
    );
    color: #ffffff;
    font: inherit;
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: 0.01em;
    cursor: pointer;
    box-shadow: 0 12px 24px rgba(46, 92, 87, 0.22);
    transition:
        transform 160ms ease,
        box-shadow 160ms ease,
        background 160ms ease,
        opacity 160ms ease;
    overflow-wrap: anywhere;
}

button:hover {
    transform: translateY(-2px);
    background: linear-gradient(
        135deg,
        var(--accent) 0%,
        #d95717 100%
    );
    box-shadow: 0 16px 30px rgba(243, 108, 33, 0.24);
}

button:active {
    transform: translateY(0);
}

button:focus-visible {
    outline: 3px solid rgba(243, 108, 33, 0.55);
    outline-offset: 3px;
}

button:disabled {
    cursor: wait;
    opacity: 0.65;
    transform: none;
    box-shadow: none;
}

#test-data-toggle,
#topic-test-data-toggle,
#topic-transcript-toggle {
    width: auto;
    justify-self: start;
    padding: 8px 12px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    font-size: 0.85rem;
    box-shadow: none;
}

#test-data-toggle:hover,
#topic-test-data-toggle:hover,
#topic-transcript-toggle:hover {
    transform: none;
    background: #ffffff;
    color: var(--primary-dark);
    box-shadow: none;
}

#test-data-toggle:focus-visible,
#topic-test-data-toggle:focus-visible,
#topic-transcript-toggle:focus-visible {
    outline: 3px solid rgba(168, 220, 203, 0.75);
    outline-offset: 3px;
}

#test-data-controls:not([hidden]),
#topic-test-data-controls:not([hidden]) {
    display: grid;
    gap: 12px;
    min-width: 0;
}

.topic-transcript-section {
    background: rgba(238, 247, 244, 0.72);
    border-style: dashed;
    box-shadow: none;
}

.topic-transcript-heading {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.topic-transcript-heading > div {
    min-width: 0;
}

.topic-transcript-heading h2 {
    margin: 0;
    padding: 0;
    border: 0;
}

.topic-transcript-heading p,
.topic-transcript-guidance {
    margin: 8px 0 0;
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.5;
}

#topic-transcript-toggle {
    flex-shrink: 0;
}

#topic-transcript-panel:not([hidden]) {
    grid-column: 1 / -1;
    display: grid;
    gap: 14px;
}

#topic-transcript {
    min-height: 240px;
    resize: vertical;
}

#extract-topic-transcript-button {
    width: min(100%, 320px);
}

.topic-transcript-status:empty {
    display: none;
}

#topic-transcript-loading,
#topic-transcript-error,
#topic-transcript-success {
    margin: 0;
    padding: 14px 16px;
    border-radius: var(--radius-medium);
    font-weight: 700;
}

#topic-transcript-loading {
    background: var(--surface-soft);
    border: 1px solid var(--primary);
    color: var(--primary-dark);
}

#topic-transcript-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: var(--error);
}

#topic-transcript-success {
    background: var(--surface-soft);
    border: 1px solid var(--primary);
    color: var(--success);
}

#loading-message,
#topic-loading-message,
#error-message,
#topic-error-message,
#topic-video-prompt-loading,
#topic-video-prompt-error {
    margin: 24px 0 0;
    padding: 16px 18px;
    border-radius: var(--radius-medium);
    font-weight: 700;
}

#loading-message,
#topic-loading-message,
#topic-video-prompt-loading {
    background: var(--surface-soft);
    border: 1px solid var(--primary);
    color: var(--primary-dark);
}

#error-message,
#topic-error-message,
#topic-video-prompt-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: var(--error);
}

#results,
#topic-results {
    margin-top: 40px;
    padding: 30px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-large);
    box-shadow: var(--shadow);
    min-width: 0;
}

#results > h2,
#topic-results > h2 {
    margin: 0 0 24px;
    font-size: 1.65rem;
    letter-spacing: -0.03em;
}

#results article,
#topic-results article {
    position: relative;
    margin-top: 24px;
    padding: 26px;

    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius-large);

    box-shadow:
        0 8px 24px rgba(46, 92, 87, 0.08);

    overflow: hidden;
    min-width: 0;

    transition:
        transform 180ms ease,
        box-shadow 180ms ease,
        border-color 180ms ease;
}

#results article::before,
#topic-results article::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;

    width: 6px;

    background: linear-gradient(
        180deg,
        var(--primary-dark),
        var(--primary)
    );
}

#results article:hover,
#topic-results article:hover {
    transform: translateY(-3px);
    border-color: var(--primary);

    box-shadow:
        0 16px 34px rgba(46, 92, 87, 0.14);
}

#results article:first-of-type,
#topic-results article:first-of-type {
    margin-top: 0;
}

article:first-of-type {
    margin-top: 0;
}

article h3 {
    margin: 0;
    color: var(--primary-dark);
    font-size: 1.08rem;
}

.result-text {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    min-height: 180px;
    padding: 18px;

    border: 1px solid var(--border);
    border-radius: var(--radius-medium);

    background: var(--surface-soft);
    color: var(--text);

    font: inherit;
    line-height: 1.7;

    resize: none;
    overflow: hidden;
    overflow-wrap: anywhere;

    transition:
        background-color 160ms ease,
        border-color 160ms ease,
        box-shadow 160ms ease;
}

.result-text:not([readonly]) {
    background: #ffffff;
    border-color: var(--accent);

    box-shadow:
        0 0 0 4px rgba(243, 108, 33, 0.12);
}

.member-email-fields {
    display: grid;
    gap: 10px;
    min-width: 0;
}

.member-email-fields input {
    margin-bottom: 8px;
    background: #ffffff;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(243, 108, 33, 0.12);
}

.image-prompt-text {
    min-height: 140px;
}

.result-guidance {
    margin: 6px 0 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.result-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;

    margin: 0 0 18px;
    padding-bottom: 14px;

    border-bottom: 1px solid var(--border);
}

.result-header > * {
    min-width: 0;
}

.result-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 10px;
    min-width: 0;
}

.package-actions {
    display: grid;
    gap: 14px;
    margin-top: 24px;
}
.result-header .copy-button,
.result-header .edit-button {
    width: auto;
    min-width: 86px;
    padding: 8px 14px;

    flex-shrink: 0;

    text-align: center;
    font-size: 0.85rem;

    color: #ffffff;
    border-radius: var(--radius-small);
    box-shadow: 0 4px 10px rgba(46, 92, 87, 0.18);
}

[hidden] {
    display: none !important;
}

@media (max-width: 760px) {
    main {
        width: min(100% - 20px, 1100px);
        padding: 36px 0 64px;
    }

    header {
        text-align: left;
    }

    header p {
        margin-left: 0;
    }

    .mode-selector {
        margin-bottom: 24px;
    }

    .topic-transcript-heading {
        align-items: stretch;
        flex-direction: column;
    }

    form {
        gap: 18px;
    }

    form section {
        grid-template-columns: 1fr;
        padding: 22px;
    }

    label,
    label:has(textarea) {
        grid-column: 1;
    }

    #results,
    #topic-results {
        padding: 18px;
    }

    #results article,
    #topic-results article {
        padding: 20px;
        border-radius: var(--radius-medium);
    }

    #results article:hover,
    #topic-results article:hover {
        transform: none;
    }

    .result-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .result-actions {
        width: 100%;
        justify-content: stretch;
    }

    .result-header .copy-button,
    .result-header .edit-button {
        flex: 1 1 120px;
        min-width: 0;
        min-height: 44px;
        padding: 10px 12px;
    }

    .result-text {
        min-height: 150px;
        padding: 14px;
    }

    .image-prompt-text {
        min-height: 130px;
    }
}

@media (max-width: 420px) {
    main {
        width: calc(100% - 12px);
        padding: 24px 0 48px;
    }

    header {
        margin-bottom: 24px;
    }

    header h1 {
        font-size: 2rem;
    }

    header p {
        margin-top: 12px;
        font-size: 1rem;
    }

    .mode-selector {
        gap: 4px;
        padding: 4px;
    }

    .mode-button {
        padding: 12px 8px;
        font-size: 0.9rem;
    }

    form section {
        gap: 14px;
        padding: 16px;
        border-radius: var(--radius-medium);
    }

    form section h2 {
        padding-bottom: 12px;
        font-size: 1.15rem;
    }

    button {
        padding: 14px 16px;
    }

    #loading-message,
    #topic-loading-message,
    #error-message,
    #topic-error-message,
    #topic-video-prompt-loading,
    #topic-video-prompt-error {
        padding: 14px;
    }

    #results,
    #topic-results {
        margin-top: 32px;
        padding: 12px;
        border-radius: var(--radius-medium);
    }

    #results > h2,
    #topic-results > h2 {
        margin-bottom: 18px;
        font-size: 1.35rem;
    }

    #results article,
    #topic-results article {
        margin-top: 16px;
        padding: 16px;
    }
}

@media (max-width: 360px) {
    .result-actions {
        flex-direction: column;
    }

    .result-header .copy-button,
    .result-header .edit-button {
        width: 100%;
        flex-basis: auto;
    }
}
