@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;
}

:root {
    --yellow: #fff19a;
    --yellow-deep: #f5df62;
    --blue: #191970;
    --blue-soft: rgba(25, 25, 112, 0.16);
    --paper: #fff8c7;
    color: var(--blue);
    background: var(--yellow);
    font-family: "Plateau Comic Sans", "Comic Sans MS", "Comic Sans", cursive;
    font-synthesis: none;
}

* { 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;
    background: var(--yellow);
    color: var(--blue);
}

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

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

button {
    border: 1px solid var(--blue);
    background: transparent;
    cursor: pointer;
}

button:hover { background: rgba(25, 25, 112, .08); }
button:focus-visible, input:focus-visible, textarea:focus-visible, canvas:focus-visible { outline: 3px solid rgba(25, 25, 112, .38); outline-offset: 3px; }

.primary { background: var(--blue); color: var(--yellow); }
.primary:hover { background: #29298b; }
.danger { color: #7c1643; border-color: #7c1643; }

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

.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(--blue-soft);
    background: rgba(255, 241, 154, .86);
    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; }
.wordmark { color: inherit; text-decoration: none; width: max-content; font-size: .84rem; letter-spacing: .08em; }
.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: transparent; }
.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: #e83f75; }
.rainbow-word > span:nth-child(2), .rainbow-word > span:nth-child(10) { color: #ef7137; }
.rainbow-word > span:nth-child(3) { color: #c39b00; }
.rainbow-word > span:nth-child(4) { color: #2a9b64; }
.rainbow-word > span:nth-child(5) { color: #168cad; }
.rainbow-word > span:nth-child(7) { color: #496bd1; }
.rainbow-word > span:nth-child(8) { color: #9354bd; }
.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: 999px; font-size: .75rem; }
.top-actions #scientific-mode[aria-pressed="true"] { background: var(--yellow-deep); box-shadow: inset 0 0 0 1px var(--blue); }
.topbar .primary { min-width: 82px; padding-inline: 14px; }

.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(--blue); 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: rgba(255, 241, 154, .94);
    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(--blue);
    color: var(--yellow);
    font-size: 2rem;
    line-height: 1;
    box-shadow: 0 5px 18px rgba(25,25,112,.24);
}
.instructions-close:hover { background: #29298b; }

.view-controls {
    position: absolute;
    right: 22px;
    bottom: 20px;
    display: flex;
    box-shadow: 0 7px 24px rgba(25,25,112,.08);
}

.view-controls button { height: 34px; min-width: 38px; padding: 0 10px; background: rgba(255,248,199,.78); }
.view-controls button + button { border-left: 0; }
.view-controls #reset-view { font-size: .68rem; letter-spacing: .08em; }

.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; }

.dog-card {
    position: fixed;
    z-index: 8;
    top: 92px;
    right: 22px;
    width: min(320px, calc(100vw - 44px));
    padding: 18px;
    border: 1px solid var(--blue);
    background: rgba(255,248,199,.96);
    box-shadow: 8px 10px 0 rgba(25,25,112,.12);
}

.dog-card[hidden] { display: none; }
.dog-card img { display: block; width: 112px; height: 112px; margin: 2px auto 18px; border-radius: 50%; object-fit: cover; border: 0; background: var(--yellow); }
.card-close { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; border: 0; font-size: 1.45rem; }
.coordinates { margin: 0 0 12px; font-size: .77rem; letter-spacing: .06em; text-align: center; }
.notes { margin: 0; max-height: 180px; overflow: auto; white-space: pre-wrap; font-size: .94rem; line-height: 1.48; }
.notes:empty::after { content: "NO NOTES"; opacity: .45; }
.card-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 18px; }
.card-actions button { padding: 9px; font-size: .72rem; letter-spacing: .06em; }

dialog {
    width: min(860px, calc(100vw - 28px));
    max-height: calc(100vh - 28px);
    padding: 0;
    color: var(--blue);
    background: var(--paper);
    border: 1px solid var(--blue);
    box-shadow: 12px 14px 0 rgba(25,25,112,.2);
    overscroll-behavior: contain;
}

dialog::backdrop { background: rgba(25,25,80,.36); 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; }
.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 { 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: 1px solid var(--blue); font-size: .7rem; letter-spacing: .06em; cursor: pointer; }
.crop-stage { position: relative; width: min(100%, 330px); aspect-ratio: 1; background: var(--yellow-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: 7%; border: 1px solid var(--blue); border-radius: 50%; pointer-events: none; box-shadow: 0 0 0 80px rgba(255,248,199,.68); }
#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; }
.zoom-label, .notes-label { display: flex; justify-content: space-between; margin: 12px 0 6px; font-size: .7rem; letter-spacing: .07em; }
input[type="range"] { width: 100%; accent-color: var(--blue); }
.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: 3ch; text-align: right; font-size: 1.12rem; }
.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(--blue); background: rgba(255,255,255,.28); line-height: 1.45; }
.form-status { min-height: 1.3em; margin: 16px 0 0; font-size: .76rem; }
.form-status.error { color: #7c1643; }
.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; }

.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; }

@media (max-width: 680px) {
    .topbar { height: 62px; padding: 10px 13px; }
    .topbar h1 img { width: 112px; }
    .wordmark { font-size: .7rem; }
    .instructions-trigger { left: 12px; bottom: max(92px, calc(env(safe-area-inset-bottom) + 84px)); min-height: auto; padding: 2px 0; font-size: .66rem; }
    .top-actions { gap: 5px; }
    .top-actions button { min-height: 35px; padding: 7px 9px; font-size: .66rem; }
    .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)); }
    .dog-card { top: 74px; right: 12px; }
    dialog form { min-height: max-content; padding: 16px; }
    .form-layout { grid-template-columns: 1fr; gap: 26px; }
    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;
    }
    .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(--paper); border-top: 1px solid var(--blue-soft); }
}

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