:root {
    color-scheme: dark;
    --bg: #11131a;
    --bg-elevated: #171b24;
    --bg-soft: #1d2230;
    --border: #2c3445;
    --text: #eef2ff;
    --text-muted: #98a2b3;
    --primary: #7c9cff;
    --primary-strong: #9cb5ff;
    --danger: #ff7272;
    --danger-soft: rgba(255, 114, 114, 0.12);
    --warning: #f6c96b;
    --warning-soft: rgba(246, 201, 107, 0.12);
    --success: #38d39f;
    --shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
    --radius: 18px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    background:
        radial-gradient(circle at top right, rgba(124, 156, 255, 0.12), transparent 32%),
        radial-gradient(circle at bottom left, rgba(56, 211, 159, 0.08), transparent 28%),
        var(--bg);
    color: var(--text);
}

a {
    color: inherit;
    text-decoration: none;
}

code {
    padding: 0.15rem 0.35rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    font-size: 0.92em;
}

.shell {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 32px 0 56px;
}

.site-header {
    margin-bottom: 24px;
}

.brand {
    display: inline-block;
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.subtitle,
.muted {
    color: var(--text-muted);
}

.subtitle {
    margin: 8px 0 0;
}

.content {
    display: grid;
    gap: 20px;
}

.panel {
    padding: 24px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.01)), var(--bg-elevated);
    box-shadow: var(--shadow);
}

.panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.panel-header h1,
.panel-header h2,
.history-card h3,
.detail-card h2 {
    margin: 0;
}

.generation-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field-wide {
    grid-column: 1 / -1;
}

label,
.meta-label,
dt {
    font-size: 0.92rem;
    color: var(--text-muted);
}

input,
select,
textarea,
button {
    font: inherit;
}

input,
select,
textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg-soft);
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: rgba(124, 156, 255, 0.8);
    box-shadow: 0 0 0 4px rgba(124, 156, 255, 0.16);
}

textarea {
    resize: vertical;
    line-height: 1.5;
}

.field-help {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-size: 0.88rem;
    color: var(--text-muted);
}

.actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 4px;
}

.actions.wrap {
    flex-wrap: wrap;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.02);
    color: var(--text);
    cursor: pointer;
}

.button:hover {
    border-color: rgba(124, 156, 255, 0.6);
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.button-primary {
    border-color: transparent;
    background: linear-gradient(180deg, var(--primary-strong), var(--primary));
    color: #09111f;
    font-weight: 700;
}

.button-secondary {
    background: rgba(124, 156, 255, 0.08);
}

.button-danger {
    border-color: rgba(255, 114, 114, 0.3);
    background: var(--danger-soft);
    color: #ffd6d6;
}

.alert {
    margin-bottom: 18px;
    padding: 14px 16px;
    border-radius: 14px;
    border: 1px solid transparent;
}

.alert.compact {
    margin-bottom: 0;
}

.alert-error {
    border-color: rgba(255, 114, 114, 0.3);
    background: var(--danger-soft);
    color: #ffdede;
}

.alert-warning {
    border-color: rgba(246, 201, 107, 0.3);
    background: var(--warning-soft);
    color: #ffe6ad;
}

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

.history-card,
.detail-card {
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.02);
}

.history-card-header,
.detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 92px;
    padding: 7px 10px;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.status-pending {
    background: rgba(246, 201, 107, 0.12);
    color: #ffd98b;
}

.status-processing {
    background: rgba(124, 156, 255, 0.14);
    color: #bed0ff;
}

.status-done {
    background: rgba(56, 211, 159, 0.14);
    color: #9ef0d0;
}

.status-failed {
    background: rgba(255, 114, 114, 0.14);
    color: #ffb2b2;
}

.meta-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin: 16px 0;
}

.meta-grid > div {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.text-preview {
    margin: 0 0 16px;
    color: #d7dcec;
    line-height: 1.6;
}

.audio-player {
    width: 100%;
    margin: 0 0 16px;
}

.empty-state {
    padding: 18px;
    border: 1px dashed var(--border);
    border-radius: 16px;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.02);
}

.empty-state.compact {
    margin-bottom: 16px;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 16px;
}

.detail-list {
    display: grid;
    gap: 14px;
    margin: 0;
}

.detail-list > div {
    display: grid;
    gap: 6px;
}

.detail-list dd {
    margin: 0;
    color: #d7dcec;
    line-height: 1.5;
}

.back-link {
    display: inline-block;
    margin-bottom: 12px;
    color: var(--text-muted);
}

.text-block {
    margin: 0;
    padding: 20px;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: rgba(0, 0, 0, 0.18);
    white-space: pre-wrap;
    word-break: break-word;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    line-height: 1.55;
}

form[data-confirm] {
    margin: 0;
}

@media (max-width: 860px) {
    .generation-form,
    .detail-grid,
    .meta-grid {
        grid-template-columns: 1fr;
    }

    .panel,
    .shell {
        width: auto;
    }
}

@media (max-width: 640px) {
    .shell {
        width: min(100% - 24px, 1180px);
        padding-top: 20px;
    }

    .panel {
        padding: 18px;
    }

    .panel-header,
    .history-card-header,
    .detail-header {
        flex-direction: column;
    }

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

    .button {
        width: 100%;
    }
}
