.graph-screen {
    min-height: 28rem;
    padding: 0;
    overflow: hidden;
    gap: 0;
    background: var(--card-bg);
    display: flex;
    flex-direction: column;
}

.explore-chrome {
    flex-shrink: 0;
    z-index: 4;
    padding: 0.7rem 0.85rem 0.55rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    background: color-mix(in srgb, var(--card-bg) 92%, transparent);
    border-bottom: 1px solid var(--border-soft);
}

.explore-head {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    min-height: 1.6rem;
}

.explore-back {
    flex-shrink: 0;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text-main);
    font: inherit;
    font-size: 0.82rem;
    font-weight: 650;
    border-radius: 999px;
    padding: 0.28rem 0.75rem;
    cursor: pointer;
    min-height: 2rem;
}

.explore-back[hidden] {
    display: none;
}

.explore-back:focus-visible,
.explore-filters button:focus-visible,
.explore-suggest:focus-visible,
.graph-action-btn:focus-visible,
.graph-detail-item:focus-visible,
.graph-related-chip:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.explore-sub {
    margin: 0;
    font-size: 0.82rem;
    line-height: 1.35;
    color: var(--text-muted);
}

.graph-screen.is-empty .explore-sub,
.graph-screen.is-empty .explore-filters,
.graph-screen.is-empty .explore-ask,
.graph-screen.is-empty .explore-ask-toggle,
.graph-screen.is-empty .explore-ask-panel,
.graph-screen.is-empty .explore-suggestions,
.graph-screen.is-empty .explore-answer {
    display: none;
}

.explore-ask-toggle {
    align-self: flex-start;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text-muted);
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: 999px;
    padding: 0.32rem 0.8rem;
    cursor: pointer;
    min-height: 2rem;
}

.explore-ask-toggle.is-open {
    color: var(--text-main);
    border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
    background: color-mix(in srgb, var(--accent) 10%, var(--bg-elevated));
}

.explore-ask-toggle.is-open #txtGraphAskToggle::after {
    content: ' ▴';
    font-size: 0.7em;
}

.explore-ask-toggle:hover {
    color: var(--text-main);
    border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

.explore-ask-panel[hidden] {
    display: none;
}

.explore-ask-panel {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.explore-ask {
    display: flex;
    align-items: stretch;
    gap: 0.45rem;
}

.explore-ask input {
    flex: 1;
    min-width: 0;
    background-color: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.62rem 0.85rem;
    border-radius: var(--radius-md);
    font-size: 1rem;
    outline: none;
    font-family: inherit;
}

.explore-ask input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.explore-ask .btn {
    flex-shrink: 0;
    min-height: 2.6rem;
}

.explore-suggestions {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.35rem;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.explore-suggestions::-webkit-scrollbar {
    display: none;
}

.explore-suggestions[hidden] {
    display: none;
}

.explore-suggest {
    flex: 0 0 auto;
    border: none;
    background: color-mix(in srgb, var(--text-muted) 10%, var(--bg-elevated));
    color: var(--text-muted);
    font: inherit;
    font-size: 0.72rem;
    font-weight: 550;
    letter-spacing: 0.01em;
    border-radius: 999px;
    padding: 0.28rem 0.7rem;
    cursor: pointer;
    max-width: 16rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.explore-suggest:hover {
    color: var(--text-main);
    background: color-mix(in srgb, var(--accent) 12%, var(--bg-elevated));
}

.explore-answer {
    margin: 0;
    font-size: 0.88rem;
    line-height: 1.4;
    color: var(--text-main);
    padding: 0.45rem 0.15rem 0.1rem;
}

.explore-answer.is-status {
    color: var(--text-muted);
    font-style: italic;
}

.explore-answer[hidden] {
    display: none;
}

.explore-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.explore-filters button {
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text-muted);
    font: inherit;
    font-size: 0.75rem;
    font-weight: 650;
    border-radius: 999px;
    padding: 0.28rem 0.7rem;
    cursor: pointer;
    min-height: 2rem;
}

.explore-filters button.is-active {
    border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
    color: var(--accent);
    background: var(--accent-soft);
}

.explore-filters button[data-filter="person"].is-active {
    color: var(--entity-person);
    border-color: color-mix(in srgb, var(--entity-person) 65%, var(--border));
    background: color-mix(in srgb, var(--entity-person) 18%, var(--bg-elevated));
}

.explore-filters button[data-filter="place"].is-active {
    color: var(--entity-place);
    border-color: color-mix(in srgb, var(--entity-place) 65%, var(--border));
    background: color-mix(in srgb, var(--entity-place) 18%, var(--bg-elevated));
}

.explore-filters button[data-filter="event"].is-active {
    color: var(--entity-date);
    border-color: color-mix(in srgb, var(--entity-date) 65%, var(--border));
    background: color-mix(in srgb, var(--entity-date) 18%, var(--bg-elevated));
}

.explore-filters button[data-filter="org"].is-active {
    color: var(--entity-org);
    border-color: color-mix(in srgb, var(--entity-org) 65%, var(--border));
    background: color-mix(in srgb, var(--entity-org) 18%, var(--bg-elevated));
}

.graph-canvas-wrap {
    position: relative;
    flex: 1;
    min-height: 22rem;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    background:
        radial-gradient(920px 480px at 50% 42%, var(--accent-soft), transparent 58%),
        var(--bg);
}

.graph-canvas-wrap svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    cursor: grab;
}

.graph-canvas-wrap svg:active {
    cursor: grabbing;
}

.graph-hull,
.graph-caption,
.graph-link,
.graph-grid,
.graph-chip-label {
    pointer-events: none;
}

.graph-dot {
    fill: var(--text-muted);
    opacity: 0.28;
}

.graph-world {
    animation: graph-in 0.55s ease;
}

@keyframes graph-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.graph-link,
.graph-hull,
.graph-caption,
.graph-node {
    transition: opacity 0.32s ease, stroke-opacity 0.32s ease, stroke-width 0.32s ease;
}

@media (prefers-reduced-motion: reduce) {
    .graph-world {
        animation: none;
    }

    .graph-detail {
        animation: none;
    }

    .graph-link,
    .graph-hull,
    .graph-caption,
    .graph-node {
        transition: opacity 0.12s ease;
    }
}

.graph-hull {
    fill-opacity: 0.1;
    stroke-opacity: 0.28;
    stroke-width: 1.4;
    stroke-linejoin: round;
}

.graph-hull.is-dim {
    fill-opacity: 0.05;
    stroke-opacity: 0.12;
}

.graph-caption {
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    text-anchor: middle;
    pointer-events: none;
    opacity: 0.92;
    font-family: inherit;
    paint-order: stroke fill;
    stroke: var(--bg);
    stroke-width: 5px;
    stroke-linejoin: round;
}

.graph-caption.is-dim {
    opacity: 0.4;
}

[dir="rtl"] .graph-caption {
    text-transform: none;
    letter-spacing: 0;
    font-size: 14px;
}

/* --link-w is the 0..1 connection strength set per line by memory-graph.js.
   Every state keeps the same slope so a strong link stays visibly stronger. */
.graph-link {
    stroke: color-mix(in srgb, var(--text-muted) 55%, transparent);
    stroke-width: calc(0.9px + var(--link-w, 0.4) * 1.7px);
    stroke-opacity: calc(0.16 + var(--link-w, 0.4) * 0.4);
    fill: none;
    stroke-linecap: round;
}

.graph-link--cooccur {
    stroke: color-mix(in srgb, var(--entity-org) 55%, var(--text-muted));
}

.graph-link.is-dim {
    stroke-opacity: 0.18;
}

.graph-link.is-hot {
    stroke-opacity: 0.88;
    stroke-width: calc(1.5px + var(--link-w, 0.4) * 1.7px);
    stroke: var(--entity-org);
}

.graph-node {
    cursor: pointer;
}

.graph-link.is-search-hit {
    stroke-opacity: 0.95;
    stroke-width: calc(1.8px + var(--link-w, 0.4) * 1.7px);
    stroke: var(--accent);
}

.graph-node.is-dim {
    opacity: 0.48;
}

.graph-node.is-linked-out {
    opacity: 0.55;
}

.graph-node.is-linked-out.is-dim {
    opacity: 0.4;
}

.graph-node.is-search-hit,
.graph-node.is-filter-hit:not(.is-linked-out) {
    opacity: 1;
}

.graph-node.is-search-hit .graph-chip {
    stroke: var(--accent);
    stroke-width: 2.2;
    filter:
        drop-shadow(0 0 6px color-mix(in srgb, var(--accent) 55%, transparent))
        drop-shadow(0 4px 12px color-mix(in srgb, var(--accent) 28%, transparent));
}

.graph-node.is-filter-hit:not(.is-linked-out) .graph-chip {
    stroke-width: 1.75;
}

.graph-node--person.is-filter-hit:not(.is-linked-out) .graph-chip {
    stroke: var(--entity-person);
}

.graph-node--place.is-filter-hit:not(.is-linked-out) .graph-chip {
    stroke: var(--entity-place);
}

.graph-node--event.is-filter-hit:not(.is-linked-out) .graph-chip {
    stroke: var(--entity-date);
}

.graph-node--org.is-filter-hit:not(.is-linked-out) .graph-chip {
    stroke: var(--entity-org);
}

.graph-chip {
    fill: var(--card-bg);
    stroke: color-mix(in srgb, var(--border) 88%, var(--text-muted));
    stroke-width: 1;
    filter:
        drop-shadow(0 1px 1px color-mix(in srgb, var(--text-main) 10%, transparent))
        drop-shadow(0 6px 14px color-mix(in srgb, var(--text-main) 8%, transparent));
}

.graph-chip-label {
    fill: var(--text-main);
    font-size: 12px;
    font-weight: 600;
    /* No letter-spacing: WebKit lays SVG text out glyph-by-glyph when it is
       set, which drops bidi reordering and renders Hebrew backwards on iOS. */
    letter-spacing: 0;
    dominant-baseline: middle;
    pointer-events: none;
    font-family: inherit;
}

.graph-node--org .graph-chip,
.graph-node--event .graph-chip {
    fill: color-mix(in srgb, var(--card-bg) 88%, var(--bg));
}

.graph-node.is-hover .graph-chip,
.graph-node.is-selected .graph-chip {
    stroke: color-mix(in srgb, var(--accent) 55%, var(--border));
    stroke-width: 1.2;
}

.graph-node.is-selected .graph-chip {
    fill: var(--card-bg);
    filter:
        drop-shadow(0 1px 2px color-mix(in srgb, var(--accent) 22%, transparent))
        drop-shadow(0 8px 16px color-mix(in srgb, var(--accent) 18%, transparent));
}

.graph-head {
    margin: 0;
    padding: 0;
    border: none;
    display: inline-flex;
    align-items: baseline;
    gap: 0.55rem;
    background: none;
    color: var(--text-main);
    min-width: 0;
}

.graph-head #txtGraphHeading {
    font-size: 0.92rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.graph-stats {
    margin: 0;
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: none;
    letter-spacing: 0;
}

.graph-empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.7rem;
    margin: 0;
    padding: 1.5rem;
    text-align: center;
    color: var(--text-muted);
}

.graph-empty-title {
    margin: 0;
    font-size: 1.12rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.3;
}

.graph-empty-body {
    margin: 0;
    max-width: 28rem;
    font-size: 0.92rem;
    line-height: 1.45;
}

.graph-empty[hidden] {
    display: none;
}

.graph-canvas-wrap.is-empty .graph-zoom,
.graph-canvas-wrap.is-empty .graph-density {
    display: none;
}

.graph-hint {
    position: absolute;
    left: 50%;
    bottom: 0.8rem;
    transform: translateX(-50%);
    margin: 0;
    z-index: 2;
    font-size: 0.68rem;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    pointer-events: none;
    transition: opacity 0.35s ease;
    white-space: nowrap;
}

.graph-hint.is-gone {
    opacity: 0;
}

.graph-zoom {
    position: absolute;
    top: 0.7rem;
    inset-inline-end: 0.7rem;
    display: flex;
    flex-direction: column;
    gap: 0.28rem;
    z-index: 2;
}

.graph-zoom button,
.graph-density button {
    width: 2.25rem;
    height: 2.25rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: color-mix(in srgb, var(--card-bg) 88%, transparent);
    color: var(--text-main);
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    backdrop-filter: blur(12px);
}

.graph-density {
    position: absolute;
    bottom: 0.75rem;
    inset-inline-start: 0.75rem;
    z-index: 2;
    display: flex;
    gap: 0.35rem;
}

.graph-density button {
    width: auto;
    padding: 0 0.8rem;
    font-size: 0.75rem;
    font-weight: 650;
}

.graph-density button.is-active {
    border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
    color: var(--accent);
}

.graph-detail {
    position: absolute;
    left: 0.7rem;
    right: 0.7rem;
    bottom: 0.7rem;
    z-index: 3;
    padding: 0.9rem 1rem 1rem;
    border-radius: 14px;
    background: color-mix(in srgb, var(--card-bg) 92%, transparent);
    border: 1px solid var(--border);
    backdrop-filter: blur(16px);
    max-height: 42%;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    color: var(--text-main);
    box-shadow: var(--shadow-card);
    animation: fade-in 0.22s ease;
}

.graph-canvas-wrap:has(.graph-detail:not([hidden])) .graph-density,
.graph-canvas-wrap:has(.graph-detail:not([hidden])) .graph-hint {
    display: none;
}

.graph-detail[hidden] {
    display: none;
}

.graph-detail-head {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.graph-detail-kicker {
    margin: 0;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent);
}

.graph-detail-name {
    margin: 0.12rem 0 0;
    font-size: 1.08rem;
    font-weight: 700;
    color: var(--text-main);
    unicode-bidi: plaintext;
}

.graph-detail-x {
    margin-inline-start: auto;
    width: 2rem;
    height: 2rem;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    font-family: inherit;
}

.graph-detail-list {
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    min-height: 0;
}

.graph-detail-item {
    display: block;
    width: 100%;
    text-align: start;
    border: 1px solid var(--border-soft);
    border-radius: 10px;
    background: var(--bg-elevated);
    color: inherit;
    font: inherit;
    font-size: 0.86rem;
    line-height: 1.35;
    padding: 0.55rem 0.65rem;
    cursor: pointer;
    min-height: 44px;
}

.graph-detail-empty {
    margin: 0;
    font-size: 0.86rem;
    color: var(--text-muted);
}

.graph-detail-summary {
    margin: 0;
    font-size: 0.86rem;
    line-height: 1.4;
    color: var(--text-muted);
}

.graph-detail-summary:empty {
    display: none;
}

.graph-detail-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.graph-detail-actions:empty {
    display: none;
}

.graph-action-btn {
    min-height: 2.4rem;
    padding: 0.4rem 0.75rem;
    font-size: 0.82rem;
    font-weight: 650;
}

.graph-detail-ask[hidden] {
    display: none;
}

.graph-related-label {
    margin: 0 0 0.3rem;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.graph-related-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.2rem;
}

.graph-related-chip {
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-elevated);
    color: var(--text-main);
    font: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.28rem 0.65rem;
    cursor: pointer;
}

.graph-related-chip--person { border-color: color-mix(in srgb, var(--entity-person) 45%, transparent); }
.graph-related-chip--place { border-color: color-mix(in srgb, var(--entity-place) 45%, transparent); }
.graph-related-chip--org { border-color: color-mix(in srgb, var(--entity-org) 45%, transparent); }
.graph-related-chip--idea { border-color: color-mix(in srgb, var(--fact) 45%, transparent); }
.graph-related-chip--event { border-color: color-mix(in srgb, var(--entity-date) 45%, transparent); }

@media (min-width: 1051px) {
    .graph-screen {
        grid-column: 2 / -1;
        grid-row: 1;
        min-height: 36rem;
        max-height: calc(100vh - 9rem);
        align-self: stretch;
    }

    .graph-canvas-wrap {
        min-height: 0;
        height: auto;
        flex: 1;
    }

    .graph-detail {
        left: auto;
        right: 0.75rem;
        top: 0.75rem;
        bottom: auto;
        width: min(22rem, 38%);
        max-height: calc(100% - 1.5rem);
    }
}

@media (max-width: 1050px) {
    body.graph-open {
        overflow: hidden;
        height: 100dvh;
        height: 100svh;
        display: flex;
        flex-direction: column;
        padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    }

    body.graph-open .topbar {
        flex-shrink: 0;
    }

    body.graph-open .container {
        flex: 1 1 auto;
        min-height: 0;
        overflow: hidden;
        padding: 0;
        gap: 0;
        width: 100%;
        max-width: none;
        display: flex;
        flex-direction: column;
        align-items: stretch;
    }

    body.graph-open #screen-graph {
        display: flex;
        flex-direction: column;
        flex: 1 1 auto;
        width: 100%;
        min-height: 0;
        height: auto;
        overflow: hidden;
        padding: 0;
        border: none;
        border-radius: 0;
        box-shadow: none;
        background: var(--bg);
    }

    body.graph-open #screen-graph .graph-canvas-wrap {
        flex: 1 1 auto;
        width: 100%;
        min-height: 0;
        height: auto;
        position: relative;
    }

    .explore-chrome {
        padding: 0.45rem 0.65rem 0.4rem;
        gap: 0.3rem;
    }

    .explore-head {
        min-height: 0;
    }

    .graph-screen:not(.is-focused) .explore-head {
        display: none;
    }

    .explore-head #txtGraphHeading {
        display: none;
    }

    .explore-back {
        width: 2.5rem;
        min-width: 2.5rem;
        padding: 0;
        font-size: 1.1rem;
    }

    .explore-sub {
        display: none;
    }

    .explore-filters {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 0.1rem;
    }

    .explore-filters::-webkit-scrollbar {
        display: none;
    }

    .explore-ask .btn {
        min-width: 4.4rem;
        min-height: 2.75rem;
        padding-inline: 0.7rem;
    }

    .explore-ask-toggle,
    .explore-filters button,
    .explore-suggest {
        min-height: 2.5rem;
        padding: 0.35rem 0.8rem;
    }

    .graph-hint {
        bottom: 0.85rem;
        font-size: 0.64rem;
    }

    .graph-density {
        bottom: 0.65rem;
    }

    .graph-detail {
        position: fixed;
        top: auto;
        left: 0.5rem;
        right: 0.5rem;
        bottom: calc(0.45rem + 64px + env(safe-area-inset-bottom, 0px));
        z-index: 19;
        max-height: min(32dvh, 10rem);
        overflow: hidden;
        padding: 0.55rem 0.7rem 0.55rem;
        gap: 0.22rem;
        border-radius: 14px;
    }

    .graph-detail-kicker {
        font-size: 0.66rem;
    }

    .graph-detail-name {
        margin: 0.08rem 0 0;
        font-size: 1.02rem;
    }

    .graph-detail-x {
        width: 2rem;
        height: 2rem;
    }

    .graph-detail-summary {
        font-size: 0.8rem;
        line-height: 1.3;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
    }

    .graph-related-label {
        display: none;
    }

    .graph-related-row {
        margin-bottom: 0.1rem;
        max-height: 2.2rem;
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    .graph-detail-list,
    .graph-detail-list:empty {
        display: none;
    }

    .graph-detail-item {
        min-height: 36px;
        padding: 0.38rem 0.55rem;
        font-size: 0.8rem;
    }

    .graph-detail .btn {
        min-height: 34px;
        padding: 0.28rem 0.6rem;
        font-size: 0.78rem;
    }

    .graph-detail-empty {
        font-size: 0.84rem;
        display: block;
        overflow: visible;
        -webkit-line-clamp: unset;
    }
}

html[dir="rtl"] .graph-hint {
    transform: translateX(50%);
    left: auto;
    right: 50%;
}
