:root {
    color-scheme: dark;
    --ink: #f2efe8;
    --muted: #aaa99f;
    --glass: rgba(9, 11, 10, 0.74);
    --line: rgba(255, 255, 255, 0.16);
    --accent: #b8d8ca;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: #090b0a;
    color: var(--ink);
    font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

button {
    color: inherit;
    font: inherit;
}

#viewport {
    position: fixed;
    inset: 0;
    overflow: hidden;
    outline: none;
    cursor: grab;
    touch-action: none;
    overscroll-behavior: none;
    background: #090b0a;
}

#viewport.is-dragging {
    cursor: grabbing;
}

#world {
    position: absolute;
    left: 0;
    top: 0;
    width: 5120px;
    height: 2562px;
    transform-origin: 0 0;
    will-change: transform;
    background: #111;
}

#tiles {
    display: grid;
    width: 100%;
    height: 100%;
    grid-template-columns: repeat(8, 640px);
    grid-template-rows: repeat(6, 427px);
}

.tile {
    position: relative;
    min-width: 0;
    min-height: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
    border: 0;
    border-radius: 0;
    background: #171916;
    cursor: pointer;
    text-align: left;
}

.tile::after {
    content: "";
    position: absolute;
    inset: 0;
    border: 1px solid rgba(255, 255, 255, 0.08);
    pointer-events: none;
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

.tile::before {
    content: "REMOVE";
    position: absolute;
    z-index: 2;
    top: 14px;
    right: 14px;
    padding: 6px 9px;
    border: 1px solid rgba(255, 225, 218, 0.82);
    border-radius: 999px;
    background: rgba(111, 24, 17, 0.88);
    color: #fff5f1;
    font-size: 10px;
    font-weight: 750;
    letter-spacing: 0.12em;
    opacity: 0;
    transform: scale(0.86);
    transition: opacity 140ms ease, transform 140ms ease;
    pointer-events: none;
}

.is-curating .tile {
    cursor: crosshair;
}

.is-curating .tile.is-removal::before {
    opacity: 1;
    transform: scale(1);
}

.is-curating .tile.is-removal::after {
    border: 6px solid rgba(218, 73, 58, 0.96);
    box-shadow: inset 0 0 0 2px rgba(255, 235, 226, 0.42);
}

.is-curating .tile.is-removal img {
    filter: grayscale(0.82) brightness(0.42) sepia(0.14);
}

.tile img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    user-select: none;
    transition: filter 180ms ease, transform 420ms cubic-bezier(.2, .8, .2, 1);
}

.tile-label {
    position: absolute;
    left: 14px;
    right: 14px;
    bottom: 12px;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    opacity: 0;
    transform: translateY(5px);
    transition: opacity 160ms ease, transform 160ms ease;
    text-shadow: 0 1px 12px rgba(0, 0, 0, 0.95);
    pointer-events: none;
}

.tile-label strong {
    flex: 0 0 auto;
    font-size: 12px;
    letter-spacing: 0.12em;
}

.tile-label span {
    flex: 1 1 auto;
    overflow: hidden;
    color: rgba(255, 255, 255, 0.9);
    font-size: 13px;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tile-label em {
    flex: 0 0 auto;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 999px;
    padding: 4px 7px;
    color: #fff;
    font-size: 9px;
    font-style: normal;
    font-weight: 600;
    letter-spacing: 0.08em;
    line-height: 1;
    text-transform: uppercase;
}

.tile:hover img,
.tile:focus-visible img {
    filter: brightness(0.68) saturate(0.82);
    transform: scale(1.015);
}

.tile:hover .tile-label,
.tile:focus-visible .tile-label {
    opacity: 1;
    transform: translateY(0);
}

.tile:hover::after,
.tile:focus-visible::after {
    border-color: rgba(184, 216, 202, 0.88);
    box-shadow: inset 0 0 0 1px rgba(184, 216, 202, 0.3);
}

.tile:focus-visible {
    outline: none;
}

.chrome {
    z-index: 20;
    border: 1px solid var(--line);
    background: var(--glass);
    box-shadow: 0 14px 50px rgba(0, 0, 0, 0.24);
    backdrop-filter: blur(18px) saturate(1.1);
    -webkit-backdrop-filter: blur(18px) saturate(1.1);
}

.topbar {
    position: fixed;
    top: max(18px, env(safe-area-inset-top));
    left: max(18px, env(safe-area-inset-left));
    display: flex;
    align-items: center;
    max-width: calc(100vw - 36px);
    padding: 10px 16px 10px 10px;
    border-radius: 14px;
}

.home-link {
    display: grid;
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.13);
    border-radius: 10px;
    color: var(--accent);
    font-size: 22px;
    text-decoration: none;
    transition: background 160ms ease, border-color 160ms ease;
}

.home-link:hover,
.home-link:focus-visible {
    border-color: var(--accent);
    background: rgba(184, 216, 202, 0.12);
    outline: none;
}

.identity {
    min-width: 0;
    margin: 0 12px;
}

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

.identity h1 {
    font-family: Georgia, "Times New Roman", serif;
    font-size: 18px;
    font-weight: 500;
    letter-spacing: 0.025em;
}

.identity p {
    margin-top: 3px;
    overflow: hidden;
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.035em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mode-link {
    flex: 0 0 auto;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 8px;
    padding: 7px 9px;
    color: var(--accent);
    font-size: 9px;
    font-weight: 650;
    letter-spacing: 0.1em;
    text-decoration: none;
    text-transform: uppercase;
    background: transparent;
    cursor: pointer;
}

.mode-actions {
    display: flex;
    flex: 0 0 auto;
    gap: 6px;
}

#curation-toggle[aria-pressed="true"] {
    border-color: #f09a83;
    background: rgba(140, 40, 27, 0.34);
    color: #ffd8cd;
}

.mode-link:hover,
.mode-link:focus-visible {
    border-color: var(--accent);
    background: rgba(184, 216, 202, 0.12);
    outline: none;
}

.zoom-controls {
    position: fixed;
    right: max(18px, env(safe-area-inset-right));
    bottom: max(18px, env(safe-area-inset-bottom));
    display: grid;
    overflow: hidden;
    border-radius: 12px;
}

.zoom-controls button {
    width: 44px;
    height: 42px;
    padding: 0;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: transparent;
    color: var(--ink);
    font-size: 22px;
    cursor: pointer;
    transition: background 140ms ease, color 140ms ease;
}

.zoom-controls button:last-child {
    border-bottom: 0;
    font-size: 17px;
}

.zoom-controls button:hover,
.zoom-controls button:focus-visible {
    background: rgba(184, 216, 202, 0.14);
    color: var(--accent);
    outline: none;
}

.gesture-hint {
    position: fixed;
    left: max(18px, env(safe-area-inset-left));
    bottom: max(18px, env(safe-area-inset-bottom));
    margin: 0;
    padding: 8px 11px;
    border-radius: 9px;
    color: rgba(255, 255, 255, 0.68);
    font-size: 10px;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    transition: opacity 450ms ease;
    pointer-events: none;
}

.gesture-hint.is-hidden {
    opacity: 0;
}

.gesture-hint strong {
    color: var(--accent);
    font-weight: 650;
}

.is-curating .gesture-hint {
    opacity: 0;
}

.curation-panel {
    position: fixed;
    left: max(18px, env(safe-area-inset-left));
    bottom: max(18px, env(safe-area-inset-bottom));
    display: grid;
    width: min(690px, calc(100vw - 100px));
    padding: 13px 14px;
    border-color: rgba(240, 154, 131, 0.5);
    border-radius: 14px;
    grid-template-columns: minmax(170px, 1fr) auto;
    gap: 10px 18px;
    opacity: 0;
    transform: translateY(12px);
    visibility: hidden;
    transition: opacity 180ms ease, transform 180ms ease, visibility 180ms ease;
}

.curation-panel.is-open {
    opacity: 1;
    transform: translateY(0);
    visibility: visible;
}

.curation-summary {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 3px;
}

.curation-summary strong {
    color: #ffd8cd;
    font-size: 12px;
    letter-spacing: 0.055em;
    text-transform: uppercase;
}

.curation-summary span,
#curation-status {
    color: var(--muted);
    font-size: 10px;
    line-height: 1.35;
}

.curation-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.curation-actions button {
    padding: 7px 9px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--ink);
    font-size: 9px;
    font-weight: 650;
    letter-spacing: 0.075em;
    text-transform: uppercase;
    cursor: pointer;
}

.curation-actions button:hover,
.curation-actions button:focus-visible {
    border-color: #f09a83;
    background: rgba(140, 40, 27, 0.26);
    outline: none;
}

.curation-actions button:disabled {
    opacity: 0.36;
    cursor: default;
}

#curation-status {
    margin: 0;
    grid-column: 1 / -1;
}

.touch-hint {
    display: none;
}

.loading {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background: #090b0a;
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    transition: opacity 420ms ease, visibility 420ms ease;
}

.loading-mark {
    color: var(--accent);
    font-size: 38px;
    animation: breathe 1.8s ease-in-out infinite;
}

.loading.is-hidden {
    visibility: hidden;
    opacity: 0;
}

@keyframes breathe {
    0%, 100% { opacity: 0.34; transform: scale(0.95); }
    50% { opacity: 1; transform: scale(1.03); }
}

.details {
    position: fixed;
    z-index: 30;
    top: 0;
    right: 0;
    width: min(470px, 92vw);
    height: 100%;
    border-left: 1px solid var(--line);
    background: rgba(8, 10, 9, 0.93);
    box-shadow: -30px 0 80px rgba(0, 0, 0, 0.52);
    backdrop-filter: blur(24px) saturate(0.9);
    -webkit-backdrop-filter: blur(24px) saturate(0.9);
    transform: translateX(104%);
    transition: transform 320ms cubic-bezier(.2, .8, .2, 1);
    pointer-events: none;
}

.details.is-open {
    transform: translateX(0);
    pointer-events: auto;
}

.detail-close {
    position: absolute;
    z-index: 2;
    top: max(14px, env(safe-area-inset-top));
    right: max(14px, env(safe-area-inset-right));
    display: grid;
    width: 38px;
    height: 38px;
    padding: 0;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 50%;
    background: rgba(7, 8, 7, 0.78);
    color: #fff;
    font-size: 25px;
    line-height: 1;
    cursor: pointer;
}

.detail-close:hover,
.detail-close:focus-visible {
    border-color: var(--accent);
    color: var(--accent);
    outline: none;
}

.detail-scroll {
    height: 100%;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0 28px max(38px, env(safe-area-inset-bottom));
}

.detail-figure {
    width: calc(100% + 56px);
    aspect-ratio: 3 / 2;
    margin: 0 0 26px -28px;
    overflow: hidden;
    background: #111;
}

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

.detail-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: var(--accent);
    font-size: 10px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

#detail-source {
    margin: 9px 0 0;
    overflow: hidden;
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.035em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.details h2 {
    margin: 10px 0 28px;
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(28px, 4vw, 40px);
    font-weight: 400;
    line-height: 1.05;
}

.prompt-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--line);
    padding-bottom: 9px;
}

.prompt-heading h3 {
    margin: 0;
    color: var(--muted);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

#copy-prompt {
    padding: 4px 8px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--accent);
    font-size: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
}

#copy-prompt:hover,
#copy-prompt:focus-visible {
    border-color: var(--accent);
    outline: none;
}

#detail-prompt {
    margin: 20px 0 0;
    color: #d5d3cb;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.62;
    white-space: pre-wrap;
}

@media (max-width: 700px) {
    .topbar {
        top: max(10px, env(safe-area-inset-top));
        left: max(10px, env(safe-area-inset-left));
        max-width: calc(100vw - 20px);
    }

    .identity p {
        display: none;
    }

    .identity {
        margin-right: 8px;
        margin-left: 8px;
    }

    .identity h1 {
        overflow: hidden;
        font-size: 15px;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .zoom-controls {
        right: max(10px, env(safe-area-inset-right));
        bottom: max(10px, env(safe-area-inset-bottom));
    }

    .gesture-hint {
        left: max(10px, env(safe-area-inset-left));
        bottom: max(10px, env(safe-area-inset-bottom));
    }

    .curation-panel {
        left: max(10px, env(safe-area-inset-left));
        bottom: max(10px, env(safe-area-inset-bottom));
        width: calc(100vw - 74px);
        grid-template-columns: 1fr;
    }

    .curation-actions {
        flex-wrap: wrap;
    }

    #curation-status {
        grid-column: 1;
    }

    .desktop-hint {
        display: none;
    }

    .touch-hint {
        display: inline;
    }

    .details {
        top: auto;
        bottom: 0;
        width: 100%;
        height: min(82vh, 760px);
        border-top: 1px solid var(--line);
        border-left: 0;
        border-radius: 20px 20px 0 0;
        transform: translateY(104%);
    }

    .details.is-open {
        transform: translateY(0);
    }

    .detail-scroll {
        padding-right: 22px;
        padding-left: 22px;
    }

    .detail-figure {
        width: calc(100% + 44px);
        aspect-ratio: 16 / 7;
        margin-left: -22px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}
