:root {
    --bg-ink: #0f1720;
    --bg-deep: #101b2d;
    --panel: #15253b;
    --panel-2: #1e3251;
    --line: #2d4a70;
    --text: #f4f6fb;
    --muted: #a7bdd8;
    --accent: #6be3c9;
    --accent-2: #f9b86b;
    --danger: #ff6b74;
    --bubble-0: #f9b86b;
    --bubble-1: #6be3c9;
    --bubble-2: #85b8ff;
    --bubble-3: #c49cff;
    --bubble-4: #f88eb2;
    --shadow: 0 16px 38px rgba(0, 0, 0, 0.34);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: "Space Grotesk", "Segoe UI", sans-serif;
    color: var(--text);
    background:
        radial-gradient(1000px 520px at 8% -6%, #284a7a 0%, transparent 52%),
        radial-gradient(820px 600px at 96% 10%, #4b3054 0%, transparent 52%),
        linear-gradient(170deg, var(--bg-ink) 0%, var(--bg-deep) 100%);
    overflow-x: hidden;
}

.ambient {
    position: fixed;
    border-radius: 50%;
    filter: blur(40px);
    opacity: 0.22;
    pointer-events: none;
}

.ambient-a {
    width: 340px;
    height: 340px;
    background: #40eac7;
    top: -110px;
    right: -90px;
    animation: driftA 16s ease-in-out infinite alternate;
}

.ambient-b {
    width: 280px;
    height: 280px;
    background: #f79a67;
    bottom: -110px;
    left: -40px;
    animation: driftB 20s ease-in-out infinite alternate;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    gap: 20px;
    align-items: end;
    justify-content: space-between;
    padding: 18px 22px;
    background: linear-gradient(180deg, rgba(7, 13, 22, 0.92), rgba(7, 13, 22, 0.56));
    backdrop-filter: blur(5px);
    border-bottom: 1px solid rgba(113, 151, 197, 0.2);
}

.brand-wrap {
    flex: 0 1 auto;
}

.eyebrow {
    margin: 0;
    color: var(--muted);
    font-size: 0.78rem;
    letter-spacing: 0.11em;
    text-transform: uppercase;
}

.brand {
    margin: 4px 0 0;
    font-family: "Fraunces", Georgia, serif;
    font-size: clamp(1.5rem, 2.6vw, 2.1rem);
    font-weight: 700;
    line-height: 1;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 999px;
    font: inherit;
    font-size: 0.9rem;
    padding: 9px 16px;
    cursor: pointer;
    text-decoration: none;
    transition: transform 120ms ease, background-color 120ms ease, border-color 120ms ease, opacity 120ms ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:disabled {
    opacity: 0.42;
    cursor: default;
    transform: none;
}

.btn-ghost {
    color: var(--text);
    border-color: #55729a;
    background: rgba(18, 36, 61, 0.72);
}

.btn-solid {
    color: #0a1d27;
    border-color: #95e9d8;
    background: linear-gradient(160deg, #73f0d6, #56c6df);
    font-weight: 700;
}

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1.7fr) minmax(280px, 0.95fr);
    gap: 18px;
    padding: 18px;
}

.map-shell,
.detail-card {
    border-radius: 18px;
    border: 1px solid rgba(116, 150, 186, 0.25);
    background: linear-gradient(160deg, rgba(20, 35, 56, 0.86), rgba(18, 31, 51, 0.84));
    box-shadow: var(--shadow);
}

.map-shell {
    display: flex;
    flex-direction: column;
    min-height: 580px;
    animation: riseIn 320ms ease;
}

.map-header {
    padding: 14px 16px 0;
}

.map-header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.map-bookmarks {
    position: relative;
}

.bookmarks-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    width: min(360px, 82vw);
    max-height: 320px;
    overflow: auto;
    border: 1px solid rgba(116, 150, 186, 0.35);
    border-radius: 12px;
    background: linear-gradient(160deg, rgba(19, 34, 56, 0.96), rgba(15, 27, 45, 0.98));
    box-shadow: var(--shadow);
    padding: 10px;
    z-index: 12;
}

.bookmarks-panel-meta {
    margin: 0 0 8px;
    color: var(--muted);
    font-size: 0.82rem;
}

.bookmarks-panel-list {
    max-height: 250px;
    overflow: auto;
}

.bookmarks-panel-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.status-pill {
    display: inline-block;
    margin: 0;
    padding: 7px 13px;
    border: 1px solid #55729a;
    border-radius: 999px;
    background: rgba(15, 31, 52, 0.86);
    color: var(--muted);
    font-size: 0.84rem;
}

.status-pill.success {
    border-color: #7ed7c3;
    color: #95f0de;
}

.status-pill.warn {
    border-color: #c69570;
    color: #ffd6a5;
}

.status-pill.error {
    border-color: #cf6071;
    color: #ffb2bf;
}

.map-canvas {
    width: 100%;
    flex: 1;
    min-height: 510px;
    padding: 8px 10px 0;
}

.map-help {
    margin: 0;
    padding: 0 16px 14px;
    color: var(--muted);
    font-size: 0.85rem;
}

.detail-card {
    padding: 20px 18px;
    overflow-y: auto;
    max-height: calc(100vh - 112px);
    animation: riseIn 420ms ease;
}

.node-title {
    margin: 0;
    font-family: "Fraunces", Georgia, serif;
    font-size: 1.66rem;
    line-height: 1.16;
}

.node-meta {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 0.9rem;
}

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

.bookmark-meta {
    margin: 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.request-controls {
    margin: 12px 0 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.request-controls .btn {
    font-size: 0.82rem;
    padding: 7px 12px;
}

.request-indicators {
    margin: 8px 0 0;
    color: #9ad7c9;
    font-size: 0.82rem;
    line-height: 1.35;
}

.request-notice {
    margin: 12px 0 0;
    border: 1px solid rgba(146, 203, 255, 0.45);
    background: rgba(40, 92, 145, 0.24);
    color: #d5edff;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 0.88rem;
    line-height: 1.35;
}

.node-description {
    margin: 14px 0 16px;
    line-height: 1.52;
    color: #e4ebf8;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.detail-search-wrap {
    position: relative;
    display: flex;
    justify-content: flex-end;
    margin: 12px 0 0;
}

.header-search-wrap {
    flex: 1 1 380px;
    margin: 0;
    justify-content: flex-end;
}

.detail-search-input {
    width: min(360px, 100%);
    border: 1px solid rgba(118, 154, 193, 0.5);
    border-radius: 12px;
    background: rgba(16, 30, 49, 0.86);
    color: var(--text);
    font: inherit;
    font-size: 0.88rem;
    padding: 9px 12px;
    outline: none;
}

.detail-search-input:focus {
    border-color: rgba(123, 211, 192, 0.85);
    box-shadow: 0 0 0 2px rgba(98, 196, 174, 0.2);
}

.detail-search-results {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: min(420px, 100%);
    max-height: 330px;
    overflow-y: auto;
    border: 1px solid rgba(116, 150, 186, 0.35);
    border-radius: 12px;
    background: linear-gradient(160deg, rgba(19, 34, 56, 0.97), rgba(15, 27, 45, 0.98));
    box-shadow: var(--shadow);
    z-index: 11;
}

.detail-search-item {
    width: 100%;
    text-align: left;
    border: 0;
    border-bottom: 1px solid rgba(110, 142, 177, 0.24);
    background: transparent;
    color: var(--text);
    padding: 10px 12px;
    cursor: pointer;
    font: inherit;
}

.detail-search-item:last-child {
    border-bottom: 0;
}

.detail-search-item:hover,
.detail-search-item:focus-visible {
    background: rgba(104, 170, 220, 0.16);
    outline: none;
}

.detail-search-item-title {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
}

.detail-search-item-meta {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 0.78rem;
}

.detail-search-empty {
    margin: 0;
    padding: 10px 12px;
    color: var(--muted);
    font-size: 0.84rem;
}

.detail-search-request-btn {
    margin: 2px 12px 10px;
    width: calc(100% - 24px);
    border-radius: 10px;
    justify-content: center;
}

.section-title {
    margin: 16px 0 8px;
    font-size: 0.97rem;
    letter-spacing: 0.03em;
    color: #d4def2;
}

.plain-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 6px;
}

.plain-list li {
    background: rgba(19, 34, 56, 0.72);
    border: 1px solid rgba(90, 120, 157, 0.3);
    border-radius: 10px;
    padding: 9px 10px;
    color: #dbe6f8;
    line-height: 1.32;
    font-size: 0.9rem;
}

.plain-list a {
    color: #9fdbff;
    text-decoration: none;
}

.plain-list a:hover {
    text-decoration: underline;
}

.node-link {
    stroke: rgba(156, 185, 222, 0.4);
    stroke-width: 2.5;
}

.node-link.parent-link {
    stroke-dasharray: 6 8;
}

.node-link.cross-link {
    stroke: rgba(255, 183, 111, 0.5);
    stroke-dasharray: 4 6;
}

.node-group {
    cursor: pointer;
    transform-origin: center;
}

.node-group.current {
    cursor: default;
}

.node-group .bubble {
    stroke: rgba(255, 255, 255, 0.68);
    stroke-width: 2;
    filter: drop-shadow(0 8px 16px rgba(9, 16, 25, 0.45));
    transition: transform 180ms ease, filter 180ms ease;
}

.node-group:hover .bubble {
    filter: drop-shadow(0 10px 20px rgba(17, 26, 40, 0.6));
}

.node-group:not(.current):hover .bubble {
    transform: scale(1.03);
}

.node-group text {
    fill: white;
    text-anchor: middle;
    dominant-baseline: middle;
    font-size: 14px;
    font-weight: 600;
    pointer-events: none;
}

.node-group.parent text {
    font-size: 12px;
}

.node-group.current text {
    font-size: 16px;
    font-weight: 700;
}

.bubble-enter {
    animation: bubbleIn 260ms ease both;
}

@media (max-width: 1040px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .detail-card {
        max-height: none;
    }
}

@media (max-width: 680px) {
    .topbar {
        flex-direction: column;
        align-items: stretch;
    }

    .controls {
        width: 100%;
    }

    .header-search-wrap {
        width: 100%;
    }

    .btn {
        flex: 1;
        min-width: 110px;
    }

    .map-shell {
        min-height: 500px;
    }

    .map-canvas {
        min-height: 440px;
    }

    .detail-search-wrap {
        justify-content: stretch;
    }

    .detail-search-input {
        width: 100%;
    }

    .detail-search-results {
        width: 100%;
    }
}

@keyframes bubbleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes riseIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes driftA {
    from {
        transform: translate(-10px, -18px);
    }
    to {
        transform: translate(24px, 16px);
    }
}

@keyframes driftB {
    from {
        transform: translate(12px, 8px);
    }
    to {
        transform: translate(-18px, -12px);
    }
}
