/*
 * Variables
 *
 * The colours, fonts & the reset come from the corporate design theme
 * (https://assets.confirm.ch/theme.css), whose tokens are mapped here.
 */

:root {
    --theme-font-size: 1rem;

    /* The opacity of the dotted grid (the welcome pages & the editor alike). */
    --grid-opacity: 0.5;
    --background: var(--theme-background);
    --surface: var(--theme-surface);
    --surface-raised: var(--theme-surface-raised);
    --border: var(--theme-border);
    --text: var(--theme-text);
    --text-muted: var(--theme-text-muted);
    --primary: var(--theme-primary);
    --primary-hover: var(--theme-primary-hover);
    --primary-contrast: var(--theme-primary-contrast);
    --radius: var(--theme-radius);
}

/* Layout */

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: var(--background);
    color: var(--text);
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    color: var(--primary-hover);
}

button {
    font: inherit;
    color: inherit;
    background: none;
    border: none;
    cursor: pointer;
}

input,
select {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
}

.main {
    flex: 1;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.muted {
    color: var(--text-muted);
}

.ui-icon {
    display: inline-block;
    width: 1em;
    height: 1em;
    vertical-align: -0.125em;
    fill: currentcolor;
}

/* Buttons */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    background: var(--primary);
    color: var(--primary-contrast);
    font-weight: 600;
}

.btn:hover {
    background: var(--primary-hover);
    color: var(--primary-contrast);
}

.link-button {
    color: var(--primary);
}

.link-button:hover {
    color: var(--primary-hover);
}

/* User */

.user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--surface-raised);
}

/* Forms */

.guest-form {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
}

/* MCP (the dialog to connect an AI agent) */

.modal.mcp {
    width: min(44rem, calc(100% - 2rem));
}

.mcp h2 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.mcp h3 {
    margin: 1.25rem 0 0.5rem;
    font-size: var(--theme-font-size);
}

.mcp-notes {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.4rem 1rem;
    margin: 0;
}

.mcp-notes dt {
    font-weight: 600;
}

.mcp-notes dd {
    margin: 0;
    color: var(--text-muted);
}

.mcp-examples {
    margin: 0;
    padding-left: 1.1rem;
}

.code {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-raised);
}

.code code {
    flex: 1;
    overflow-x: auto;
    padding: 0;
    border: none;
    background: none;
    font-family: var(--theme-font-mono);
    font-size: var(--theme-font-size-sm);
    white-space: nowrap;
}

.code-copy {
    display: flex;
    color: var(--text-muted);
}

.code-copy:hover,
.code-copy.is-copied {
    color: var(--theme-success);
}

.mcp-tools details {
    border-bottom: 1px solid var(--border);
}

.mcp-tools summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    cursor: pointer;
    list-style: none;
}

.mcp-tools summary::-webkit-details-marker {
    display: none;
}

.mcp-tools summary code {
    font-family: var(--theme-font-mono);
    font-size: var(--theme-font-size-sm);
}

.mcp-tools details[open] summary .ui-icon {
    transform: rotate(180deg);
}

.mcp-tools p {
    margin: 0 0 0.75rem;
    color: var(--text-muted);
    font-size: var(--theme-font-size-sm);
}

/* Presence (the others in the scribble) */

.editor-presence {
    display: flex;
}

.presence-avatar {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 28px;
    height: 28px;
    margin-left: -6px;
    border: 2px solid var(--surface);
    border-radius: 50%;
    background: var(--theme-info-subtle);
    color: var(--theme-info-text);
    font-size: var(--theme-font-size-sm);
    font-weight: 600;
}

/* Toasts (centered under the bar, they fade out after a few seconds) */

.toast-container {
    position: fixed;
    top: 5.5rem;
    left: 50%;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    transform: translateX(-50%);
    pointer-events: none;
}

.toast {
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius);
    background: var(--theme-info);
    color: var(--theme-info-contrast);
    box-shadow: var(--theme-shadow);
    font-weight: 500;
    animation: toast-out 0.4s ease-in 4s forwards;
}

.toast.success {
    background: var(--theme-success);
    color: var(--theme-success-contrast);
}

.toast.error {
    background: var(--theme-error);
    color: var(--theme-error-contrast);
}

@keyframes toast-out {
    to {
        opacity: 0;
        visibility: hidden;
    }
}

/* The easter egg of the welcome pages (see giotto.js). */

.giotto-canvas {
    position: fixed;
    inset: 0;
    z-index: 20;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.giotto-caption {
    position: fixed;
    top: 85%;
    left: 50%;
    z-index: 21;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.5rem 2.5rem;
    border-radius: var(--radius);
    background: var(--cd-yellow-60);
    color: var(--cd-warm-grey-10);
    box-shadow: 0 1rem 3rem rgb(0 0 0 / 40%);
    font-family: Georgia, serif;
    font-size: clamp(1.25rem, 6vw, 2.5rem);
    font-style: italic;
    white-space: nowrap;
    pointer-events: none;
    animation: giotto-caption 3.2s ease-in-out forwards;
}

.giotto-caption small {
    font-size: 1rem;
    opacity: 0.7;
}

@keyframes giotto-caption {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.3) rotate(-12deg);
    }

    15% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.08) rotate(2deg);
    }

    25%,
    80% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1) rotate(0);
    }

    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.9);
    }
}

/* Welcome (the login & guest name pages, like Noddl) */

/* The welcome pages are a sketchpad: dotted paper (like the editor), with doodles. */

.page-welcome {
    --paper: var(--cd-warm-grey-100);
    --grid: var(--cd-warm-grey-80);

    background-color: var(--paper);
    background-image: radial-gradient(
        circle,
        color-mix(in srgb, var(--grid) calc(var(--grid-opacity) * 100%), transparent) 1.2px,
        transparent 1.6px
    );
    background-size: 24px 24px;
    touch-action: none;
    user-select: none;
}

@media (prefers-color-scheme: dark) {
    .page-welcome {
        --paper: var(--cd-warm-grey-20);
        --grid: var(--cd-warm-grey-40);
    }
}

.doodles,
.welcome-trail {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.doodle {
    fill: none;
    stroke-width: 5;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 1;
    stroke-dashoffset: 1;
    opacity: 0.7;
    animation: doodle 24s ease-in-out infinite;
}

.doodle-1 {
    stroke: var(--cd-purple-60);
    animation-delay: 0.0s;
}

.doodle-2 {
    stroke: var(--cd-orange-60);
    animation-delay: 2.4s;
}

.doodle-3 {
    stroke: var(--cd-green-60);
    animation-delay: 4.8s;
}

.doodle-4 {
    stroke: var(--cd-azure-60);
    animation-delay: 7.2s;
}

.doodle-5 {
    stroke: var(--cd-rose-60);
    animation-delay: 9.6s;
}

.doodle-6 {
    stroke: var(--cd-yellow-60);
    animation-delay: 12.0s;
}

.doodle-7 {
    stroke: var(--cd-sea-green-60);
    animation-delay: 14.4s;
}

.doodle-8 {
    stroke: var(--cd-violet-60);
    animation-delay: 16.8s;
}

.doodle-9 {
    stroke: var(--cd-red-60);
    animation-delay: 19.2s;
}

.doodle-10 {
    stroke: var(--cd-blue-60);
    animation-delay: 21.6s;
}

/* Every doodle is drawn, stays a while, and fades (to be drawn again). */
@keyframes doodle {
    0% {
        stroke-dashoffset: 1;
        opacity: 0.7;
    }

    15%,
    70% {
        stroke-dashoffset: 0;
        opacity: 0.7;
    }

    85%,
    100% {
        stroke-dashoffset: 0;
        opacity: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .doodle {
        stroke-dashoffset: 0;
        animation: none;
    }
}

.page-welcome .main {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.welcome {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 4rem;
    align-items: center;
    width: 100%;
    max-width: 56rem;
}

.welcome-logo {
    width: 100%;
    height: auto;
    filter: drop-shadow(0 0.5rem 1rem rgb(0 0 0 / 25%));
}

.welcome-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1.5rem;
}

.welcome-title {
    font-size: 3rem;
    font-weight: 300;
    line-height: 1.2;
}

.welcome-title strong {
    font-weight: 600;
}

.welcome-text .tagline {
    margin-top: -1rem;
    font-size: 1.25rem;
    font-weight: 300;
    text-transform: uppercase;
}

.welcome .guest-form {
    justify-content: flex-start;
}

.welcome-input {
    background: var(--surface);
}

.btn-outline,
.btn-outline:hover {
    border: 3px solid var(--text);
    background: var(--paper);
    color: var(--text);
}

.btn-outline:hover {
    background: var(--text);
    color: var(--paper);
}

@media (width <= 720px) {
    .welcome {
        grid-template-columns: 1fr;
        gap: 2rem;
        justify-items: center;
        text-align: center;
    }

    .welcome-logo {
        max-width: 12rem;
    }

    .welcome-text {
        align-items: center;
    }

    .welcome-title {
        font-size: 2rem;
    }

    .welcome .guest-form {
        justify-content: center;
    }

    .footer {
        flex-direction: column;
    }

    .footer p {
        margin-left: 0;
        text-align: center;
    }
}

/* Footer */

.footer {
    position: relative;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 2rem;
    font-size: 0.8rem;
    font-weight: 300;
    opacity: 0.6;
}

.footer p {
    margin-left: auto;
    text-align: right;
}

.footer a {
    color: inherit;
    font-weight: 600;
}

.footer a:hover {
    opacity: 0.7;
}

.footer-logo {
    display: block;
    width: auto;
    height: 1.5rem;
}

/* Modals */

.modal {
    width: min(64rem, calc(100% - 2rem));
    max-height: calc(100% - 4rem);
    padding: 1.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--theme-shadow);
}

/* The popover of the details, which opens under the title. */
.popover {
    --arrow: 2rem;

    position: absolute;
    top: 5rem;
    left: 1rem;
    z-index: 3;
    width: min(24rem, calc(100% - 2rem));
    max-height: calc(100% - 6rem);
    margin: 0;
    overflow: visible;
    padding: 1rem 1.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--theme-shadow);
}

/* The triangle, which points to the button of the popover. */
.popover::before {
    content: "";
    position: absolute;
    top: -7px;
    left: calc(var(--arrow) - 6px);
    width: 12px;
    height: 12px;
    border-top: 1px solid var(--border);
    border-left: 1px solid var(--border);
    background: var(--surface);
    transform: rotate(45deg);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.popover.guests {
    width: min(30rem, calc(100% - 2rem));
}

.guests-intro {
    margin: 0 0 1rem;
    font-size: var(--theme-font-size-sm);
}

.guests-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.guests-field {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 0.25rem;
    color: var(--text-muted);
    font-size: var(--theme-font-size-sm);
}

.guests-field-name {
    flex-basis: 100%;
}

.guests-form .btn {
    align-self: flex-end;
    padding-block: 0.55rem;
}

.guests-field input,
.guests-field select {
    font-size: var(--theme-font-size);
}

.guests-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.guests-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 1rem 0 0;
    padding: 0;
    list-style: none;
    max-height: 40vh;
    overflow: auto;
}

.guests-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.guests-info {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    min-width: 0;
    font-size: var(--theme-font-size-sm);
}

.guests-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.guests-access {
    flex-shrink: 0;
    padding: 0.05rem 0.5rem;
    border-radius: var(--theme-radius-round);
    background: var(--theme-success-subtle);
    color: var(--theme-success-text);
    font-weight: 600;
}

.guests-access-rw {
    background: var(--theme-warning-subtle);
    color: var(--theme-warning-text);
}

.guests-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    white-space: nowrap;
}

.guests-copy {
    padding: 0.3rem 0.75rem;
    font-size: var(--theme-font-size-sm);
}

.guests-empty {
    margin: 1rem 0 0;
    font-size: var(--theme-font-size-sm);
}

.guests-list:not(:empty) + .guests-empty {
    display: none;
}

.popover.export {
    width: min(18rem, calc(100% - 2rem));
}

.export-scope {
    margin: 0 0 0.5rem;
    font-size: var(--theme-font-size-sm);
}

.export-formats {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.export-format {
    display: flex;
    flex-direction: column;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    color: var(--text);
}

.export-format:hover {
    background: var(--surface-raised);
    color: var(--text);
}

.export-format .muted {
    font-size: var(--theme-font-size-sm);
}

.popover h2 {
    font-size: var(--theme-font-size-lg);
}

.modal::backdrop {
    background: color-mix(in srgb, var(--cd-black) 40%, transparent);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.modal-header h2 {
    margin: 0;
}

.popover .modal-header {
    margin-bottom: 0.5rem;
}

.browse-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.search {
    display: flex;
    flex: 1;
    align-items: center;
    gap: 0.5rem;
    min-width: 12rem;
    padding-left: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text-muted);
}

.search input {
    flex: 1;
    border: none;
    background: none;
    outline: none;
}

.browse-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    list-style: none;
    margin: 0;
    padding: 0;
}

.browse-card {
    display: flex;
    flex-direction: column;
    height: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    overflow: hidden;
}

.browse-card:hover,
.browse-card[aria-current="page"] {
    color: var(--text);
    border-color: var(--primary);
}

.browse-thumbnail {
    display: block;
    aspect-ratio: 4 / 3;
    background: var(--cd-warm-grey-100);
}

.browse-thumbnail.is-dark {
    background: var(--cd-warm-grey-20);
}

.browse-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.browse-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.75rem;
}

.browse-description {
    display: -webkit-box;
    overflow: hidden;
    color: var(--text-muted);
    font-size: var(--theme-font-size-sm);
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.browse-meta {
    color: var(--text-muted);
    font-size: var(--theme-font-size-sm);
}

/* The switch between the scribbles & the trash (a segmented control). */
.browse-tabs {
    display: inline-grid;
    grid-auto-columns: 1fr;
    grid-auto-flow: column;
    padding: 3px;
    border: 1px solid var(--border);
    border-radius: var(--theme-radius-round);
    background: var(--background);
}

.browse-tab {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 1rem;
    border-radius: var(--theme-radius-round);
    color: var(--text-muted);
    font-size: var(--theme-font-size-sm);
    font-weight: 500;
    transition: background var(--theme-transition), color var(--theme-transition);
}

.browse-tab:hover {
    color: var(--text);
}

.browse-tab[aria-selected="true"] {
    background: var(--primary);
    color: var(--primary-contrast);
}

.browse-trashed {
    opacity: 0.9;
}

.browse-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.browse-actions button {
    white-space: nowrap;
}

.browse-restore {
    padding: 0.3rem 0.75rem;
    font-size: var(--theme-font-size-sm);
}

/* The destructive actions (delete, revoke) are text only, in the error colour. */
.link-button.danger {
    color: var(--theme-error-text);
}

.link-button.danger:hover {
    color: var(--theme-error);
}

.browse-empty {
    margin: 2rem 0;
    text-align: center;
}

/* Editor */

.editor-page .main {
    max-width: none;
    padding: 0;
}

/*
 * The canvas is always paper-like (also in the dark theme), so the scribbles
 * look the same for everyone.
 */
.editor {
    --paper: var(--cd-warm-grey-100);
    --grid: var(--cd-warm-grey-80);

    position: fixed;
    inset: 0;
    background: var(--paper);
    overflow: hidden;
    user-select: none;
    -webkit-touch-callout: none;

    /* No double tap zoom (e.g. on the buttons), the canvas handles its gestures itself. */
    touch-action: manipulation;
}

/* The dark paper (stored with the scribble, see paper.js). */
.editor[data-paper="dark"] {
    --paper: var(--cd-warm-grey-20);
    --grid: var(--cd-warm-grey-40);
}

.editor-canvas,
.editor-overlay {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
}

.editor-overlay {
    touch-action: none;
    cursor: crosshair;
}

.editor-bar,
.editor-tools {
    position: absolute;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--theme-shadow);
}

.editor-bar {
    top: 1rem;
    left: 1rem;
    right: 1rem;
}

.editor-button {
    display: flex;
    color: var(--text);
    font-size: 1.25rem;
}

.editor-title {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 0;
    max-width: 40%;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius);
    line-height: 1.2;
    text-align: left;
}

.editor-title:hover {
    background: var(--surface-raised);
}

.editor-separator {
    align-self: stretch;
    width: 1px;
    background: var(--border);
}

.editor-action {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius);
    font-weight: 500;
}

.editor-action:hover {
    background: var(--surface-raised);
}

.editor-spacer {
    flex: 1;
}

.editor-details {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.editor-details label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: var(--theme-font-size-sm);
    color: var(--text-muted);
}

.editor-details textarea {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    resize: vertical;
}

.combobox {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: var(--theme-font-size-sm);
    color: var(--text-muted);
}

.combobox-options {
    position: absolute;
    top: calc(100% + 0.25rem);
    left: 0;
    right: 0;
    z-index: 1;
    max-height: 14rem;
    margin: 0;
    padding: 0.25rem;
    overflow: auto;
    list-style: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-raised);
    box-shadow: var(--theme-shadow);
}

.combobox-options[hidden] {
    display: none;
}

.combobox-option {
    padding: 0.45rem 0.75rem;
    border-radius: var(--theme-radius-sm);
    color: var(--text);
    font-size: var(--theme-font-size);
    cursor: pointer;
}

.combobox-option:hover,
.combobox-option[aria-selected="true"] {
    background: var(--primary);
    color: var(--primary-contrast);
}

.combobox-create {
    color: var(--primary);
    font-style: italic;
}

.editor-dates {
    font-size: var(--theme-font-size-sm);
}

.editor-error {
    color: var(--theme-error-text);
}

.details-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}


.editor-title strong {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.editor-user {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-left: 1rem;
    border-left: 1px solid var(--border);
    font-size: var(--theme-font-size-sm);
}

.editor-title .muted,
.editor-status,
.editor-zoom {
    font-size: var(--theme-font-size-sm);
}

/* "Saved" only flashes (the progress & the errors stay). */
.editor-status[data-state="saved"] {
    animation: status-out 0.4s ease-in 2s forwards;
}

@keyframes status-out {
    to {
        opacity: 0;
    }
}

.editor-status[data-state="error"] {
    color: var(--theme-error-text);
}

/*
 * Centered via the auto margins (and not left: 50%, which would limit the
 * width to the half of the screen). The tools, thickness & actions are on top,
 * and the colours below.
 */
.editor-tools {
    /* The ink of the icons (see below). */
    --ink-ui: var(--ink);

    right: 1rem;
    bottom: calc(1rem + env(safe-area-inset-bottom));
    left: 1rem;
    flex-direction: column;
    gap: 0.5rem;
    width: fit-content;
    margin-inline: auto;
}

.editor-group {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.25rem;
}

/* On small screens (e.g. phones), the bar only shows the icons of its actions. */
@media (width <= 720px) {
    .action-label,
    .editor-user .user-name,
    .editor-status {
        display: none;
    }

    /* The name on the first line, and the actions on the second. */
    .editor-bar {
        flex-wrap: wrap;
        justify-content: space-between;
        gap: 0.25rem 0.5rem;
        padding: 0.5rem;
    }

    .editor-bar .editor-title {
        flex-basis: 100%;
        max-width: 100%;
    }

    .popover {
        top: 7.5rem;
    }

    .editor-owner,
    .editor-separator,
    .editor-spacer {
        display: none;
    }

    .editor-user {
        padding-left: 0;
        border-left: none;
    }
}

.editor-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 1rem;
}

.editor-row > .editor-group:not(:first-child) {
    padding-left: 1rem;
    border-left: 1px solid var(--border);
}

.editor-row > .editor-group.is-line-start {
    padding-left: 0;
    border-left: none;
}

.editor-colours {
    flex-wrap: wrap;
    justify-content: center;
}

/* The toggle, which collapses the toolbar (to the current tool & colour). */
.toolbar-toggle {
    position: absolute;
    top: -0.9rem;
    right: 1rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.15rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--theme-radius-round);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 1rem;
}

.toolbar-toggle:hover {
    color: var(--text);
}

.toolbar-current {
    display: none;
    align-items: center;
    gap: 0.4rem;
    color: var(--text);
    font-size: 1.25rem;
}

.toolbar-colour {
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
    box-shadow: 0 0 0 1px var(--border);
}

.editor-tools.is-collapsed {
    padding: 0;
    border: none;
    background: none;
    box-shadow: none;
}

.editor-tools.is-collapsed .editor-row,
.editor-tools.is-collapsed .editor-colours {
    display: none;
}

.editor-tools.is-collapsed .toolbar-toggle {
    position: static;
    padding: 0.5rem 0.75rem;
    box-shadow: var(--theme-shadow);
}

.editor-tools.is-collapsed .toolbar-toggle .ui-icon {
    transform: rotate(180deg);
}

.editor-tools.is-collapsed .toolbar-current {
    display: flex;
}

/* The menu of the selection (of the lasso), above it. */
.selection-menu {
    position: absolute;
    z-index: 2;
    display: flex;
    gap: 0.25rem;
    padding: 0.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--theme-shadow);
}

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

.selection-menu button {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.6rem;
    border-radius: var(--radius);
    font-size: var(--theme-font-size-sm);
}

.selection-menu button:hover {
    background: var(--surface-raised);
}

/* The field of the text tool, which is typed into on the canvas. */
.text-field {
    position: absolute;
    z-index: 2;
    min-width: 8rem;
    padding: 0;
    border: none;
    outline: 1px dashed var(--primary);
    background: transparent;
    margin: 0;
    overflow: hidden;
    font-family: Poppins, sans-serif;
    font-weight: 400;
    line-height: 1.25;
    letter-spacing: normal;
    white-space: pre;
    resize: none;
    field-sizing: content;
}

.image-input {
    display: none;
}


.editor-tool,
.editor-colour,
.editor-width {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: var(--radius);
    font-size: 1.35rem;
}

.editor-tool:hover,
.editor-colour:hover,
.editor-width:hover {
    background: var(--surface-raised);
}

.editor-tool[aria-pressed="true"],
.editor-colour[aria-pressed="true"],
.editor-width[aria-pressed="true"] {
    background: var(--surface-raised);
    color: var(--primary);
    box-shadow: inset 0 0 0 2px var(--primary);
}

/*
 * The ink of the icons (see colours.js) keeps a minimal contrast to the
 * toolbar: the dark inks are lightened in the dark theme, the light ones
 * darkened in the light theme (the hue stays, the drawing keeps the ink).
 */
@supports (color: oklch(from red l c h)) {
    .editor-tools {
        --ink-ui: oklch(from var(--ink) min(l, 0.7) c h);
    }

    @media (prefers-color-scheme: dark) {
        .editor-tools {
            --ink-ui: oklch(from var(--ink) max(l, 0.55) c h);
        }
    }
}

/*
 * The outlines of the drawing tools are a tint of the ink (the text colour,
 * mixed with the ink), also when they're selected (see icons.html).
 */
.ui-icon-drawing,
.editor-tool[aria-pressed="true"] .ui-icon-drawing {
    color: color-mix(in srgb, var(--ink-ui, var(--text)) 35%, var(--text));
}

/* The figures (lines, rectangles & ellipses) are outlined in the ink itself. */
.ui-icon-ink,
.editor-tool[aria-pressed="true"] .ui-icon-ink {
    color: var(--ink-ui, currentcolor);
}

.editor-colour span {
    width: 1.4rem;
    height: 1.4rem;
    border-radius: 50%;
    box-shadow: 0 0 0 1px var(--border);
}


.editor-width span {
    width: var(--size);
    height: var(--size);
    border-radius: 50%;

    /* The widths are dots of the ink. */
    background: var(--ink-ui, currentcolor);
}

.editor-width[data-width="1.5"] { --size: 5px; }
.editor-width[data-width="3"] { --size: 8px; }
.editor-width[data-width="6"] { --size: 14px; }

/* The paper toggle shows the sun on the light paper, and the moon on the dark one. */
.editor-paper span {
    display: flex;
}

.editor[data-paper="dark"] .paper-light,
.editor:not([data-paper="dark"]) .paper-dark {
    display: none;
}

/* The shades of a colour family, which fan out above its swatch. */
.colour-fan {
    position: fixed;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    padding: 0.4rem;
    border: 1px solid var(--border);
    border-radius: var(--theme-radius-round);
    background: var(--surface);
    box-shadow: var(--theme-shadow);
}

.colour-fan[hidden] {
    display: none;
}

.colour-shade {
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 50%;
    box-shadow: 0 0 0 1px var(--border);
    transition: transform var(--theme-transition);
}

.colour-shade:hover,
.colour-shade[aria-checked="true"] {
    transform: scale(1.15);
    box-shadow: 0 0 0 2px var(--primary);
}

.editor-zoom {
    min-width: 3rem;
    text-align: right;
}

/* The tooltips of the editor (see tooltip.js): shown right away, above the buttons. */

.tooltip {
    position: fixed;
    z-index: 30;
    max-width: min(20rem, calc(100vw - 1rem));
    padding: 0.35rem 0.65rem;
    border-radius: calc(var(--radius) * 0.75);
    border: 1px solid var(--cd-warm-grey-30);
    background: var(--cd-warm-grey-10);
    color: var(--cd-warm-grey-100);
    box-shadow: 0 0.5rem 1.5rem rgb(0 0 0 / 40%);
    font-size: var(--theme-font-size-sm);
    font-weight: 500;
    line-height: 1.3;
    pointer-events: none;
    animation: tooltip-in 0.08s ease-out;
}

.tooltip strong,
.tooltip span {
    display: block;
}

.tooltip strong {
    font-weight: 600;
}

.tooltip span {
    font-weight: 400;
    opacity: 0.75;
}

.tooltip[hidden] {
    display: none;
}

@keyframes tooltip-in {
    from {
        opacity: 0;
        transform: translateY(2px);
    }
}

/* The tips of the drawing tools show the selected ink (see colours.js). */

.ui-icon-tip {
    fill: var(--ink-ui, currentcolor);
}

