/* ==========================================================================
   Dog space styles

   Contents
     1. Fonts
     2. Theme tokens      <- the variables a theme changes (see docs/THEMES.md)
     3. Base elements
     4. Top bar and menus
     5. 3D view, panels and controls
     6. Dog card, cluster card, picture viewer, undo notice
     7. Add / edit dialog
     8. Themes dialog
     9. Phones
   ========================================================================== */


/* 1. Fonts -------------------------------------------------------------- */

@font-face {
    font-family: "Plateau Comic Sans";
    src: url("fonts/Comic Sans MS.ttf") format("truetype");
    font-style: normal;
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: "Plateau Comic Sans";
    src: url("fonts/Comic Sans MS Bold.ttf") format("truetype");
    font-style: normal;
    font-weight: 700;
    font-display: swap;
}


/* 2. Theme tokens ---------------------------------------------------------
   A theme works by replacing the values in the first block. Everything in the
   second block is worked out from those, so a theme only has to supply a few
   colours. dogs.js reads the same variables to paint the 3D graph.
   If you add a token here, also add it to src/Themes/ThemeCatalog.php.          */

:root {
    --ds-page: #fff19a;           /* page background */
    --ds-page-deep: #f5df62;      /* behind the photo cropper */
    --ds-paper: #fff8c7;          /* panels, cards and dialogs */
    --ds-ink: #191970;            /* text and lines */
    --ds-accent: #d51d2d;         /* selected things, active toggles */
    --ds-danger: #7c1643;         /* delete and error messages */
    --ds-space: #080830;          /* horoscope sky */
    --ds-star: #ffffff;           /* a dog in the horoscope sky */
    --ds-star-glow: #fff7cf;
    --ds-other: #ff6d9d;          /* "anything else" in the horoscope sky */
    --ds-other-glow: #ef3f77;

    --ds-font: "Plateau Comic Sans", "Comic Sans MS", "Comic Sans", cursive;

    /* Set by themes.js when a theme or visitor picks a background picture. */
    --ds-page-image: none;
    --ds-page-image-size: cover;
    --ds-page-image-repeat: no-repeat;
    --ds-page-image-opacity: 1;

    /* Worked out from the tokens above. */
    --ds-ink-line: color-mix(in srgb, var(--ds-ink) 16%, transparent);
    --ds-ink-hover: color-mix(in srgb, var(--ds-ink) 8%, transparent);
    --ds-ink-focus: color-mix(in srgb, var(--ds-ink) 38%, transparent);
    --ds-ink-quiet: color-mix(in srgb, var(--ds-ink) 62%, transparent);
    --ds-shadow: color-mix(in srgb, var(--ds-ink) 11%, transparent);
    --ds-shadow-strong: color-mix(in srgb, var(--ds-ink) 20%, transparent);
    --ds-bar: color-mix(in srgb, var(--ds-page) 86%, transparent);
    --ds-veil: color-mix(in srgb, var(--ds-page) 94%, transparent);
    --ds-panel: color-mix(in srgb, var(--ds-paper) 97%, transparent);
    --ds-panel-soft: color-mix(in srgb, var(--ds-paper) 94%, transparent);
    --ds-panel-glass: color-mix(in srgb, var(--ds-paper) 78%, transparent);
    --ds-ink-bright: color-mix(in srgb, var(--ds-ink) 82%, white);
    /* Text boxes: a little lighter than the panel on light themes, a little deeper on dark ones. */
    --ds-field: light-dark(color-mix(in srgb, var(--ds-paper) 72%, white), color-mix(in srgb, var(--ds-paper) 82%, black));

    color: var(--ds-ink);
    background: var(--ds-page);
    font-family: var(--ds-font);
    font-synthesis: none;
    color-scheme: light;
}

/* The page picture sits behind everything. */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background-image: var(--ds-page-image);
    background-size: var(--ds-page-image-size);
    background-repeat: var(--ds-page-image-repeat);
    background-position: center;
    opacity: var(--ds-page-image-opacity);
}


/* 3. Base elements ----------------------------------------------------- */

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

html.crop-mode, html.crop-mode body { overflow: hidden; overscroll-behavior: none; }

body {
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    color: var(--ds-ink);
}

.dog-space, dialog { text-transform: lowercase; }

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

button {
    border: 0;
    background: transparent;
    cursor: pointer;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 4px;
}

button:hover { background: var(--ds-ink-hover); }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, canvas:focus-visible { outline: 3px solid var(--ds-ink-focus); outline-offset: 3px; }

.primary { background: transparent; color: var(--ds-ink); }
.primary:hover { background: var(--ds-ink-hover); }
.danger { color: var(--ds-danger); }

.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.dog-space { min-height: 100vh; min-height: 100dvh; position: relative; }


/* 4. Top bar and menus --------------------------------------------------- */

.topbar {
    position: fixed;
    inset: 0 0 auto 0;
    height: 72px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 14px 22px;
    z-index: 5;
    border-bottom: 1px solid var(--ds-ink-line);
    background: var(--ds-bar);
    backdrop-filter: blur(12px);
}

.topbar h1 { grid-column: 2; display: flex; align-items: center; justify-content: center; margin: 0; }
.topbar h1 img { display: block; width: clamp(118px, 18vw, 190px); height: auto; border: 0; }
.logo-refresh { display: block; padding: 4px 6px; text-decoration: none; line-height: 0; }

.left-actions { grid-column: 1; justify-self: start; display: flex; align-items: center; gap: 8px; min-width: 0; }
.left-actions > div { position: relative; }
.left-actions button { min-height: 36px; padding: 7px 9px; font-size: .72rem; }
.top-actions { grid-column: 3; justify-self: end; display: flex; align-items: center; gap: 8px; }
.top-actions button { min-height: 39px; padding: 9px 13px; border-radius: 0; font-size: .75rem; }
.top-actions button:hover { background: transparent; color: var(--ds-ink-bright); }
.top-actions #scientific-mode[aria-pressed="true"],
.top-actions #horoscope-mode[aria-pressed="true"] { background: transparent; color: var(--ds-accent); }
.topbar .primary { min-width: 82px; padding-inline: 14px; }

/* Pop-up menus. They open and close with a click or tap (dogs.js), not with the mouse hovering,
   so they work on phones and from the keyboard. The `hidden` attribute is what closes them. */
.popover {
    position: absolute;
    z-index: 20;
    top: calc(100% + 4px);
    padding: 13px;
    border: 1px solid var(--ds-ink);
    background: var(--ds-panel);
    box-shadow: 6px 7px 0 var(--ds-shadow);
}
.popover[hidden] { display: none; }

.view-options { left: 0; width: 216px; }
.view-options .analysis-toggle:last-of-type { margin-bottom: 0; }
.view-divider { height: 1px; margin: 2px 0 11px; background: var(--ds-ink-line); }
.view-options .menu-action { display: block; width: 100%; margin-top: 11px; padding: 8px 2px 2px; border-top: 1px solid var(--ds-ink-line); font-size: .72rem; text-align: left; }

/* "+ anything else" appears when a mouse rests on "+ DOG". Phones and tablets have no hover, so they get a
   checkbox at the end of the add form instead (.type-toggle, shown in the same conditions below). */
.add-menu { position: relative; padding-bottom: 12px; margin-bottom: -12px; }
.add-dropdown {
    position: absolute;
    z-index: 20;
    top: calc(100% + 4px);
    right: 0;
    width: max-content;
    padding: 6px 9px;
    border: 1px solid var(--ds-ink);
    background: var(--ds-panel);
    box-shadow: 5px 6px 0 var(--ds-shadow);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity .12s ease, transform .12s ease, visibility .12s;
}
.add-menu:hover .add-dropdown,
.add-menu:focus-within .add-dropdown { opacity: 1; visibility: visible; transform: translateY(0); }
.add-dropdown button { min-height: 28px; padding: 4px 2px; }

.search-toggle { width: 36px; padding: 7px !important; line-height: 0; text-decoration: none; }
.search-toggle img { display: block; width: 18px; height: 18px; object-fit: contain; }
.search-toggle[aria-expanded="true"] { color: var(--ds-accent); }
.search-panel {
    position: absolute;
    z-index: 20;
    top: calc(100% + 4px);
    left: 0;
    display: block;
    width: min(310px, calc(100vw - 28px));
    padding: 8px;
    border: 1px solid var(--ds-ink);
    background: var(--ds-panel);
    box-shadow: 6px 7px 0 var(--ds-shadow);
}
.search-panel[hidden] { display: none; }
.search-row { display: flex; }
.search-panel input { min-width: 0; flex: 1; padding: 7px 8px; border: 1px solid var(--ds-ink); background: var(--ds-field); font-size: .68rem; }
.search-row button { width: 30px; min-height: 30px; padding: 0; text-decoration: none; }
.search-results { max-height: min(320px, 50vh); margin: 7px -8px -8px; overflow-y: auto; border-top: 1px solid var(--ds-ink-line); }
.search-results[hidden] { display: none; }
.search-result { display: block; width: 100%; padding: 8px; text-align: left; text-decoration: none; }
.search-result + .search-result { border-top: 1px solid var(--ds-ink-line); }
.search-result strong { display: block; font-size: .7rem; font-weight: 700; }
.search-result span { display: block; margin-top: 2px; overflow: hidden; font-size: .6rem; opacity: .68; text-overflow: ellipsis; white-space: nowrap; }
.search-empty { margin: 0; padding: 10px 8px; font-size: .65rem; opacity: .65; }

.instructions-trigger {
    position: absolute;
    left: 22px;
    bottom: 102px;
    z-index: 10;
    width: max-content;
    min-height: auto;
    padding: 3px 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .08em;
}
.instructions-trigger:hover { background: var(--ds-ink-hover); }
.rainbow-word > span { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 5px; }
.rainbow-word > span:nth-child(1), .rainbow-word > span:nth-child(9) { color: #ed1c24; }
.rainbow-word > span:nth-child(2), .rainbow-word > span:nth-child(10) { color: #f58220; }
.rainbow-word > span:nth-child(3) { color: #ffd400; }
.rainbow-word > span:nth-child(4) { color: #00a651; }
.rainbow-word > span:nth-child(5) { color: #00aeef; }
.rainbow-word > span:nth-child(7) { color: #2e3192; }
.rainbow-word > span:nth-child(8) { color: #92278f; }
.instructions-trigger.seen .rainbow-word > span { color: var(--ds-ink); }


/* 5. 3D view, panels and controls --------------------------------------- */

.viewer { position: fixed; inset: 72px 0 0; }
#space-canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#space-canvas.dragging { cursor: grabbing; }

.axis-key {
    position: absolute;
    left: 22px;
    bottom: 20px;
    z-index: 10;
    display: grid;
    grid-template-columns: max-content 70px max-content;
    gap: 6px 9px;
    align-items: center;
    font-size: .69rem;
    letter-spacing: .07em;
    pointer-events: none;
}
.axis-key i { display: block; height: 1px; background: var(--ds-ink); opacity: .55; }
.axis-key span:nth-child(3n) { text-align: right; }
.axis-key b { font-size: .82rem; }

.instructions-overlay {
    position: fixed;
    inset: 72px 0 0;
    z-index: 7;
    display: grid;
    place-items: center;
    padding: 10px 16px 12px;
    background: var(--ds-veil);
    backdrop-filter: blur(6px);
}
.instructions-overlay[hidden] { display: none; }
.instructions-overlay img {
    display: block;
    width: auto;
    height: calc(100vh - 94px);
    height: calc(100dvh - 94px);
    max-width: calc(100vw - 32px);
    object-fit: contain;
    border: 0;
}
.instructions-close {
    position: absolute;
    top: 14px;
    right: 18px;
    z-index: 2;
    width: 44px;
    height: 44px;
    padding: 0 0 3px;
    border: 0;
    border-radius: 50%;
    background: var(--ds-ink);
    color: var(--ds-page);
    font-size: 2rem;
    line-height: 1;
    box-shadow: 0 5px 18px var(--ds-shadow-strong);
    text-decoration: none;
}
.instructions-close:hover { background: var(--ds-ink-bright); }

.view-controls { position: absolute; right: 22px; bottom: 20px; display: flex; gap: 4px; }
.view-controls button { height: 34px; min-width: 38px; padding: 0 10px; background: var(--ds-panel-glass); text-decoration: none; }
.view-controls button:hover { background: var(--ds-panel); }
#reset-view, #custom-pov-toggle { font-size: .68rem; letter-spacing: .04em; }

.analysis-panel,
.constellation-editor,
.horoscope-panel {
    position: absolute;
    z-index: 6;
    top: 18px;
    left: 22px;
    width: min(230px, calc(100vw - 44px));
    padding: 14px;
    border: 1px solid var(--ds-ink);
    background: var(--ds-panel-soft);
    box-shadow: 6px 7px 0 var(--ds-shadow);
}
.analysis-panel { left: 22px; right: auto; }
.analysis-panel[hidden], .constellation-editor[hidden], .horoscope-panel[hidden] { display: none; }
.analysis-panel h2, .constellation-editor h2 { margin: 0 0 12px; font-size: .78rem; letter-spacing: .08em; }
.analysis-heading { display: flex; align-items: flex-start; justify-content: space-between; }
.analysis-heading h2 { margin-bottom: 12px; }
.analysis-panel .panel-collapse { width: 24px; height: 22px; margin: -5px -5px 0 0; padding: 0; text-decoration: none; line-height: 1; }
.analysis-toggle { display: flex; gap: 7px; align-items: center; margin-bottom: 12px; font-size: .72rem; cursor: pointer; }
.analysis-toggle input { accent-color: var(--ds-accent); }
.analysis-toggle input:checked + span { color: var(--ds-accent); }
.analysis-panel button { padding: 4px 2px; font-size: .72rem; }

.horoscope-panel {
    top: auto;
    right: 22px;
    bottom: 106px;
    left: auto;
    width: min(310px, calc(100vw - 44px));
    transform: none;
}
.horoscope-panel h2 { margin: 0 0 9px; font-size: .72rem; letter-spacing: .08em; }
.observer-fields { display: grid; gap: 9px; }
.observer-fields .observer-axis { margin: 0; }
.observer-fields .observer-axis > div:first-child { font-size: .68rem; }
.observer-fields .observer-axis output { min-width: 9ch; font-size: .62rem; }
.observer-axis .axis-ends { font-size: .54rem; }
.horoscope-panel > button { margin-top: 8px; padding: 3px 1px; font-size: .65rem; }
body.sky-chart .axis-key { display: none; }
body.sky-chart #zoom-in,
body.sky-chart #zoom-out { display: none; }

.constellation-editor { z-index: 9; top: 18px; left: 22px; width: min(280px, calc(100vw - 44px)); }
.constellation-editor > p { margin: 0 0 12px; font-size: .7rem; line-height: 1.4; }
.colour-field { display: flex; align-items: center; justify-content: space-between; margin: 10px 0; font-size: .72rem; }
.colour-field input { width: 42px; height: 28px; padding: 0; border: 0; background: transparent; cursor: pointer; }
.constellation-editor .constellation-count { margin-bottom: 0; opacity: .72; }
.constellation-editor .form-status { margin: 7px 0 0; }
.constellation-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.constellation-actions .danger { margin-right: auto; }
.constellation-actions button { padding: 5px 3px; font-size: .7rem; }

.viewer-status {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    font-size: .69rem;
    letter-spacing: .08em;
    pointer-events: none;
}
.viewer-status:empty { display: none; }


/* 6. Dog card, cluster card, picture viewer, undo notice ------------------ */

.dog-card, .cluster-card {
    position: fixed;
    z-index: 8;
    top: 92px;
    right: 22px;
    border: 1px solid var(--ds-ink);
    background: var(--ds-panel);
}
.dog-card[hidden], .cluster-card[hidden] { display: none; }

.dog-card {
    width: min(320px, calc(100vw - 24px));
    max-height: calc(100dvh - 112px);
    overflow-y: auto;
    padding: 16px;
    box-shadow: 6px 7px 0 var(--ds-shadow);
}

.card-picture {
    position: relative;
    display: block;
    width: 168px;
    height: 168px;
    margin: 4px auto 14px;
    padding: 0;
    border: 1px solid var(--ds-ink-line);
    border-radius: 50%;
    overflow: hidden;
    background: var(--ds-page);
    text-decoration: none;
    cursor: zoom-in;
}
.card-picture:hover { background: var(--ds-page); }
.card-picture img { display: block; width: 100%; height: 100%; object-fit: cover; }
.card-picture::after {
    content: "\2922";   /* arrows pointing out: "make bigger" */
    position: absolute;
    right: 14px;
    bottom: 14px;
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--ds-ink);
    color: var(--ds-paper);
    font-size: 1rem;
    line-height: 1;
    opacity: .85;
}
.card-picture:hover::after, .card-picture:focus-visible::after { opacity: 1; }

.card-close { position: absolute; top: 6px; right: 6px; width: 34px; height: 34px; padding: 0; border: 0; font-size: 1.3rem; text-decoration: none; }
.card-name { margin: 0 0 2px; font-size: 1.2rem; letter-spacing: .02em; text-align: center; overflow-wrap: anywhere; }
.card-breed { margin: 0 0 10px; font-size: .88rem; text-align: center; opacity: .75; overflow-wrap: anywhere; }
.coordinates { margin: 0 0 10px; font-size: .82rem; letter-spacing: .03em; text-align: center; }
.notes { margin: 0; max-height: 220px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .95rem; line-height: 1.4; }
.notes:empty::after { content: "NO NOTES"; opacity: .45; }
.card-timestamp { margin: 10px 0 0; font-size: .72rem; letter-spacing: .02em; opacity: .64; }
.card-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--ds-ink-line); }
.card-actions #view-from-item { grid-column: 1 / -1; }
.card-actions button { padding: 8px 4px; font-size: .8rem; letter-spacing: .03em; }

.cluster-card { width: min(300px, calc(100vw - 44px)); padding: 18px; box-shadow: 8px 10px 0 var(--ds-shadow); }
.cluster-card h2 { margin: 0 34px 14px 0; font-size: .9rem; letter-spacing: .06em; }
.cluster-members { display: grid; grid-template-columns: repeat(auto-fit, minmax(64px, 1fr)); gap: 14px 8px; }
.cluster-member { min-width: 0; text-align: center; }
.cluster-member img { display: block; width: 52px; height: 52px; margin: 0 auto 5px; border-radius: 50%; object-fit: cover; }
.cluster-member span { display: block; overflow: hidden; font-size: .75rem; text-overflow: ellipsis; white-space: nowrap; }

/* Full-size picture viewer */
#image-viewer {
    width: fit-content;
    height: fit-content;
    max-width: 96vw;
    max-height: 96vh;
    padding: 14px 14px 12px;
    text-align: center;
}
#image-viewer img {
    display: block;
    width: min(92vw, 82vh, 920px);
    height: min(92vw, 82vh, 920px);
    object-fit: contain;
    background: var(--ds-page);
}
#image-viewer figcaption { margin: 10px 30px 0; font-size: .95rem; overflow-wrap: anywhere; }
#image-viewer figure { margin: 0; }
#image-viewer .dialog-close { position: absolute; top: 6px; right: 6px; background: var(--ds-paper); border-radius: 50%; }

/* "Deleted. Undo" notice */
.toast {
    position: fixed;
    left: 50%;
    bottom: max(78px, calc(env(safe-area-inset-bottom) + 70px));
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 14px;
    max-width: calc(100vw - 28px);
    padding: 10px 14px;
    border: 1px solid var(--ds-ink);
    background: var(--ds-paper);
    box-shadow: 5px 6px 0 var(--ds-shadow-strong);
    font-size: .8rem;
    transform: translateX(-50%);
    text-transform: lowercase;
}
.toast[hidden] { display: none; }
.toast button { padding: 6px 8px; font-weight: 700; }


/* 7. Add / edit dialog ------------------------------------------------- */

dialog {
    width: min(860px, calc(100vw - 28px));
    max-height: calc(100vh - 28px);
    padding: 0;
    color: var(--ds-ink);
    background: var(--ds-paper);
    border: 1px solid var(--ds-ink);
    box-shadow: 12px 14px 0 var(--ds-shadow-strong);
    overscroll-behavior: contain;
}
dialog::backdrop { background: rgba(10, 10, 40, .42); backdrop-filter: blur(3px); }
dialog form { padding: 22px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.dialog-heading h2 { margin: 0; font-size: 1rem; letter-spacing: .1em; }
.dialog-close { border: 0; width: 34px; height: 34px; font-size: 1.5rem; text-decoration: none; }
.form-layout { display: grid; grid-template-columns: minmax(250px, .86fr) minmax(300px, 1.14fr); gap: 34px; }
.form-layout h3 { margin: 0 0 12px; font-size: .7rem; letter-spacing: .12em; }
#dog-photo, #theme-bg-file { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.file-button { display: inline-block; margin-bottom: 10px; padding: 8px 12px; border: 0; font-size: .7rem; letter-spacing: .06em; cursor: pointer; text-decoration: underline; text-underline-offset: 4px; }
.file-button:hover { background: var(--ds-ink-hover); }
.crop-stage { position: relative; width: min(100%, 330px); aspect-ratio: 1; background: var(--ds-page-deep); overflow: hidden; cursor: move; touch-action: none; overscroll-behavior: none; user-select: none; -webkit-user-select: none; }
.crop-stage::after { content: ""; position: absolute; inset: 0; border: 1px solid var(--ds-ink); pointer-events: none; }
#crop-canvas { display: block; width: 100%; height: 100%; }
#crop-prompt { position: absolute; inset: 50% auto auto 50%; transform: translate(-50%,-50%); width: 90%; margin: 0; text-align: center; font-size: .72rem; letter-spacing: .08em; pointer-events: none; }
#crop-prompt::before { content: "+"; display: block; margin-bottom: 4px; font-size: 2.6rem; line-height: 1; }
/* Until a picture is chosen the whole square works like the CHOOSE IMAGE button. */
.crop-stage.empty { cursor: pointer; }
.crop-stage.empty:hover { background: color-mix(in srgb, var(--ds-page-deep) 86%, var(--ds-ink)); }
.crop-stage.empty:focus-visible { outline: 3px solid var(--ds-ink-focus); outline-offset: 3px; }

.type-toggle { display: none; align-items: center; gap: 12px; margin-top: 22px; font-size: .84rem; cursor: pointer; }
.type-toggle input { flex: none; width: 24px; height: 24px; margin: 0; accent-color: var(--ds-accent); }

/* Phones, tablets and narrow windows: no hover, so no hover menu; the add form has the checkbox instead. */
@media (max-width: 680px), (hover: none), (pointer: coarse) {
    .add-dropdown { display: none; }
    .type-toggle { display: flex; }
}
.zoom-label, .notes-label { display: flex; justify-content: space-between; margin: 12px 0 6px; font-size: .7rem; letter-spacing: .07em; }
.identity-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 22px; }
.text-input { width: 100%; min-width: 0; padding: 9px 11px; border: 1px solid var(--ds-ink); background: var(--ds-field); }
input[type="range"] { width: 100%; accent-color: var(--ds-ink); }
.axis-input { margin-bottom: 24px; }
.axis-input > div:first-child { display: flex; justify-content: space-between; align-items: baseline; font-size: .82rem; }
.axis-input output { min-width: 10ch; text-align: right; font-size: .76rem; }
.axis-ends { display: flex; justify-content: space-between; font-size: .62rem; letter-spacing: .04em; opacity: .72; }
textarea { width: 100%; resize: vertical; min-height: 116px; padding: 11px; border: 1px solid var(--ds-ink); background: var(--ds-field); line-height: 1.45; }
.form-status { min-height: 1.3em; margin: 16px 0 0; font-size: .76rem; }
.form-status.error { color: var(--ds-danger); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.form-actions button { padding: 10px 14px; font-size: .72rem; letter-spacing: .06em; }


/* 8. Themes dialog ----------------------------------------------------- */

#theme-dialog { width: min(640px, calc(100vw - 28px)); }
.theme-panel { padding: 22px; }
.theme-note { margin: -8px 0 16px; font-size: .74rem; opacity: .75; }
.theme-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 10px; margin-bottom: 18px; }
.theme-choice {
    display: block;
    padding: 10px;
    border: 1px solid var(--ds-ink-line);
    text-align: left;
    text-decoration: none;
}
.theme-choice[aria-checked="true"] { border: 2px solid var(--ds-accent); padding: 9px; }
.theme-choice strong { display: block; margin-top: 8px; font-size: .82rem; }
.theme-choice span.theme-blurb { display: block; margin-top: 2px; font-size: .68rem; opacity: .7; }
.theme-swatches { display: flex; height: 22px; border: 1px solid var(--ds-ink-line); }
.theme-swatches i { flex: 1; }
.theme-custom { margin: 0 0 14px; border-top: 1px solid var(--ds-ink-line); padding-top: 12px; }
.theme-custom summary { cursor: pointer; font-size: .8rem; letter-spacing: .06em; }
.theme-custom h3 { margin: 16px 0 8px; font-size: .7rem; letter-spacing: .12em; }
.theme-colours { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px 16px; margin-top: 12px; }
.theme-colour { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: .72rem; }
.theme-colour input { flex: none; width: 42px; height: 28px; padding: 0; border: 0; background: transparent; cursor: pointer; }
.theme-background { display: grid; gap: 10px; }
.theme-background-choices { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .74rem; }
.theme-background-choices label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.theme-background .theme-field { display: grid; grid-template-columns: 90px 1fr; align-items: center; gap: 10px; font-size: .72rem; }
.theme-background select { padding: 6px 8px; border: 1px solid var(--ds-ink); background: var(--ds-field); }
.theme-background[data-source="none"] .theme-field,
.theme-background[data-source="none"] .file-button { display: none; }
.theme-background[data-source="theme"] .file-button { display: none; }


/* 9. Phones ------------------------------------------------------------ */

@media (max-width: 680px) {
    .topbar { height: 62px; padding: 10px 13px; }
    .topbar h1 img { width: 112px; }
    .instructions-trigger { left: 12px; bottom: max(92px, calc(env(safe-area-inset-bottom) + 84px)); min-height: auto; padding: 2px 0; font-size: .66rem; }
    .left-actions { gap: 2px; }
    .left-actions button { min-height: 32px; padding: 5px 6px; font-size: .64rem; }
    .search-toggle { width: 30px; padding: 6px !important; }
    .search-toggle img { width: 16px; height: 16px; }
    .popover, .search-panel { top: calc(100% + 5px); }
    .top-actions { gap: 2px; }
    .top-actions button { min-height: 35px; padding: 7px 5px; font-size: .6rem; }
    .topbar .primary { min-width: 62px; }
    .viewer { top: 62px; }
    .axis-key { left: 12px; bottom: max(18px, calc(env(safe-area-inset-bottom) + 12px)); grid-template-columns: max-content 35px max-content; font-size: .58rem; gap: 5px; }
    .instructions-overlay { inset: 62px 0 0; padding: 8px 10px max(12px, env(safe-area-inset-bottom)); }
    .instructions-overlay img { height: calc(100vh - 84px); height: calc(100dvh - 84px - env(safe-area-inset-bottom)); max-width: calc(100vw - 20px); }
    .instructions-close { top: 10px; right: 10px; width: 40px; height: 40px; }
    .view-controls { right: 12px; bottom: max(18px, calc(env(safe-area-inset-bottom) + 12px)); }
    .analysis-panel { top: 10px; right: auto; left: 12px; }
    .horoscope-panel { top: auto; right: 12px; bottom: max(104px, calc(env(safe-area-inset-bottom) + 98px)); }
    .constellation-editor { top: 10px; left: 12px; }

    .dog-card, .cluster-card { top: 74px; right: 12px; }
    .dog-card { width: min(236px, calc(100vw - 24px)); padding: 12px; max-height: calc(100dvh - 160px); }
    .card-picture { width: 112px; height: 112px; margin-bottom: 10px; }
    .card-picture::after { right: 8px; bottom: 8px; width: 24px; height: 24px; font-size: .85rem; }
    .card-name { font-size: 1rem; }
    .card-breed { font-size: .78rem; }
    .coordinates { font-size: .72rem; }
    .notes { max-height: 110px; font-size: .84rem; }
    .card-timestamp { font-size: .66rem; }
    .card-actions button { padding: 9px 4px; font-size: .72rem; }
    .toast { bottom: max(84px, calc(env(safe-area-inset-bottom) + 76px)); }

    dialog form { min-height: max-content; padding: 16px; }
    .form-layout { grid-template-columns: 1fr; gap: 26px; }
    .identity-fields { grid-template-columns: 1fr; }
    dialog {
        --dialog-top: max(12px, env(safe-area-inset-top));
        --dialog-bottom: max(30px, calc(env(safe-area-inset-bottom) + 22px));
        position: fixed;
        inset: var(--dialog-top) 14px var(--dialog-bottom) 14px;
        width: auto;
        height: calc(100vh - 56px);
        height: calc(100dvh - var(--dialog-top) - var(--dialog-bottom));
        max-width: none;
        max-height: none;
        margin: 0;
        overflow-y: auto;
        overscroll-behavior-y: contain;
        touch-action: pan-y;
        -webkit-overflow-scrolling: touch;
    }
    #image-viewer { inset: 50% auto auto 50%; width: fit-content; height: fit-content; max-width: 96vw; max-height: 96vh; transform: translate(-50%, -50%); overflow: visible; }
    #image-viewer img { width: min(90vw, 70vh); height: min(90vw, 70vh); }
    .theme-panel { padding: 16px; }
    .theme-list { grid-template-columns: 1fr 1fr; }
    .crop-stage { margin-inline: auto; }
    .form-actions { position: sticky; bottom: 0; z-index: 2; margin-inline: -16px; padding: 12px 16px max(18px, calc(env(safe-area-inset-bottom) + 10px)); background: var(--ds-paper); border-top: 1px solid var(--ds-ink-line); }
}

@media (prefers-reduced-motion: reduce) {
    * { scroll-behavior: auto !important; }
}
