/* --- design tokens -------------------------------------------------- */

:root {
    --bg: #0a0a0b;
    --surface: #12131a;
    --surface-2: #1a1b23;
    --border: #24252f;
    --border-2: #2f3140;
    --text: #ececf0;
    --muted: #9094a3;
    --dim: #5e6270;

    --accent: #d4a574;
    /* warm brass */
    --accent-2: #7a9cc6;
    /* steel blue */
    --accent-3: #b8b0e0;
    /* soft violet */

    --dynamic: #d4a574;
    --condenser: #7ec5b0;
    --ribbon: #c48ac4;
    --brand-hub: #4a4d5e;
    --danger: #d47a7a;
    --ok: #7ec5b0;

    --font-body: 'Inter', system-ui, -apple-system, sans-serif;
    --font-display: 'Instrument Serif', ui-serif, Georgia, serif;
    --font-header: 'Space Grotesk', 'Inter', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;

    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background:
        radial-gradient(1200px 600px at 20% -10%, rgba(212, 165, 116, 0.06), transparent 60%),
        radial-gradient(1000px 500px at 90% 110%, rgba(122, 156, 198, 0.05), transparent 60%),
        var(--bg);
    min-height: 100vh;
}

/* --- header --------------------------------------------------------- */

header {
    padding: 48px 56px 24px;
    border-bottom: 1px solid var(--border);
}

.hero h1 {
    font-family: var(--font-header);
    font-weight: 500;
    font-size: 46px;
    line-height: 1.05;
    margin: 0 0 12px;
    letter-spacing: -0.025em;
}

.mark {
    color: var(--accent);
    margin-right: 10px;
    display: inline-block;
    transform: translateY(-4px);
    font-size: 0.65em;
}

.sub {
    color: var(--muted);
    max-width: 720px;
    margin: 0 0 20px;
    font-size: 15px;
    line-height: 1.55;
}

.stats {
    display: flex;
    flex-wrap: wrap;
    gap: 32px;
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.09em;
    font-family: var(--font-mono);
}

.stats span strong {
    display: block;
    color: var(--text);
    font-weight: 500;
    font-size: 22px;
    line-height: 1.1;
    margin-bottom: 4px;
    letter-spacing: 0;
    font-family: var(--font-display);
}

/* --- main layout ---------------------------------------------------- */

main {
    display: grid;
    grid-template-columns: 260px 1fr 420px;
    gap: 1px;
    background: var(--border);
    height: calc(100vh - 220px);
    min-height: 600px;
}

main>* {
    background: var(--bg);
    overflow-y: auto;
}

/* --- filters -------------------------------------------------------- */

.filters {
    padding: 24px 20px;
}

.search {
    position: relative;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--dim);
    pointer-events: none;
}

.search input {
    width: 100%;
    padding: 10px 12px 10px 34px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font: inherit;
    font-size: 13px;
    transition: border-color 0.15s, background 0.15s;
}

.search input::placeholder {
    color: var(--dim);
}

.search input:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--surface-2);
}

.search input:focus~.search-icon,
.search:focus-within .search-icon {
    color: var(--accent);
}

fieldset.chip-group {
    border: none;
    padding: 0;
    margin: 24px 0 0;
}

fieldset.chip-group legend {
    padding: 0;
    margin-bottom: 10px;
    color: var(--muted);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-family: var(--font-mono);
}

.chip {
    display: inline-block;
    padding: 4px 10px;
    margin: 0 4px 5px 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 12px;
    color: var(--muted);
    cursor: pointer;
    user-select: none;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    line-height: 1.2;
}

.chip:hover {
    color: var(--text);
    border-color: var(--border-2);
}

.chip.on {
    color: var(--bg);
    background: var(--accent);
    border-color: var(--accent);
}

.chip .count {
    color: var(--dim);
    margin-left: 6px;
    font-variant-numeric: tabular-nums;
    font-family: var(--font-mono);
    font-size: 10px;
}

.chip.on .count {
    color: rgba(10, 10, 11, 0.55);
}

.clear {
    margin-top: 20px;
    background: none;
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font: inherit;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    transition: color 0.15s, border-color 0.15s;
}

.clear:hover {
    color: var(--text);
    border-color: var(--border-2);
}

/* --- graph ---------------------------------------------------------- */

.graph {
    position: relative;
    overflow: hidden;
}

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

#graph:active {
    cursor: grabbing;
}

.legend {
    position: absolute;
    top: 20px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.09em;
    font-family: var(--font-mono);
    padding: 12px 16px;
    background: rgba(18, 19, 26, 0.6);
    border: 1px solid var(--border);
    border-radius: 6px;
    backdrop-filter: blur(8px);
}

.l::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 8px;
    vertical-align: middle;
}

.l-dynamic::before {
    background: var(--dynamic);
}

.l-condenser::before {
    background: var(--condenser);
}

.l-ribbon::before {
    background: var(--ribbon);
}

.l-brand::before {
    background: var(--brand-hub);
}

.hint {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: var(--dim);
    font-family: var(--font-mono);
    letter-spacing: 0.03em;
    padding: 6px 12px;
    background: rgba(18, 19, 26, 0.5);
    border-radius: 999px;
    pointer-events: none;
    animation: fadeIn 0.6s ease-out 1.5s both;
}

/* --- graph nodes and links ------------------------------------------ */

.node {
    cursor: pointer;
    transition: r 0.15s, opacity 0.2s;
    stroke: var(--bg);
    stroke-width: 2;
}

.node:hover {
    stroke: var(--text);
}

.node.selected {
    stroke: var(--text);
    stroke-width: 3;
    filter: drop-shadow(0 0 8px currentColor);
}

.node.dimmed {
    opacity: 0.12;
}

.node-brand {
    stroke: rgba(255, 255, 255, 0.06);
}

.node-label {
    font-family: var(--font-mono);
    font-size: 10px;
    fill: var(--muted);
    pointer-events: none;
    text-anchor: middle;
    transition: opacity 0.15s;
}

.node-label.brand {
    font-size: 10px;
    fill: var(--dim);
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.node-label.unit {
    opacity: 0;
}

.node-label.unit.show {
    opacity: 1;
    fill: var(--text);
}

.node-label.dimmed {
    opacity: 0.08 !important;
}

.link {
    stroke-linecap: round;
    transition: stroke-opacity 0.2s;
}

.link-membership {
    stroke: var(--border-2);
    stroke-width: 1;
}

.link-similarity {
    stroke: var(--accent-2);
    stroke-opacity: 0.28;
    stroke-dasharray: 2 5;
    stroke-width: 1;
}

.link.dimmed {
    opacity: 0.04;
}

.link.highlighted {
    stroke-opacity: 0.9;
    stroke-width: 1.6;
    stroke-dasharray: 0;
}

/* --- detail panel --------------------------------------------------- */

.detail {
    padding: 32px 32px 48px;
    border-left: 1px solid var(--border);
    position: relative;
}

.detail .empty {
    color: var(--muted);
    margin-top: 80px;
    text-align: center;
}

.empty-mark {
    font-size: 44px;
    color: var(--accent);
    opacity: 0.5;
    margin-bottom: 12px;
    animation: floatY 3s ease-in-out infinite;
}

.empty-hint {
    font-size: 12px;
    margin-top: 8px;
    color: var(--dim);
}

.detail-header {
    margin-bottom: 24px;
}

.detail .brand-line {
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin: 0 0 6px;
    font-family: var(--font-mono);
}

.detail h2 {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 40px;
    margin: 0 0 12px;
    letter-spacing: -0.015em;
    line-height: 1.05;
}

.close-btn {
    position: absolute;
    top: 24px;
    right: 24px;
    background: none;
    border: 1px solid var(--border);
    color: var(--muted);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, border-color 0.15s;
    padding: 0;
}

.close-btn:hover {
    color: var(--text);
    border-color: var(--border-2);
}

.badges {
    margin: 8px 0 14px;
}

.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 4px;
    font-size: 10px;
    font-family: var(--font-mono);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-right: 6px;
}

.badge-type-dynamic {
    background: rgba(212, 165, 116, 0.15);
    color: var(--dynamic);
}

.badge-type-condenser {
    background: rgba(126, 197, 176, 0.15);
    color: var(--condenser);
}

.badge-type-ribbon {
    background: rgba(196, 138, 196, 0.15);
    color: var(--ribbon);
}

.badge-status-verified {
    background: rgba(126, 197, 176, 0.10);
    color: var(--ok);
}

.badge-status-stale {
    background: rgba(212, 122, 122, 0.15);
    color: var(--danger);
}

.badge-status-draft {
    background: var(--surface-2);
    color: var(--muted);
}

.usecases {
    margin-bottom: 8px;
}

.usecases .chip {
    cursor: default;
    background: transparent;
    color: var(--text);
    border-color: var(--border);
    padding: 3px 10px;
}

.usecases .chip:hover {
    color: var(--text);
    border-color: var(--border);
}

/* --- polar + freq visualisations ------------------------------------ */

.viz-row {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 16px;
    align-items: center;
    margin: 20px 0;
    padding: 20px 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.viz-row-full {
    display: block;
    padding: 20px 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    margin: 20px 0;
}

.polar-viz {
    width: 120px;
    height: 120px;
    position: relative;
}

.polar-viz svg {
    width: 100%;
    height: 100%;
    overflow: visible;
}

.polar-viz .polar-name {
    position: absolute;
    bottom: -20px;
    left: 0;
    right: 0;
    text-align: center;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.polar-viz .no-pattern {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--dim);
    font-family: var(--font-mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    border: 1px dashed var(--border);
    border-radius: 6px;
}

.freq-viz .label {
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.09em;
    margin-bottom: 8px;
    font-family: var(--font-mono);
    display: flex;
    justify-content: space-between;
}

.freq-viz .label .val {
    color: var(--text);
}

.freq-viz svg {
    width: 100%;
    height: 48px;
    display: block;
}

/* --- specs ---------------------------------------------------------- */

section.specs {
    margin: 20px 0;
}

.section-label {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 500;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin: 0 0 14px;
}

.specs table {
    width: 100%;
    font-family: var(--font-mono);
    font-size: 12px;
    border-collapse: collapse;
}

.specs td {
    padding: 5px 0;
    vertical-align: top;
}

.specs td.k {
    color: var(--muted);
    width: 42%;
    text-transform: lowercase;
}

.specs td.v {
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

/* --- body ----------------------------------------------------------- */

section.body {
    margin: 24px 0;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.body p {
    font-family: var(--font-display);
    font-size: 17px;
    line-height: 1.55;
    color: var(--text);
    margin: 0 0 14px;
    letter-spacing: -0.005em;
}

.body p:last-child {
    margin-bottom: 0;
}

/* --- rivals --------------------------------------------------------- */

section.rivals {
    border-top: 1px solid var(--border);
    padding-top: 20px;
    margin-top: 24px;
}

.rival {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: padding-left 0.15s;
}

.rival:hover {
    padding-left: 6px;
}

.rival:last-child {
    border-bottom: none;
}

.rival-info .name {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text);
    margin-bottom: 2px;
}

.rival-info .brand {
    font-size: 11px;
    color: var(--muted);
    font-family: var(--font-body);
    text-transform: none;
    letter-spacing: 0;
}

.rival-info .brand::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--accent-2);
    margin-right: 6px;
    vertical-align: middle;
    opacity: 0.6;
}

.rival-score {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--dim);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* --- source --------------------------------------------------------- */

section.source {
    border-top: 1px solid var(--border);
    padding-top: 20px;
    margin-top: 24px;
}

.source a {
    color: var(--accent);
    text-decoration: none;
    font-family: var(--font-mono);
    font-size: 11px;
    word-break: break-all;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.source a:hover {
    text-decoration: underline;
}

.source .meta {
    color: var(--dim);
    font-size: 11px;
    margin-top: 8px;
    font-family: var(--font-mono);
}

/* --- footer --------------------------------------------------------- */

footer {
    padding: 16px 56px;
    border-top: 1px solid var(--border);
    color: var(--dim);
    font-size: 11px;
    font-family: var(--font-mono);
    display: flex;
    justify-content: space-between;
    letter-spacing: 0.03em;
}

footer code {
    color: var(--muted);
    background: transparent;
    font-family: var(--font-mono);
}

/* --- scrollbars ----------------------------------------------------- */

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--dim);
}

/* --- animations ----------------------------------------------------- */

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes floatY {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-6px);
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* --- responsive ----------------------------------------------------- */

@media (max-width: 1200px) {
    main {
        grid-template-columns: 240px 1fr 380px;
    }

    header {
        padding: 40px 40px 20px;
    }

    footer {
        padding: 14px 40px;
    }
}

@media (max-width: 960px) {
    main {
        grid-template-columns: 1fr;
        grid-template-rows: auto 480px auto;
        height: auto;
        min-height: 0;
    }

    .filters {
        border-bottom: 1px solid var(--border);
        padding: 16px 20px;
    }

    .detail {
        border-left: none;
        border-top: 1px solid var(--border);
    }

    .hero h1 {
        font-size: 40px;
    }

    header {
        padding: 32px 24px 18px;
    }

    footer {
        padding: 12px 24px;
        flex-direction: column;
        gap: 4px;
    }

    .legend {
        top: 12px;
        right: 12px;
    }
}