@font-face {
    font-family: 'Bricolage Grotesque';
    src: url('fonts/bricolage-grotesque-latin-wght-normal.woff2') format('woff2');
    font-weight: 200 800;
    font-display: block;
}

@font-face {
    font-family: 'Instrument Sans';
    src: url('fonts/instrument-sans-latin-wght-normal.woff2') format('woff2');
    font-weight: 400 700;
    font-display: block;
}

:root {
    --paper: #f6f8f5;
    --desk: #cfd9d5;
    --ink: #14272d;
    --ink-soft: #4d6168;
    --line: #c9d3cf;
    --brand: #0e4a5a;
    --brand-tint: #e1ecea;
    --focus: #b3530f;
}

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font: 400 15px/1.45 'Instrument Sans', system-ui, sans-serif;
}

button,
input,
select,
textarea {
    font: inherit;
    color: inherit;
}

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

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

/* Masthead */

.masthead {
    display: flex;
    align-items: baseline;
    gap: 16px;
    padding: 14px 24px;
    background: var(--brand);
    color: #f4f1e4;
}

.masthead p,
.masthead h1 {
    margin: 0;
}

.masthead-brand {
    font: 700 17px/1.2 'Bricolage Grotesque', sans-serif;
}

.masthead-tool {
    font: 400 15px/1.2 'Instrument Sans', sans-serif;
    padding-left: 16px;
    border-left: 1px solid rgb(244 241 228 / 0.4);
}

.masthead-size {
    margin-left: auto !important;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    opacity: 0.8;
}

/* Workbench */

.workbench {
    display: grid;
    grid-template-columns: minmax(320px, 400px) 1fr;
    align-items: start;
}

.controls {
    grid-column: 1;
    grid-row: 1;
    padding: 8px 24px 48px;
    border-right: 1px solid var(--line);
    min-height: calc(100vh - 50px);
}

.stage {
    grid-column: 2;
    grid-row: 1;
    position: sticky;
    top: 0;
    height: 100vh;
    background: var(--desk);
    display: grid;
    place-items: center;
    padding: 24px;
}

.stage.is-drop-target {
    background: #b9c9c3;
}

.stage-inner {
    display: grid;
    justify-items: center;
    gap: 12px;
}

.artboard {
    display: block;
    height: min(calc(100vh - 190px), 860px);
    width: auto;
    max-width: 100%;
    aspect-ratio: 1200 / 1530;
    background: #fff;
    box-shadow: 0 1px 2px rgb(20 39 45 / 0.25), 0 18px 40px -12px rgb(20 39 45 / 0.45);
    cursor: grab;
    touch-action: none;
}

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

.stage-hint,
.status {
    margin: 0;
    font-size: 13px;
    color: var(--ink-soft);
}

.status {
    min-height: 1.45em;
    color: var(--ink);
}

.downloads {
    display: flex;
    gap: 8px;
}

/* Control groups */

.group {
    margin: 0;
    padding: 20px 0;
    border: 0;
    border-bottom: 1px solid var(--line);
    min-width: 0;
}

.group:last-child {
    border-bottom: 0;
}

.group legend {
    padding: 0;
    margin-bottom: 12px;
    float: left;
    width: 100%;
    font: 700 18px/1.2 'Bricolage Grotesque', sans-serif;
}

.group legend + * {
    clear: both;
}

.group-note {
    margin: 0 0 12px;
    color: var(--ink-soft);
    font-size: 14px;
}

.field {
    display: grid;
    gap: 6px;
    margin-top: 16px;
}

.field-label {
    font-weight: 600;
    font-size: 14px;
}

input[type='text'],
textarea,
select {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid #9fb0ab;
    border-radius: 4px;
    background: #fff;
}

textarea {
    resize: vertical;
    line-height: 1.3;
}

input[type='range'] {
    width: 100%;
    accent-color: var(--brand);
}

.check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
}

.check input {
    width: 17px;
    height: 17px;
    margin: 0;
    accent-color: var(--brand);
}

/* Buttons */

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 9px 16px;
    border: 1px solid var(--brand);
    border-radius: 4px;
    background: #fff;
    color: var(--brand);
    font-weight: 600;
    cursor: pointer;
}

.button:hover {
    background: var(--brand-tint);
}

.button-primary {
    background: var(--brand);
    color: #f4f1e4;
}

.button-primary:hover {
    background: #0a3946;
}

.button-quiet {
    border-color: transparent;
    background: none;
    text-decoration: underline;
}

.button-file:focus-within {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

.upload-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 12px;
}

.upload-note {
    color: var(--ink-soft);
    font-size: 14px;
}

/* Pickers: the whole tile is the button */

.layout-picker {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.pick {
    display: grid;
    gap: 8px;
    justify-items: start;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    font-weight: 600;
    font-size: 14px;
    text-align: left;
    cursor: pointer;
}

.pick[aria-pressed='true'] {
    border-color: var(--brand);
    box-shadow: 0 0 0 2px var(--brand);
    background: var(--brand-tint);
}

.layout-sketch {
    position: relative;
    width: 100%;
    aspect-ratio: 1200 / 900;
    border-radius: 2px;
    overflow: hidden;
    background: repeating-linear-gradient(135deg, #9fb5ae 0 6px, #b3c6c0 6px 12px);
}

.layout-sketch::after {
    content: '';
    position: absolute;
    inset: auto 0 0 0;
}

.layout-sketch[data-layout='split']::after {
    height: 40%;
    background: var(--brand);
}

.layout-sketch[data-layout='full']::after {
    height: 62%;
    background: linear-gradient(to top, var(--brand) 25%, transparent);
}

.theme-picker {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.theme-chip {
    display: flex;
    width: 100%;
    height: 36px;
    border-radius: 3px;
    overflow: hidden;
    border: 1px solid rgb(20 39 45 / 0.2);
}

.theme-chip span {
    flex: 1;
}

.theme-chip span:first-child {
    flex: 2.2;
}

.library {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.library-photo {
    padding: 0;
    border: 0;
    border-radius: 4px;
    overflow: hidden;
    background: var(--desk);
    aspect-ratio: 5 / 4;
    cursor: pointer;
}

.library-photo img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.library-photo[aria-pressed='true'] {
    box-shadow: 0 0 0 2px var(--paper), 0 0 0 5px var(--brand);
}

.segmented {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    border: 1px solid var(--brand);
    border-radius: 4px;
    overflow: hidden;
}

.segmented button {
    padding: 8px 6px;
    border: 0;
    border-left: 1px solid var(--brand);
    background: #fff;
    color: var(--brand);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
}

.segmented button:first-child {
    border-left: 0;
}

.segmented button[aria-pressed='true'] {
    background: var(--brand);
    color: #f4f1e4;
}

.segmented button:focus-visible {
    outline-offset: -4px;
}

/* Small screens: preview first, controls below */

@media (max-width: 820px) {
    .masthead {
        flex-wrap: wrap;
        gap: 4px 12px;
        padding: 12px 16px;
    }

    .masthead-tool {
        flex-basis: 100%;
        padding-left: 0;
        border-left: 0;
    }

    .masthead-size {
        display: none;
    }

    .workbench {
        grid-template-columns: minmax(0, 1fr);
    }

    .stage {
        grid-column: 1;
        grid-row: 1;
        position: static;
        height: auto;
        padding: 20px 16px;
    }

    .artboard {
        height: auto;
        width: min(100%, 40vh);
    }

    .controls {
        grid-column: 1;
        grid-row: 2;
        padding: 0 16px 40px;
        border-right: 0;
        min-height: 0;
    }
}
