/* ============================================================
   Nevai Math — main stylesheet
   Themes: light / dark · silent motion · mobile responsive
   ============================================================ */

*, *::before, *::after {
    box-sizing: border-box;
}

/* ------------------------------------------------------------
   Theme variables
   ------------------------------------------------------------ */

:root {
    /* Accent colours (shared across themes). */
    --accent: hsl(212, 100%, 56%);
    --accent-strong: hsl(212, 100%, 48%);
    --accent-contrast: hsl(0, 0%, 100%);
    --accent-soft: hsla(212, 100%, 56%, 0.16);
    --highlight: hsl(32, 95%, 55%);
    --highlight-soft: hsla(32, 95%, 55%, 0.2);

    /* Dark theme (default). */
    --canvas: hsl(224, 16%, 9%);
    --panel: hsla(225, 15%, 13%, 0.88);
    --panel-solid: hsl(225, 15%, 13%);
    --panel-border: hsla(228, 40%, 100%, 0.09);
    --text: hsla(220, 30%, 100%, 0.85);
    --text-dim: hsla(220, 20%, 100%, 0.55);
    --text-faint: hsla(220, 20%, 100%, 0.35);
    --hover: hsla(228, 60%, 100%, 0.08);
    --active: hsla(228, 60%, 100%, 0.16);
    --input-bg: hsla(228, 40%, 100%, 0.06);
    --input-border: hsla(228, 40%, 100%, 0.14);
    --grid-line: hsla(220, 30%, 85%, 0.13);
    --diagram-fg: hsl(220, 15%, 92%);
    --shadow: 0 10px 36px hsla(230, 45%, 2%, 0.55);
    --shadow-small: 0 2px 10px hsla(230, 45%, 2%, 0.4);
    --scroll-thumb: hsla(228, 30%, 100%, 0.18);

    /* Cell states. */
    --cell-hover: hsla(228, 60%, 100%, 0.09);
    --cell-selected: hsla(212, 100%, 62%, 0.22);
    --cell-source: hsla(145, 70%, 45%, 0.22);
    --cell-target: hsla(14, 90%, 55%, 0.22);

    /* Semantic colours. */
    --error: hsl(0, 62%, 52%);
    --warning: hsl(45, 100%, 58%);
    --success: hsl(145, 60%, 45%);

    /* Layout metrics. */
    --radius: 12px;
    --radius-small: 8px;
    --toolbar-height: 60px;
    --panel-width: 288px;
    --blur: blur(14px) saturate(1.35);

    /* Motion: silent by default. */
    --speed: 0s;
    --speed-fast: 0s;

    /* Icons are white; keep them white on dark. */
    --icon-filter: none;
}

html[data-theme="light"] {
    --canvas: hsl(0, 0%, 100%);
    --panel: hsla(0, 0%, 100%, 0.9);
    --panel-solid: hsl(0, 0%, 100%);
    --panel-border: hsla(224, 20%, 20%, 0.12);
    --text: hsla(224, 25%, 12%, 0.88);
    --text-dim: hsla(224, 15%, 20%, 0.62);
    --text-faint: hsla(224, 15%, 20%, 0.4);
    --hover: hsla(224, 30%, 20%, 0.07);
    --active: hsla(224, 30%, 20%, 0.14);
    --input-bg: hsla(224, 25%, 20%, 0.05);
    --input-border: hsla(224, 25%, 20%, 0.18);
    --grid-line: hsla(224, 20%, 25%, 0.18);
    --diagram-fg: hsl(224, 25%, 12%);
    --shadow: 0 10px 36px hsla(228, 40%, 30%, 0.16);
    --shadow-small: 0 2px 10px hsla(228, 40%, 30%, 0.1);
    --scroll-thumb: hsla(224, 20%, 20%, 0.22);

    --cell-hover: hsla(224, 30%, 20%, 0.08);
    --cell-selected: hsla(212, 100%, 50%, 0.16);
    --cell-source: hsla(145, 70%, 40%, 0.16);
    --cell-target: hsla(14, 90%, 50%, 0.16);

    /* Icons are white; darken them on light backgrounds. */
    --icon-filter: invert(1) brightness(0.25);
}

/* Optional smooth motion (opt-in via the account panel). */
html[data-motion="smooth"] {
    --speed: 0.12s;
    --speed-fast: 0.08s;
}

/* Diagram foreground: default (black) labels and arrows follow the theme. */
.label, .focus-point {
    color: var(--diagram-fg);
}
[stroke="var(--diagram-fg)"] { stroke: var(--diagram-fg); }
[fill="var(--diagram-fg)"] { fill: var(--diagram-fg); }

/* ------------------------------------------------------------
   Root styles
   ------------------------------------------------------------ */

body {
    position: absolute;
    width: 100%; height: 100%;
    margin: 0;
    overflow: hidden;

    background: var(--canvas);

    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;

    /* Safari on iOS does not currently respect `none`: double-tap-to-zoom is not disabled. We are
    forced to prevent this in JavaScript instead. */
    touch-action: none;

    color: var(--text);
}

body.embedded {
    background: transparent;
}

body:not(.modal) {
    user-select: none;
}

noscript {
    display: inline-block;
    position: fixed;
    left: 50%; top: 50%;
    padding: 6pt 8pt;
    transform: translate(-50%, -50%);

    background: var(--panel-solid);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-small);

    text-align: center;
    color: var(--text);
}

/* We occasionally want to disable transitions on a particular element. */
.no-transition {
    transition: none !important;
}

/* Accessible focus indicators for keyboard users. */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Respect users who prefer reduced motion. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0s !important;
        animation-duration: 0s !important;
    }
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--scroll-thumb);
    border-radius: 8px;
}
* {
    scrollbar-width: thin;
    scrollbar-color: var(--scroll-thumb) transparent;
}

/* ------------------------------------------------------------
   Special elements
   ------------------------------------------------------------ */

.error-banner {
    position: fixed;
    width: 100%;
    left: 0; top: 0;
    z-index: 200;
    padding: 8px 0;

    background: var(--error);
    color: var(--accent-contrast);

    text-align: center;

    user-select: none;

    transition: transform var(--speed-fast);
}

.error-banner.hidden {
    transform: translateY(-100%);
}

.close {
    width: 28px; height: 28px;
    margin-left: 20px;

    background: transparent;
    border: none;
    border-radius: 100%;
    outline: none;

    text-align: center;
    color: inherit;
    font-size: 20px;
}

.close:hover {
    background: var(--hover);
}

.close:active {
    background: var(--active);
}

.close::before {
    content: "×";
}

a > .logo {
    position: fixed;
    left: 16px; bottom: 12px;
    width: 100px;
    z-index: 90;

    opacity: 0.85;
    filter: drop-shadow(0 1px 4px hsla(0, 0%, 0%, 0.2));
}

a > .logo:hover {
    opacity: 1;
}

.tooltip {
    display: block;
    position: absolute;
    left: 50%;
    padding: 8px 12px;
    line-height: 18pt;
    transform: translateX(-50%);
    z-index: 80;

    background: var(--accent);
    border-radius: 6px;
    box-shadow: var(--shadow-small);

    text-align: center;
    color: var(--accent-contrast);
}

.ui > .tooltip {
    /* Display just below the toolbar. */
    top: calc(16px + var(--toolbar-height) + 8px);
}

kbd {
    white-space: pre;
}

.tooltip kbd, .pane kbd, .port kbd {
    padding: 1px 6px;

    border-radius: 4px;
}

.tooltip kbd {
    background: var(--accent-contrast);
    border: hsla(0, 0%, 0%, 0.35) 1px solid;
    color: hsl(0, 0%, 12%);
}

.tooltip kbd + kbd, .pane kbd + kbd {
    margin-left: 4px;
}

/* Loading screen: silent — appears and disappears without animation. */
.loading-screen {
    position: fixed;
    left: 0; right: 0;
    top: 0; bottom: 0;
    z-index: 400;

    background: var(--canvas);
}

.loading-screen.hidden {
    display: none;
}

.loading-screen .logo {
    position: fixed;
    left: 50%; top: 50%;
    width: min(288px, 60vw);
    transform: translate(-50%, -50%);
}

.loading-screen span {
    display: inline-block;
    position: fixed;
    left: 50%; top: 50%;
    transform: translate(-50%, -50%);
    margin-left: 20px; margin-top: 32px;

    color: var(--accent);
    white-space: nowrap;
}

.embedded .loading-screen {
    background: white;
}

html[data-theme="dark"] .embedded .loading-screen {
    background: var(--canvas);
}

.embedded .loading-screen .logo {
    max-width: 60%;
}

.embedded .loading-screen span {
    /* Hide the "Loading diagram..." text in an `<iframe>` */
    display: none;
}

/* ------------------------------------------------------------
   The canvas of cells
   ------------------------------------------------------------ */

.container {
    position: fixed;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
}

.canvas {
    position: absolute;
    left: 50%;
    top: 50%;
    transform-origin: top left;
}

.ui.pan .container {
    cursor: grab;
}

.ui.pan .container:active {
    cursor: grabbing;
}

/* ------------------------------------------------------------
   Grid interaction
   ------------------------------------------------------------ */

.grid {
    position: fixed;
    top: 0; left: 0;
    pointer-events: none;
    z-index: -100;
}

.grid.hidden {
    display: none;
}

.focus-point {
    display: block;
    position: absolute;
    margin-left: 1px; margin-top: 1px;
    width: 126px; height: 126px;

    background: hsla(0, 0%, 0%, 0);

    text-align: center;
    font: 16px Arial, sans-serif;
}

.focus-point.revealed {
    background: var(--cell-hover);
}

.focus-point.focused {
    border: var(--accent) 3px solid;
    border-radius: var(--radius);
}

.focus-point.smooth {
    transition: left var(--speed), top var(--speed),
        width var(--speed), height var(--speed), padding-top var(--speed);
}

.focus-point::before {
    content: "Add vertex";
    visibility: hidden;
    position: relative;
    top: -8px;

    color: var(--text-faint);
}

.focus-point.active::before {
    content: "Add edge";
}

.focus-point.revealed::before {
    visibility: visible;
}

.ui:not(.show-hints) .focus-point .tooltip, .focus-point:not(.focused) .tooltip, .tooltip:empty {
    display: none;
}

.focus-point .tooltip {
    bottom: 100%;
    margin-bottom: 24px;

    white-space: nowrap;
}

.focus-point .tooltip::before {
    content: "";
    position: absolute;
    top: 100%; left: calc(50% - 14px);
    /* Make sure there's not a subpixel gap between this and the tooltip. */
    margin-top: -1px;
    width: 0; height: 0;

    border: 14px solid transparent;
    border-top-color: var(--accent);
    border-bottom: none;
}

.inline-error {
    position: absolute;
    padding: 4px 8px;
    transform: translate(-50%, -50%);
    z-index: 81;

    white-space: nowrap;

    background: var(--error);
    color: var(--accent-contrast);

    border-radius: 6px;
    box-shadow: var(--shadow-small);
}

/* ------------------------------------------------------------
   Vertices
   ------------------------------------------------------------ */

.vertex {
    position: absolute;
}

.ui.default .vertex {
    cursor: move;
}

.vertex .content {
    position: absolute;
    transform: translate(-50%, -50%);
    z-index: 2;

    border-radius: 16px;

    text-align: center;
}

.grid:not(.hidden) + .container .vertex.empty:not(.selected) .content:not(:hover) {
    border: var(--cell-hover) 2px solid;
    border-radius: 16px;
}

.ui.default .vertex .content {
    cursor: default;
}

/* This is so explicit because of the CSS specificity rules. */
.ui.default .vertex:not(.selected):not(.source):not(.target) .content:hover,
.ui.command .vertex:not(.selected):not(.source):not(.target) .content:hover {
    background: var(--cell-hover);
}

.vertex.source .content {
    background: var(--cell-source);
}

.vertex.target .content {
    background: var(--cell-target);
}

.vertex.selected .content {
    background: var(--cell-selected);
}

.label {
    display: block;
    position: absolute;
    left: 50%; top: 50%;
    transform: translate(-50%, -50%);

    text-align: center;
    font-family: inherit;
    font-size: 26px;
    white-space: nowrap;

    pointer-events: none;
    user-select: none;
}

/* The overlay edge drawn while connecting cells. */
.overlay, .overlay .arrow-background  {
    pointer-events: none !important;
}

/* ------------------------------------------------------------
   The side panel
   ------------------------------------------------------------ */

.panel {
    position: fixed;
    z-index: 91;
    overflow-y: auto;

    font: 14px/1.45 Arial, sans-serif;
    color: var(--text-dim);
}

.side.panel {
    width: var(--panel-width);
    top: 16px;
    bottom: 16px;
    right: 16px;

    transition: transform var(--speed);
}

.side.panel.hidden {
    /* We use `translateX` instead of `right` to avoid continually performing layout. */
    transform: translateX(calc(var(--panel-width) + 24px));
}

.ui.connect .panel {
    pointer-events: none;
}

.panel label, .panel button {
    user-select: none;
}

.global {
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    height: 46px;
    padding: 8px 12px;
    /* Display above the import/export pane. */
    z-index: 101;

    background: var(--panel);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid var(--panel-border);
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;

    text-align: center;
    white-space: nowrap;
}

.panel > .wrapper {
    position: absolute;
    left: 0;
    width: 100%;
    padding: 10px 16px;

    background: var(--panel);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.side label {
    display: block;
    margin-bottom: 8px;
}

.side:not(.nonloop) .nonloop {
    height: 0;
    margin: 0;
    overflow: hidden;
}

.side.no-transition .nonloop .slider .thumb, .side.no-transition .loop .slider .thumb {
    transition: none;
}

.side:not(.loop) .loop {
    display: none;
}

label.inline {
    display: inline-block;
}

.label-input-container {
    position: fixed;
    left: 50%; height: 36px;
    /* Position 8px above the global panel. */
    bottom: calc(8px + 46px);
    width: 40%;
    min-width: 560px;
    transform: translateX(-50%);

    background: var(--panel);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    box-shadow: var(--shadow);

    color: var(--text);

    transition: transform var(--speed);
}

.label-input-container.hidden {
    transform: translate(-50%, calc(16pt + 4px * 2 + 16px + 8px + 46px + 4px));
}

.ui.connect .label-input-container {
    pointer-events: none;
}

.ui.command .label-input-container {
    background: var(--highlight);
    border-color: transparent;

    color: hsl(0, 0%, 10%);
}

.label-input {
    width: 100%; height: 34px;
    padding: 4px 6px;
    padding-right: calc(24px + 6px);

    background: transparent;
    border: none;
    border-radius: 10px;
    outline: none;

    font-family: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
    font-size: 16pt;
    color: inherit;
    text-align: center;

    transition: width var(--speed);
}

.label-input:hover:not(:disabled):not(:focus) {
    background: var(--hover);
}

.label-input:focus {
    background: var(--accent);

    color: var(--accent-contrast);
}

.input-mode {
    display: inline-block;
    vertical-align: bottom;
    width: 0px; height: 34px;
    line-height: 34px;
    overflow: hidden;

    border-radius: 10px 0 0 10px;

    font-size: 12pt;
    text-align: center;

    transition: width var(--speed);
}

.command .input-mode {
    width: 80px;
}

.command .label-input:focus {
    width: calc(100% - 80px);

    background: var(--highlight);
    color: hsl(0, 0%, 10%);
}

.label-input::selection {
    background-color: var(--accent-contrast);
}

.label-input-container .colour-indicator {
    position: absolute;
    top: 50%;
    right: 4px;
    width: 24px;
    transform: translateY(-50%);
    border-radius: 4px;
}

.command .label-input-container .colour-indicator {
    display: none;
}

.panel input[type="text"],
.port .options input[type="number"] {
    padding: 3px 6px;

    background: var(--input-bg);
    border: var(--input-border) solid 1px;
    border-radius: 6px;
    outline: none;

    font-size: inherit;
    font-family: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
    color: var(--text);
}

.panel input[type="text"]::placeholder,
.port .options input[type="number"]::placeholder {
    color: var(--text-faint);
}

.panel input[type="text"]:hover:not(:disabled):not(:focus),
.port .options input[type="number"]:hover:not(:disabled):not(:focus) {
    background: var(--hover);
}

.panel input[type="text"]:focus,
.port .options input[type="number"]:focus {
    background: var(--accent);
    border-color: var(--accent);

    color: var(--accent-contrast);
}

.panel input[type="text"]:focus::placeholder,
.port .options input[type="number"]:focus::placeholder {
    color: hsla(0, 0%, 100%, 0.55);
}

.panel .options {
    position: relative;
    margin: 8px 0;

    text-align: center;
}

.panel input[type="radio"] {
    -webkit-appearance: none;
    appearance: none;
    display: inline-block;
    width: 48px; height: 48px;

    background-color: var(--input-bg);
    background-repeat: no-repeat;
    background-position: center;
    background-size: 0%, auto;
    border: var(--input-border) solid 1px;
    border-radius: 6px;
    outline: none;
}

.panel .large {
    white-space: nowrap;
}

.panel .large input[type="radio"] {
    width: 72px;
    height: 64px;
}

.panel .options.focused input[type="radio"]:not(:checked) {
    background-size: auto, 0%;
    background-color: var(--accent-contrast);
    border-color: var(--accent);
}

.panel input.hidden, .panel div.hidden, .panel label.hidden {
    display: none;
}

.panel .centred {
    text-align: center;
}

.panel .vertical {
    display: inline-block;
    width: calc(100% - (20% + 4px) * 2);
    vertical-align: top;
}

.panel .vertical + .vertical:not(.centre) {
    margin-left: 4px;
}

.panel .short {
    width: 20%;
}

.panel .centre {
    position: relative;
    left: 50%;
    transform: translateX(-50%);
}

.panel .vertical input[type="radio"] {
    position: relative;
    display: block;
    width: 100%; height: 32px;
    left: 50%;
    transform: translateX(-50%);
    margin: 0; margin-top: -1px;

    border-radius: 0;
}

.panel .vertical input[type="radio"]:first-of-type {
    margin-top: 0;

    border-radius: 6px 6px 0 0;
}

.panel .vertical input[type="radio"]:not(.short):last-of-type {
    border-radius: 0 0 6px 6px;
}

.panel .vertical input[type="radio"].short {
    display: inline-block;
    width: 50%;
    left: 0;
    transform: none;
    margin-bottom: -3px;
}

.panel .vertical input[type="radio"].short.start-of-line + input[type="radio"].short {
    border-left-width: 0;
}

.panel .vertical input[type="radio"].short.start-of-line:nth-last-of-type(2) {
    border-bottom-left-radius: 6px;
}

.panel .vertical input[type="radio"].short:last-of-type {
    border-bottom-right-radius: 6px;
}

.panel input[type="radio"]:hover:not(:disabled):not(:active):not(:checked) {
    background-color: var(--hover);
}

.panel input[type="radio"]:active:not(:disabled) {
    background-color: var(--active);
}

.panel input[type="radio"]:checked:not(:disabled) {
    background-color: var(--accent);
    background-size: auto, 0%;
    border-color: var(--accent);
}

.panel label {
    position: relative;
}

/* A non-native range input, supporting multiple thumbs. */
div.slider {
    display: inline-block;
    vertical-align: middle;
    position: absolute;

    touch-action: none;
}

.linked-sliders {
    display: inline-block;
}

.panel div.slider {
    width: 55%;
    left: 56px;
}

.options div.slider {
    position: relative;
    width: 80px;
    margin: -14px 8px 0 4px;
}

.slider-values {
    display: inline-block;
    position: absolute;
    right: 0;

    pointer-events: none;
}

.options .slider-values {
    position: relative;
    width: 54px;
}

.slider-values .slider-value {
    display: inline-block;
    min-width: 24px;

    text-align: right;
}

.slider .thumb {
    display: inline-block;
    position: absolute;
    width: 20px;
    height: 20px;
    margin-top: -3px;
    top: 0;
    transform: translateX(-50%);
    z-index: 1;

    background: var(--panel-solid);
    border: var(--input-border) solid 1px;
    border-radius: 20px;
    box-shadow: var(--shadow-small);

    transition: left var(--speed);

    pointer-events: none;
}

/* Disable transitions when the user is dragging the thumb. */
.thumb.active, .linked-sliders.linked.active .thumb {
    transition: none;
}

.slider.focused .thumb {
    background: var(--accent-contrast);
    border-color: var(--accent);
}

.slider .thumb.focused, .slider.symmetric.focused .thumb {
    background: var(--accent);
}

.slider:not(.disabled):not(.focused) .thumb.hover,
.slider.symmetric:not(.disabled):not(.focused):hover .thumb,
.linked-sliders.linked:hover .thumb
{
    background: var(--hover);
    background-color: var(--hover);
}

.slider:not(.disabled):not(.focused) .thumb.active,
.slider.symmetric:not(.disabled):not(.focused).active .thumb,
.linked-sliders.linked.active .thumb {
    background: var(--active);
    background-color: var(--active);
}

.slider .track {
    display: inline-block;
    vertical-align: middle;
    width: 100%;
    height: 14px;
    position: absolute;

    background: var(--input-bg);
    border: var(--input-border) solid 1px;
    border-radius: 14px;
}

.slider.focused .track {
    background: var(--accent-contrast);
    border-color: var(--accent);
}

.panel button, .pane button, .port button, select {
    position: relative;
    display: block;
    width: 100%; height: 30px;
    margin: 8px 0;

    background: var(--input-bg);
    border: var(--input-border) solid 1px;
    border-radius: 6px;
    outline: none;

    font: inherit;
    color: var(--text);
    text-align: center;
    cursor: pointer;
}

.panel button:disabled, .pane button:disabled, .port button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

select {
    display: inline-block;
    width: auto;
    margin: 0;

    text-align: left;
    cursor: pointer;
}

select option {
    background: var(--panel-solid);
    color: var(--text);
}

.global button {
    display: inline-block;
    width: 72px;
    margin: 0 2px;
}

.global button.short {
    width: 56px;
}

.global button + label, select + label {
    margin-left: 12px;
}

.panel button:hover:not(:disabled):not(:active),
.pane button:hover:not(:disabled):not(:active),
.port button:hover:not(:disabled):not(:active) {
    background: var(--hover);
}

.panel button:not(:disabled):not(:active):active,
.pane button:not(:disabled):not(:active):active,
.port button:not(:disabled):not(:active):active {
    background: var(--active);
}

kbd.hint {
    position: absolute;
    min-width: 20px;
    padding: 2px 4px;

    background: var(--highlight);
    border-radius: 4px;

    color: hsl(0, 0%, 10%);
    text-align: center;

    pointer-events: none;
}

.colour-indicator {
    display: inline-block;
    vertical-align: middle;
    position: relative;
    width: 48px;
    height: 24px;

    border: var(--input-border) solid 1px;
    border-radius: 6px;

    cursor: pointer;
}

/* Highlight the hints when their codes are (partially) typed. */
kbd.hint.focused, kbd.hint .focused {
    color: var(--accent-contrast);
}

.ui:not(.command).show-queue kbd.hint.queue {
    background: var(--accent-contrast);
    border: var(--accent) 1px solid;

    color: var(--accent);
}

.ui:not(.command).show-queue .cell.selected kbd.hint.queue {
    background: var(--accent);

    color: var(--accent-contrast);
}

.ui:not(.command):not(.show-queue):not(.show-hints) kbd.hint.queue {
    display: none;
}

.ui:not(.show-hints) kbd.hint:not(.queue) {
    display: none;
}

kbd.hint.button, kbd.hint.input {
    left: 0; top: 0;
    transform: translate(-25%, -25%);
}

.label-input-container kbd.hint.colour {
    right: 0; top: 0;
    transform: translate(25%, -25%);
}

/* Hide the keyboard shortcut for changing colour when the user is typing. */
.label-input-container .label-input:focus ~ kbd.hint.colour {
    display: none;
}

kbd.hint.colour {
    transform: translate(-25%, -25%);
}

kbd.hint.slider {
    left: calc(56px + 55%); top: 0;
    transform: translate(-25%, -75%);
}

.ui.command .cell kbd.hint {
    display: block;
}

.vertex kbd.hint {
    left: 50%; top: 0;
    transform: translateX(-50%);
}

.arrow kbd {
    z-index: 10;
    transform: translate(-50%, -50%);
}

/* `.kbd-requires-focus` and `.triggers-focus` are mutually exclusive classes. */
.kbd-requires-focus:not(.focused) kbd.hint:not(.triggers-focus) {
    display: none;
}

.kbd-requires-focus:not(.next-to-focus) kbd.hint.triggers-focus {
    display: none;
}

/* We always display shortcuts for lists when they're focused. */
.kbd-requires-focus.focused kbd.hint {
    display: block;
}

/* Display a semicolon symbol for the usual keyboard shortcut symbol. */
.ui:not(.command) .cell kbd.hint::before {
    content: ";";
}

.ui.command kbd.hint:empty::after,
.cell kbd.hint:empty:not(.queue)::after,
.ui:not(.show-queue) kbd.hint:empty::after {
    content: attr(data-code);
}

/* When cells are queued, we can press Tab to select them. */
.ui:not(.command).show-queue .cell kbd.queue.hint::before {
    content: "⇥";
}

.indicator-container {
    display: inline-block;
    margin-left: 12px;
}

.panel .success-indicator {
    display: inline-block;
    vertical-align: middle;
    margin-left: 8px;
    width: 18px; height: 18px;

    background: var(--text-faint);
    border-radius: 100%;

    color: var(--panel-solid);
    text-align: center;
    line-height: 18px;

    transform: scale(0);

    transition: transform var(--speed);
}

.panel .success-indicator.unknown,
.panel .success-indicator.success,
.panel .success-indicator.failure {
    transform: scale(1);
}

.panel .success-indicator.success {
    background: var(--success);
}

.panel .success-indicator.success::before {
    content: "✓";
}

.panel .success-indicator.failure {
    background: var(--error);
}

.panel .success-indicator.failure::before {
    content: "✕";
}

/* ------------------------------------------------------------
   The colour picker
   ------------------------------------------------------------ */

.colour-panel {
    position: fixed;
    width: calc(16px * 20);
    padding: 8px 16px;
    padding-top: calc(192px + 16px * 2);
    max-height: calc(100% - (8px + 46px + 32px) * 2 - 16px * 2);
    overflow-y: auto;

    background: var(--panel);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);

    font: 14px Arial, sans-serif;
    color: var(--text-dim);

    transition: opacity var(--speed);
}

.colour-panel.target-label {
    bottom: calc(8px + 46px + 32px + 8px);
    right: calc(50% - 20%);
}

/* The colour panel position when selecting a colour for an edge. */
.colour-panel.target-edge {
    top: 50%;
    right: calc(16px * 20);
    transform: translateY(-50%);
}

.colour-panel.hidden {
    opacity: 0;

    pointer-events: none;
}

.colour-wheel {
    position: absolute;
    left: 50%; top: 16px;
    transform: translateX(-50%);

    border-radius: 50%;
}

.colour-picker {
    position: absolute;
    width: 32px; height: 32px;
    transform: translate(-50%, -50%);

    background: var(--panel-solid);
    border: var(--panel-solid) 2px solid;
    border-radius: 50%;

    transition: background var(--speed), left var(--speed), top var(--speed);

    pointer-events: none;
}

.colour-panel.active .colour-picker, .colour-panel.active .thumb {
    transition: none;
}

.colour-panel > .wrapper {
    position: relative;
}

.colour-panel div.slider {
    width: 55%;
    left: 80px;
}

.colour-panel label {
    display: block;
    margin: 8px 0;
}

.palette {
    margin-top: -2px;
}

.palette label {
    margin: 4px 0;
}

.palette label .empty {
    margin-left: 4px;

    opacity: 0.6;
}

.palette .colour {
    display: inline-block;
    vertical-align: middle;
    width: 20px; height: 20px;
    margin: 2px 2px;

    border: var(--panel-border) solid 1px;
    border-radius: 4px;

    cursor: pointer;
}

.palette label .colour:first-of-type {
    margin-left: 4px;
}

/* ------------------------------------------------------------
   The toolbar
   ------------------------------------------------------------ */

.toolbar {
    position: fixed;
    height: var(--toolbar-height);
    left: 50%; top: 16px;
    transform: translateX(-50%);
    z-index: 90;
    max-width: calc(100vw - 24px);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;

    background: var(--panel);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);

    color: var(--text);
    white-space: nowrap;

    transition: opacity var(--speed);
}

.toolbar::-webkit-scrollbar {
    display: none;
}

.ui:not(.default):not(.modal) .toolbar {
    opacity: 0.2;

    pointer-events: none;
}

.toolbar .action {
    position: relative;
    vertical-align: middle;
    width: 56px; height: 100%;

    background: transparent;
    border: none;
    outline: none;

    font: inherit;
    text-align: center;
    font-size: 20px;
    color: inherit;
    white-space: nowrap;

    cursor: default;
    user-select: none;
}

.toolbar .action:first-of-type {
    border-radius: var(--radius) 0 0 var(--radius);
}

.toolbar .action:last-of-type {
    border-radius: 0 var(--radius) var(--radius) 0;
}

.toolbar .action:hover:not(:disabled) {
    background: var(--hover);
}

.toolbar .action:not(:disabled):not(.dropdown):active {
    background: var(--accent-soft);
}

.toolbar .action img {
    width: 26px;
    vertical-align: middle;
    pointer-events: none;
    filter: var(--icon-filter, none);
}

.toolbar .action:disabled {
    background: transparent;
    cursor: not-allowed;
}

.toolbar .action:disabled img {
    opacity: 0.4;
}

.toolbar .action:disabled .name, .toolbar .action:disabled .shortcut {
    color: var(--text-faint);
}

.toolbar .action.dropdown > .shortcut:empty::before {
    content: "▾";
}

.subtoolbar {
    display: none;
    position: fixed;
    transform: translateX(-50%);
    z-index: 95;
    white-space: nowrap;

    background: var(--panel);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.subtoolbar.open {
    display: flex;
    flex-direction: row;
    align-items: stretch;
}

.toolbar .action.open {
    background: var(--accent-soft);
}

.subtoolbar .action {
    position: relative;
    flex: 0 0 auto;
    width: 104px;
    height: 60px;
    padding: 0;
    border: none;
    border-radius: 0;
    outline: none;

    background: transparent;
    font: inherit;
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
}

.subtoolbar .action:hover {
    background: var(--hover);
}

.subtoolbar .action:active {
    background: var(--accent-soft);
}

.subtoolbar .action img {
    width: 24px;
    margin-top: 16px;
    vertical-align: middle;
    filter: var(--icon-filter, none);
    pointer-events: none;
}

.subtoolbar .action .name,
.subtoolbar .action .shortcut {
    position: absolute;
    left: 0;
    right: 0;
    transform: none;

    font-size: 9.5px;
    line-height: 9.5px;
    text-align: center;
    color: var(--text-dim);
}

.subtoolbar .action .name {
    top: 6px;
}

.subtoolbar .action .shortcut {
    bottom: 6px;
}

.toolbar .action .name, .toolbar .action .shortcut {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);

    font-size: 9.5px;
    line-height: 9.5px;
    color: var(--text-dim);
}

.toolbar .action .name {
    top: 6px;
}

.toolbar .action .shortcut {
    bottom: 6px;
}

/* ------------------------------------------------------------
   The welcome / keyboard shortcuts / about panes
   ------------------------------------------------------------ */

.pane {
    position: fixed;
    /* Display just below the toolbar. */
    left: 50%;
    top: calc(16px + var(--toolbar-height) + 8px);
    transform: translateX(-50%);
    width: min(50%, 720px);
    /* Display at most to just above the global panel. */
    max-height: calc(100% - (16px + var(--toolbar-height) + 8px + 16pt + 4px * 2 + 16px + 8px));
    padding: 8pt 20pt;
    overflow-y: auto;
    z-index: 90;

    background: var(--panel);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);

    color: var(--text);

    transition: opacity var(--speed), transform var(--speed);
}

.pane.hidden {
    pointer-events: none;
    display: none;
}

.pane h1 {
    margin: 0;

    border-bottom: var(--panel-border) 1px solid;
    padding-bottom: 6px;

    font-size: 18pt;
    font-weight: 600;
    text-align: center;
}

.pane h1 .right {
    margin-left: 16pt;
}

.pane h1 kbd {
    font-size: 12pt;
}

.pane kbd, .port kbd {
    display: inline-block;
    height: 16.5pt;
    vertical-align: middle;

    border: var(--input-border) 1px solid;
}

.pane kbd {
    background: var(--input-bg);
}

.port kbd {
    background: var(--accent-contrast);
    color: hsl(0, 0%, 12%);
}

.pane h2 {
    margin-bottom: 6pt;

    font-size: 14pt;
    font-weight: 600;
}

.pane table {
    width: 100%;

    border-spacing: 0;

    color: var(--text-dim);
    white-space: pre-line;
}

.pane table td {
    width: 50%;
    padding: 4pt 0;
}

.pane table tr:first-child td {
    padding-top: 0;
}

.pane table kbd {
    height: 14.5pt;

    font-size: 10pt;
    color: var(--text);
}

.pane a {
    color: var(--accent);
}

.pane ul {
    margin: 0;
    padding: 0 20pt;
}

.pane p, .pane li {
    color: var(--text-dim);
}

.pane li {
    margin: 4pt 0;
}

.pane button {
    width: 50%;
    margin-left: auto;
    margin-right: auto;
    margin-top: 12pt;
}

.pane button.primary {
    background: var(--accent);
    border-color: transparent;
    color: var(--accent-contrast);
}

.pane button.primary:hover:not(:disabled) {
    background: var(--accent-strong);
}

.pane footer {
    margin-top: 8pt;
    padding-top: 8pt;

    border-top: var(--panel-border) 1px solid;

    text-align: center;
}

/* ------------------------------------------------------------
   Modal elements (import / export)
   ------------------------------------------------------------ */

.port {
    position: fixed;
    width: 100%; height: 100%;
    left: 0; top: 0;
    z-index: 100;
    padding: 20px 24px;
    padding-bottom: calc(46px + 8px);
    overflow-y: auto;

    background: hsla(224, 20%, 6%, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

html[data-theme="light"] .port {
    background: hsla(224, 25%, 15%, 0.35);
}

.port a {
    color: var(--accent);
}

.port .tip, .port div.warning, .port div.error {
    display: inline-block;
    width: 100%;
    padding: 8pt;
    margin-bottom: 8pt;

    border-radius: var(--radius-small);

    cursor: default;
}

.port .tip {
    background: var(--panel-solid);
    border: 1px solid var(--panel-border);

    color: var(--text);
}

.port .tip > code {
    cursor: text;
}

.port .tip .update {
    padding: 0pt 4pt;
    padding-bottom: 1pt;
    margin-left: 8pt;

    background: var(--accent);
    border-radius: 4px;

    color: var(--accent-contrast);
    font-variant: small-caps;
    font-size: 10pt;
}

.port .tip .update time {
    font-size: 8pt;
}

.port div.error {
    color: var(--accent-contrast);
    background: var(--error);
}

.port div.warning {
    background: var(--warning);
    color: hsl(0, 0%, 12%);
}

.port .hidden {
    display: none !important;
}

.port div.error ul, .port div.warning ul {
    margin: 4pt 0;

    list-style-type: circle;
}

.port.import div.error ul li:hover,
.port.import div.error ul li.highlight,
.port.import div.warning ul li:hover,
.port.import div.warning ul li.highlight {
    list-style-type: disc;
}

.port div.warning a {
    color: inherit;
}

.port .options {
    margin-bottom: 8pt;
    padding: 6pt 4pt;
    line-height: 18pt;

    background: var(--panel-solid);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-small);

    color: var(--text);

    user-select: none;
}

.port .options label {
    position: relative;
    top: 1px;
    margin-right: 20pt;
}

.port .note {
    display: inline-block;
    width: 100%;
    padding: 8pt;
    margin-bottom: 8pt;

    background: var(--accent);
    border-radius: var(--radius-small);

    color: var(--accent-contrast);

    user-select: none;
}

.port .note.hidden {
    display: none;
}

.port .options label kbd.hint {
    transform: translate(-50%, -50%);
}

.port .options input[type="number"] {
    width: 64px;
    margin-right: -12pt;
}

.port .options select {
    margin-left: 8pt;
}

/* Disable the up/down buttons for `type="number"` inputs. */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

label input[type="checkbox"] {
    margin-top: -1px;
    margin-right: 6pt;
    width: 12pt;
    height: 12pt;
    vertical-align: middle;

    -webkit-appearance: none;
    appearance: none;
    background: var(--accent-contrast);
    border: var(--input-border) 1px solid;
    border-radius: 4px;
    outline: none;
    cursor: pointer;
}

label input[type="checkbox"]:hover {
    background: var(--hover);
    background-color: var(--hover);
}

label input[type="checkbox"]:checked {
    background: var(--accent);

    text-align: center;
}

label input[type="checkbox"]:checked::before {
    content: "✓";

    color: var(--accent-contrast);
}

.port .code, .port div[contenteditable] {
    font: 15px ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
    color: var(--text);

    white-space: pre-wrap;
    overflow-wrap: break-word;
    tab-size: 4;
    -moz-tab-size: 4;
}

.port div[contenteditable] {
    width: 100%;
    height: 252pt;
    resize: none;
    padding: 6pt 8pt;
    overflow-y: auto;

    background: var(--input-bg);

    border: 1px solid var(--input-border);
    border-radius: var(--radius-small);
    outline: none;
}

.port div[contenteditable]:focus {
    border-color: var(--accent);
}

/* We pad empty fragments so that we can see their highlight. */
.port .fragment:empty::before {
    content: " ";
}

.port .fragment.error {
    text-decoration: var(--error) wavy underline;
}
.port .fragment.error:hover, .port .fragment.error.highlight {
    background: var(--error);

    color: var(--accent-contrast);
}

.port .fragment.warning {
    text-decoration: var(--warning) wavy underline;
}
.port .fragment.warning:hover, .port .fragment.highlight.warning {
    background: var(--warning);

    color: hsl(0, 0%, 12%);
}

/* ------------------------------------------------------------
   Arrows
   ------------------------------------------------------------ */

.arrow > svg {
    position: absolute;
    left: 0;
    top: 0;
    overflow: visible;
    pointer-events: none;
}

.arrow.invalid, .arrow .invalid {
    display: none;
}

.arrow > svg:first-child {
    z-index: 1;
}

.arrow > svg:nth-child(2) {
    z-index: 4;
}

.arrow:not(.reconnecting) > svg:first-child > .arrow-background {
    pointer-events: stroke;
}

.arrow:not(.target):not(.selected) > svg:first-child:not(:hover) > .arrow-background,
.ui.connect .cell:not(.target):not(.selected) > svg:first-child:hover > .arrow-background,
.ui.pointer-move .cell:not(.selected) > svg:first-child:hover > .arrow-background {
    opacity: 0;
}

.arrow:not(.target):not(.selected) > svg:first-child:hover {
    opacity: 0.1 !important;
}

.arrow-endpoint {
    display: none;
}

.ui.default .arrow:hover .arrow-endpoint, .ui.default .arrow.selected .arrow-endpoint {
    display: block;
}

.arrow-endpoint {
    position: absolute;
    z-index: 3;

    background: var(--accent-contrast);
}

.arrow-endpoint:hover {
    border: var(--accent) 2px solid;
}

/* Arrow labels */

.arrow .katex, .arrow .katex-error {
    font-size: 1em;
}

.typst-error {
  color: var(--error);
}

/* ------------------------------------------------------------
   Embedded view
   ------------------------------------------------------------ */

.ui.embedded .panel,
.ui.embedded .toolbar,
.ui.embedded .grid,
.ui.embedded .focus-point,
.ui.embedded .arrow:not(.target):not(.selected) > svg:first-child:hover {
    display: none;
}

.ui.embedded a > .logo {
    top: auto; bottom: 12px;
    left: 12px;
    transform: scale(0.75);

    opacity: 0;

    transition: opacity var(--speed);
}

.ui.embedded:hover a > .logo {
    opacity: 0.2;
}

.ui.embedded a > .logo:hover {
    opacity: 0.4;
}

.ui.embedded #welcome-pane {
    display: none;
}

/* Some interface elements are only relevant to certain renderers. */
body:has(select[name="renderer"] > option[value="typst"]:checked) .katex-only,
body:has(select[name="renderer"] > option[value="katex"]:checked) .typst-only {
    display: none;
}

/* ------------------------------------------------------------
   Toasts (silent notifications)
   ------------------------------------------------------------ */

.toast-container {
    position: fixed;
    left: 50%;
    bottom: calc(46px + 52px);
    transform: translateX(-50%);
    z-index: 300;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.toast {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;

    background: var(--panel);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid var(--panel-border);
    border-radius: 999px;
    box-shadow: var(--shadow);

    color: var(--text);
    font-size: 13px;
    white-space: nowrap;
}

.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--error); }

/* ------------------------------------------------------------
   Zen mode: hide all interface chrome for a clean canvas.
   ------------------------------------------------------------ */

.ui.zen .toolbar,
.ui.zen .subtoolbar,
.ui.zen .global,
.ui.zen .side.panel,
.ui.zen .label-input-container,
.ui.zen .colour-panel,
.ui.zen .pane,
.ui.zen #matrix-math-login-btn,
.ui.zen a > .logo {
    display: none !important;
}

/* ------------------------------------------------------------
   Logo link
   ------------------------------------------------------------ */

#logo-link {
    display: inline-block;
    line-height: 0;
}

/* ------------------------------------------------------------
   Responsive / mobile
   ------------------------------------------------------------ */

@media (max-width: 900px) {
    a > .logo {
        left: 10px; bottom: 56px;
        width: 64px;
    }

    .toolbar {
        left: 8px; right: 8px;
        top: 8px;
        transform: none;
        max-width: none;
        height: 54px;
    }

    .toolbar .action {
        width: 48px;
        flex: 0 0 auto;
    }

    .toolbar .action .name {
        font-size: 8px;
    }

    .toolbar .action .shortcut {
        display: none;
    }

    .ui > .tooltip {
        top: calc(8px + 54px + 8px);
    }

    .pane {
        top: calc(8px + 54px + 8px);
        width: calc(100vw - 16px);
        max-height: calc(100% - 8px - 54px - 8px - 46px - 8px - 36px - 8px);
        padding: 8pt 12pt;
    }

    .pane h1 {
        font-size: 15pt;
    }

    .pane table td {
        display: block;
        width: 100%;
        padding: 2pt 0;
    }

    .pane table td + td {
        margin-bottom: 6pt;
    }

    /* Side panel: compact sheet pinned to the right edge. */
    .side.panel {
        top: auto;
        bottom: calc(46px + 44px + 12px);
        right: 8px;
        width: min(86vw, var(--panel-width));
        max-height: 62vh;
    }

    .side.panel.hidden {
        transform: translateX(calc(min(86vw, var(--panel-width)) + 16px));
    }

    .label-input-container {
        width: calc(100vw - 16px);
        min-width: 0;
        bottom: calc(46px + 44px + 8px);
        height: 40px;
    }

    .label-input {
        height: 38px;
        font-size: 14pt;
    }

    .global {
        height: 44px;
        padding: 6px 8px;
        width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        text-align: left;
        scrollbar-width: none;
    }

    .global::-webkit-scrollbar {
        display: none;
    }

    .global button {
        width: 64px;
        height: 30px;
    }

    .colour-panel {
        width: calc(100vw - 16px);
        right: 8px;
        padding-top: calc(160px + 12px);
    }

    .colour-panel.target-edge {
        right: 8px;
        top: auto;
        bottom: calc(46px + 44px + 60px);
        transform: none;
    }

    .colour-panel.target-label {
        right: 8px;
    }

    .port {
        padding: 12px 10px;
        padding-bottom: calc(44px + 8px);
    }

    .port div[contenteditable] {
        height: 200pt;
    }

    .port .options label {
        display: block;
        margin: 4pt 0;
    }

    #matrix-math-login-btn {
        bottom: auto;
        top: 70px;
        right: 8px;
        padding: 6px 10px;
        font-size: 12px;
    }

    .toast-container {
        bottom: calc(44px + 44px + 48px);
        width: calc(100vw - 16px);
    }

    .toast {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

@media (max-width: 480px) {
    .toolbar .action {
        width: 42px;
    }

    .toolbar .action img {
        width: 22px;
    }

    .toolbar .action .name {
        display: none;
    }

    a > .logo {
        width: 52px;
    }
}

/* Tall phones in landscape: keep the toolbar reachable. */
@media (max-height: 480px) {
    .toolbar {
        top: 6px;
        height: 46px;
    }

    .pane {
        top: 58px;
    }
}
