:root {
    --font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --mono-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    --radius-sm: 7px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --transition: 160ms ease;
}

[data-theme="light"] {
    --bg-primary: #f7f7f4;
    --surface: #ffffff;
    --surface-raised: #fbfbf8;
    --surface-soft: #eeeeea;
    --surface-hover: #e7e7e1;
    --text-primary: #171817;
    --text-secondary: #515750;
    --text-muted: #858b83;
    --border-color: #dadbd3;
    --accent: #2f6f5e;
    --accent-hover: #255d4e;
    --accent-soft: #ddebe6;
    --success: #2f6f5e;
    --success-soft: #ddebe6;
    --warning: #9a6a16;
    --warning-soft: #f3ead6;
    --danger: #b33a3a;
    --danger-soft: #f3dfdc;
    --shadow: 0 18px 52px rgba(23, 24, 23, 0.12);
}

[data-theme="dark"] {
    --bg-primary: #111311;
    --surface: #181b18;
    --surface-raised: #1e221f;
    --surface-soft: #252a26;
    --surface-hover: #2d342f;
    --text-primary: #f4f5f0;
    --text-secondary: #c2c8bd;
    --text-muted: #899185;
    --border-color: #333a34;
    --accent: #8fd1b8;
    --accent-hover: #a6ddca;
    --accent-soft: rgba(143, 209, 184, 0.16);
    --success: #8fd1b8;
    --success-soft: rgba(143, 209, 184, 0.16);
    --warning: #e4be71;
    --warning-soft: rgba(228, 190, 113, 0.15);
    --danger: #ef8a82;
    --danger-soft: rgba(239, 138, 130, 0.15);
    --shadow: 0 22px 60px rgba(0, 0, 0, 0.34);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: 15px;
}

body {
    margin: 0;
    min-height: 100dvh;
    background:
        linear-gradient(180deg, color-mix(in srgb, var(--accent-soft) 34%, transparent), transparent 260px),
        var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-family);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

button {
    border: 0;
}

input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text-primary);
    outline: none;
    padding: 10px 12px;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

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

input:focus,
textarea:focus,
select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

a {
    color: var(--accent);
    text-underline-offset: 3px;
}

a:hover {
    color: var(--accent-hover);
}

.hidden {
    display: none !important;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 38px;
    border-radius: 999px;
    padding: 8px 15px;
    cursor: pointer;
    font-weight: 700;
    white-space: nowrap;
    transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition);
}

.btn:active,
.btn-icon:active,
.project-tab:active {
    transform: translateY(1px);
}

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

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--surface-hover);
}

.btn-danger {
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid transparent;
}

.btn-danger:hover {
    border-color: var(--danger);
}

.btn-sm {
    min-height: 32px;
    padding: 6px 12px;
    font-size: 0.86rem;
}

.btn-full {
    width: 100%;
}

.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border: 1px solid transparent;
    transition: background var(--transition), color var(--transition), border-color var(--transition), transform var(--transition);
}

.btn-icon:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

.btn-icon.danger:hover {
    background: var(--danger-soft);
    color: var(--danger);
}

.auth-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(17, 19, 17, 0.62);
    backdrop-filter: blur(12px);
    opacity: 1;
    transition: opacity var(--transition);
}

.auth-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.auth-box {
    width: min(390px, 100%);
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 34px;
}

.auth-box h1 {
    margin: 0 0 8px;
    font-size: 1.55rem;
    letter-spacing: -0.02em;
}

.auth-box p {
    margin: 0 0 22px;
    color: var(--text-secondary);
}

.auth-error {
    display: none;
    margin-bottom: 12px;
    color: var(--danger);
    font-size: 0.9rem;
}

.top-nav {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 18px;
    min-height: 66px;
    padding: 12px 28px;
    background: color-mix(in srgb, var(--bg-primary) 88%, transparent);
    border-bottom: 1px solid color-mix(in srgb, var(--border-color) 76%, transparent);
    backdrop-filter: blur(14px);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: max-content;
    font-weight: 800;
    letter-spacing: -0.01em;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: var(--text-primary);
    color: var(--bg-primary);
    font-family: var(--mono-family);
    font-size: 0.78rem;
}

.search-wrapper {
    position: relative;
    flex: 1;
    max-width: 520px;
}

.search-wrapper input {
    border-radius: 999px;
    padding-left: 38px;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
}

.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
    font-family: var(--mono-family);
}

.nav-actions,
.commit-actions,
.row-actions,
.summary-actions,
.heading-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.inline-select {
    width: auto;
    min-height: 32px;
    border-radius: 999px;
    padding: 5px 30px 5px 12px;
    background: var(--surface);
    color: var(--text-primary);
    font-size: 0.86rem;
}

.inline-toggle,
.checkbox-field {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 0.88rem;
    font-weight: 700;
}

.inline-toggle input,
.checkbox-field input {
    width: auto;
    margin: 0;
}

.nav-actions {
    margin-left: auto;
    justify-content: flex-end;
}

.project-bar {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    max-width: 1160px;
    margin: 0 auto;
    padding: 18px 28px 0;
}

.project-tab {
    min-height: 34px;
    padding: 7px 13px;
    border-radius: 999px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--transition), color var(--transition), border-color var(--transition), transform var(--transition);
}

.project-tab:hover {
    background: var(--surface);
    border-color: var(--border-color);
}

.project-tab.active {
    background: var(--text-primary);
    color: var(--bg-primary);
    border-color: var(--text-primary);
}

.app-layout {
    max-width: 1160px;
    margin: 0 auto;
    padding: 26px 28px 120px;
}

.content-area {
    min-width: 0;
}

.content-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 28px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--border-color);
}

.content-heading h1 {
    margin: 0 0 8px;
    font-size: clamp(2rem, 5vw, 4.8rem);
    line-height: 0.98;
    letter-spacing: -0.055em;
    max-width: 780px;
}

.content-heading p {
    margin: 0;
    max-width: 62ch;
    color: var(--text-secondary);
}

.version-list {
    display: grid;
    gap: 14px;
}

.version-section {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: color-mix(in srgb, var(--surface) 74%, transparent);
    overflow: hidden;
}

.version-section.archived {
    opacity: 0.74;
}

.version-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    gap: 14px;
    align-items: start;
    padding: 18px;
    transition: background var(--transition);
}

.version-header:hover {
    background: var(--surface-raised);
}

.collapse-button {
    width: 30px;
    height: 30px;
    border-radius: 999px;
    background: var(--surface);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    cursor: pointer;
    font-size: 1.1rem;
}

.version-title h2,
.parent-title-line h3 {
    margin: 5px 0;
    letter-spacing: -0.02em;
}

.version-title h2 {
    font-size: 1.25rem;
}

.version-progress {
    display: grid;
    gap: 6px;
    justify-items: end;
    color: var(--text-secondary);
    font-family: var(--mono-family);
    font-size: 0.84rem;
}

.progress-track {
    width: 130px;
    height: 2px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--border-color);
}

.progress-track span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
}

.progress-track.small {
    width: 92px;
}

.version-body {
    display: none;
    padding: 0 18px 18px 58px;
}

.version-body.open {
    display: grid;
    gap: 12px;
}

.parent-task {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.parent-title-line,
.child-title-line {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.title-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.parent-progress {
    margin-top: 10px;
    color: var(--text-muted);
    font-family: var(--mono-family);
    font-size: 0.8rem;
}

.child-list {
    grid-column: 1 / -1;
    display: grid;
    gap: 0;
    padding-top: 2px;
}

.child-task {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 10px;
    align-items: start;
    padding: 12px 0;
    border-top: 1px solid var(--border-color);
}

.check-button {
    width: 19px;
    height: 19px;
    margin-top: 4px;
    border-radius: 50%;
    border: 1.5px solid var(--border-color);
    background: var(--surface);
    cursor: pointer;
}

.check-button.checked {
    border-color: var(--accent);
    background: var(--accent);
    box-shadow: inset 0 0 0 4px var(--surface);
}

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 800;
}

.status-todo {
    color: var(--text-secondary);
    background: var(--surface-soft);
}

.status-doing {
    color: var(--warning);
    background: var(--warning-soft);
}

.status-done {
    color: var(--success);
    background: var(--success-soft);
}

.priority-pill,
.archive-pill {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 800;
}

.priority-pill {
    color: var(--danger);
    background: var(--danger-soft);
}

.archive-pill {
    color: var(--text-secondary);
    background: var(--surface-soft);
}

.high-priority {
    border-color: color-mix(in srgb, var(--danger) 35%, var(--border-color));
}

.meta-line {
    margin-top: 8px;
    color: var(--text-muted);
    font-family: var(--mono-family);
    font-size: 0.78rem;
}

.rich-description {
    color: var(--text-secondary);
}

.rich-description p {
    margin: 0;
}

.description-images {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
    margin-top: 12px;
}

.description-images a {
    display: block;
    overflow: hidden;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--surface-soft);
}

.description-images img {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    transition: transform 220ms ease;
}

.description-images a:hover img {
    transform: scale(1.025);
}

.empty-state,
.loading-state {
    display: grid;
    place-items: center;
    gap: 12px;
    min-height: 260px;
    text-align: center;
    color: var(--text-secondary);
    background: color-mix(in srgb, var(--surface) 72%, transparent);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 34px;
}

.empty-state h2 {
    margin: 0;
    color: var(--text-primary);
}

.empty-state p {
    margin: 0;
}

.empty-inline {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 16px;
    color: var(--text-muted);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-md);
}

.link-button {
    background: transparent;
    color: var(--accent);
    cursor: pointer;
    font-weight: 800;
}

.link-button:hover {
    color: var(--accent-hover);
}

.loading-spinner {
    width: 22px;
    height: 22px;
    border: 2px solid var(--surface-soft);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(17, 19, 17, 0.58);
    backdrop-filter: blur(6px);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.modal,
.project-overview-panel {
    width: min(580px, 100%);
    max-height: min(760px, 90vh);
    overflow: auto;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 24px;
}

.modal h2 {
    margin: 0 0 18px;
    font-size: 1.25rem;
    letter-spacing: -0.02em;
}

.modal label {
    display: block;
    margin: 14px 0 7px;
    font-weight: 750;
}

.field-hint {
    margin: 7px 0 0;
    color: var(--text-muted);
    font-size: 0.84rem;
}

.checkbox-field {
    margin-top: 14px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 22px;
}

.overview-topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    color: var(--text-muted);
    font-size: 0.88rem;
    font-weight: 800;
}

.summary-panel {
    display: grid;
    gap: 18px;
}

.summary-header h2 {
    margin: 0 0 10px;
    font-size: 2rem;
    line-height: 1;
    letter-spacing: -0.045em;
}

.progress-block {
    margin: 0;
}

.progress-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-family: var(--mono-family);
    font-size: 0.84rem;
}

.summary-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.summary-stats div {
    padding: 11px;
    background: var(--surface-raised);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.summary-stats strong {
    display: block;
    font-size: 1.25rem;
}

.summary-stats span {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.summary-empty {
    color: var(--text-muted);
}

.status-check-list {
    display: grid;
    gap: 10px;
}

.status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--surface-raised);
}

.status-row span {
    color: var(--text-secondary);
    text-align: right;
}

.status-row.ok {
    border-color: color-mix(in srgb, var(--success) 28%, var(--border-color));
}

.status-row.warn {
    border-color: color-mix(in srgb, var(--warning) 35%, var(--border-color));
}

.status-row.error {
    border-color: color-mix(in srgb, var(--danger) 35%, var(--border-color));
}

.toast-container {
    position: fixed;
    top: 76px;
    right: 24px;
    z-index: 1100;
    display: grid;
    gap: 10px;
    width: min(360px, calc(100vw - 32px));
}

.toast {
    padding: 12px 14px;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    background: var(--surface);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    animation: toastIn 0.2s ease, toastOut 0.25s ease 2.95s forwards;
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.warning {
    border-left: 4px solid var(--warning);
}

.toast.error {
    border-left: 4px solid var(--danger);
}

.toast.info {
    border-left: 4px solid var(--accent);
}

@keyframes toastIn {
    from {
        transform: translateY(-8px);
        opacity: 0;
    }
}

@keyframes toastOut {
    to {
        transform: translateY(-8px);
        opacity: 0;
    }
}

.commit-bar {
    position: fixed;
    left: 50%;
    bottom: 18px;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    width: min(720px, calc(100vw - 32px));
    padding: 14px 16px;
    border-radius: var(--radius-lg);
    background: var(--surface);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    transform: translate(-50%, 140%);
    transition: transform 0.24s ease;
}

.commit-bar.visible {
    transform: translate(-50%, 0);
}

.changes-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
}

.changes-info strong {
    color: var(--warning);
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 1ms !important;
        scroll-behavior: auto !important;
        transition-duration: 1ms !important;
    }
}

@media (max-width: 840px) {
    .top-nav {
        flex-wrap: wrap;
        padding: 12px 16px;
    }

    .nav-brand {
        width: calc(100% - 104px);
    }

    .search-wrapper {
        order: 3;
        flex-basis: 100%;
        max-width: none;
    }

    .project-bar {
        padding: 12px 16px 0;
    }

    .app-layout {
        padding: 22px 16px 120px;
    }

    .content-heading,
    .commit-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .heading-actions {
        justify-content: flex-start;
    }

    .version-header {
        grid-template-columns: auto minmax(0, 1fr);
    }

    .version-progress,
    .version-header > .row-actions {
        grid-column: 2;
        justify-items: start;
        justify-content: flex-start;
    }

    .version-body {
        padding: 0 14px 14px;
    }

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

    .child-task {
        grid-template-columns: auto minmax(0, 1fr);
    }

    .child-actions {
        grid-column: 2;
        justify-content: flex-start;
    }

    .nav-actions {
        margin-left: auto;
    }
}

@media (max-width: 520px) {
    .nav-brand span:last-child {
        display: none;
    }

    .summary-stats {
        grid-template-columns: 1fr;
    }

    .modal,
    .project-overview-panel {
        padding: 20px;
    }

    .description-images {
        grid-template-columns: 1fr;
    }
}
