:root {
    --bg: #100e0c;
    --bg-2: #171410;
    --card: #1f1a15;
    --card-2: #261f18;
    --line: rgba(232, 201, 140, 0.16);
    --gold: #e0b15c;
    --gold-2: #f4d9a4;
    --mint: #8fceb0;
    --sky: #8bb8d8;
    --text: #f6f0e6;
    --muted: #a39888;
    --danger: #e08a7a;
    --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
    --radius: 22px;
    --safe-b: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    background:
        radial-gradient(1200px 500px at 10% -10%, rgba(224, 177, 92, 0.12), transparent 50%),
        radial-gradient(900px 400px at 100% 0%, rgba(143, 206, 176, 0.08), transparent 45%),
        var(--bg);
    color: var(--text);
    font-family: Manrope, sans-serif;
}

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

h1, h2, .display {
    font-family: Unbounded, Manrope, sans-serif;
    letter-spacing: -0.03em;
}

.app {
    width: 100%;
    max-width: 1120px;
    margin: 0 auto;
    padding: 16px max(16px, env(safe-area-inset-right)) calc(28px + var(--safe-b)) max(16px, env(safe-area-inset-left));
    overflow-x: hidden;
}

.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    min-width: 0;
}

.topbar > div { min-width: 0; }

.topbar h1 {
    margin: 4px 0 0;
    font-size: clamp(22px, 6vw, 28px);
    line-height: 1.15;
    overflow-wrap: anywhere;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
    flex-shrink: 0;
}

.account {
    position: relative;
    flex-shrink: 0;
}

.who-btn {
    border: 1px solid var(--line);
    background: var(--card);
    border-radius: 999px;
    padding: 8px 14px;
    cursor: pointer;
    font-weight: 700;
    max-width: min(220px, 52vw);
    color: inherit;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.who-btn span:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.who-caret {
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid var(--muted);
    flex-shrink: 0;
}

.account.is-open .who-btn {
    border-color: var(--gold);
}

.account.is-open .who-caret {
    transform: rotate(180deg);
    border-top-color: var(--gold);
}

.account-menu {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    min-width: 220px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 6px;
    box-shadow: var(--shadow);
    z-index: 12;
}

.account.is-open .account-menu {
    display: grid;
    gap: 2px;
}

.account-login {
    margin: 0 4px 4px;
    color: var(--muted);
    font-size: 12px;
}

.account-item {
    display: block;
    width: 100%;
    text-align: left;
    border: 0;
    background: var(--card-2);
    color: var(--text);
    border-radius: 12px;
    padding: 10px 12px;
    cursor: pointer;
    text-decoration: none;
    font: inherit;
    font-weight: 700;
}

.password-fields {
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
    padding: 8px 0 !important;
    grid-template-columns: 1fr;
}

.back-link {
    border: 0;
    background: transparent;
    color: var(--gold);
    padding: 0;
    margin-bottom: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
    display: inline-block;
}

.home-lead { margin: 0 0 14px; }

.loan-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.loan-card {
    text-align: left;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 16px;
    cursor: pointer;
    min-width: 0;
}

.loan-card h2 {
    margin: 6px 0 8px;
    font-size: 18px;
    overflow-wrap: anywhere;
}

.loan-card p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.user-card {
    grid-template-columns: minmax(0, 1fr) auto;
    cursor: default;
}

.user-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-end;
}

.loan-switch {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 6px;
    min-width: 0;
    width: 100%;
}

.loan-switch select {
    flex: 1;
    min-width: 0;
    max-width: 100%;
    background: #100e0c;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 8px 12px;
}

.loan-switch .ghost-btn {
    flex-shrink: 0;
    white-space: nowrap;
}

.user-list { display: grid; gap: 10px; margin-top: 16px; }

.eyebrow {
    margin: 0;
    color: var(--gold);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.hint { color: var(--muted); font-size: 13px; }

.ghost-link, .ghost-btn {
    display: inline-flex;
    align-items: center;
    width: max-content;
    color: var(--muted);
    text-decoration: none;
    border: 1px solid var(--line);
    background: transparent;
    border-radius: 999px;
    padding: 8px 14px;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}

.summary-block {
    display: grid;
    gap: 10px;
    margin-bottom: 18px;
    min-width: 0;
}

.debt-card {
    background: linear-gradient(180deg, var(--card), var(--bg-2));
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 16px 18px;
    box-shadow: var(--shadow);
    min-width: 0;
}

.debt-card > span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 6px;
}

.debt-card strong {
    display: block;
    font-family: Unbounded, sans-serif;
    font-size: clamp(26px, 7vw, 36px);
    font-weight: 600;
    line-height: 1.1;
}

.benefit-spoiler {
    min-width: 0;
}

.benefit-spoiler > summary {
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    cursor: pointer;
    background: rgba(31, 26, 21, 0.94);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 12px 16px;
    font-weight: 700;
}

.benefit-spoiler > summary::-webkit-details-marker {
    display: none;
}

.benefit-spoiler[open] > summary {
    border-color: var(--gold);
    margin-bottom: 10px;
}

.benefit-spoiler[open] > summary .who-caret {
    transform: rotate(180deg);
    border-top-color: var(--gold);
}

.summary-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    min-width: 0;
}

.stat {
    background: linear-gradient(180deg, var(--card), var(--bg-2));
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 14px 16px;
    box-shadow: var(--shadow);
    min-width: 0;
    overflow: hidden;
}

.stat > span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 6px;
}

.stat strong {
    display: block;
    font-family: Unbounded, sans-serif;
    font-size: clamp(14px, 4.2vw, 18px);
    font-weight: 600;
    overflow-wrap: anywhere;
    width: max-content;
    max-width: 100%;
}

.stat.good strong, .stat.good .sum { color: var(--mint); }

.mini b {
    width: max-content;
    max-width: 100%;
}

.tabs {
    position: sticky;
    top: 10px;
    z-index: 8;
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin-bottom: 18px;
    padding: 4px;
    background: rgba(31, 26, 21, 0.94);
    border: 1px solid var(--line);
    border-radius: 999px;
    backdrop-filter: blur(12px);
}

.tabs::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    flex: 0 0 auto;
    white-space: nowrap;
    border: 0;
    background: transparent;
    color: var(--muted);
    border-radius: 999px;
    padding: 10px 16px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.tab-btn.is-active {
    background: var(--gold);
    color: #1a140d;
}

.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

.hero, .card, .plan-item, .scene, .field-grid, .loan-note {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    min-width: 0;
    max-width: 100%;
}

.hero {
    padding: 22px;
    margin-bottom: 14px;
    overflow: hidden;
    background:
        linear-gradient(180deg, rgba(224, 177, 92, 0.08), transparent 46%),
        var(--card);
}

.hero-kicker {
    color: var(--muted);
    margin: 0 0 8px;
}

.hero h2 {
    margin: 0 0 6px;
    font-size: 15px;
    font-weight: 500;
    color: var(--gold-2);
}

.hero h2.profile-title {
    font-size: clamp(22px, 6vw, 28px);
    color: var(--text);
    font-weight: 600;
}

.big-money {
    font-family: Unbounded, sans-serif;
    font-size: clamp(28px, 8vw, 52px);
    line-height: 1.05;
    margin: 8px 0 12px;
    overflow-wrap: anywhere;
}

.cash-label {
    display: block;
    margin: 14px 0 8px;
    color: var(--muted);
    font-size: 13px;
}

.cash-wrap {
    position: relative;
}

.cash-wrap .sum {
    border-bottom: 0;
    text-decoration: none;
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gold-2);
    font-family: Unbounded, sans-serif;
    font-size: 20px;
    pointer-events: auto;
}

.cash-input {
    width: 100%;
    font-family: Unbounded, sans-serif;
    font-size: clamp(28px, 7vw, 44px);
    line-height: 1.1;
    background: #100e0c;
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 12px 48px 12px 16px;
}

.cash-input:focus {
    outline: 2px solid rgba(224, 177, 92, 0.55);
    border-color: var(--gold);
}

.preset-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0 16px;
}

.preset-row .chip {
    cursor: pointer;
}

.preset-row .chip.is-active {
    background: var(--gold);
    color: #1a140c;
    border-color: var(--gold);
}

.type-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin: 0 0 16px;
}

.type-btn {
    text-align: left;
    background: var(--card-2);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 14px;
    cursor: pointer;
}

.type-btn strong {
    display: block;
    font-size: 16px;
    margin-bottom: 6px;
}

.type-btn span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.type-btn.term.is-active {
    border-color: var(--gold);
    background: rgba(224, 177, 92, 0.14);
}

.type-btn.term.is-active strong { color: var(--gold-2); }

.type-btn.pay.is-active {
    border-color: var(--sky);
    background: rgba(139, 184, 216, 0.14);
}

.type-btn.pay.is-active strong { color: var(--sky); }

.type-btn em {
    font-style: normal;
    margin-left: 8px;
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--mint);
}

.advice {
    margin: 0 0 12px;
    padding: 12px 14px;
    border-radius: 16px;
    background: rgba(143, 206, 176, 0.1);
    border: 1px solid rgba(143, 206, 176, 0.25);
    color: var(--text);
    font-size: 14px;
    line-height: 1.45;
}

.advice b { color: var(--gold-2); }

.mark {
    display: inline-block;
    margin-left: 6px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
}

.mark.is-on { color: var(--mint); }

.hero-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

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

.chip.term { color: var(--gold-2); }
.chip.pay { color: var(--sky); }
.chip.mint { color: var(--mint); }

.hero-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.mini {
    background: rgba(16, 14, 12, 0.45);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 12px;
}

.pay-mini {
    display: flex;
    align-items: center;
    gap: 10px;
}

.pay-mini-text {
    flex: 1;
    min-width: 0;
}

.pay-check {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    margin: 0;
    padding: 0;
    border: 2px solid rgba(224, 177, 92, 0.65);
    border-radius: 12px;
    background: rgba(16, 14, 12, 0.55);
    cursor: pointer;
    position: relative;
}

.pay-check::after {
    content: "";
    position: absolute;
    left: 13px;
    top: 7px;
    width: 9px;
    height: 16px;
    border-right: 3px solid transparent;
    border-bottom: 3px solid transparent;
    transform: rotate(40deg);
}

.pay-mini.is-on .pay-check {
    background: rgba(143, 206, 176, 0.18);
    border-color: var(--mint);
}

.pay-mini.is-on .pay-check::after {
    border-color: var(--mint);
}

.mini > span,
.pay-mini-text > span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 4px;
}

.mini b { font-size: 16px; }

.mini em {
    display: block;
    margin-top: 6px;
    font-style: normal;
    font-size: 12px;
    font-weight: 700;
    color: var(--gold-2);
}

.mini.is-on {
    border-color: rgba(143, 206, 176, 0.55);
    background: rgba(143, 206, 176, 0.1);
}

.mini.is-on em { color: var(--mint); }

.whatif {
    padding: 18px 20px 20px;
    margin-bottom: 14px;
}

.whatif h3 {
    margin: 0 0 6px;
    font-size: 16px;
}

.whatif p.hint {
    margin: 0 0 14px;
    color: var(--muted);
    font-size: 13px;
}

.slider-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: center;
}

input[type="range"] {
    width: 100%;
    accent-color: var(--gold);
}

.money-input {
    width: 148px;
    background: #100e0c;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 12px;
    text-align: right;
}

.whatif-result {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 16px;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}

.btn {
    border: 0;
    border-radius: 999px;
    padding: 11px 16px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.btn-gold { background: var(--gold); color: #1a140c; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }

.plan-head, .section-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    margin: 8px 4px 12px;
    flex-wrap: wrap;
    min-width: 0;
}

.section-head h2, .plan-head h2 {
    margin: 0;
    font-size: 20px;
}

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

.plan-item {
    padding: 14px 16px;
    cursor: pointer;
    display: grid;
    grid-template-columns: 84px minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
}

.plan-item.is-current {
    border-color: rgba(224, 177, 92, 0.55);
    box-shadow: 0 0 0 1px rgba(224, 177, 92, 0.25), var(--shadow);
}

.plan-item.is-paid { opacity: 0.62; }

.plan-item .n {
    color: var(--muted);
    font-size: 12px;
}

.plan-item .when { font-weight: 700; }
.plan-item .sub { color: var(--muted); font-size: 12px; margin-top: 3px; }
.plan-item .right { text-align: right; }
.plan-item .right b { display: block; }

.badge {
    display: inline-block;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.badge.term { background: rgba(224, 177, 92, 0.16); color: var(--gold-2); }
.badge.pay { background: rgba(139, 184, 216, 0.16); color: var(--sky); }

.scene-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.scene {
    padding: 16px;
    cursor: pointer;
    text-align: left;
}

.scene.is-active { border-color: var(--gold); }
.scene h3 { margin: 0 0 10px; font-size: 16px; }
.scene dl { margin: 0; display: grid; gap: 6px; }
.scene dt { color: var(--muted); font-size: 12px; }
.scene dd { margin: 0; font-weight: 700; }

.field-grid {
    padding: 18px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px 14px;
}

.field-grid.full { grid-template-columns: 1fr; }

label {
    display: grid;
    gap: 6px;
    font-size: 12px;
    color: var(--muted);
}

input, select {
    background: #100e0c;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 11px 12px;
}

.rate-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 90px auto;
    gap: 8px;
    align-items: end;
}

.loan-note {
    margin-top: 12px;
    padding: 14px 16px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
}

.sheet {
    position: fixed;
    inset: 0;
    background: rgba(8, 6, 4, 0.62);
    display: grid;
    align-items: end;
    z-index: 20;
}

.sheet[hidden] { display: none !important; }

.sheet.dialog {
    align-items: center;
    justify-items: center;
    padding: 16px;
}

.sheet.dialog .sheet-card {
    width: min(420px, 100%);
    border-radius: 22px;
    padding: 22px 18px 18px;
}

.sheet-card {
    background: var(--card-2);
    border-radius: 28px 28px 0 0;
    padding: 22px 18px calc(22px + var(--safe-b));
    border: 1px solid var(--line);
    max-height: 88vh;
    overflow: auto;
}

.sheet-close {
    position: absolute;
    right: 18px;
    top: 12px;
    border: 0;
    background: transparent;
    font-size: 28px;
    color: var(--muted);
    cursor: pointer;
}

.sheet-card { position: relative; }

.check {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-size: 14px;
}

.spark {
    width: 100%;
    max-width: 100%;
    height: 84px;
    margin-top: 12px;
    display: block;
}

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(420px, 100%);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 28px;
    padding: 28px 24px;
    box-shadow: var(--shadow);
}

.login-card h1 { margin: 8px 0 8px; }
.login-lead { color: var(--muted); margin: 0 0 20px; }
.login-card label { margin-bottom: 12px; }
.login-card button {
    width: 100%;
    margin-top: 16px;
    border: 0;
    border-radius: 999px;
    padding: 12px;
    background: var(--gold);
    color: #1a140c;
    font-weight: 800;
    cursor: pointer;
}
.login-error { color: var(--danger); margin: 8px 0 0; }

main, .tab-panel {
    min-width: 0;
    max-width: 100%;
}

.hint, .hero-kicker, .advice, .loan-note {
    overflow-wrap: anywhere;
}

@media (max-width: 820px) {
    .summary-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .hero-grid, .whatif-result, .scene-grid, .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .plan-item { grid-template-columns: minmax(0, 1fr) auto; }
    .plan-item .n { display: none; }
}

@media (max-width: 720px) {
    .topbar {
        align-items: flex-start;
    }
    .loan-grid { grid-template-columns: 1fr; }
    .tabs { top: 0; }
    .hero { padding: 16px; }
    .slider-row {
        grid-template-columns: 1fr;
    }
    .money-input { width: 100%; }
}

@media (max-width: 560px) {
    .topbar h1 { font-size: clamp(22px, 7vw, 24px); }
    .whatif-result, .hero-grid { grid-template-columns: 1fr; }
    .field-grid, .rate-row, .type-switch { grid-template-columns: 1fr; }
    .stat { padding: 12px; }
    .cash-input { font-size: clamp(24px, 8vw, 36px); }
}

.sum {
    display: inline;
    width: max-content;
    max-width: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    font-weight: inherit;
    font-family: inherit;
    cursor: pointer;
    text-align: inherit;
    text-decoration: underline dotted;
    text-underline-offset: 3px;
    -webkit-tap-highlight-color: rgba(224, 177, 92, 0.35);
}

#copyToast {
    position: fixed;
    left: 50%;
    bottom: calc(20px + var(--safe-b));
    transform: translateX(-50%);
    background: var(--gold);
    color: #1a140c;
    padding: 8px 16px;
    border-radius: 999px;
    z-index: 40;
    font-weight: 800;
    font-size: 13px;
}

#copyToast[hidden] { display: none !important; }
