/* ─── Sunburst-specific Styles ─────────────────────────────────────── */

/* ── SVG Chart Container ──────────────────────────────────────────── */
#chart {
    width: 100vw;
    height: calc(100vh - 64px);
    height: calc(100dvh - 64px);   /* dynamic viewport — excludes mobile browser chrome */
    position: absolute;
    top: 64px;
    left: 0;
    touch-action: none;            /* let JS handle pinch-to-zoom on the diagram */
}

#chart path {
    cursor: pointer;
    stroke: rgba(255, 255, 255, 0.15);
    stroke-width: 1px;
    transition: opacity 0.25s ease, stroke 0.15s ease, filter 0.18s ease;
    will-change: opacity, filter;
}

#chart path:hover {
    stroke: rgba(255, 255, 255, 0.5);
}

/* ── CSS-driven hover dimming (Opt 3) ────────────────────────────── */
#chart g.has-hover path.arc {
    fill-opacity: 0.4;
    transition: fill-opacity 0.18s ease;
}

#chart g.has-hover path.arc.highlighted {
    fill-opacity: 1;
    transition: fill-opacity 0.18s ease;
}

/* ── Leaf node feedback ──────────────────────────────────────────── */
#chart path.arc.leaf {
    cursor: default;
}

@keyframes leaf-pulse {
    0%   { filter: brightness(1);   }
    40%  { filter: brightness(1.45); }
    100% { filter: brightness(1);   }
}

#chart path.arc.leaf-pulse {
    animation: leaf-pulse 0.4s ease-out;
}

/* Body Background Override for Sunburst */
body {
    background-color: var(--bg);
    background-image: url('../images/background6.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

#chart text {
    pointer-events: none;
    font-family: 'Inter', sans-serif;
    fill: #fff;
    font-weight: 600;
    paint-order: stroke fill;
    stroke: rgba(0, 0, 0, 0.55);
    stroke-width: 3px;
    stroke-linejoin: round;
    will-change: opacity;
}

/* ── Center Label (HTML overlay, used by treemap) ─────────────────── */
.center-label {
    position: absolute;
    pointer-events: none;
    text-align: center;
    font-weight: 700;
    font-size: 18px;
    color: var(--text-primary);
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    line-height: 1.3;
}

/* ── Center Label (SVG foreignObject, used by sunburst) ───────────── */
.center-fo {
    overflow: visible;    /* let content extend beyond the foreignObject rect */
    pointer-events: none; /* let arc clicks pass through by default */
}

.center-label-inner {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-family: 'Inter', sans-serif;
    font-weight: 700;
    font-size: clamp(14px, 2.5vmin, 22px);
    color: var(--text-primary);
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    line-height: 1.3;
    pointer-events: none;
    overflow: hidden;
    word-break: break-word;
    max-width: 100%;
    box-sizing: border-box;
    padding: 4px;
}

/* Buttons inside the foreignObject must be clickable and stop propagation */
.center-label-inner button {
    pointer-events: auto;
}

.center-label .subtitle,
.center-label-inner .subtitle {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-top: 4px;
}

.center-label .back-btn,
.center-label-inner .back-btn {
    pointer-events: auto;
    margin-top: 6px;
    background: rgba(220, 60, 60, 0.35);
    color: #fecaca;
    border: 1px solid rgba(248, 113, 113, 0.5);
    border-radius: 14px;
    padding: 5px 14px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s;
    font-family: 'Inter', sans-serif;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.center-label .back-btn:hover,
.center-label-inner .back-btn:hover {
    background: rgba(220, 60, 60, 0.5);
    color: #fff;
    border-color: rgba(248, 113, 113, 0.7);
}

.center-label .back-btn svg,
.center-label-inner .back-btn svg {
    margin-right: 4px;
}

.center-label .cheatsheet-btn,
.center-label-inner .cheatsheet-btn {
    pointer-events: auto;
    margin-top: 8px;
    background: rgba(59, 130, 246, 0.4);
    color: #bfdbfe;
    border: 1px solid rgba(96, 165, 250, 0.5);
    border-radius: 18px;
    padding: 5px 14px;
    font-size: clamp(10px, 1.8vmin, 14px);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Inter', sans-serif;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
}

.center-label .cheatsheet-btn:hover,
.center-label-inner .cheatsheet-btn:hover {
    background: rgba(59, 130, 246, 0.45);
    border-color: rgba(96, 165, 250, 0.7);
    color: #e0f2fe;
}

/* ── Breadcrumb ────────────────────────────────────────────────────── */
.breadcrumb {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    background: rgba(25, 27, 35, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: 14px;
    border: 1px solid var(--border);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
    max-width: 90vw;
    overflow-x: auto;
    white-space: nowrap;
}

.breadcrumb span {
    cursor: pointer;
    transition: color 0.15s;
}

.breadcrumb span:hover {
    color: var(--text-primary);
}

.breadcrumb span:last-child {
    color: var(--text-primary);
    font-weight: 600;
}

.breadcrumb .sep {
    color: rgba(255, 255, 255, 0.2);
    cursor: default;
}

/* ── Tooltip ───────────────────────────────────────────────────────── */
.tooltip {
    position: fixed;
    z-index: 200;
    padding: 10px 16px;
    background: rgba(30, 32, 44, 0.92);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    max-width: 280px;
}

.tooltip .tip-depth {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 3px;
}

/* ── Sunburst Modal ────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.modal-content {
    background: #1e202c;
    width: 90vw;
    max-width: 1200px;
    height: 85vh;
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    transition: color 0.2s;
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.modal-close:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
}

.modal-body {
    flex: 1;
    background: #fff;
    position: relative;
}

.modal-body iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

.cheatsheet-list-container {
    display: none;
    padding: 30px;
    overflow-y: auto;
    width: 100%;
    height: 100%;
    background: var(--bg);
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10;
}

.cheatsheet-list-container h3 {
    margin-bottom: 20px;
    font-size: 16px;
    font-weight: 500;
    color: var(--text-secondary);
}

/* ── Center Label – mobile sunburst responsiveness ─────────────── */
@media (max-width: 767px) {
    .sunburst-mode .center-label,
    .sunburst-mode .center-label-inner {
        font-size: 14px;
        max-width: 28vw;
        line-height: 1.2;
    }
    .sunburst-mode .center-label .subtitle,
    .sunburst-mode .center-label-inner .subtitle {
        font-size: 9px;
        margin-top: 2px;
    }
    .sunburst-mode .center-label .back-btn,
    .sunburst-mode .center-label-inner .back-btn {
        margin-top: 3px;
        padding: 3px 8px;
        font-size: 10px;
        border-radius: 10px;
    }
    .sunburst-mode .center-label .back-btn svg,
    .sunburst-mode .center-label-inner .back-btn svg {
        width: 10px;
        height: 10px;
    }
    .sunburst-mode .center-label .cheatsheet-btn,
    .sunburst-mode .center-label-inner .cheatsheet-btn {
        margin-top: 4px;
        padding: 3px 8px;
        font-size: 9px;
        border-radius: 12px;
    }
}

/* ── Sunburst Modal – mobile responsiveness ────────────────────── */
@media (max-width: 600px) {
    .modal-overlay {
        align-items: flex-start;
    }
    .modal-content {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        max-width: 100vw;
        border-radius: 0;
        border: none;
    }
    .modal-header {
        padding: 10px 12px;
        padding-top: max(10px, env(safe-area-inset-top, 10px));
        padding-right: max(12px, env(safe-area-inset-right, 0px));
        padding-left: max(12px, env(safe-area-inset-left, 0px));
    }
    .modal-header h2 {
        font-size: 13px;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .modal-close {
        min-width: 44px;
        min-height: 44px;
        flex-shrink: 0;
    }
}