:root {
    --ink: #221c16;
    --paper: #e7dccb;
    --card: #f7f1e7;
    --line: #d4c4ae;
    --muted: #6f6256;
    --rust: #8d3822;
    --gold: #a67c45;
    --serif: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
    --sans: "Avenir Next", "Segoe UI", sans-serif;
    color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    min-height: 100vh;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.45;
}
img { max-width: 100%; }
a { color: inherit; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2 { font-family: var(--serif); font-weight: 560; letter-spacing: -0.02em; }
h1 { font-size: clamp(2rem, 4vw, 3.4rem); margin: 0 0 .3rem; }
h2 { font-size: 1.35rem; margin: 0; }

.theme-room {
    --ink: #f4ecdf;
    --paper: #0e0d0c;
    --card: #171512;
    --line: #3a332c;
    --muted: #b5a89a;
    --rust: #e7b2a2;
    --gold: #e4c48a;
    color-scheme: dark;
}

.wrap { width: min(1120px, calc(100% - 32px)); margin: 0 auto; padding-bottom: 64px; }
.wrap.wide { width: min(1440px, calc(100% - 20px)); }
.top { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 22px 0 8px; }
.brand { margin: 0; font-size: 12px; letter-spacing: .34em; text-transform: uppercase; text-decoration: none; }
.brand-block { display: grid; gap: 4px; min-width: 0; }
.brand-note {
    margin: 0;
    max-width: 42ch;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
    letter-spacing: 0;
    text-transform: none;
}
.brand-note a {
    color: inherit;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    opacity: .92;
}
.brand-note a:hover { opacity: 1; }
.brand-note span { margin: 0 .25em; opacity: .55; }
.gate .brand-block { justify-items: center; text-align: center; }
.links { display: flex; align-items: center; gap: 16px; }
.links a { text-decoration: none; }
.title-row { display: flex; justify-content: space-between; align-items: end; gap: 16px; flex-wrap: wrap; margin-top: 12px; }
.muted { color: var(--muted); }
.disk { margin: 6px 0 0; font-size: 14px; }
.disk.is-low { color: var(--rust); font-weight: 600; }
.lede { color: var(--muted); margin-top: 0; }
.back { margin: 8px 0 0; }
.note { max-width: 62ch; white-space: pre-wrap; }
.status, .error { padding: 10px 12px; }
.status { background: #e7f0df; color: #24301c; }
.theme-room .status { background: #24301c; color: #e7f0df; }
.error { background: #f3ddd6; color: #6e291b; }
.theme-room .error { background: #3a221c; color: #f3ddd6; }
.empty { padding: 28px 0; color: var(--muted); }

label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; letter-spacing: .04em; text-transform: uppercase; }
input, textarea {
    width: 100%;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: transparent;
    padding: 8px 0 10px;
    border-radius: 0;
    text-transform: none;
    letter-spacing: 0;
    font-size: 16px;
}
textarea { resize: vertical; }
.check { flex-direction: row; align-items: center; text-transform: none; letter-spacing: 0; font-size: 15px; gap: 8px; }
.check input { width: auto; }

.btn, button.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: var(--ink);
    color: var(--paper);
    text-decoration: none;
    padding: 11px 16px;
    letter-spacing: .03em;
    font-size: 14px;
}
.theme-room .btn { background: var(--gold); color: #1b140c; }
.btn.ghost, .theme-room .btn.ghost { background: transparent; color: inherit; border: 1px solid var(--line); }
button.text, .text {
    background: none;
    border: 0;
    padding: 0;
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 3px;
}
button.danger { background: none; border: 0; color: var(--rust); padding: 12px 0; }

.gate { width: min(420px, calc(100% - 32px)); margin: 12vh auto; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.narrow { max-width: 460px; }

.create {
    display: grid;
    grid-template-columns: 1.5fr .45fr .9fr auto;
    gap: 14px 16px;
    align-items: end;
    margin: 22px 0 28px;
    padding: 16px 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}
.create .wide { grid-column: 1 / -1; }
.share { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; margin: 8px 0 18px; }
.share label { flex: 1; min-width: 240px; }
.panel { margin: 8px 0 22px; }
.panel summary { cursor: pointer; margin-bottom: 12px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }
.card { background: var(--card); border: 1px solid var(--line); }
.card .cover { display: grid; place-items: center; aspect-ratio: 4 / 3; background: #ddd2c2; text-decoration: none; overflow: hidden; }
.theme-room .card .cover { background: #241f1b; }
.card .cover img { width: 100%; height: 100%; object-fit: cover; }
.card .meta { padding: 12px 14px 16px; }
.card .meta a { text-decoration: none; }
.card .meta p { margin: 4px 0 0; }
.card.is-dead { opacity: .72; }

.drop {
    border: 1px dashed var(--line);
    padding: 18px;
    margin: 8px 0 22px;
    background:
        linear-gradient(180deg, rgba(255,255,255,.35), transparent 48%),
        var(--card);
}
.drop.is-over {
    border-color: var(--gold);
    background: rgba(166, 124, 69, .12);
}
.drop.is-busy { outline: 2px solid color-mix(in srgb, var(--gold) 55%, transparent); }
.drop-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}
.drop-copy { min-width: min(100%, 280px); flex: 1; }
.drop-title {
    margin: 0;
    font-family: var(--serif);
    font-size: 1.35rem;
    letter-spacing: -0.02em;
}
.drop-hint {
    margin: 6px 0 0;
    color: var(--muted);
    max-width: 52ch;
    font-size: 14px;
}
.upload-panel {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}
.upload-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: baseline;
    flex-wrap: wrap;
}
.upload-progress {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}
.upload-summary {
    margin: 0;
    font-size: 13px;
    color: var(--muted);
}
.upload-bar {
    position: relative;
    margin-top: 12px;
    height: 8px;
    background: color-mix(in srgb, var(--line) 80%, transparent);
    overflow: hidden;
}
.upload-bar span {
    display: block;
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #8d6a35, var(--gold), #d8b56a);
    background-size: 200% 100%;
    transition: width .35s ease;
}
.upload-panel.is-active .upload-bar span {
    animation: upload-shine 1.1s linear infinite;
}
@keyframes upload-shine {
    from { background-position: 100% 0; }
    to { background-position: -100% 0; }
}
@media (max-width: 560px) {
    .drop-main { align-items: stretch; }
    .drop-main .btn { width: 100%; }
}

.toolbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    padding: 10px 0;
    background: color-mix(in srgb, var(--paper) 92%, transparent);
}
.save-hint {
    margin: 0 0 12px;
    max-width: 52ch;
    font-size: 13px;
}
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
    gap: 10px;
}
.tile {
    position: relative;
    display: flex;
    flex-direction: column;
    background: transparent;
    content-visibility: auto;
    contain-intrinsic-size: 160px 160px;
}
.tile-frame {
    position: relative;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border-radius: 12px;
    background:
        linear-gradient(145deg, color-mix(in srgb, var(--card) 70%, #000 8%), var(--card));
    box-shadow: 0 1px 0 color-mix(in srgb, var(--ink) 6%, transparent);
}
.tile-frame.is-loading::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    background:
        linear-gradient(
            110deg,
            transparent 20%,
            color-mix(in srgb, #fff 18%, transparent) 45%,
            transparent 70%
        ),
        color-mix(in srgb, var(--card) 82%, var(--ink) 8%);
    background-size: 220% 100%, 100% 100%;
    animation: thumb-shimmer 1.15s ease-in-out infinite;
    pointer-events: none;
}
.theme-room .tile-frame.is-loading::before {
    background:
        linear-gradient(
            110deg,
            transparent 20%,
            color-mix(in srgb, #fff 10%, transparent) 45%,
            transparent 70%
        ),
        color-mix(in srgb, var(--card) 88%, #fff 5%);
    background-size: 220% 100%, 100% 100%;
}
@keyframes thumb-shimmer {
    from { background-position: 120% 0, 0 0; }
    to { background-position: -120% 0, 0 0; }
}
.tile button[data-open] {
    display: block;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    background: none;
}
.tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
    opacity: 0;
    transform: scale(1.04);
    transition: opacity .35s ease, transform .45s ease, filter .45s ease;
}
.tile img.is-ready {
    opacity: 1;
    transform: scale(1.001);
}
.tile:hover img.is-ready { transform: scale(1.04); }
@media (hover: none) {
    .tile:hover img.is-ready { transform: none; }
}
@media (prefers-reduced-motion: reduce) {
    .tile-frame.is-loading::before { animation: none; }
    .tile img { transition: none; }
}
.tile-meta { display: flex; flex-direction: column; gap: 2px; padding: 8px 2px 0; font-size: 12px; color: var(--muted); }
.tile-meta span:first-child { color: var(--ink); }
.tile.is-selected .tile-frame {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}
.tick {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 2;
    text-transform: none;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,.35));
}
.tick input { width: 22px; height: 22px; accent-color: #8d3822; }
.heart {
    position: absolute;
    right: 8px;
    bottom: 8px;
    z-index: 2;
    border: 0;
    border-radius: 999px;
    background: rgba(14, 13, 12, .55);
    color: #f4ecdf;
    padding: 6px 9px;
    font-size: 13px;
    backdrop-filter: blur(6px);
}
.heart.is-on { background: var(--rust); color: #fff8f4; }

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(8, 7, 6, .96);
    color: #f4ecdf;
    display: flex;
    flex-direction: column;
}
.lightbox[hidden] { display: none; }
.lb-top, .lb-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px; flex-wrap: wrap; }
.lb-top a, .lb-top button { color: #f4ecdf; }
.lb-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.lb-mark {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-transform: none;
    letter-spacing: 0;
    font-size: 14px;
    color: #f4ecdf;
    cursor: pointer;
    user-select: none;
}
.lb-mark input { width: 18px; height: 18px; accent-color: #e4c48a; }
.stage { position: relative; flex: 1; display: grid; grid-template-columns: auto 1fr auto; place-items: center; min-height: 0; }
.stage.is-loading::before {
    content: "";
    position: absolute;
    width: min(42vw, 180px);
    height: min(42vw, 180px);
    border-radius: 18px;
    background:
        linear-gradient(
            110deg,
            transparent 20%,
            rgba(255,255,255,.12) 45%,
            transparent 70%
        ),
        rgba(255,255,255,.06);
    background-size: 220% 100%, 100% 100%;
    animation: thumb-shimmer 1.15s ease-in-out infinite;
    pointer-events: none;
}
.stage img {
    max-width: min(100%, 1400px);
    max-height: calc(100vh - 140px);
    object-fit: contain;
    touch-action: none;
    opacity: 0;
    transition: opacity .28s ease;
}
.stage img.is-ready { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
    .stage.is-loading::before { animation: none; }
    .stage img { transition: none; }
}
.nav { width: 48px; height: 72px; border: 0; background: transparent; color: #f4ecdf; font-size: 42px; }
.hint { color: #b5a89a; font-size: 13px; }
body.is-locked { overflow: hidden; }

.stats-panel {
    margin: 18px 0 22px;
    padding: 16px 18px;
    border: 1px solid var(--line);
    background: color-mix(in srgb, var(--card) 88%, transparent);
}
.stats-panel h2 { margin-bottom: 4px; font-size: 1.15rem; }
.stats-list {
    list-style: none;
    margin: 12px 0 0;
    padding: 0;
    display: grid;
    gap: 6px;
}
.stats-list li {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 6px 0;
    border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
    font-size: 14px;
}
.stats-list li:last-child { border-bottom: 0; }
.stats-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats-count { color: var(--muted); flex: none; font-variant-numeric: tabular-nums; }

.site-credit {
    margin: 48px 0 8px;
    padding-top: 18px;
    border-top: 1px solid color-mix(in srgb, var(--line) 65%, transparent);
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
}
.site-credit p { margin: 0; }
.site-credit a {
    color: inherit;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    opacity: .92;
}
.site-credit a:hover { opacity: 1; }
.site-credit-soft { margin-top: 2px !important; opacity: .78; }
.gate .site-credit { margin-top: 28px; border-top: 0; padding-top: 0; text-align: center; }

@media (max-width: 860px) {
    .create { grid-template-columns: 1fr 1fr; }
    .create button.btn { grid-column: 1 / -1; }
    .hint { display: none; }
    .nav { width: 36px; }
    .grid { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; }
    .tile-frame { border-radius: 10px; }
}
@media (max-width: 560px) {
    .create { grid-template-columns: 1fr; }
}
