:root {
    --bg: #f6f7f3;
    --surface: #ffffff;
    --surface-soft: #eef2ea;
    --ink: #1e2722;
    --muted: #647067;
    --line: #d9ded6;
    --primary: #246b55;
    --primary-strong: #174938;
    --accent: #b75d38;
    --warning: #a66a05;
    --danger: #a43f42;
    --shadow: 0 10px 30px rgba(31, 45, 38, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

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

.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 64px;
    padding: 0 28px;
    border-bottom: 1px solid var(--line);
    background: rgba(246, 247, 243, 0.94);
    backdrop-filter: blur(12px);
}

.brand {
    font-weight: 800;
    letter-spacing: 0;
}

.topbar-actions,
.action-row,
.meta-row,
.card-head,
.study-states {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-actions {
    justify-content: flex-end;
}

.user-chip,
.status {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 0.86rem;
    font-weight: 700;
    border: 1px solid var(--line);
    background: var(--surface);
    white-space: nowrap;
}

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

.auth-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
    gap: 36px;
    align-items: start;
    min-height: calc(100vh - 150px);
    padding-top: 32px;
}

.auth-copy {
    padding-top: 32px;
}

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

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    max-width: 760px;
    margin-bottom: 14px;
    font-size: clamp(2.3rem, 6vw, 4.7rem);
    line-height: 0.98;
    letter-spacing: 0;
}

h2 {
    margin-bottom: 14px;
    font-size: 1.1rem;
}

h3 {
    margin-bottom: 8px;
    font-size: 1rem;
}

.lede {
    max-width: 650px;
    color: var(--muted);
    font-size: 1.08rem;
    line-height: 1.6;
}

.lede.small {
    font-size: 1rem;
}

.study-states {
    flex-wrap: wrap;
    margin-top: 28px;
}

.study-states span {
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    font-weight: 700;
}

.auth-panels,
.stack,
.task-list,
.library-list,
.turn-list {
    display: grid;
    gap: 16px;
}

.panel,
.task-card,
.library-card,
.empty-state,
.turn-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.panel {
    padding: 22px;
}

.task-card,
.library-card,
.turn-card {
    padding: 18px;
}

.task-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 16px;
    align-items: center;
}

.task-card p,
.library-card p,
.turn-card p,
.empty-state p,
.description {
    color: var(--muted);
    line-height: 1.55;
}

.card-head {
    justify-content: space-between;
    align-items: flex-start;
}

.card-head h2,
.card-head h3 {
    margin-bottom: 0;
}

.meta-row {
    flex-wrap: wrap;
    color: var(--muted);
    font-size: 0.9rem;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 14px;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 800;
    text-align: center;
}

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

.button-primary {
    background: var(--primary);
    color: #ffffff;
}

.button-primary:hover {
    background: var(--primary-strong);
}

.button-secondary {
    border-color: var(--line);
    background: var(--surface-soft);
}

.button-secondary:hover,
.button-ghost:hover {
    border-color: #b9c2b8;
    background: #e5ebe0;
}

.button-ghost {
    border-color: transparent;
    background: transparent;
}

.button-github {
    width: 100%;
    margin-top: 14px;
    border-color: #24292f;
    background: #24292f;
    color: #ffffff;
}

label {
    display: grid;
    gap: 7px;
    color: var(--ink);
    font-size: 0.92rem;
    font-weight: 800;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fbfcfa;
    color: var(--ink);
    outline: none;
}

input {
    height: 42px;
    padding: 0 12px;
}

select {
    width: auto;
    min-width: 150px;
    height: 40px;
    padding: 0 34px 0 12px;
}

textarea {
    min-height: 150px;
    resize: vertical;
    padding: 12px;
    line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(36, 107, 85, 0.14);
}

.field-note {
    min-height: 20px;
    color: var(--muted);
    font-size: 0.86rem;
}

.field-note-good {
    color: var(--primary);
}

.field-note-bad {
    color: var(--danger);
}

.notice {
    padding: 12px 14px;
    border-radius: 8px;
    font-weight: 700;
}

.notice-error {
    border: 1px solid rgba(164, 63, 66, 0.26);
    background: #fbebeb;
    color: var(--danger);
}

.page-title {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 24px;
}

.page-title h1 {
    margin-bottom: 0;
    font-size: clamp(2rem, 5vw, 3.5rem);
}

.split-title {
    align-items: start;
}

.content-grid,
.detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
    gap: 22px;
    align-items: start;
}

.main-column,
.side-column {
    display: grid;
    gap: 16px;
}

.empty-state {
    padding: 26px;
}

.empty-state.compact {
    padding: 18px;
}

.backend-state {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-top: 18px;
}

.backend-state div {
    min-width: 0;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
}

.backend-state span {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
}

.backend-state strong {
    display: block;
    overflow-wrap: anywhere;
}

.status-not_started {
    color: #4b5563;
}

.status-running {
    border-color: rgba(166, 106, 5, 0.3);
    background: #fff6df;
    color: var(--warning);
}

.status-creating_repo {
    border-color: rgba(166, 106, 5, 0.3);
    background: #fff6df;
    color: var(--warning);
}

.status-repo_ready {
    border-color: rgba(36, 107, 85, 0.3);
    background: #e6f2ed;
    color: var(--primary);
}

.status-repo_creation_failed {
    border-color: rgba(164, 63, 66, 0.26);
    background: #fbebeb;
    color: var(--danger);
}

.status-ready_for_review {
    border-color: rgba(36, 107, 85, 0.3);
    background: #e6f2ed;
    color: var(--primary);
}

.status-completed {
    border-color: rgba(42, 82, 126, 0.24);
    background: #e8eef7;
    color: #2a527e;
}

.turn-note {
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.turn-result {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 0.9rem;
}

.turn-result span:first-child {
    color: var(--ink);
    font-weight: 800;
    overflow-wrap: anywhere;
}

.dictation-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfa;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 40px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
    font-weight: 800;
}

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

.mic-button {
    position: relative;
    color: transparent;
}

.mic-button::before {
    content: "";
    width: 11px;
    height: 18px;
    border: 2px solid currentColor;
    border-radius: 8px;
    color: var(--ink);
}

.mic-button::after {
    content: "";
    position: absolute;
    top: 25px;
    width: 16px;
    height: 9px;
    border: 2px solid var(--ink);
    border-top: 0;
    border-radius: 0 0 10px 10px;
}

.mic-button.is-listening {
    border-color: rgba(183, 93, 56, 0.36);
    background: #fff0e9;
}

.mic-button.is-listening::before,
.mic-button.is-listening::after {
    color: var(--accent);
    border-color: var(--accent);
}

.dictation-language {
    flex: 0 1 190px;
}

.dictation-clear {
    min-height: 40px;
}

.dictation-state {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 5px 10px;
    border-radius: 999px;
    background: var(--surface-soft);
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 800;
}

.dictation-state.is-active {
    background: #fff0e9;
    color: var(--accent);
}

.dictation-state.is-processing {
    background: #fff6df;
    color: var(--warning);
}

.dictation-state.is-error {
    background: #fbebeb;
    color: var(--danger);
}

.dictation-interim {
    min-height: 42px;
    padding: 10px 12px;
    border: 1px dashed rgba(183, 93, 56, 0.52);
    border-radius: 8px;
    background: #fff9f5;
    color: var(--accent);
    line-height: 1.45;
}

.narrow {
    width: min(680px, 100%);
    margin: 60px auto;
}

.code-block {
    overflow: auto;
    padding: 14px;
    border-radius: 8px;
    background: #1f2723;
    color: #eef7f1;
}

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

.summary-tile {
    min-height: 112px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.summary-tile span,
.summary-tile small {
    display: block;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 700;
}

.summary-tile strong {
    display: block;
    margin: 8px 0 4px;
    font-size: 2rem;
    line-height: 1;
}

.video-grid {
    display: grid;
    gap: 18px;
}

.video-card {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.video-card-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: start;
    margin-bottom: 12px;
}

.video-card h3 {
    overflow-wrap: anywhere;
    margin-bottom: 0;
}

.video-card video {
    display: block;
    width: 100%;
    max-height: min(68vh, 720px);
    aspect-ratio: 16 / 9;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #101511;
}

@media (max-width: 860px) {
    .auth-layout,
    .content-grid,
    .detail-grid,
    .summary-grid {
        grid-template-columns: 1fr;
    }

    .auth-copy {
        padding-top: 0;
    }

    .task-card {
        grid-template-columns: 1fr;
    }

    .backend-state {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    .topbar {
        padding: 0 16px;
    }

    .topbar-actions {
        gap: 6px;
    }

    .shell {
        width: min(100% - 22px, 1180px);
        padding-top: 22px;
    }

    .panel,
    .task-card,
    .library-card,
    .turn-card,
    .empty-state {
        padding: 16px;
    }

    .page-title,
    .split-title,
    .card-head,
    .video-card-head {
        display: grid;
        grid-template-columns: 1fr;
    }

    .button {
        width: 100%;
    }
}
