:root {
    --bg: #0a0b0f;
    --card: #111319;
    --card-2: #171a22;
    --line: rgba(255, 255, 255, 0.07);
    --line-2: rgba(255, 255, 255, 0.04);
    --ink: #e7e9ee;
    --muted: #8b93a3;
    --faint: #5b6270;
    --violet: #8b5cf6;
    --violet-soft: rgba(139, 92, 246, 0.16);
    --green: #4ade80;
    --green-soft: rgba(74, 222, 128, 0.14);
    --red: #f87171;
    --red-soft: rgba(248, 113, 113, 0.14);
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    color: var(--ink);
    background:
        radial-gradient(1100px 420px at 72% -12%, rgba(124, 58, 237, 0.28), transparent 62%),
        radial-gradient(900px 380px at 8% -8%, rgba(59, 130, 246, 0.12), transparent 60%),
        var(--bg);
    background-attachment: fixed;
    font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.num {
    font-variant-numeric: tabular-nums;
}

/* Loading feedback */
.loadbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    z-index: 50;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

body.loading .loadbar {
    opacity: 1;
}

.loadbar::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    width: 40%;
    background: linear-gradient(90deg, transparent, var(--violet), transparent);
    transform: translateX(-100%);
    animation: loadslide 0.9s ease-in-out infinite;
}

@keyframes loadslide {
    0% {
        transform: translateX(-120%);
    }
    100% {
        transform: translateX(360%);
    }
}

/* While recomputing, soften the live figures so the new value visibly lands. */
.hero-figure,
.hero-exact,
.donut-val,
.alloc-bar,
#chips,
#legend {
    transition: opacity 0.18s ease;
}

body.loading .hero-figure,
body.loading .donut-val {
    opacity: 0.5;
}

body.loading .hero-exact,
body.loading .alloc-bar,
body.loading #chips,
body.loading #legend {
    opacity: 0.65;
}

@media (prefers-reduced-motion: reduce) {
    .loadbar::before {
        animation: none;
    }
}

.app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 22px clamp(14px, 3vw, 32px) 56px;
}

/* Top bar */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding-bottom: 18px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
}

.mark {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    display: grid;
    place-items: center;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #a78bfa, #7c3aed);
    box-shadow: 0 4px 14px rgba(124, 58, 237, 0.35);
}

.brand-name {
    font-size: 17px;
    font-weight: 650;
    letter-spacing: -0.01em;
}

.brand-tag {
    color: var(--violet);
    font-weight: 500;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.film-picker {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 11px;
    color: var(--muted);
}

select {
    appearance: none;
    font: inherit;
    font-size: 13.5px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--card-2);
    color: var(--ink);
    min-width: 220px;
    cursor: pointer;
}

select:focus-visible {
    outline: 2px solid var(--violet);
    outline-offset: 1px;
}

.badge {
    font-size: 13px;
    font-weight: 600;
    padding: 8px 13px;
    border-radius: 999px;
    color: var(--green);
    background: var(--green-soft);
    white-space: nowrap;
}

.badge::before {
    content: "\2713  ";
}

.badge.broken {
    color: var(--red);
    background: var(--red-soft);
}

.badge.broken::before {
    content: "\2717  ";
}

/* Grid */
.grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 16px;
    align-items: start;
}

.terms {
    grid-column: span 5;
}

.hero {
    grid-column: span 7;
}

.alloc {
    grid-column: span 5;
}

.waterfall {
    grid-column: span 7;
}

.ledger-card {
    grid-column: span 12;
}

@media (max-width: 980px) {
    .grid > section {
        grid-column: 1 / -1;
    }
}

/* Cards */
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 20px;
}

.card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.card-head h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}

.note {
    font-size: 12px;
    color: var(--faint);
}

.tag {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    padding: 4px 9px;
    border-radius: 7px;
    color: var(--muted);
    background: var(--card-2);
}

.tag.loss {
    color: var(--red);
    background: var(--red-soft);
}

.tag.profit {
    color: var(--green);
    background: var(--green-soft);
}

button {
    font: inherit;
    font-size: 13px;
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

button:hover {
    border-color: var(--violet);
    color: var(--violet);
}

/* Deal-term sliders */
.sliders {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 16px 18px;
}

.slider label {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 7px;
}

.slider .value {
    color: var(--ink);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.slider input[type="range"] {
    width: 100%;
    height: 4px;
    accent-color: var(--violet);
    cursor: pointer;
}

/* Hero */
.hero-figure {
    font-size: clamp(40px, 6vw, 58px);
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.hero-figure.neg {
    color: var(--red);
}

.hero-figure.pos {
    color: var(--green);
}

.hero-exact {
    margin-top: 8px;
    font-size: 14px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.hero-exact .dim {
    color: var(--faint);
}

.verdict {
    margin: 16px 0 0;
    font-size: 14.5px;
    color: var(--muted);
    max-width: 52ch;
}

.alloc-bar {
    display: flex;
    gap: 2px;
    height: 10px;
    margin: 18px 0 16px;
}

.alloc-bar span {
    height: 100%;
    border-radius: 3px;
    min-width: 2px;
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.chip-stat {
    flex: 1 1 110px;
    background: var(--card-2);
    border: 1px solid var(--line-2);
    border-radius: 11px;
    padding: 10px 12px;
}

.chip-stat .k {
    font-size: 11px;
    color: var(--muted);
}

.chip-stat .v {
    margin-top: 3px;
    font-size: 16px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* Allocation donut */
.donut-row {
    display: flex;
    align-items: center;
    gap: 22px;
    flex-wrap: wrap;
}

.donut-wrap {
    position: relative;
    width: 156px;
    height: 156px;
    flex: 0 0 auto;
}

.donut-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.donut-val {
    font-size: 19px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.donut-val.neg {
    color: var(--red);
}

.donut-val.pos {
    color: var(--green);
}

.donut-label {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 2px;
}

.legend {
    list-style: none;
    margin: 0;
    padding: 0;
    flex: 1 1 200px;
    min-width: 200px;
}

.legend li {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 7px 0;
    border-bottom: 1px solid var(--line-2);
    font-size: 13px;
}

.legend li:last-child {
    border-bottom: none;
}

.legend .dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex: 0 0 auto;
}

.legend .name {
    flex: 1;
    color: var(--ink);
}

.legend .val {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.legend .pct {
    width: 50px;
    text-align: right;
    color: var(--faint);
    font-variant-numeric: tabular-nums;
}

/* Waterfall */
.chart-wrap {
    height: 300px;
}

/* Ledger */
.ledger-scroll {
    overflow-x: auto;
}

.ledger {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
    min-width: 640px;
}

.ledger th {
    text-align: left;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 0 12px 11px;
    border-bottom: 1px solid var(--line);
}

.ledger th.num,
.ledger td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.ledger td {
    padding: 12px;
    border-bottom: 1px solid var(--line-2);
}

.ledger td.seq {
    color: var(--faint);
    width: 28px;
}

.ledger .flow {
    display: flex;
    align-items: center;
    gap: 9px;
    white-space: nowrap;
}

.ledger .chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--card-2);
    border: 1px solid var(--line-2);
    font-size: 12.5px;
}

.ledger .chip .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
}

.ledger .arrow {
    color: var(--faint);
}

.ledger .amt {
    font-weight: 600;
}

.ledger .check {
    color: var(--green);
}

.ledger tfoot td {
    border-bottom: none;
    border-top: 1px solid var(--line);
    padding-top: 13px;
    font-weight: 600;
}

.ledger tfoot tr:not(:first-child) td {
    border-top: none;
    padding-top: 4px;
}

footer {
    margin-top: 28px;
    color: var(--faint);
    font-size: 12px;
    max-width: 90ch;
}

/* Mobile */
@media (max-width: 620px) {
    .app {
        padding: 16px 14px 40px;
    }

    .topbar {
        align-items: stretch;
        gap: 14px;
    }

    .topbar-actions {
        width: 100%;
        justify-content: space-between;
    }

    .film-picker {
        flex: 1;
    }

    select {
        width: 100%;
        min-width: 0;
    }

    .grid {
        gap: 12px;
    }

    .card {
        padding: 16px;
        border-radius: 14px;
    }

    .card-head {
        flex-wrap: wrap;
        gap: 8px;
    }

    .chart-wrap {
        height: 240px;
    }

    .donut-row {
        justify-content: center;
    }

    .hero-figure {
        font-size: 42px;
    }
}
