* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #0a0a0a;
    --bg-secondary: rgba(20, 20, 20, 0.95);
    --fg: #fafafa;
    --fg-muted: #71717a;
    --fg-subtle: #3f3f46;
    --border: rgba(255, 255, 255, 0.1);
    --node-fill: rgb(18, 18, 18);
    --node-stroke: #52525b;
    --link-color: #3f3f46;
}

[data-theme="light"] {
    --bg: #fafafa;
    --bg-secondary: rgba(255, 255, 255, 0.95);
    --fg: #18181b;
    --fg-muted: #71717a;
    --fg-subtle: #a1a1aa;
    --border: rgba(0, 0, 0, 0.1);
    --node-fill: rgb(244, 244, 244);
    --node-stroke: #a1a1aa;
    --link-color: #d4d4d8;
}

body {
    font-family: 'SF Mono', SFMono-Regular, ui-monospace, Menlo, Monaco, monospace;
    background: var(--bg);
    color: var(--fg);
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    transition: background 0.3s ease, color 0.3s ease;
}

#graph {
    width: 100%;
    height: 100%;
    display: block;
}

/* Theme Toggle */
#theme-toggle {
    position: absolute;
    top: 24px;
    right: 24px;
    z-index: 100;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--fg-muted);
    padding: 8px 12px;
    font-family: inherit;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s ease;
}

#theme-toggle:hover {
    color: var(--fg);
    border-color: var(--fg-muted);
}

#labels-toggle:hover {
    color: var(--fg);
    border-color: var(--fg-muted);
}

#labels-toggle {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--fg-muted);
    padding: 6px 10px;
    font-family: inherit;
    font-size: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 12px;
}

#view-toggle {
    position: absolute;
    top: 24px;
    right: 90px;
    z-index: 100;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--fg-muted);
    padding: 8px 12px;
    font-family: inherit;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s ease;
}

#view-toggle:hover {
    color: var(--fg);
    border-color: var(--fg-muted);
}

/* Hidden labels state */
.labels-hidden .node .label,
.labels-hidden .node.project foreignObject {
    opacity: 0;
    pointer-events: none;
}

/* Tooltip */
#tooltip {
    position: absolute;
    pointer-events: none;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    padding: 12px 16px;
    font-size: 11px;
    max-width: 240px;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 1000;
    backdrop-filter: blur(10px);
}

#tooltip.visible {
    opacity: 1;
}

#tooltip .title {
    font-weight: 500;
    font-size: 12px;
    margin-bottom: 4px;
    color: var(--fg);
}

#tooltip .org {
    color: var(--fg-muted);
    font-size: 10px;
    margin-bottom: 4px;
}

#tooltip .date {
    color: var(--fg-subtle);
    font-size: 10px;
}

/* Link styles */
.link {
    fill: none;
    stroke: var(--link-color);
    stroke-opacity: 0.4;
}

.link.theme-link {
    stroke-width: 1px;
}

.link.theme-link.secondary {
    stroke-dasharray: 2, 4;
    stroke-opacity: 0.2;
}

.link.sibling-link {
    stroke-dasharray: 1, 3;
    stroke-opacity: 0.15;
}

.link.origin-link {
    stroke-width: 1px;
    stroke-opacity: 0.25;
}

/* Node styles */
.node {
    cursor: pointer;
}

.node circle {
    transition: all 0.2s ease;
    fill: var(--node-fill);
    stroke: var(--node-stroke);
}

.node text {
    fill: var(--fg);
    pointer-events: none;
    text-anchor: middle;
    dominant-baseline: middle;
}

.node.origin .symbol {
    font-size: 28px;
    fill: var(--fg);
}

.node.origin .label {
    font-size: 11px;
    fill: var(--fg);
    letter-spacing: 0.02em;
}

.node.theme .symbol {
    font-size: 24px;
    fill: var(--fg);
}

.node.theme .label {
    font-size: 9px;
    fill: var(--fg-muted);
    letter-spacing: 0.05em;
}

.node.project .label {
    max-width: 100px;
    font-size: 9px;
    color: var(--fg-muted);
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: inherit;
}

/* Featured projects */
.node.featured circle {
    stroke: bisque;
    stroke-width: 2px;
    [data-theme=light] & {
        stroke: springgreen;
        ;
      }
}

.node.featured .label {
    color: bisque;
    [data-theme=light] & {
        color: springgreen;
        ;
      }
}

/* Dimmed state */
.dimmed .link {
    stroke-opacity: 0.05 !important;
}

.dimmed .node circle {
    opacity: 0.2;
}

.dimmed .node text {
    opacity: 0.2;
}

.dimmed .node.highlighted circle {
    opacity: 1;
    stroke: var(--fg);
}

.dimmed .link.highlighted {
    stroke-opacity: 0.6 !important;
    stroke: var(--fg-muted);
}

.dimmed .node.highlighted text {
    opacity: 1;
}

/* Header */
#header {
    position: absolute;
    top: 24px;
    left: 24px;
    z-index: 100;
}

#header h1 {
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.02em;
}

#header p {
    font-size: 10px;
    color: var(--fg-muted);
    margin-top: 4px;
}

/* Legend */
#legend {
    position: absolute;
    bottom: 24px;
    left: 24px;
    font-size: 10px;
    color: var(--fg-muted);
    z-index: 100;
}

#legend .item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
    text-transform: uppercase;
}

#legend .symbol {
    width: 20px;
    text-align: center;
    font-size: 14px;
    color: var(--fg);
}

/* Instructions */
#instructions {
    position: absolute;
    bottom: 24px;
    right: 24px;
    font-size: 9px;
    color: var(--fg-subtle);
    text-align: right;
    z-index: 100;
    line-height: 1.6;
}

/* Project Popup */
#project-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.95);
    width: 60vw;
    height: 60vh;
    background: var(--bg);
    border: 1px solid var(--border);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

#project-popup.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: grab;
    user-select: none;
}

.popup-header:active {
    cursor: grabbing;
}

#project-popup.dragging,
#description-popup.dragging {
    transition: none;
}

.popup-title {
    font-size: 12px;
    color: var(--fg);
}

.popup-close {
    background: transparent;
    border: none;
    color: var(--fg-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    transition: color 0.2s ease;
}

.popup-close:hover {
    color: var(--fg);
}

.popup-frame {
    flex: 1;
    border: none;
    background: var(--bg);
}

/* Description Popup */
#description-popup {
    position: fixed;
    top: 50%;
    left: 30%;
    transform: translate(-50%, -50%) scale(0.95);
    width: 400px;
    max-width: 90vw;
    background: var(--bg);
    border: 1px solid var(--border);
    z-index: 2001;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

#description-popup.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

#description-popup .popup-content {
    padding: 20px 16px;
}

#description-popup .popup-description {
    font-size: 13px;
    line-height: 1.6;
    color: var(--fg);
    margin-bottom: 16px;
}

#description-popup .popup-meta {
    font-size: 11px;
    color: var(--fg-muted);
    margin-bottom: 16px;
}

#description-popup .popup-meta span {
    margin-right: 12px;
}

#description-popup .popup-link {
    font-size: 11px;
    color: var(--fg-muted);
    text-decoration: none;
    transition: color 0.2s ease;
}

#description-popup .popup-link:hover {
    color: var(--fg);
}

/* List View */
#list-view {
    display: none;
    position: absolute;
    top: 80px;
    left: 24px;
    right: 24px;
    bottom: 80px;
    overflow: auto;
}

.list-view-active #graph {
    display: none;
}

.list-view-active #list-view {
    display: block;
}

.list-view-active #labels-toggle {
    display: none;
}

.list-view-active #legend {
    display: none;
}

#list-view table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

#list-view th {
    text-align: left;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--fg-muted);
    font-weight: 400;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    user-select: none;
    transition: color 0.2s ease;
}

#list-view th:hover {
    color: var(--fg);
}

#list-view th::after {
    content: '';
    margin-left: 6px;
}

#list-view th.sorted-asc::after {
    content: '↑';
}

#list-view th.sorted-desc::after {
    content: '↓';
}

#list-view td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--fg);
}

.list-row {
    cursor: pointer;
    transition: background 0.2s ease;
}

.list-row:hover {
    background: var(--bg-secondary);
}

.list-project {
    font-weight: 500;
}

.list-org {
    color: var(--fg-muted);
}

.list-theme {
    color: var(--fg-muted);
}

.theme-tag {
    display: inline-block;
    margin-right: 8px;
}

.theme-tag.secondary {
    opacity: 0.6;
}

.theme-symbol {
    margin-right: 4px;
}

.list-date {
    color: var(--fg-subtle);
    font-size: 11px;
}

.list-row.featured .list-project {
    color: springgreen;
}
