/* ========================================
   TOKEN DISTRIBUTION — Interactive Donut Chart
   Matches PuBear design system
   ======================================== */

/* ── Section ─────────────────────────────────────────────── */

.token-dist {
    padding: var(--space-3xl) 0;
    position: relative;
    overflow: hidden;
}

/* Subtle radial background glow — uses ::after to keep ::before free for section-divider */
.token-dist::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 700px;
    height: 700px;
    background: radial-gradient(ellipse, rgba(153, 69, 255, 0.05) 0%, transparent 65%);
    pointer-events: none;
    z-index: 0;
}

/* ── Container ───────────────────────────────────────────── */

.td-container {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 var(--space-lg);
    position: relative;
    z-index: 1;
}

/* ── Header ──────────────────────────────────────────────── */

.td-header {
    text-align: center;
    margin-bottom: var(--space-2xl);
}

.td-title {
    font-size: clamp(var(--font-2xl), 4vw, var(--font-3xl));
    font-weight: 800;
    margin-bottom: var(--space-sm);
}

.td-subtitle {
    font-size: var(--font-md);
    color: var(--color-text-muted);
    max-width: 520px;
    margin: 0 auto;
}

/* ── Body: chart + legend side-by-side ───────────────────── */

.td-body {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(var(--space-2xl), 6vw, 72px);
}

/* ── Donut Chart Wrapper ─────────────────────────────────── */

.td-chart-wrap {
    position: relative;
    flex-shrink: 0;
    width: clamp(220px, 28vw, 280px);
    height: clamp(220px, 28vw, 280px);
}

.td-donut-svg {
    width: 100%;
    height: 100%;
    overflow: visible; /* glow effects bleed outside viewBox */
}

/* ── Center label (inside donut hole) ────────────────────── */

.td-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    pointer-events: none;
}

/* Default state */
.td-center-default {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    transition: opacity 0.2s ease;
}

.td-center-token {
    font-size: clamp(0.85rem, 2.2vw, 1rem);
    font-weight: 800;
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.2;
}

.td-center-label {
    font-size: var(--font-xs);
    color: var(--color-text-muted);
}

/* ── Infinity symbol (default center) ───────────────────── */

.td-infinity-svg {
    width:  clamp(58px, 6vw, 74px);
    height: auto;
    overflow: visible;
}

/* Dim background track — pulses subtly */
.td-inf-track {
    fill:         none;
    stroke:       rgba(255, 255, 255, 0.09);
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    animation: td-inf-breathe 4s ease-in-out infinite;
}

/* Glowing comet segment — driven by Web Animations API in JS */
.td-inf-glow {
    fill:         none;
    stroke:       url(#td-inf-grad);
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 0 4px rgba(153, 69, 255, 0.7))
            drop-shadow(0 0 8px rgba(20, 241, 149, 0.35));
}

@keyframes td-inf-breathe {
    0%,  100% { stroke-opacity: 0.09; }
    50%       { stroke-opacity: 0.22; }
}

/* Hover state */
.td-center-hover {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.td-center.is-hovered .td-center-default {
    display: none;
}

.td-center.is-hovered .td-center-hover {
    display: flex;
}

.td-center-pct {
    font-size: clamp(1.5rem, 4vw, 1.9rem);
    font-weight: 800;
    line-height: 1;
    transition: color 0.2s ease, text-shadow 0.2s ease;
}

.td-center-name {
    font-size: var(--font-xs);
    color: var(--color-text-muted);
    white-space: nowrap;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Legend ──────────────────────────────────────────────── */

.td-legend {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    flex: 1;
    min-width: 210px;
    max-width: 320px;
}

/* Legend card */
.td-legend-item {
    display: grid;
    grid-template-columns: 4px 1fr auto;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition:
        background 0.25s ease,
        border-color 0.25s ease,
        transform 0.25s ease,
        box-shadow 0.25s ease;
    position: relative;
    overflow: hidden;
}

/* Left color bar indicator */
.td-legend-indicator {
    width: 4px;
    height: 32px;
    border-radius: 4px;
    background: var(--seg-color);
    box-shadow: 0 0 10px var(--seg-glow);
    flex-shrink: 0;
    transition: height 0.25s ease, box-shadow 0.25s ease;
    align-self: center;
}

/* Text block */
.td-legend-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.td-legend-name {
    font-size: var(--font-sm);
    font-weight: 600;
    color: var(--color-text);
    white-space: nowrap;
}

.td-legend-desc {
    font-size: var(--font-xs);
    color: var(--color-text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Percentage badge (right column) */
.td-legend-pct {
    font-size: clamp(1.05rem, 2.5vw, 1.3rem);
    font-weight: 800;
    color: var(--seg-color);
    text-shadow: 0 0 14px var(--seg-glow);
    white-space: nowrap;
    line-height: 1;
}

/* Hover / active state */
.td-legend-item:hover,
.td-legend-item:focus-visible,
.td-legend-item--active {
    background: rgba(255, 255, 255, 0.055);
    border-color: var(--seg-color);
    transform: translateX(6px);
    box-shadow:
        -3px 0 0 var(--seg-color),
        0 4px 24px rgba(0, 0, 0, 0.35);
    outline: none;
}

.td-legend-item:hover .td-legend-indicator,
.td-legend-item:focus-visible .td-legend-indicator,
.td-legend-item--active .td-legend-indicator {
    height: 42px;
    box-shadow: 0 0 18px var(--seg-glow);
}

/* Shimmer effect on hover */
.td-legend-item::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        135deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.03) 50%,
        rgba(255, 255, 255, 0) 100%
    );
    opacity: 0;
    transition: opacity 0.25s ease;
    pointer-events: none;
}

.td-legend-item:hover::after,
.td-legend-item--active::after {
    opacity: 1;
}

/* ── Per-segment color variables ─────────────────────────── */

.td-legend-item[data-idx="0"] {
    --seg-color: #14F195;
    --seg-glow:  rgba(20, 241, 149, 0.4);
}

.td-legend-item[data-idx="1"] {
    --seg-color: #9945FF;
    --seg-glow:  rgba(153, 69, 255, 0.4);
}

.td-legend-item[data-idx="2"] {
    --seg-color: #FFB800;
    --seg-glow:  rgba(255, 184, 0, 0.4);
}

/* ── Responsive ──────────────────────────────────────────── */

@media (max-width: 768px) {
    .td-body {
        flex-direction: column;
        gap: var(--space-2xl);
    }

    .td-legend {
        width: 100%;
        max-width: 420px;
        min-width: unset;
    }
}

@media (max-width: 480px) {
    .td-legend-item {
        padding: var(--space-sm) var(--space-md);
        gap: var(--space-sm);
    }

    .td-legend-pct {
        font-size: 1rem;
    }

    .td-legend-desc {
        display: none;
    }
}

/* ── Reduced motion ──────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    .td-legend-item,
    .td-legend-indicator {
        transition: none !important;
    }
}
