:root {
    color-scheme: light dark;
    --bg: #0b0b10;
    --fg: #e9e9ef;
    --muted: #a0a0b0;
    --panel: #15151e;
    --bg-light: #161622;
    --accent: #5b9bd5;
    --border: #2a2a35;
    --tooltip-bg: rgba(0, 0, 0, 0.92);
    --tooltip-fg: #fff;
    --shadow-s: 0 1px 2px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.05), inset 0 -2px 6px rgba(0, 0, 0, 0.35);
    --shadow-s-reverse: 0 -1px 2px rgba(0, 0, 0, 0.45), 0 -2px 6px rgba(0, 0, 0, 0.35), inset 0 -1px 0 rgba(255, 255, 255, 0.05), inset 0 2px 6px rgba(0, 0, 0, 0.35);
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font-family: system-ui, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;
    background: var(--bg);
    color: var(--fg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

header {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.gh-btn {
    height: 28px;
    display: inline-grid;
    place-items: center;
    padding: 4px 10px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: var(--fg);
    text-decoration: none;
    background: transparent;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), inset 0 -3px 10px rgba(0, 0, 0, 0.5);
    font-size: 12px;
}

.gh-btn:hover {
    background: rgba(255, 255, 255, 0.06);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-right: 8px;
}

.logo {
    width: 37px;
    height: 37px;
    display: block;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}

.brand-text {
    line-height: 1;
}

.brand-title {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 0.2px;
    color: var(--fg);
    margin-bottom: 2px;
}

.brand-sub {
    font-size: 11px;
    font-weight: 500;
    color: var(--muted);
    letter-spacing: 0.3px;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.gh-btn {
    height: 28px;
    display: inline-grid;
    place-items: center;
    padding: 4px 10px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: var(--fg);
    text-decoration: none;
    background: transparent;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), inset 0 -3px 10px rgba(0, 0, 0, 0.5);
    font-size: 12px;
}

.gh-btn:hover {
    background: rgba(255, 255, 255, 0.06);
}

.control {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-light);
    padding: 6px 12px;
    border-radius: 10px;
    border: none;
    box-shadow: var(--shadow-s-reverse);
    height: 36px;
}

.control.clickable {
    cursor: pointer;
    user-select: none;
}

.control.clickable:hover {
    filter: brightness(1.05);
}

.control label {
    font-size: 12px;
    color: var(--muted);
}

input[type="number"],
select {
    background: #0f0f15;
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 8px;
    height: 28px;
}

input[type="range"] {
    height: 4px;
    accent-color: var(--accent);
}

input[type="file"] {
    display: none;
}

.btn {
    background: #1b1b2a;
    color: var(--fg);
    border: 1px solid var(--border);
    padding: 6px 12px;
    border-radius: 8px;
    cursor: pointer;
    height: 32px;
    line-height: 18px;
}

.btn-secondary {
    background: transparent;
    color: var(--fg);
    border-color: rgba(255, 255, 255, 0.18);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.06);
}

.btn:hover {
    filter: brightness(1.1);
}

.muted {
    color: var(--muted);
}

main {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-rows: 1fr;
}

.seo-text {
    margin: 10px 16px 8px;
    color: var(--muted);
    font-size: 13px;
    max-width: 1000px;
}

#chart {
    position: relative;
    padding: 12px 16px;
    height: 100%;
    overflow: hidden;
}

/* Card style for treemap container */
.card {
    background: var(--bg-light);
    border-radius: 10px;
    box-shadow: var(--shadow-s);
}

svg {
    width: 100%;
    height: 100%;
    display: block;
    background: #0d0d14;
    border-radius: 8px;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.node {
    cursor: pointer;
}

.node rect {
    stroke: rgba(255, 255, 255, 0.08);
    stroke-width: 1;
}

.node text {
    font-size: 11px;
    fill: #e8e8ee;
    pointer-events: none;
    font-family: Ubuntu, Segoe UI, Roboto, system-ui, sans-serif;
}

.node-percent {
    font-size: 12px;
    font-weight: 600;
    fill: #ffffff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
    paint-order: stroke;
    stroke: rgba(0, 0, 0, 0.35);
    stroke-width: 1px;
}

.node-label {
    font-weight: 600;
    letter-spacing: 0.1px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    fill: #ffffff;
}

.breadcrumb {
    position: absolute;
    left: 20px;
    top: 16px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
    color: var(--muted);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), inset 0 -2px 8px rgba(0, 0, 0, 0.28);
}

.breadcrumb .crumb {
    color: var(--fg);
    cursor: pointer;
}

.breadcrumb .crumb:hover {
    text-decoration: underline;
}

#tooltip {
    position: absolute;
    pointer-events: none;
    background: var(--tooltip-bg);
    color: var(--tooltip-fg);
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 12px;
    line-height: 1.3;
    opacity: 0;
    transition: opacity 80ms ease;
    max-width: 440px;
    white-space: pre-wrap;
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.tooltip-full {
    color: var(--muted);
    font-style: italic;
}

/* Overlay up button */
.overlay-up {
    position: absolute;
    left: 50%;
    top: 0;
    transform: translate(-50%, -40%);
    width: 36px;
    height: 36px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.6);
    color: var(--fg);
    display: grid;
    place-items: center;
    cursor: pointer;
    z-index: 5;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.05), inset 0 -2px 6px rgba(0, 0, 0, 0.35);
}

.overlay-up:hover {
    filter: brightness(1.15);
}

/* Ancestor highlight (filled via inline attributes for gradient opacity) */
.ancestor-fill,
.ancestor-stroke {
    pointer-events: none;
}

.overlay-highlight {
    pointer-events: none;
}

/* Empty state hint */
#emptyHint {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 14px;
    text-align: center;
    pointer-events: none;
}

.hint-help {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: var(--fg);
    text-decoration: none;
    margin-left: 6px;
    background: rgba(0, 0, 0, 0.35);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
    font-weight: 700;
    font-size: 12px;
    pointer-events: auto;
}

.hint-help:hover {
    background: rgba(255, 255, 255, 0.08);
}

/* Toast (self-fading error popup) */
#toast {
    position: fixed;
    left: 50%;
    top: 70px;
    transform: translateX(-50%);
    z-index: 9999;
    pointer-events: none;
}

footer {
    padding: 10px 16px;
    color: var(--muted);
    border-top: 1px solid var(--border);
    background: var(--panel);
}

.footer-inner {
    display: flex;
    gap: 12px;
    align-items: center;
}

.footer-inner a {
    color: var(--fg);
    text-decoration: none;
}

.footer-inner a:hover {
    text-decoration: underline;
}

.toast-msg {
    background: rgba(220, 53, 69, 0.95);
    color: #fff;
    padding: 8px 12px;
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    margin-top: 8px;
    opacity: 0;
    animation: toastfade 3s ease forwards;
    font-size: 13px;
}

@keyframes toastfade {
    0% {
        opacity: 0;
        transform: translate(0%, -6px);
    }

    10% {
        opacity: 1;
        transform: translate(0%, 0);
    }

    80% {
        opacity: 1;
    }

    100% {
        opacity: 0;
        transform: translate(0%, -6px);
    }
}