/* ═══ Design System ═══ */
:root {
    --bg-base: #04060c;
    --bg-surface: #0a0d15;
    --bg-card: #0e1118;
    --bg-card-alt: #111520;
    --bg-elevated: #151a26;
    --border-dim: rgba(148, 163, 184, 0.04);
    --border-subtle: rgba(148, 163, 184, 0.07);
    --border-medium: rgba(148, 163, 184, 0.12);
    --text-bright: #f8fafc;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #475569;
    --text-dim: #334155;
    --bitcoin: #f7931a;
    --bitcoin-light: #fbbf24;
    --emerald: #34d399;
    --emerald-dim: #059669;
    --rose: #fb7185;
    --rose-dim: #e11d48;
    --cyan: #22d3ee;
    --violet: #a78bfa;
    --blue: #60a5fa;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
}

/* ═══ Reset & Base ═══ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: var(--bg-base);
    background-image:
        radial-gradient(ellipse at 15% 0%, rgba(247, 147, 26, 0.04) 0%, transparent 45%),
        radial-gradient(ellipse at 85% 100%, rgba(34, 211, 238, 0.025) 0%, transparent 45%),
        radial-gradient(ellipse at 50% 50%, rgba(167, 139, 250, 0.015) 0%, transparent 60%);
    background-attachment: fixed;
    font-family: 'Inter', -apple-system, sans-serif;
    color: var(--text-primary);
    min-height: 100vh;
    padding: 0.5rem 1.5rem 0;
    max-width: 1440px;
    margin: 0 auto;
}

/* ═══ Header ═══ */
.app-header {
    text-align: center;
    padding: 1.25rem 0 0.5rem;
}

.app-logo {
    font-size: 1.8rem;
    font-weight: 900;
    letter-spacing: -1px;
    line-height: 1;
}

.app-logo .btc-icon {
    display: inline-block;
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #f7931a, #fbbf24);
    border-radius: 50%;
    color: #fff;
    font-size: 1.2rem;
    font-weight: 900;
    line-height: 36px;
    text-align: center;
    margin-right: 0.4rem;
    vertical-align: middle;
    box-shadow: 0 0 20px rgba(247, 147, 26, 0.25);
}

.app-logo .text-white { color: var(--text-bright); }
.app-logo .text-gold {
    background: linear-gradient(135deg, #f7931a, #fbbf24);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.app-subtitle {
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 2.5px;
    text-transform: uppercase;
    margin-top: 0.25rem;
}

/* ═══ Zone Badge ═══ */
.zone-strip {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    margin: 0.75rem auto 0.5rem;
    padding: 0.5rem 1.2rem;
    border-radius: 100px;
    width: fit-content;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.zone-green {
    background: rgba(52, 211, 153, 0.08);
    border: 1px solid rgba(52, 211, 153, 0.15);
    color: var(--emerald);
}
.zone-yellow {
    background: rgba(251, 191, 36, 0.08);
    border: 1px solid rgba(251, 191, 36, 0.15);
    color: var(--bitcoin-light);
}
.zone-orange {
    background: rgba(247, 147, 26, 0.08);
    border: 1px solid rgba(247, 147, 26, 0.15);
    color: var(--bitcoin);
}
.zone-red {
    background: rgba(251, 113, 133, 0.08);
    border: 1px solid rgba(251, 113, 133, 0.15);
    color: var(--rose);
}

/* ═══ Tabs ═══ */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: 0;
}

.tab {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.7rem 1.4rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.tab-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}
.tab.active .tab-icon { opacity: 1; }
.tab:hover .tab-icon { opacity: 0.9; }

.tab:hover { color: var(--text-secondary); }
.tab.active {
    color: var(--bitcoin);
    border-bottom-color: var(--bitcoin);
}

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

/* ═══ Metric Cards ═══ */
.metric-row {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.6rem;
    margin: 0.4rem 0 0.75rem;
}

.m-card {
    background: var(--bg-card);
    border: 1px solid var(--border-dim);
    border-radius: var(--radius-md);
    padding: 1rem 0.6rem;
    text-align: center;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

.m-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    opacity: 0.6;
}

.m-card:hover {
    border-color: var(--border-medium);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.3);
}

.m-card-orange::before { background: linear-gradient(90deg, transparent, var(--bitcoin), transparent); }
.m-card-white::before { background: linear-gradient(90deg, transparent, var(--text-secondary), transparent); }
.m-card-green::before { background: linear-gradient(90deg, transparent, var(--emerald), transparent); }
.m-card-red::before { background: linear-gradient(90deg, transparent, var(--rose), transparent); }
.m-card-cyan::before { background: linear-gradient(90deg, transparent, var(--cyan), transparent); }

.m-label {
    color: var(--text-muted);
    font-size: 0.58rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.6rem;
}

.m-val {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.m-val-orange { color: var(--bitcoin); }
.m-val-white { color: var(--text-bright); }
.m-val-green { color: var(--emerald); }
.m-val-red { color: var(--rose); }
.m-val-cyan { color: var(--cyan); }

/* ═══ Chart ═══ */
.chart-container {
    background: #080a12;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-dim);
    padding: 0.5rem;
    margin-top: 0.25rem;
    position: relative;
    height: 680px;
}

.chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

/* ── HTML Legend overlay (inside chart, top-left like Plotly) ── */
.chart-legend {
    position: absolute;
    top: 10px;  /* overridden by JS after chart layout */
    left: 10px; /* overridden by JS after chart layout */
    background: rgba(4, 6, 12, 0.88);
    border: 1px solid rgba(148, 163, 184, 0.10);
    border-radius: 6px;
    padding: 8px 11px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    z-index: 10;
    pointer-events: none;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 500;
    color: #cbd5e1;
    white-space: nowrap;
    letter-spacing: 0.01em;
}

.legend-rect {
    display: inline-block;
    width: 24px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}

/* Thin line swatch for BTC Price and Power Law */
.legend-line-sw {
    display: inline-block;
    width: 24px;
    height: 2.5px;
    border-radius: 2px;
    flex-shrink: 0;
    margin: auto 0;
}

/* Separator between lines and bands */
.legend-sep {
    width: 100%;
    height: 1px;
    background: rgba(148, 163, 184, 0.10);
    margin: 1px 0;
}

@media (max-width: 768px) {
    .chart-legend { padding: 5px 8px; gap: 3px; }
    .legend-item { font-size: 10px; gap: 6px; }
    .legend-rect { width: 20px; height: 10px; }
    .legend-line-sw { width: 20px; }
}

/* ═══ Calculator ═══ */
.calculator-card {
    max-width: 600px;
    margin: 0 auto;
}

.calc-header {
    text-align: center;
    padding: 1.75rem 0 1.25rem;
}

.calc-header h2 {
    color: var(--text-bright);
    font-size: 1.4rem;
    font-weight: 800;
    margin: 0 0 0.2rem;
    letter-spacing: -0.5px;
}

.calc-header h2 .hl {
    background: linear-gradient(135deg, var(--bitcoin), var(--bitcoin-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.calc-header p {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin: 0;
}

/* ─── Calculator Input ─── */
.calc-input-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 260px;
    margin: 0 auto;
    position: relative;
}

.calc-input-prefix {
    position: absolute;
    left: 0.7rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.4rem;
    font-weight: 700;
    pointer-events: none;
}

.calc-input-wrap input {
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-bright);
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.4rem;
    font-weight: 700;
    padding: 0.7rem 0.7rem 0.7rem 2rem;
    text-align: center;
    transition: all 0.25s ease;
    width: 100%;
    outline: none;
}

.calc-input-wrap input:hover { border-color: rgba(247, 147, 26, 0.25); }
.calc-input-wrap input:focus {
    border-color: rgba(247, 147, 26, 0.5);
    box-shadow: 0 0 0 3px rgba(247, 147, 26, 0.08);
}

/* Remove number input arrows */
.calc-input-wrap input::-webkit-outer-spin-button,
.calc-input-wrap input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.calc-input-wrap input[type=number] {
    -moz-appearance: textfield;
}

/* ─── Calculator Error ─── */
.calc-error {
    text-align: center;
    color: var(--rose);
    font-size: 0.72rem;
    font-weight: 500;
    margin-top: 0.5rem;
    opacity: 0.9;
}

/* ─── Result Card ─── */
.result-card {
    text-align: center;
    padding: 2rem 1.5rem;
    margin: 1rem auto 0;
    background: linear-gradient(135deg, rgba(247, 147, 26, 0.03), rgba(251, 191, 36, 0.02));
    border: 1px solid rgba(247, 147, 26, 0.08);
    border-radius: var(--radius-lg);
    position: relative;
    overflow: hidden;
}

.result-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--bitcoin), transparent);
    opacity: 0.5;
}

.result-badge {
    display: inline-block;
    background: rgba(247, 147, 26, 0.1);
    border: 1px solid rgba(247, 147, 26, 0.15);
    border-radius: 100px;
    padding: 0.3rem 1rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--bitcoin);
    letter-spacing: 1px;
    margin-bottom: 1rem;
}

.result-date {
    font-size: 2.4rem;
    font-weight: 900;
    letter-spacing: -1.5px;
    line-height: 1.1;
    margin-bottom: 0.4rem;
    background: linear-gradient(135deg, #f7931a 0%, #fbbf24 60%, #f7931a 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.result-sub {
    color: var(--text-secondary);
    font-size: 0.82rem;
}

/* ─── Floor Card ─── */
.floor-card {
    text-align: center;
    padding: 1.3rem 1rem;
    margin: 0.5rem auto 0;
    background: linear-gradient(135deg, rgba(52, 211, 153, 0.03), rgba(5, 150, 105, 0.02));
    border: 1px solid rgba(52, 211, 153, 0.08);
    border-radius: var(--radius-md);
    position: relative;
    overflow: hidden;
}

.floor-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--emerald), transparent);
    opacity: 0.4;
}

.floor-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    background: rgba(52, 211, 153, 0.08);
    border: 1px solid rgba(52, 211, 153, 0.12);
    border-radius: 100px;
    padding: 0.25rem 0.8rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.58rem;
    font-weight: 700;
    color: var(--emerald);
    letter-spacing: 1px;
    margin-bottom: 0.65rem;
}

.floor-date {
    color: var(--emerald);
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    margin-bottom: 0.3rem;
}

.floor-sub {
    color: var(--text-muted);
    font-size: 0.7rem;
    line-height: 1.5;
}

/* ─── Stats Row ─── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin: 0.6rem auto 0;
}

.stat-box {
    text-align: center;
    padding: 0.85rem 0.4rem;
    background: var(--bg-card);
    border: 1px solid var(--border-dim);
    border-radius: var(--radius-sm);
    transition: border-color 0.25s ease;
}

.stat-box:hover { border-color: var(--border-medium); }

.stat-label {
    color: var(--text-muted);
    font-size: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-weight: 600;
    margin-bottom: 0.3rem;
}

.stat-val {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem;
    font-weight: 800;
}

/* ═══ Footer ═══ */
.app-footer {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.65rem;
    margin-top: 2rem;
    padding-bottom: 1rem;
    letter-spacing: 0.3px;
}

/* ═══ Preset Buttons ═══ */
.preset-row {
    display: flex;
    gap: 0.4rem;
    justify-content: center;
    margin-top: 0.6rem;
}
.preset-btn {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 100px;
    color: var(--text-secondary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.3rem 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
    letter-spacing: 0.5px;
}
.preset-btn:hover {
    border-color: rgba(247, 147, 26, 0.3);
    color: var(--bitcoin);
    background: rgba(247, 147, 26, 0.06);
}
.preset-btn.active {
    border-color: rgba(247, 147, 26, 0.4);
    color: var(--bitcoin);
    background: rgba(247, 147, 26, 0.1);
}

/* ═══ Updated Badge ═══ */
.updated-badge {
    text-align: center;
    font-size: 0.6rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
    letter-spacing: 0.5px;
}
.updated-dot {
    display: inline-block;
    width: 6px; height: 6px;
    background: var(--emerald);
    border-radius: 50%;
    margin-right: 0.3rem;
    vertical-align: middle;
    animation: dotPulse 2s ease-in-out infinite;
}
@keyframes dotPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ═══ Skeleton Loading ═══ */
.skeleton {
    background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-card-alt) 50%, var(--bg-card) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
}
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.skeleton-val {
    height: 1.25rem;
    width: 70%;
    margin: 0 auto;
    border-radius: 4px;
}

/* ═══ Pull to Refresh ═══ */
.ptr-wrap {
    height: 0;
    overflow: hidden;
    transition: height 0.2s ease;
    position: relative;
    z-index: 50;
}
.ptr-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 50px;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.ptr-arrow {
    color: var(--bitcoin);
    transition: transform 0.1s linear;
}
.ptr-text {
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
}
.ptr-indicator.ready .ptr-arrow { color: var(--emerald); }
.ptr-indicator.ready .ptr-text { color: var(--emerald); }
.ptr-indicator.refreshing .ptr-arrow {
    animation: ptrSpin 0.8s linear infinite;
    color: var(--bitcoin);
}
.ptr-indicator.refreshing .ptr-text { color: var(--bitcoin); }
@keyframes ptrSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ═══ Gain Total Return ═══ */
.gain-total {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

/* ═══ Gain Calculator ═══ */
.gain-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.5rem;
    margin-top: 1rem;
}
.gain-card {
    background: var(--bg-card);
    border: 1px solid var(--border-dim);
    border-radius: var(--radius-md);
    padding: 0.9rem 0.5rem;
    text-align: center;
    position: relative;
    overflow: hidden;
    transition: all 0.2s ease;
}
.gain-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
}
.gain-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.3);
}
.gain-year {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    letter-spacing: 1px;
}
.gain-price {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
}
.gain-mult {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem;
    font-weight: 800;
}
.gain-card.gain-green::before { background: linear-gradient(90deg, transparent, var(--emerald), transparent); }
.gain-card.gain-green .gain-mult { color: var(--emerald); }
.gain-card.gain-gold::before { background: linear-gradient(90deg, transparent, var(--bitcoin), transparent); }
.gain-card.gain-gold .gain-mult { color: var(--bitcoin); }
.gain-card.gain-cyan::before { background: linear-gradient(90deg, transparent, var(--cyan), transparent); }
.gain-card.gain-cyan .gain-mult { color: var(--cyan); }

/* ═══ Responsive — Tablet ═══ */
@media (max-width: 768px) {
    body { padding: 0.3rem 0.5rem 0; }

    .app-logo { font-size: 1.4rem; }
    .app-logo .btc-icon { width: 28px; height: 28px; font-size: 1rem; line-height: 28px; }
    .app-subtitle { font-size: 0.6rem; letter-spacing: 2px; }

    .zone-strip {
        font-size: 0.65rem;
        padding: 0.4rem 0.9rem;
        position: sticky;
        top: 0;
        z-index: 50;
        margin-left: -0.5rem;
        margin-right: -0.5rem;
        border-radius: 0;
        backdrop-filter: blur(8px);
    }

    .metric-row { grid-template-columns: repeat(3, 1fr); gap: 0.4rem; }
    .m-card { padding: 0.7rem 0.4rem; }
    .m-label { font-size: 0.5rem; margin-bottom: 0.35rem; }
    .m-val { font-size: 0.95rem; }

    .tab { font-size: 0.78rem; padding: 0.6rem 0.8rem; }

    .chart-container { height: 450px; }

    .calc-header { padding: 1rem 0 0.75rem; }
    .calc-header h2 { font-size: 1.15rem; }
    .calc-input-wrap { max-width: 200px; }
    .calc-input-wrap input { font-size: 1.2rem; padding: 0.6rem 0.6rem 0.6rem 1.8rem; }
    .calc-input-prefix { font-size: 1.2rem; }

    .result-card { padding: 1.5rem 0.8rem; }
    .result-date { font-size: 1.6rem; }
    .result-sub { font-size: 0.72rem; }

    .floor-card { padding: 1rem 0.7rem; }
    .floor-date { font-size: 1.2rem; }
    .floor-sub { font-size: 0.65rem; }

    .stats-row { gap: 0.35rem; }
    .stat-box { padding: 0.6rem 0.25rem; }
    .stat-val { font-size: 0.9rem; }
    .stat-label { font-size: 0.42rem; }

    .gain-grid { grid-template-columns: repeat(2, 1fr); gap: 0.4rem; }
    .gain-card { padding: 0.7rem 0.4rem; }
    .gain-year { font-size: 0.58rem; }
    .gain-price { font-size: 0.7rem; }
    .gain-mult { font-size: 0.95rem; }

    .preset-btn { font-size: 0.6rem; padding: 0.25rem 0.65rem; }
}

/* ═══ Responsive — Mobile ═══ */
@media (max-width: 480px) {
    body { padding: 0.2rem 0.35rem 0; }

    .app-logo { font-size: 1.2rem; }
    .app-logo .btc-icon { width: 24px; height: 24px; font-size: 0.85rem; line-height: 24px; }

    .metric-row { grid-template-columns: repeat(3, 1fr); gap: 0.3rem; }
    .m-card { padding: 0.5rem 0.25rem; border-radius: var(--radius-sm); }
    .m-label { font-size: 0.42rem; }
    .m-val { font-size: 0.78rem; }

    .tab { font-size: 0.72rem; padding: 0.5rem 0.5rem; }

    .chart-container { height: 350px; }

    .calc-header h2 { font-size: 1rem; }
    .calc-input-wrap { max-width: 180px; }
    .calc-input-wrap input { font-size: 1.05rem; padding: 0.5rem 0.5rem 0.5rem 1.6rem; }
    .calc-input-prefix { font-size: 1.05rem; }

    .result-date { font-size: 1.35rem; }
    .result-card { padding: 1.2rem 0.6rem; }

    .floor-date { font-size: 1rem; }
    .stat-val { font-size: 0.78rem; }
    .stat-label { font-size: 0.38rem; }

    .gain-grid { grid-template-columns: repeat(2, 1fr); gap: 0.3rem; }
    .gain-card { padding: 0.6rem 0.3rem; }
    .gain-year { font-size: 0.52rem; }
    .gain-price { font-size: 0.65rem; }
    .gain-mult { font-size: 0.85rem; }
}
