:root {
    --bg: #f7f7f9;
    --surface: #ffffff;
    --border: #d4d4d8;
    --text: #18181b;
    --text-muted: #71717a;
    --accent: #2563eb;
    --warn: #d97706;
    --danger: #dc2626;
    --ok: #16a34a;
    --code-bg: #f3f4f6;
    --prio-1: #dc2626;
    --prio-2: #d97706;
    --prio-3: #71717a;
    --prio-4: #a1a1aa;
    --prio-5: #d4d4d8;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #18181b;
        --surface: #27272a;
        --border: #3f3f46;
        --text: #f4f4f5;
        --text-muted: #a1a1aa;
        --accent: #60a5fa;
        --warn: #fbbf24;
        --danger: #f87171;
        --ok: #4ade80;
        --code-bg: #18181b;
    }
    .badge.status-open { background: #1e3a8a; border-color: #1e40af; color: #bfdbfe; }
    .badge.status-wip { background: #78350f; border-color: #92400e; color: #fed7aa; }
    .badge.status-blocked { background: #7f1d1d; border-color: #991b1b; color: #fecaca; }
    .badge.status-completed { background: #14532d; border-color: #166534; color: #bbf7d0; }
    .badge.status-wontfix { background: #3f3f46; border-color: #52525b; color: #d4d4d8; }
    .badge.status-draft { background: #4c1d95; border-color: #5b21b6; color: #ddd6fe; }
    .activity del { background: #7f1d1d; color: #fecaca; }
    .activity ins { background: #14532d; color: #bbf7d0; }
    .heat-cell.tier-0 { background: #3f3f46; }
    .dashboard-stats .stat.draft .stat-value { color: #c4b5fd; }
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.45;
}
nav.site {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.6rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
}
nav.site a { color: var(--text-muted); text-decoration: none; font-size: 0.9rem; }
nav.site a:hover, nav.site a.active { color: var(--text); }
nav.site .brand { color: var(--accent); font-weight: 700; font-size: 1.05rem; }
nav.site .right { margin-left: auto; display: flex; gap: 1.25rem; align-items: center; }
nav.site form.logout { display: inline; }
nav.site form.logout button {
    background: none;
    border: none;
    padding: 0;
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
}
nav.site form.logout button:hover { color: var(--text); text-decoration: underline; }
nav.site form.deploy-form { display: inline; margin: 0; }
nav.site form.deploy-form button.btn-deploy {
    background: var(--warn);
    border-color: var(--warn);
    color: #fff;
    padding: 0.2rem 0.7rem;
    font-size: 0.8rem;
    border-radius: 4px;
    cursor: pointer;
}
nav.site form.deploy-form button.btn-deploy:hover { filter: brightness(1.05); }
.site-nav-deploying {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--warn);
    animation: site-nav-deploying-pulse 1.4s ease-in-out infinite;
}
.site-nav-deploying-dots { display: inline-block; width: 1.2em; text-align: left; }
.site-nav-deploying-dots::after { content: "…"; }
@keyframes site-nav-deploying-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.55; }
}
main { max-width: 1200px; margin: 0 auto; padding: 1.25rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 1rem; margin-bottom: 1rem; }
h1 { font-size: 1.4rem; margin-bottom: 0.75rem; }
h2 { font-size: 1.1rem; margin-bottom: 0.5rem; }
h2.spaced { margin-top: 1rem; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.45rem 0.5rem; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.9rem; vertical-align: top; }
th { color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: none; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.badge { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 10px; font-size: 0.75rem; background: var(--bg); border: 1px solid var(--border); color: var(--text-muted); }
.badge.status-open { background: #dbeafe; border-color: #93c5fd; color: #1e40af; }
.badge.status-wip { background: #fef3c7; border-color: #fcd34d; color: #92400e; }
.badge.status-blocked { background: #fee2e2; border-color: #fca5a5; color: #991b1b; }
.badge.status-completed { background: #dcfce7; border-color: #86efac; color: #166534; }
.badge.status-wontfix { background: #f3f4f6; border-color: #d1d5db; color: #4b5563; }
.badge.status-draft { background: #ede9fe; border-color: #c4b5fd; color: #5b21b6; }
.star { color: var(--warn); }
.meta { color: var(--text-muted); font-size: 0.85rem; }
.empty { color: var(--text-muted); padding: 1rem; text-align: center; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1rem; }
dl.kv dt { color: var(--text-muted); font-size: 0.8rem; }
button, input, select, textarea { font: inherit; padding: 0.4rem 0.6rem; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); color: var(--text); }
button { background: var(--accent); border-color: var(--accent); color: #fff; cursor: pointer; }
button:hover { filter: brightness(1.05); }
button.secondary:hover, .form-actions a.secondary:hover { border-color: var(--accent); color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.login-card { max-width: 360px; margin: 4rem auto; }
.login-card form { display: grid; gap: 0.75rem; }
.login-card label { display: block; color: var(--text-muted); font-size: 0.8rem; margin-bottom: 0.25rem; }
.login-card input { width: 100%; }
.error { color: var(--danger); font-size: 0.85rem; }
.prose { white-space: normal; font-family: inherit; }
.prose p { margin: 0.25rem 0; }
.prose pre { background: var(--code-bg); padding: 0.5rem; border-radius: 4px; overflow-x: auto; }
.prose code { background: var(--code-bg); padding: 0 0.2rem; border-radius: 3px; }
.prose pre code { padding: 0; background: none; }
.comment { border-bottom: 1px solid var(--border); padding: 0.5rem 0; }
.comment:last-of-type { border-bottom: none; }
.comment .prose { margin-top: 0.25rem; }

nav.site a.new-issue { color: var(--accent); }

.quick-filters { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.quick-filter {
    display: inline-block;
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
    font-size: 0.85rem;
}
.quick-filter:hover { text-decoration: none; border-color: var(--accent); }
.quick-filter.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.quick-filter.active:hover { color: #fff; }

.issue-filters {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.75rem;
    margin-bottom: 1rem;
}
.filter-row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-start; }
.filter-row label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.8rem; color: var(--text-muted); }
.filter-row label.inline { flex-direction: row; align-items: center; gap: 0.4rem; margin-top: 1.2rem; }
.filter-row label.wide { flex: 1; }
.filter-row label.wide input { width: 100%; }

.reorder-col { width: 4rem; white-space: nowrap; }
.reorder-btn {
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--border);
    padding: 0.1rem 0.35rem;
    font-size: 0.75rem;
    cursor: pointer;
}
.reorder-btn:hover { color: var(--accent); border-color: var(--accent); }

.issue-form { max-width: 900px; }
.issue-form .form-field { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 0.75rem; }
.issue-form .form-field.wide { width: 100%; }
.issue-form .form-field.inline { flex-direction: row; align-items: center; }
.issue-form .form-field label { font-size: 0.85rem; color: var(--text-muted); }
.issue-form .form-row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-start; }
.issue-form .form-row .form-field { flex: 1 1 12rem; }
.issue-form textarea { width: 100%; font-family: ui-monospace, Menlo, monospace; }
.issue-form input[type=text], .issue-form select { width: 100%; }
.issue-form label.inline { display: inline-flex; align-items: center; gap: 0.4rem; }
.issue-form .hidden { display: none; }
.form-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.form-actions button.secondary, .form-actions a.secondary,
button.secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    text-decoration: none;
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
}
.form-preview-controls { margin-top: 0.25rem; }
.preview { background: var(--bg); border: 1px dashed var(--border); padding: 0.5rem; margin-top: 0.5rem; min-height: 1rem; }
.preview:empty { display: none; }

.layout-detail { display: grid; grid-template-columns: 2fr 1fr; gap: 1rem; }
@media (max-width: 900px) { .layout-detail { grid-template-columns: 1fr; } }
.description-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.25rem; }
.description-form textarea { width: 100%; font-family: ui-monospace, Menlo, monospace; }
.comment-form { margin-top: 0.75rem; }
.comment-form textarea { width: 100%; font-family: inherit; }

.highlight-toggle {
    background: none;
    border: none;
    color: var(--warn);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 0.25rem;
}
.link-button {
    background: none;
    border: none;
    color: var(--accent);
    padding: 0;
    cursor: pointer;
    font-size: inherit;
}
.edit-link { float: right; font-size: 0.9rem; }

.issue-header { margin-bottom: 1rem; }
.issue-header-top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
    font-size: 0.9rem;
}
.issue-header-top .px { font-family: ui-monospace, Menlo, monospace; color: var(--text-muted); }
.issue-header-top .chip { color: var(--text); text-decoration: none; }
.issue-header-top .chip:hover { border-color: var(--accent); color: var(--accent); }
.issue-header-actions { margin-left: auto; display: flex; gap: 0.5rem; align-items: center; }
.issue-title { font-size: 1.5rem; line-height: 1.25; margin: 0; }

.action-label {
    font-family: ui-monospace, Menlo, monospace;
    font-size: 0.8rem;
    color: var(--text);
}

.activity { list-style: none; }
.activity li { border-bottom: 1px solid var(--border); padding: 0.25rem 0; }
.activity li:last-child { border-bottom: none; }
.activity summary { cursor: pointer; font-size: 0.85rem; }
.activity dl.diff { margin-top: 0.25rem; font-size: 0.8rem; }
.activity dl.diff dt { color: var(--text-muted); }
.activity dl.diff dd { margin-bottom: 0.25rem; }
.activity del { background: #fee2e2; color: #991b1b; text-decoration: line-through; padding: 0 0.2rem; }
.activity ins { background: #dcfce7; color: #166534; text-decoration: none; padding: 0 0.2rem; }

.kanban { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.75rem; margin-top: 0.5rem; }
@media (max-width: 900px) { .kanban { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .kanban { grid-template-columns: 1fr; } }
.kanban-col {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    min-height: 8rem;
}
.kanban-col > h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}
.kanban-col > h3 .count { font-size: 0.75rem; color: var(--text-muted); font-weight: normal; }
.kanban-cards { display: flex; flex-direction: column; gap: 0.35rem; min-height: 3rem; flex: 1; }
.kanban-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.45rem 0.55rem;
    font-size: 0.85rem;
    cursor: grab;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}
.kanban-card:active { cursor: grabbing; }
.kanban-card .head { display: flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; }
.kanban-card .head a { font-weight: 500; }
.kanban-card .px { color: var(--text-muted); font-size: 0.75rem; font-family: ui-monospace, Menlo, monospace; }
.kanban-card .card-meta { color: var(--text-muted); font-size: 0.75rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }
.kanban-card.sortable-ghost { opacity: 0.35; }
.kanban-card.sortable-chosen { box-shadow: 0 0 0 2px var(--accent); }
.kanban-card.wontfix { opacity: 0.6; }
.kanban-card.wontfix .head a { text-decoration: line-through; }
.kanban-empty { color: var(--text-muted); font-size: 0.75rem; padding: 0.4rem; text-align: center; font-style: italic; }

.heatmap-summary { font-size: 0.9rem; margin-bottom: 0.4rem; }
.heatmap-summary strong { font-weight: 600; }
.heatmap {
    display: grid;
    grid-template-rows: repeat(7, 0.85rem);
    grid-auto-flow: column;
    grid-auto-columns: 0.85rem;
    gap: 2px;
    overflow-x: auto;
    padding-bottom: 0.25rem;
}
.heat-cell { width: 0.85rem; height: 0.85rem; border-radius: 2px; }
.heat-cell.empty { background: transparent; }
.heat-cell.tier-0 { background: #ebedf0; }
.heat-cell.tier-1 { background: #9be9a8; }
.heat-cell.tier-2 { background: #40c463; }
.heat-cell.tier-3 { background: #30a14e; }
.heat-cell.tier-4 { background: #216e39; }
.heat-legend { display: flex; gap: 2px; align-items: center; margin-top: 0.5rem; font-size: 0.8rem; }
.heat-legend .meta { margin: 0 0.3rem; }

.pagination { display: flex; gap: 1rem; align-items: center; margin-top: 0.75rem; }

.dashboard-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.dashboard-stats { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.dashboard-stats .stat {
    display: flex; flex-direction: column; align-items: center;
    padding: 0.4rem 0.9rem; border: 1px solid var(--border); border-radius: 6px;
    background: var(--surface); color: var(--text); text-decoration: none;
    min-width: 4.5rem;
}
.dashboard-stats .stat:hover { border-color: var(--accent); text-decoration: none; }
.dashboard-stats .stat-value { font-size: 1.25rem; font-weight: 600; line-height: 1.1; }
.dashboard-stats .stat-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.dashboard-stats .stat.draft .stat-value { color: #5b21b6; }
.dashboard-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; align-items: start; }
@media (max-width: 900px) { .dashboard-grid { grid-template-columns: 1fr; } }
.dashboard-panel h2 { margin-bottom: 0.5rem; }
.dashboard-wide { grid-column: 1 / -1; }
.issue-bullets { list-style: none; display: flex; flex-direction: column; gap: 0.35rem; }
.issue-bullets li { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; font-size: 0.9rem; }
.issue-bullets .px { font-family: ui-monospace, Menlo, monospace; font-size: 0.8rem; color: var(--text-muted); }
.issue-bullets .title { color: var(--text); }
.issue-bullets .title:hover { color: var(--accent); }
.chip { font-size: 0.7rem; padding: 0.05rem 0.45rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); color: var(--text-muted); }

.prio { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.85rem; }
.prio::before { content: ""; width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--prio-3); display: inline-block; }
.prio.prio-1::before { background: var(--prio-1); }
.prio.prio-2::before { background: var(--prio-2); }
.prio.prio-3::before { background: var(--prio-3); }
.prio.prio-4::before { background: var(--prio-4); }
.prio.prio-5::before { background: var(--prio-5); }

kbd {
    display: inline-block; padding: 0.05rem 0.4rem;
    border: 1px solid var(--border); border-bottom-width: 2px;
    border-radius: 3px; background: var(--surface); color: var(--text);
    font: 0.8em ui-monospace, Menlo, monospace;
}
.help-dialog {
    border: 1px solid var(--border); border-radius: 8px;
    padding: 1.25rem; max-width: 26rem; background: var(--surface); color: var(--text);
}
.help-dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
.help-dialog h2 { margin-bottom: 0.75rem; }
.help-dialog dl.kv { grid-template-columns: max-content 1fr; gap: 0.4rem 1rem; }
.help-dialog dl.kv dt { color: var(--text); display: flex; gap: 0.25rem; align-items: center; }
body[data-g-prefix]::after {
    content: "g…";
    position: fixed; bottom: 1rem; right: 1rem;
    background: var(--text); color: var(--surface);
    padding: 0.3rem 0.6rem; border-radius: 4px;
    font: 0.8rem ui-monospace, Menlo, monospace;
    pointer-events: none; z-index: 10;
}
.help-toggle {
    color: var(--text-muted); font-family: ui-monospace, Menlo, monospace;
    width: 1.6rem; height: 1.6rem; border-radius: 50%;
    border: 1px solid var(--border); display: inline-flex;
    align-items: center; justify-content: center;
}
.help-toggle:hover { color: var(--accent); border-color: var(--accent); }
