/* The page fills the window: toolbar at the top, status at the bottom, source and preview side by side between. */
:root {
    --highlight: light-dark(#2563eb, #60a5fa);
}

body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    margin: 0;
}

body > nav { flex: none; padding-inline: var(--space-6); }

main {
    flex: 1;
    min-height: 20rem;
    display: flex;
    flex-direction: column;
    padding: var(--space-4) var(--space-6);
}

/* --- Toolbar */

.toolbar { margin-bottom: var(--space-4); justify-content: space-between; }
.toolbar menu.buttons { margin: 0; }
.toolbar menu.buttons button { width: 2.25rem; height: 2.25rem; }

.toolbar svg {
    width: 1.15rem;
    height: 1.15rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.toolbar svg .solid { fill: currentColor; stroke: none; }

.toolbar .end { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-6); }
.zoom, .backgrounds { display: flex; align-items: center; gap: var(--space-3); font-size: 0.85rem; }
#zoom-level { min-width: 3.5em; text-align: right; font-variant-numeric: tabular-nums; }
.toolbar button[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-foreground); }

/* --- Source and preview, one half each */

.panels {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
}

.panels > section { min-width: 0; min-height: 0; margin: 0; padding: 0; }

@media (max-width: 48rem) {
    .panels { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
}

.preview {
    height: 100%;
    display: flex;
    padding: var(--space-4);
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-large);
}

/* The canvas is sized to the zoomed image. Auto margins centre it but, unlike centring the
   flex box, still let a zoomed image scroll to its edges. */
.canvas { position: relative; margin: auto; flex: none; }
.canvas img { display: block; width: 100%; height: 100%; max-width: none; }
.preview:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }
.preview.fit { overflow: hidden; }

/* Guidelines: the edge of the SVG's viewport, just outside the image, and its centre lines. */
.guides {
    --guide: color-mix(in srgb, var(--highlight) 55%, transparent);
    position: absolute;
    inset: -1px;
    border: 1px dashed var(--guide);
    pointer-events: none;
}
.guides::before, .guides::after { content: ""; position: absolute; }
.guides::before { left: 50%; top: 0; bottom: 0; border-left: 1px dashed var(--guide); }
.guides::after { top: 50%; left: 0; right: 0; border-top: 1px dashed var(--guide); }
.preview:not(.show-guides) .guides { display: none; }

.preview.stale img { opacity: 0.4; }

.preview.bg-light { background: #fff; }
.preview.bg-dark { background: #1a1a1a; }
.preview.bg-checker {
    --check: light-dark(#e5e5e5, #333);
    background-color: light-dark(#fff, #1a1a1a);
    background-image:
        linear-gradient(45deg, var(--check) 25%, transparent 25%, transparent 75%, var(--check) 75%),
        linear-gradient(45deg, var(--check) 25%, transparent 25%, transparent 75%, var(--check) 75%);
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
}

/* --- CodeMirror, themed to match Oat */

.CodeMirror {
    height: 100%;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    background: var(--background);
    color: var(--foreground);
    border: 1px solid var(--border);
    border-radius: var(--radius-large);
}

.CodeMirror-focused { border-color: var(--ring); }

.CodeMirror-gutters {
    background: var(--faint);
    border-right: 1px solid var(--border);
}

.CodeMirror-linenumber { color: var(--muted-foreground); }
.CodeMirror-cursor { border-left-color: var(--foreground); }
.CodeMirror-selected, .CodeMirror-focused .CodeMirror-selected { background: color-mix(in srgb, var(--highlight) 25%, transparent); }
.CodeMirror-matchingtag { background: color-mix(in srgb, var(--highlight) 15%, transparent); }

.cm-s-default .cm-tag { color: var(--highlight); }
.cm-s-default .cm-attribute { color: var(--warning); }
.cm-s-default .cm-string { color: var(--success); }
.cm-s-default .cm-comment { color: var(--muted-foreground); }
.cm-s-default .cm-meta, .cm-s-default .cm-bracket { color: var(--muted-foreground); }
.cm-s-default .cm-atom { color: var(--danger); }
.cm-s-default .cm-error { color: var(--danger); }

.CodeMirror .error-line { background: color-mix(in srgb, var(--danger) 15%, transparent); }

/* --- Status */

#message {
    margin: var(--space-3) 0 0;
    min-height: 1.4em;
    font-size: 0.85rem;
    text-align: right;
    color: var(--muted-foreground);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

#message.error { color: var(--danger); }

#share-dialog fieldset.group { margin: 0 0 var(--space-2); }
#share-url { font-family: var(--font-mono); font-size: var(--text-8); }
