     :root {
    /* Define unified color palette and metrics first */
    --bg: #ffffff;
    --panel: rgba(255, 255, 255, .92);
    --ink: #0b1220;
    --muted: #5b6472;
    --line: rgba(148, 163, 184, .25); /* Standardized border color */
    --line-strong: rgba(15, 23, 42, .12);
    --nodeBorder: #0f172a;
    --accent: #2563eb;
    --accent-hover: rgba(56, 189, 248, .6);
    --shadow: 0 6px 18px rgba(15, 23, 42, .10);

    /* Alert / Status Colors */
    --alert-bg: #fef2f2;
    --alert-text: #991b1b;
    --alert-border: #fecaca;

    /* Metrics */
    --colW: 44px; /* narrow column for vertical names */
    --rowH: 120px;
    --nav-height: 60px;
    --header-height: 64px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    /* Unified Font Stack */
    font-family: "Noto Serif CJK TC", "Source Han Serif TC", "Songti SC", "SimSun", "PMingLiU", serif;
    overflow: hidden; /* Kept from original logic for App feel */
}

/* --- Standard Elements (Homogenized) --- */

nav {
    height: var(--nav-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid var(--line-strong);
    background: var(--bg);
    z-index: 20;
    position: relative;
    font-size: 14px;
}

nav a {
    margin-right: 20px;
    text-decoration: none;
    color: var(--accent);
    font-weight: 600;
    transition: color 0.2s ease;
}

nav a:hover {
    color: var(--ink);
}

.alert {
    padding: 12px 16px;
    background-color: var(--alert-bg);
    color: var(--alert-text);
    border: 1px solid var(--alert-border);
    margin-bottom: 15px;
    border-radius: 10px; /* Matches other UI elements */
    font-size: 13px;
}

table {
    width: 100%;
    border-collapse: separate; /* Changed for border-radius support */
    border-spacing: 0;
    margin-top: 20px;
    font-size: 13px;
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
}

th, td {
    border-bottom: 1px solid var(--line);
    border-right: 1px solid var(--line);
    padding: 10px 12px;
    text-align: left;
}

th:last-child, td:last-child {
    border-right: none;
}

tr:last-child td {
    border-bottom: none;
}

th {
    background-color: rgba(248, 250, 252, 0.8); /* Softer header */
    font-weight: 700;
    color: var(--ink);
}

/* --- App / Interface Components --- */

.secondheader {
    position: fixed;
    inset: var(--nav-height) 0 auto 0;
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    padding: 12px 14px;
    background: var(--panel);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line-strong);
    z-index: 10;
    height: var(--header-height);
}

.secondheader .title {
    font-weight: 700;
    letter-spacing: .2px;
    margin-right: 8px;
}

.secondheader .pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, .85);
    color: var(--ink);
    box-shadow: var(--shadow);
}

.secondheader button,
.secondheader select {
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, .9);
    color: var(--ink);
    padding: 8px 10px;
    border-radius: 10px;
    cursor: pointer;
    font-family: inherit; /* Inherits CJK Serif */
    transition: border-color 0.2s;
}

.secondheader button:hover {
    border-color: var(--accent-hover);
}

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

/* --- App Viewport --- */

#app {
    position: absolute;
    inset: calc(var(--nav-height) + var(--header-height)) 0 0 0;
    overflow: hidden;
    background: radial-gradient(circle at center, rgba(37,99,235,0.03) 0%, transparent 70%); /* Subtle depth */
}

#viewport {
    position: absolute;
    inset: 0;
    transform-origin: 0 0;
    will-change: transform;
}

svg#edges {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

#nodes {
    position: absolute;
    inset: 0;
}

.node {
    position: absolute;
    width: var(--colW);
    padding: 6px 6px 4px;
    border: 1px solid rgba(15, 23, 42, .55);
    border-radius: 2px;
    background: transparent;
    box-shadow: none;
    cursor: pointer;
    user-select: none;
    transition: border-color 0.15s;
}

.node:hover {
    border-color: rgba(37, 99, 235, .9);
}

.node.active {
    outline: 2px solid rgba(37, 99, 235, .25);
    outline-offset: 2px;
}

.node .name {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-size: 18px;
    line-height: 1.1;
    margin: 0;
    white-space: nowrap;
}

.sexmark {
    position: absolute;
    top: 4px;
    left: 4px;
    font-size: 12px;
    line-height: 1;
    color: rgba(15, 23, 42, .75);
    writing-mode: horizontal-tb;
}

.node .meta {
    display: none; /* Kept as requested */
    font-size: 12px;
    color: var(--muted);
    display: flex; /* Overridden by display:none, assumes JS toggles this */
    gap: 8px;
    align-items: center;
    justify-content: space-between;
}

/* --- Badges & Toast --- */

.badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid var(--line);
    color: var(--muted);
}

.badge.m {
    border-color: rgba(56, 189, 248, .35);
    color: rgba(37, 99, 235, .8); /* Adjusted for readability on light bg */
}

.badge.f {
    border-color: rgba(251, 113, 133, .35);
    color: rgba(225, 29, 72, 0.85); /* Adjusted for readability on light bg */
}

.badge.u {
    border-color: var(--line);
    color: var(--muted);
}

#toast {
    position: fixed;
    right: 14px;
    bottom: 14px;
    max-width: 460px;
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(15, 23, 42, .95); /* Slightly darker */
    border: 1px solid rgba(148, 163, 184, .2);
    box-shadow: var(--shadow);
    color: #e2e8f0; /* Lighter text for dark toast */
    font-size: 12px;
    display: none;
    z-index: 100;
}

/* --- Sidebar --- */

#sidebar {
    position: fixed;
    top: calc(var(--nav-height) + var(--header-height));
    right: 0;
    bottom: 0;
    width: 360px;
    transform: translateX(0);
    background: rgba(255, 255, 255, .94);
    backdrop-filter: blur(10px);
    border-left: 1px solid var(--line-strong);
    box-shadow: var(--shadow);
    padding: 12px 12px 18px;
    overflow: auto;
    z-index: 9;
}

#sidebar h2 {
    font-size: 14px;
    margin: 6px 0 8px;
    color: var(--ink);
    letter-spacing: .2px;
}

#sidebar .small {
    color: var(--muted);
    font-size: 12px;
    margin: 0 0 10px;
}

#sidebar .kv {
    display: grid;
    grid-template-columns: 92px 1fr;
    gap: 6px 10px;
    font-size: 12px;
    color: var(--muted);
    padding: 10px;
    border: 1px solid rgba(148, 163, 184, .18);
    border-radius: 14px;
    background: rgba(255, 255, 255, .9);
    margin-bottom: 10px;
}

#sidebar .kv b {
    color: var(--ink);
    font-weight: 600;
}

#sidebar .list {
    border: 1px solid rgba(148, 163, 184, .18);
    border-radius: 14px;
    background: rgba(255, 255, 255, .9);
    padding: 10px;
    margin-bottom: 12px;
}

#sidebar .list .item {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 0;
    border-top: 1px dashed rgba(148, 163, 184, .12);
    font-size: 12px;
    color: var(--muted);
    cursor: pointer;
    transition: color 0.2s;
}

#sidebar .list .item:first-child {
    border-top: none;
}

#sidebar .list .item:hover {
    color: var(--accent);
}

#sidebar .list .item span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#sidebar .footer {
    color: var(--muted);
    font-size: 11px;
    margin-top: 6px;
}

@media (max-width: 980px) {
    #sidebar {
        display: none;
    }
}