:root {
    --bg: #0f1115;
    --panel: #171a21;
    --line: #262b36;
    --text: #e7e9ee;
    --muted: #9aa1ae;
    --accent: #7c5cff;
    --good: #3ecf8e;
    --bad: #ff6b6b;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
}

.brand { font-weight: 700; }

.tag {
    font-size: 12px;
    color: var(--muted);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 1px 8px;
}

.logout { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user { color: var(--muted); font-size: 13px; }

.content { max-width: 880px; margin: 0 auto; padding: 32px 24px; }

h1 { margin: 0 0 4px; font-size: 26px; }
h2 { margin: 0 0 12px; font-size: 17px; }
.muted { color: var(--muted); }

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 20px;
    margin-top: 20px;
}

.card.narrow { max-width: 400px; margin: 64px auto; }

form label { display: block; margin: 12px 0 4px; font-size: 13px; color: var(--muted); }

input {
    width: 100%;
    padding: 9px 11px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--bg);
    color: var(--text);
}

button {
    padding: 8px 14px;
    border: 0;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

.card form button { margin-top: 16px; }
.logout button { background: transparent; border: 1px solid var(--line); color: var(--text); }

.error {
    margin: 12px 0;
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(255, 107, 107, 0.12);
    color: var(--bad);
}

.status { display: grid; grid-template-columns: 180px 1fr; gap: 8px 16px; margin: 0; }
.status dt { color: var(--muted); }
.status dd { margin: 0; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.notice { padding: 24px; }

textarea {
    width: 100%;
    padding: 9px 11px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--bg);
    color: var(--text);
    font: inherit;
    resize: vertical;
}

label { display: block; margin: 12px 0 4px; font-size: 13px; color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
code { font-size: 12px; }

button:disabled { opacity: 0.5; cursor: not-allowed; }
button.secondary { background: transparent; border: 1px solid var(--line); color: var(--text); }
button.danger { background: #d9485f; }

.confirm {
    margin-top: 12px;
    padding: 12px;
    border: 1px solid #d9485f;
    border-radius: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.confirm p { margin: 0 0 4px; flex-basis: 100%; }

.notice-box { margin: 8px 0 12px; padding: 10px 12px; border-radius: 8px; }
.notice-box.warn { background: rgba(255, 190, 80, 0.12); color: #ffcf7a; }

.badge {
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 9px;
    border-radius: 999px;
    vertical-align: middle;
}
.tone-neutral { background: rgba(154, 161, 174, 0.15); color: var(--muted); }
.tone-busy { background: rgba(124, 92, 255, 0.18); color: #b7a6ff; }
.tone-good { background: rgba(62, 207, 142, 0.15); color: var(--good); }
.tone-warn { background: rgba(255, 190, 80, 0.15); color: #ffcf7a; }
.tone-bad { background: rgba(255, 107, 107, 0.15); color: var(--bad); }

table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { color: var(--muted); font-weight: 500; font-size: 13px; }
.prompt-cell { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a { color: #b7a6ff; }

.prompt { white-space: pre-wrap; background: var(--bg); padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); }

.tracks { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin-top: 16px; }
.track { border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: var(--bg); }
.track header { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.track audio { width: 100%; margin-top: 12px; }
.track .links { display: flex; gap: 16px; }
.status dd { overflow-wrap: anywhere; }

select {
    width: 100%;
    padding: 9px 11px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--bg);
    color: var(--text);
    font: inherit;
}
select option:disabled { color: var(--muted); }
.channel-info { margin: 10px 0 6px; }
button.small-button { padding: 4px 10px; font-size: 12px; font-weight: 500; margin-left: 6px; }

input[type=number] { max-width: 140px; }
details.debug { margin-top: 24px; padding-top: 12px; border-top: 1px solid var(--line); }
details.debug summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.concept-line { margin: 4px 0 10px; color: var(--muted); font-size: 13px; }
.header-badges { display: flex; gap: 6px; align-items: center; }

.schema-editor { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.error ul { margin: 0; padding-left: 18px; }
.nav { display: flex; gap: 16px; margin-left: 24px; font-size: 14px; }
.nav a { color: var(--text); text-decoration: none; }
.nav a:hover { color: #b7a6ff; }
.test-run { border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-top: 16px; }
.test-run > header { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 8px; }
.test-run > footer { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.test-prompt { margin-top: 12px; }
.test-prompt p { margin: 0 0 6px; }
.rating { display: flex; gap: 6px; margin-top: 10px; }
.rating button { margin-left: 0; }
button.selected { background: #7c5cff; color: #fff; }
input.note { width: 100%; margin-top: 8px; }
.chat { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.chat-msg { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); }
.chat-msg.owner { background: rgba(124, 92, 255, 0.08); }
.chat-msg.assistant { background: var(--bg); }
.chat-meta { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.chat-text { white-space: pre-wrap; margin: 0 0 6px; }
.proposal { margin-top: 8px; }
.attachment { margin: 12px 0 6px; }

/* ----- Calibration workspace ----- */
.content:has(.cal-page) { max-width: 1240px; }
.cal-page { --cal-fill: #6b4ef0; --cal-soft: #b7a6ff; --cal-warn: #ffcf7a; --cal-panel-2: #141820; --cal-control: #2c3240; }
.cal-page h1 { margin-bottom: 4px; }
.cal-page h2 { margin: 0; }
.cal-page h3 { margin: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.cal-i { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.cal-sub { font-size: 12px; color: var(--muted); line-height: 1.45; }
.cal-hint { font-size: 13px; color: var(--muted); max-width: 300px; text-align: right; line-height: 1.4; }
.cal-empty-page { margin-top: 24px; }

.cal-btn { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.cal-btn-primary { background: var(--cal-fill); border: 1px solid var(--cal-fill); color: #fff; }
.cal-btn-outline { background: transparent; border: 1px solid #3a4050; color: var(--text); }
.cal-btn-ghost { background: transparent; border: 1px solid var(--cal-control); color: var(--text); font-weight: 500; }
.cal-btn-small { height: 32px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
.cal-link { background: none; border: 0; padding: 0; color: var(--cal-soft); font: inherit; font-weight: 400; cursor: pointer; text-decoration: underline; }
.cal-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.cal-actions-end { justify-content: flex-end; }
.cal-page button:focus-visible, .cal-page select:focus-visible, .cal-page textarea:focus-visible, .cal-page input:focus-visible, .cal-page summary:focus-visible { outline: 2px solid #9d85ff; outline-offset: 2px; }

/* Top bar: channel, niche, status, automation */
.cal-bar { display: grid; grid-template-columns: 280px minmax(0, 1fr) 300px 330px; margin-top: 20px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.cal-cell { position: relative; padding: 16px 20px; min-width: 0; }
.cal-cell + .cal-cell { border-left: 1px solid var(--line); }
.cal-page label.cal-label, .cal-label { display: block; margin: 0 0 6px; font-size: 12px; color: var(--muted); }
.cal-select { height: 40px; font-weight: 600; }
.cal-niche { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-status-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.cal-status { display: inline-flex; align-items: center; gap: 8px; height: 32px; font-size: 15px; font-weight: 600; }
.cal-dot { width: 8px; height: 8px; border-radius: 999px; background: currentColor; }
.cal-status.is-calibrating { color: var(--cal-warn); }
.cal-status.is-ready { color: var(--good); }
.cal-status.is-none { color: #c3c8d2; }
.cal-status.is-none .cal-dot { background: transparent; border: 1.5px solid var(--muted); }
.cal-toggle-row { display: flex; align-items: center; gap: 12px; }
.cal-switch { display: inline-flex; align-items: center; gap: 10px; height: 40px; padding: 0 14px 0 8px; border-radius: 999px; border: 1px solid var(--cal-control); background: var(--bg); color: var(--text); font-size: 14px; font-weight: 600; flex-shrink: 0; }
.cal-switch:disabled { opacity: 1; color: var(--muted); }
.cal-switch-track { position: relative; display: block; width: 40px; height: 22px; border-radius: 999px; background: #3a4050; }
.cal-switch:disabled .cal-switch-track { background: var(--line); }
.cal-switch-knob { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 999px; background: var(--text); transition: left .15s; }
.cal-switch:disabled .cal-switch-knob { background: #5b6272; }
.cal-switch.is-on { border-color: rgba(124, 92, 255, 0.6); }
.cal-switch.is-on .cal-switch-track { background: var(--accent); }
.cal-switch.is-on .cal-switch-knob { left: 21px; background: #fff; }
.cal-popover { position: absolute; top: calc(100% - 6px); right: 12px; z-index: 5; width: 340px; display: flex; flex-direction: column; gap: 10px; padding: 16px; background: #1b1f28; border: 1px solid #343a48; border-radius: 12px; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5); }
.cal-popover h3 { font-size: 15px; }
.cal-popover p { margin: 0; font-size: 13px; line-height: 1.5; color: #c3c8d2; }

/* Chat workspace with the small current direction */
.cal-workspace { display: grid; grid-template-columns: minmax(0, 1fr) 260px; height: 720px; margin-top: 20px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.cal-chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.cal-chat-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 16px 24px; border-bottom: 1px solid var(--line); }
.cal-chat-head h2 { font-size: 17px; }
.cal-messages { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column-reverse; gap: 18px; padding: 20px 24px; }
.cal-chat-empty { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 24px 48px; text-align: center; }
.cal-chat-empty h3 { font-size: 20px; }
.cal-chat-empty .cal-sub { font-size: 14px; max-width: 520px; }
.cal-msg-you { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.cal-bubble { max-width: 560px; padding: 10px 14px; background: rgba(124, 92, 255, 0.12); border: 1px solid rgba(124, 92, 255, 0.3); border-radius: 12px 12px 4px 12px; font-size: 14px; white-space: pre-wrap; }
.cal-msg-ai { display: flex; gap: 12px; align-items: flex-start; max-width: 760px; }
.cal-msg-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
.cal-avatar { width: 30px; height: 30px; border-radius: 999px; background: rgba(124, 92, 255, 0.18); color: var(--cal-soft); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.cal-avatar-large { width: 44px; height: 44px; }
.cal-meta { font-size: 12px; color: var(--muted); }
.cal-text { margin: 0; font-size: 14px; line-height: 1.55; white-space: pre-wrap; }
.cal-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; font-size: 12px; color: #c3c8d2; background: #1d212a; border: 1px solid var(--cal-control); border-radius: 999px; }
.cal-chip-removable { align-self: flex-start; padding-right: 4px; }
.cal-chip-removable button { width: 22px; height: 22px; padding: 0; display: flex; align-items: center; justify-content: center; border: 0; border-radius: 999px; background: transparent; color: var(--muted); }
.cal-divider { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--muted); }
.cal-divider::before, .cal-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.cal-composer { display: flex; flex-direction: column; gap: 10px; padding: 14px 24px 16px; border-top: 1px solid var(--line); }
.cal-composer-row { display: flex; gap: 10px; align-items: flex-end; }
.cal-composer textarea { height: 52px; resize: none; padding: 14px; border-radius: 10px; border-color: var(--cal-control); font-size: 14px; }
.cal-send { width: 52px; height: 52px; padding: 0; flex-shrink: 0; display: flex; align-items: center; justify-content: center; border-radius: 10px; background: var(--cal-fill); }
.cal-try { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.cal-chip-button { height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--cal-control); background: transparent; color: #c3c8d2; font-size: 12.5px; font-weight: 400; }
.cal-direction { display: flex; flex-direction: column; gap: 12px; padding: 18px 16px; background: var(--cal-panel-2); border-left: 1px solid var(--line); overflow-y: auto; }
.cal-direction h3 { font-size: 13px; }
.cal-direction p { margin: 0; }
.cal-direction dl, .cal-first-direction { margin: 0; display: flex; flex-direction: column; gap: 8px; }
.cal-direction dt, .cal-first-direction dt { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); }
.cal-direction dd, .cal-first-direction dd { margin: 0; font-size: 13px; line-height: 1.4; }
.cal-change-dot { width: 6px; height: 6px; border-radius: 999px; background: var(--cal-warn); }

/* AI proposal */
.cal-proposal { margin-top: 8px; display: flex; flex-direction: column; gap: 12px; padding: 14px 16px; background: #12151b; border: 1px solid var(--cal-control); border-radius: 10px; }
.cal-proposal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.cal-proposal-title { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; }
.cal-proposal-title .cal-i { color: var(--cal-soft); }
.cal-pill { font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--cal-control); color: var(--muted); white-space: nowrap; }
.cal-pill.is-draft { color: var(--cal-warn); border-color: rgba(255, 207, 122, 0.45); }
.cal-pill.is-saved { color: var(--good); border-color: rgba(62, 207, 142, 0.45); }
.cal-pill.is-invalid { color: var(--bad); border-color: rgba(255, 107, 107, 0.45); }
.cal-changes { display: grid; grid-template-columns: max-content minmax(0, 1fr) 16px minmax(0, 1fr); column-gap: 10px; row-gap: 8px; align-items: baseline; font-size: 13px; line-height: 1.45; }
.cal-change-label { color: var(--muted); }
.cal-change-before { color: var(--muted); text-decoration: line-through; }
.cal-change-arrow { color: var(--muted); }
.cal-change-list { grid-column: span 3; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.cal-added { color: var(--good); }
.cal-removed { color: #ff8a8a; }
.cal-saved-line { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 13px; color: #c3c8d2; }
.cal-saved-line .cal-i { color: var(--good); }
.cal-confirm-replace { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; border: 1px solid rgba(255, 207, 122, 0.45); border-radius: 10px; background: rgba(255, 190, 80, 0.08); }
.cal-confirm-replace p { margin: 0; font-size: 13px; line-height: 1.5; }

/* Test beats */
.cal-beats { margin-top: 36px; }
.cal-beats-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 16px; }
.cal-beats-head h2 { font-size: 20px; }
.cal-beats-head .cal-sub { font-size: 14px; margin: 4px 0 0; }
.cal-beats-actions { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.cal-beats-controls { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }
.cal-count { display: flex; align-items: center; gap: 8px; }
.cal-page .cal-count label { margin: 0; font-size: 13px; }
.cal-count input { width: 72px; height: 40px; border-color: var(--cal-control); }
.cal-cost { margin: 0; font-size: 12px; color: var(--muted); text-align: right; }
.cal-beats-empty { display: flex; align-items: center; justify-content: center; height: 140px; border: 1px dashed #343a48; border-radius: 12px; color: var(--muted); font-size: 14px; }
.cal-round { display: flex; flex-direction: column; gap: 14px; }
.cal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; align-items: start; }
.cal-beat { min-width: 0; display: flex; flex-direction: column; gap: 10px; padding: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.cal-beat-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cal-beat h3 { font-size: 16px; }
.cal-tag { font-size: 11px; color: var(--muted); border: 1px solid var(--cal-control); border-radius: 999px; padding: 1px 8px; white-space: nowrap; }
.cal-beat-title { font-size: 14px; color: #d2d6de; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: -6px; }
.cal-beat-meta { font-size: 12px; color: var(--muted); line-height: 1.45; }
.cal-player { display: flex; align-items: center; min-height: 64px; padding: 8px; box-sizing: border-box; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.cal-player audio { width: 100%; color-scheme: dark; }
.cal-player.is-empty { padding: 0 12px; font-size: 12px; color: var(--muted); }
.cal-player-status { font-size: 13px; font-weight: 600; }
.cal-inline-status { margin-top: -4px; }
.tone-busy.cal-player-status, .tone-busy.cal-inline-status { background: none; color: var(--cal-soft); }
.tone-warn.cal-player-status, .tone-warn.cal-inline-status { background: none; color: var(--cal-warn); }
.tone-bad.cal-player-status, .tone-bad.cal-inline-status { background: none; color: var(--bad); }
.tone-neutral.cal-player-status, .tone-good.cal-player-status { background: none; }
.cal-prompt { font-size: 12px; color: var(--muted); }
.cal-prompt summary, .cal-fold summary { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; list-style: none; }
.cal-prompt summary::-webkit-details-marker, .cal-fold summary::-webkit-details-marker { display: none; }
.cal-prompt[open] .cal-chevron, .cal-fold[open] > summary .cal-chevron { transform: rotate(90deg); }
.cal-prompt p { margin: 8px 0 0; line-height: 1.5; color: #c3c8d2; }
.cal-skeleton { height: 12px; width: 70%; border-radius: 6px; background: #222733; }
.cal-skeleton.is-short { width: 90%; height: 10px; background: #1f242e; }
.cal-confirm { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 18px; background: rgba(124, 92, 255, 0.08); border: 1px solid rgba(124, 92, 255, 0.45); border-radius: 12px; }
.cal-confirm .cal-sub { font-size: 13px; color: #c3c8d2; }
.cal-prompts { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 16px; }
.cal-prompt-card { display: flex; flex-direction: column; gap: 10px; padding: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.cal-prompt-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.cal-prompt-head h3 { font-size: 16px; }
.cal-prompt-text { margin: 0; padding: 12px 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; font-size: 13px; line-height: 1.55; color: #c3c8d2; }

/* Earlier rounds and Advanced, folded by default */
.cal-fold { margin-top: 28px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.cal-fold > summary { display: flex; width: 100%; box-sizing: border-box; height: 52px; padding: 0 18px; gap: 10px; font-size: 14px; font-weight: 600; }
.cal-fold > summary .cal-sub { font-weight: 400; font-size: 13px; }
.cal-advanced { margin: 12px 0 48px; }
.cal-fold-button { width: 100%; height: 52px; display: flex; align-items: center; gap: 10px; padding: 0 18px; background: transparent; border: 1px solid var(--line); border-radius: 12px; color: var(--text); font-size: 14px; font-weight: 600; text-align: left; }
.cal-fold-button .cal-sub { font-weight: 400; font-size: 13px; }
.cal-card { display: flex; flex-direction: column; gap: 12px; }
.cal-card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; }
.cal-card h2 { font-size: 17px; }
.cal-advanced-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.cal-inline-field { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.cal-page .cal-inline-field label { margin: 0; }
.cal-sent summary { cursor: pointer; font-size: 13px; color: #c3c8d2; }
.cal-sent pre { max-height: 220px; overflow: auto; font-size: 11.5px; overflow-wrap: anywhere; }

@media (max-width: 1100px) {
    .cal-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .cal-cell:nth-child(3) { border-left: 0; }
    .cal-cell:nth-child(n + 3) { border-top: 1px solid var(--line); }
}

@media (max-width: 860px) {
    .cal-workspace { grid-template-columns: minmax(0, 1fr); height: auto; }
    .cal-messages { max-height: 560px; }
    .cal-direction { border-left: 0; border-top: 1px solid var(--line); }
    .cal-beats-head { flex-direction: column; align-items: stretch; }
    .cal-beats-controls { align-items: stretch; }
    .cal-beats-actions { flex-wrap: wrap; }
    .cal-cost { text-align: left; }
    .cal-hint { text-align: left; }
    .cal-advanced-grid { grid-template-columns: minmax(0, 1fr); }
    .cal-prompts { grid-template-columns: minmax(0, 1fr); }
    .cal-confirm { flex-direction: column; align-items: stretch; }
}

@media (max-width: 560px) {
    .cal-bar { grid-template-columns: minmax(0, 1fr); }
    .cal-cell + .cal-cell { border-left: 0; border-top: 1px solid var(--line); }
    .cal-popover { left: 12px; right: 12px; width: auto; }
}

/* Hand-over to BeatManager (RunDetail) */
.handoff-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0 12px; }
.handoff-toolbar button.small-button { margin-left: 0; }
.handoff-toolbar .count { margin-left: auto; color: var(--muted); font-size: 13px; }
.table-scroll { overflow-x: auto; }
table.list input[type=checkbox] { width: auto; margin: 0; }
table.list tr.locked td { color: var(--muted); }
.handoff-send { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 12px; }
.handoff-list { margin-top: 20px; }
.handoff-list h3 { margin: 0 0 4px; font-weight: 500; }
.handoff-item { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-top: 10px; background: var(--bg); }
.handoff-item > header { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-bottom: 6px; }
.handoff-item > footer { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.handoff-item > footer button.small-button { margin-left: 0; }

/* Generating: the newest round while it is planned, waiting for the owner's confirmation or being made */
.gen-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 14px; }
.gen-dot { width: 8px; height: 8px; border-radius: 999px; flex-shrink: 0; }
.gen-dot.tone-busy { background: var(--cal-soft); animation: gen-pulse 1.4s ease-in-out infinite; }
.gen-dot.tone-warn { background: var(--cal-warn); }
@keyframes gen-pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .gen-dot.tone-busy { animation: none; } }
.gen-details { margin-left: auto; }
.gen-progress { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.gen-lines { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.gen-lines:empty { display: none; }
.gen-lines li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; font-size: 13px; }
.gen-status { font-size: 12.5px; font-weight: 600; background: none; }
.gen-status.tone-busy { background: none; color: var(--cal-soft); }
.gen-status.tone-warn { background: none; color: var(--cal-warn); }
.gen-status.tone-bad { background: none; color: var(--bad); }
.gen-status.tone-good, .gen-status.tone-neutral { background: none; }
.gen-prompts summary { font-size: 13px; }
.gen-prompt { margin-top: 10px; font-size: 13px; }
.gen-prompt p { margin: 4px 0 0; }

/* The beat picker: every finished beat of the channel in one scrollable list */
.bp { margin-top: 32px; display: flex; flex-direction: column; gap: 12px; }
.bp-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.bp-head h2 { font-size: 20px; }
.bp-head .cal-sub { font-size: 14px; margin: 4px 0 0; }
.bp-tools { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.bp-tools .cal-link:disabled { color: var(--muted); text-decoration: none; cursor: default; }
.bp-list { height: 560px; max-height: 75vh; overflow-y: auto; overscroll-behavior: contain; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.bp-empty { display: flex; align-items: center; justify-content: center; height: 100%; padding: 0 16px; color: var(--muted); font-size: 14px; text-align: center; }
.bp-more { padding: 12px 16px; text-align: center; }
.bp-row { display: grid; grid-template-columns: 24px 34px minmax(0, 1fr) auto auto; align-items: start; gap: 4px 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.bp-row.is-selectable { cursor: pointer; }
.bp-row.is-selectable:hover { background: rgba(124, 92, 255, 0.05); }
.bp-row.is-selected, .bp-row.is-selected:hover { background: rgba(124, 92, 255, 0.12); }
.bp-row.is-locked .bp-name { color: #c3c8d2; }
.bp-check { display: flex; align-items: center; justify-content: center; height: 34px; }
.bp-check input { width: 16px; height: 16px; margin: 0; accent-color: var(--cal-fill); cursor: pointer; }
.bp-sent-icon { color: var(--good); }
.bp-play { width: 34px; height: 34px; margin: 0; padding: 0; border-radius: 999px; border: 1px solid var(--cal-control); background: var(--bg); color: var(--text); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.bp-play:hover { border-color: var(--cal-soft); }
.bp-play svg { fill: currentColor; }
.bp-play .bp-icon-pause, .bp-play.is-playing .bp-icon-play { display: none; }
.bp-play.is-playing .bp-icon-pause { display: block; }
.bp-play.is-playing { background: var(--cal-fill); border-color: var(--cal-fill); color: #fff; }
.bp-main { min-width: 0; padding-top: 1px; }
.bp-title { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.bp-name { font-size: 14.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bp-take { font-size: 12px; color: var(--muted); white-space: nowrap; }
.bp-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.bp-details { margin-top: 2px; font-size: 12px; color: var(--muted); cursor: auto; }
.bp-details summary { display: inline-block; cursor: pointer; color: var(--cal-soft); }
.bp-details-body { margin-top: 6px; display: flex; flex-direction: column; gap: 6px; color: #c3c8d2; line-height: 1.5; }
.bp-details-body p { margin: 0; padding: 8px 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
.bp-length { height: 34px; display: flex; align-items: center; font-size: 13px; color: #c3c8d2; font-variant-numeric: tabular-nums; }
.bp-status { min-height: 34px; min-width: 96px; display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.bp-now { display: none; align-items: center; gap: 12px; padding: 8px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.bp-now.is-active { display: flex; }
.bp-now-title { max-width: 40%; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bp-now audio { flex: 1; min-width: 0; height: 36px; color-scheme: dark; }
.bp-send { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px 16px; }
.bp-count { margin-right: auto; font-size: 14px; font-weight: 600; }
.bp-note { margin: 0; }

@media (max-width: 560px) {
    .bp-head { flex-direction: column; align-items: stretch; }
    .bp-row { grid-template-columns: 24px 34px minmax(0, 1fr) auto; padding: 10px 12px; }
    .bp-status { grid-column: 3 / -1; min-height: 0; justify-content: flex-start; }
    .bp-now { flex-wrap: wrap; }
    .bp-now-title { max-width: 100%; }
    .bp-send .cal-btn { width: 100%; justify-content: center; }
}
