/* The home page: a header of two bubbles, then a bubble per app placed by
   js/layout.js, with the lines between them drawn while one is active.
   Colours come from theme.css; these add one per kind of relationship. */

:root {
    --edge-data: #2f5d9e;
    --edge-api: #b7791f;
    --edge-backup: #2c8a7a;
    --edge-link: #7a6a9e;
    --ring-auth: #b5543c;
    --ring-stats: #2c8a7a;
    --ring-docs: #5b7a2e;
    --dim: 0.32;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-scheme="light"]) {
        --edge-data: #8fb4ec;
        --edge-api: #e8b25c;
        --edge-backup: #6fd0bd;
        --edge-link: #b9a8e4;
        --ring-auth: #f08f74;
        --ring-stats: #6fd0bd;
        --ring-docs: #b5d77c;
        --dim: 0.28;
    }
}

:root[data-scheme="dark"] {
    --edge-data: #8fb4ec;
    --edge-api: #e8b25c;
    --edge-backup: #6fd0bd;
    --edge-link: #b9a8e4;
    --ring-auth: #f08f74;
    --ring-stats: #6fd0bd;
    --ring-docs: #b5d77c;
    --dim: 0.28;
}

body {
    overflow-x: hidden;
}

.map {
    position: relative;
    max-width: 1600px;
    min-height: 100vh;
    margin: 0 auto;
}

/* ---- The header: photo and welcome ---- */

.intro {
    position: relative;
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 14px;
    width: fit-content;
    max-width: calc(100% - 90px);
    padding: 24px 0 0 24px;
}

.photo img {
    display: block;
    width: 128px;
    height: 128px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--surface);
    box-shadow: 0 0 0 1px var(--border-strong), var(--shadow);
}

.welcome {
    padding: 18px 36px 18px 30px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.welcome h1 {
    margin: 0;
    font-size: 1.5rem;
    letter-spacing: -0.01em;
}

.welcome p {
    margin: 3px 0 0;
    color: var(--text-soft);
}

.welcome .hint {
    font-size: 0.9rem;
    font-style: italic;
}

.hint-touch {
    display: none;
}

@media (hover: none) {
    .hint-hover {
        display: none;
    }

    .hint-touch {
        display: inline;
    }
}

/* ---- The theme menu, left of the light/dark button (under it on phones) ---- */

.theme-menu-button {
    position: fixed;
    top: 20px;
    right: 66px;
    z-index: 100;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text-soft);
    cursor: pointer;
    transition:
        color 0.15s ease,
        border-color 0.15s ease;
}

.theme-menu-button[hidden] {
    display: none;
}

.theme-menu-button:hover {
    color: var(--text);
    border-color: var(--accent);
}

/* Apart from the rule above: a browser that doesn't know :popover-open
   would drop the whole rule. */
.theme-menu-button:has(+ .theme-menu:popover-open) {
    color: var(--text);
    border-color: var(--accent);
}

.theme-menu-button svg {
    width: 18px;
    height: 18px;
}

.theme-menu {
    position: fixed;
    inset: 66px 20px auto auto;
    margin: 0;
    padding: 6px;
    width: 230px;
    max-height: calc(100dvh - 86px);
    overflow-y: auto;
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

.theme-menu fieldset {
    margin: 0;
    padding: 0;
    border: 0;
}

.theme-menu legend {
    padding: 6px 10px 8px;
    font-size: 0.75rem;
    color: var(--text-soft);
}

.theme-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
}

.theme-option:hover {
    background: var(--surface-hover);
}

/* The radio is there for the keyboard and screen readers; the row shows it. */
.theme-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.theme-option:has(input:focus-visible) {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.theme-option:has(input:checked) {
    font-weight: 600;
}

.theme-option:has(input:checked)::after {
    content: "✓";
    margin-left: auto;
    color: var(--accent);
}

.swatch {
    display: inline-flex;
    flex: none;
    width: 30px;
    height: 20px;
    overflow: hidden;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
}

/* Each part is in its own theme (data-theme), so these are its colours. */
.swatch > span {
    position: relative;
    flex: 1;
    background: var(--background);
}

.swatch > span::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    translate: -50% -50%;
}

/* ---- The reset control, under the theme buttons (shown after a drag) ---- */

.reset-layout {
    position: fixed;
    top: 66px;
    right: 20px;
    z-index: 100;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text-soft);
    cursor: pointer;
}

.reset-layout[hidden] {
    display: none;
}

.reset-layout:hover {
    color: var(--text);
    border-color: var(--accent);
}

.reset-layout svg {
    width: 18px;
    height: 18px;
}

/* ---- Without JavaScript: a plain list of links ---- */

.fallback {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin: 0;
    padding: 32px 24px;
    list-style: none;
}

.fallback a {
    display: block;
    padding: 12px 20px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
    font-weight: 600;
    text-decoration: none;
}

/* With JavaScript the map replaces it. If the map never comes (an error, an
   old browser), the list shows after a few seconds anyway. */
.js .fallback {
    visibility: hidden;
    animation: reveal 0s linear 4s forwards;
}

.ready .fallback {
    display: none;
}

@keyframes reveal {
    to {
        visibility: visible;
    }
}

/* ---- Bubbles ---- */

.bubbles {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
}

/* Sizes are for --s: 1. js/main.js sets --s on the map so the bubbles fill
   a share of the screen (FILL), between its limits; the max()es keep the
   text and the external bubbles readable at the smallest. */
.bubble {
    --d: 112px;
    --d-min: 0px;
    --w: 1;
    --hl: var(--border-strong);

    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: calc(6px * var(--s, 1));
    width: max(var(--d-min), calc(var(--d) * var(--w) * var(--s, 1)));
    height: max(var(--d-min), calc(var(--d) * var(--w) * var(--s, 1)));
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    box-shadow: var(--shadow);
    color: var(--text);
    font-size: max(11px, calc(13px * var(--s, 1)));
    font-weight: 600;
    line-height: 1.15;
    text-align: center;
    text-decoration: none;
    pointer-events: auto;
    cursor: pointer;
    /* Moved by js/motion.js every frame (by the top-left corner), so never
       transitioned; `scale` is, and grows the bubble from its centre. */
    top: 0;
    left: 0;
    translate: var(--x, 0) var(--y, 0);
    scale: 0.6;
    opacity: 0;
    transition:
        opacity 0.25s ease,
        scale 0.25s ease,
        box-shadow 0.2s ease,
        border-color 0.2s ease,
        visibility 0.25s;
}

.placed .bubble {
    scale: 1;
    opacity: 1;
}

/* Dragging (mouse and pen): no text selection, no caption in the way. */
.bubble {
    user-select: none;
    -webkit-user-select: none;
}

.is-dragging .bubble {
    cursor: grabbing;
}

.is-dragging .caption {
    display: none;
}

.bubble svg {
    width: max(20px, calc(26px * var(--s, 1)));
    height: max(20px, calc(26px * var(--s, 1)));
    flex: none;
}

.bubble .name {
    max-width: 100%;
}

.bubble.long {
    font-size: max(9.5px, calc(11.5px * var(--s, 1)));
    letter-spacing: -0.01em;
}

.bubble.external.long {
    font-size: max(8.5px, calc(10px * var(--s, 1)));
}

.bubble.external {
    --d: 86px;
    --d-min: 70px;
    gap: calc(3px * var(--s, 1));
    border-style: solid;
    background: var(--background);
    font-size: max(10px, calc(11px * var(--s, 1)));
    font-weight: 500;
}

.bubble.external svg,
.bubble img.favicon {
    width: max(15px, calc(18px * var(--s, 1)));
    height: max(15px, calc(18px * var(--s, 1)));
}

.bubble img.favicon,
.caption .chip img.favicon {
    flex: none;
    border-radius: 3px;
    object-fit: contain;
}

.bubble.external .name::after {
    content: " ↗";
    color: var(--text-soft);
}

.bubble.planned {
    border-style: dashed;
    border-color: var(--border-strong);
    background: var(--background);
    color: var(--text-soft);
    box-shadow: none;
    cursor: default;
}

.bubble .tag {
    font-size: max(8.5px, calc(10px * var(--s, 1)));
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    opacity: 0.8;
}

.bubble:hover,
.bubble:focus-visible {
    border-color: var(--accent);
}

.bubble:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

/* On-hover bubbles (external sites) only show next to an active neighbour. */
.placed .bubble.on-hover {
    visibility: hidden;
    opacity: 0;
    scale: 0.7;
}

.placed .bubble.on-hover.is-shown {
    visibility: visible;
    opacity: 1;
    scale: 1;
}

/* ---- While a bubble is active ---- */

.has-active .bubble {
    opacity: var(--dim);
}

.has-active .bubble.is-active,
.has-active .bubble.is-neighbour,
.has-active .bubble.is-ringed {
    opacity: 1;
}

.has-active .bubble.is-faint {
    opacity: 0.7;
}

.bubble.is-active {
    z-index: 2;
    border-color: var(--accent);
    scale: 1.06;
}

.placed .bubble.on-hover.is-shown.is-active {
    scale: 1.06;
}

.bubble.is-neighbour {
    border-color: var(--hl);
    box-shadow: 0 0 0 3px var(--hl), var(--shadow);
}

.bubble.is-faint {
    box-shadow: 0 0 0 2px var(--hl);
}

.bubble.is-ringed {
    box-shadow: 0 0 0 3px var(--hl), var(--shadow);
}

.via-data { --hl: var(--edge-data); }
.via-api { --hl: var(--edge-api); }
.via-backup { --hl: var(--edge-backup); }
.via-link { --hl: var(--edge-link); }
.via-auth { --hl: var(--ring-auth); }
.via-stats { --hl: var(--ring-stats); }
.via-docs { --hl: var(--ring-docs); }

/* ---- Lines: under the bubbles, hidden until their bubble is active ---- */

.lines {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
}

.lines .edge {
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.lines .edge.is-shown {
    opacity: 1;
}

.k-data { stroke: var(--edge-data); }
.k-api { stroke: var(--edge-api); }
.k-backup { stroke: var(--edge-backup); stroke-dasharray: 1 6; stroke-width: 2.5; }
.k-link { stroke: var(--edge-link); stroke-width: 1.5; stroke-dasharray: 6 4; }

.lines marker path {
    stroke: none;
}

#arrow-data path { fill: var(--edge-data); }
#arrow-api path { fill: var(--edge-api); }
#arrow-backup path { fill: var(--edge-backup); }

/* ---- What moves along the lines (js/flows.js) ---- */

/* The dotted backup line flows toward Cloud, the dashed link line toward
   the outside site (a dash pattern's period per cycle). */
.lines .k-backup.is-shown { animation: flow-backup 0.7s linear infinite; }
.lines .k-link.is-shown { animation: flow-link 1.6s linear infinite; }

@keyframes flow-backup { to { stroke-dashoffset: -7; } }
@keyframes flow-link { to { stroke-dashoffset: -10; } }

/* Travellers: only next to a shown line. */
.lines .flow {
    display: none;
    fill: var(--surface);
    stroke-width: 1.4;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: none;
}

.lines .edge.is-shown + .flow {
    display: inline;
}

.lines .flow .ink { fill: none; }
.lines .flow.k-data .dot { fill: var(--edge-data); stroke: none; }
.lines .flow.k-api .answer { fill: var(--edge-api); stroke: none; }

/* Badges for the "every app" rings, on the rim of each ringed app, in a
   wave outward from the active bubble (--wave, set by js/interact.js). */
.bubble svg.mark {
    position: absolute;
    top: calc(14.6% - 13px);
    right: calc(14.6% - 13px);
    display: none;
    width: 26px;
    height: 26px;
    padding: 4px;
    border-radius: 50%;
    background: var(--surface);
    box-shadow: 0 0 0 2px var(--ring);
    color: var(--ring);
}

.ring-auth { --ring: var(--ring-auth); }
.ring-stats { --ring: var(--ring-stats); }
.ring-docs { --ring: var(--ring-docs); }

.bubble.is-ringed.ring-auth .mark-auth,
.bubble.is-ringed.ring-stats .mark-stats,
.bubble.is-ringed.ring-docs .mark-docs {
    display: block;
    animation: mark-in 0.3s ease-out var(--wave, 0ms) both;
}

@keyframes mark-in {
    from { scale: 0; }
    70% { scale: 1.15; }
    to { scale: 1; }
}

/* Passwords: the padlock clicks shut. */
.mark-auth .shackle {
    animation: lock 0.35s cubic-bezier(0.5, 0, 0.75, 0) calc(var(--wave, 0ms) + 0.3s) both;
}

@keyframes lock {
    from { translate: 0 -3.5px; }
    to { translate: 0 0; }
}

/* Statistics: the bars fill up. */
.mark-stats .bar {
    transform-box: fill-box;
    transform-origin: bottom;
    animation: bar 0.4s ease-out both;
}

.mark-stats .bar:nth-of-type(1) { animation-delay: calc(var(--wave, 0ms) + 0.25s); }
.mark-stats .bar:nth-of-type(2) { animation-delay: calc(var(--wave, 0ms) + 0.35s); }
.mark-stats .bar:nth-of-type(3) { animation-delay: calc(var(--wave, 0ms) + 0.45s); }

@keyframes bar {
    from { scale: 1 0; }
    to { scale: 1 1; }
}

/* Documentation: the page is written, line by line. */
.mark-docs .write {
    stroke-dasharray: 1;
    animation: write 0.25s linear both;
}

.mark-docs .write:nth-of-type(2) { animation-delay: calc(var(--wave, 0ms) + 0.25s); }
.mark-docs .write:nth-of-type(3) { animation-delay: calc(var(--wave, 0ms) + 0.5s); }
.mark-docs .write:nth-of-type(4) { animation-delay: calc(var(--wave, 0ms) + 0.75s); }

@keyframes write {
    from { stroke-dashoffset: 1; }
    to { stroke-dashoffset: 0; }
}

/* ---- The caption next to the active bubble ---- */

.caption {
    position: absolute;
    z-index: 4;
    width: 290px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--shadow);
    font-size: 14px;
    line-height: 1.4;
}

.caption[hidden] {
    display: none;
}

/* Bubbles under the caption stay reachable, unless it has links to click. */
.caption:not(.has-links) {
    pointer-events: none;
}

.caption h2 {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin: 0;
    font-size: 1rem;
}

.caption .tag {
    padding: 1px 7px;
    border: 1px dashed var(--border-strong);
    border-radius: 999px;
    color: var(--text-soft);
    font-size: 11px;
    font-weight: 500;
}

.caption .blurb,
.caption .host {
    margin: 4px 0 0;
    color: var(--text-soft);
}

.caption .host {
    font-size: 12px;
}

.caption ul {
    margin: 10px 0 0;
    padding: 0;
    list-style: none;
}

.caption li {
    position: relative;
    margin-top: 4px;
    padding-left: 16px;
}

.caption li::before {
    content: "";
    position: absolute;
    top: 0.55em;
    left: 2px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--hl, var(--border-strong));
}

.caption .chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.caption .chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 9px 2px 7px;
    border: 1px solid var(--hl);
    border-radius: 999px;
    color: var(--text-soft);
    font-size: 12px;
}

.caption .chip svg,
.caption .chip img.favicon {
    width: 13px;
    height: 13px;
}

.caption a {
    color: var(--text);
    font-weight: 600;
}

/* ---- Phones ---- */

@media (max-width: 640px) {
    .intro {
        gap: 10px;
        max-width: calc(100% - 66px);
        padding: 16px 0 0 16px;
    }

    .photo img {
        width: 76px;
        height: 76px;
    }

    .welcome {
        padding: 10px 18px 10px 16px;
        border-radius: 28px;
    }

    .welcome h1 {
        font-size: 1.1rem;
    }

    .welcome p {
        font-size: 0.85rem;
    }

    .welcome .hint {
        font-size: 0.8rem;
    }

    .theme-toggle {
        top: 16px;
        right: 16px;
    }

    /* Under the light/dark button, not beside it, where it would cover the
       welcome bubble. */
    .theme-menu-button {
        top: 62px;
        right: 16px;
    }

    .theme-menu {
        inset: 108px 16px auto auto;
        max-height: calc(100dvh - 124px);
    }

    .reset-layout {
        top: 108px;
        right: 16px;
    }

    .caption {
        position: fixed;
        top: auto !important;
        right: 12px;
        bottom: 12px;
        left: 12px !important;
        width: auto;
        max-height: 45vh;
        overflow-y: auto;
    }

    .caption.at-top {
        top: 12px !important;
        bottom: auto;
    }
}

/* ---- ?debug ---- */

.debug .bubble.on-hover {
    visibility: visible !important;
    opacity: 0.75 !important;
    scale: 1 !important;
    border-style: dashed;
}

.debug .lines .edge {
    opacity: 0.55;
}

.debug .lines .obstacle {
    fill: none;
    stroke: var(--danger);
    stroke-dasharray: 4 4;
}

.debug-panel {
    position: fixed;
    bottom: 12px;
    left: 12px;
    z-index: 10;
    margin: 0;
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: var(--surface);
    font: 12px/1.4 ui-monospace, monospace;
    white-space: pre;
}

@media (prefers-reduced-motion: reduce) {
    .bubble,
    .lines .edge {
        transition: none;
    }

    /* The badges just appear, finished; nothing travels along the lines. */
    .lines .edge.is-shown,
    .bubble svg.mark,
    .bubble svg.mark * {
        animation: none !important;
    }

    .lines .edge.is-shown + .flow {
        display: none;
    }
}
