:root {
    color-scheme: dark light;
    --bg: #1a1412;
    --surface: #261d1a;
    --surface-2: #33261f;
    --text: #f6ede6;
    --muted: #b9a79b;
    --accent: #ff6a1a;
    --accent-2: #ffb02e;
    --accent-text: #1a0e07;
    --danger: #ff5a5a;
    --line: #47352c;
    --radius: 16px;
    --shadow: 0 6px 24px rgb(0 0 0 / 0.35);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #fbf5f0;
        --surface: #ffffff;
        --surface-2: #f4e9e0;
        --text: #24160f;
        --muted: #6f5b4f;
        --accent: #e4520a;
        --accent-2: #f39a12;
        --accent-text: #ffffff;
        --danger: #c62828;
        --line: #ead8cb;
        --shadow: 0 4px 18px rgb(80 40 10 / 0.10);
    }
}

* { box-sizing: border-box; }

html, body { margin: 0; background: var(--bg); color: var(--text); }

body {
    min-height: 100dvh;
    -webkit-tap-highlight-color: transparent;
    line-height: 1.45;
}

main {
    max-width: 560px;
    margin: 0 auto;
    padding: 12px 16px calc(96px + env(safe-area-inset-bottom));
    display: grid;
    gap: 12px;
}

h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.2rem; }
h2 { font-size: 1.05rem; }

a { color: var(--accent-2); }

.bar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
}
.bar h1 { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .back { font-size: 2rem; line-height: 1; text-decoration: none; color: var(--text); padding: 0 6px; }
.bar .logo { font-size: 1.4rem; }
.bar .bell { text-decoration: none; font-size: 1.2rem; }

.tabs {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 5;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--line);
}
.tabs a {
    display: grid;
    justify-items: center;
    gap: 2px;
    padding: 6px 0;
    color: var(--muted);
    font-size: 0.75rem;
    text-decoration: none;
    border-radius: 12px;
}
.tabs a span { font-size: 1.3rem; line-height: 1; }
.tabs a[aria-current="page"] { color: var(--text); background: var(--surface-2); }
.tabs a.cta span { color: var(--accent); font-weight: 700; }

.card {
    display: grid;
    gap: 12px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    color: inherit;
    text-decoration: none;
}
.card.center { justify-items: center; text-align: center; }
.card.hint { background: var(--surface-2); }
.card.invite { border-color: var(--accent); }

label { display: grid; gap: 6px; font-weight: 600; font-size: 0.92rem; }

input, textarea {
    width: 100%;
    font: inherit;
    font-weight: 400;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px;
    min-height: 46px;
}
input:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
    outline: 2px solid var(--accent-2);
    outline-offset: 2px;
}

button, .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 46px;
    padding: 10px 16px;
    font: inherit;
    font-weight: 600;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 999px;
    cursor: pointer;
    text-decoration: none;
}
button:disabled { opacity: 0.5; cursor: default; }
.primary {
    color: var(--accent-text);
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    border-color: transparent;
}
.big { min-height: 64px; font-size: 1.1rem; width: 100%; border-radius: var(--radius); }
button.link { background: none; border: none; color: var(--muted); text-decoration: underline; min-height: 36px; padding: 4px; font-weight: 400; }
.danger { color: var(--danger); }
button.danger:not(.link) { border-color: var(--danger); background: none; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row input { flex: 1; min-width: 0; }
.row > button { flex: 0 0 auto; }

.small { color: var(--muted); font-size: 0.85rem; margin: 0; }
.empty { text-align: center; color: var(--muted); padding: 32px 0; display: grid; gap: 12px; justify-items: center; }
.hero { font-size: 4rem; margin: 0; line-height: 1; text-align: center; }

.welcome { padding-top: 24px; }
.welcome h2 { text-align: center; font-size: 1.4rem; }
details summary { cursor: pointer; font-weight: 600; }
details[open] summary { margin-bottom: 12px; }
details form { display: grid; gap: 12px; }

.post { padding: 0; overflow: hidden; }
.post-link {
    display: grid;
    grid-template-columns: 56px 1fr;
    gap: 4px 12px;
    padding: 12px 14px;
    color: inherit;
    text-decoration: none;
}
.thumb {
    grid-row: span 2;
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    font-size: 1.8rem;
    border-radius: 14px;
    background: var(--surface-2);
}
.post.fresh .thumb { background: radial-gradient(circle at 50% 70%, var(--accent-2), var(--accent) 55%, #7a1d00); animation: glow 2.4s ease-in-out infinite; }
.post.seen { opacity: 0.85; }
.meta { display: grid; min-width: 0; }
.meta span, .meta time { color: var(--muted); font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.counts { display: flex; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: 0.85rem; align-items: center; }
.badge { background: var(--accent); color: var(--accent-text); border-radius: 999px; padding: 0 8px; font-weight: 700; }

@keyframes glow { 50% { filter: brightness(1.25) saturate(1.2); } }
@media (prefers-reduced-motion: reduce) { .post.fresh .thumb { animation: none; } }

.pick { display: grid; gap: 12px; padding-top: 24px; }
.preview { width: 100%; max-height: 50vh; object-fit: cover; border-radius: 12px; }

.reveal { animation: glow 2.4s ease-in-out infinite; }
.gone { margin: 0; padding: 18px; text-align: center; background: var(--surface-2); border-radius: 12px; color: var(--muted); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.map { margin-left: 6px; }

.reactions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.reactions button { min-width: 78px; }
.reactions .chosen { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 22%, var(--surface-2)); }

.comments .comment { margin: 0; padding: 10px 12px; background: var(--surface-2); border-radius: 12px 12px 12px 4px; display: grid; gap: 2px; overflow-wrap: anywhere; }
.comments .comment.mine { border-radius: 12px 12px 4px 12px; background: color-mix(in srgb, var(--accent) 16%, var(--surface-2)); }
.comment time { color: var(--muted); font-size: 0.75rem; }

.qr { width: min(240px, 70vw); height: auto; border-radius: 12px; }
code { font-size: 0.95em; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }

.friends { list-style: none; margin: 0; padding: 0; display: grid; }
.friends li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.friends li:last-child { border-bottom: none; }

#scan-video { width: 100%; border-radius: 12px; background: #000; }

.viewer {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    grid-template-rows: 1fr auto;
    place-items: center;
    padding: env(safe-area-inset-top) 0 calc(16px + env(safe-area-inset-bottom));
    background: #000;
    color: #fff;
}
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.viewer p { margin: 8px 16px 0; color: #ccc; font-size: 0.9rem; }

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(88px + env(safe-area-inset-bottom));
    z-index: 30;
    transform: translateX(-50%);
    width: max-content;
    max-width: calc(100vw - 32px);
    padding: 12px 18px;
    border-radius: 14px;
    background: var(--text);
    color: var(--bg);
    font-weight: 600;
    box-shadow: var(--shadow);
}

h3 { margin: 6px 0 0; font-size: 0.95rem; }
.stack { display: grid; gap: 12px; }
.stack form { display: grid; gap: 8px; padding-top: 8px; border-top: 1px solid var(--line); }

.card.hint { display: flex; gap: 10px; align-items: flex-start; }
section.card.hint { display: grid; }
.steps { margin: 0; padding-left: 22px; display: grid; gap: 10px; }
.steps li { padding-left: 4px; }
.glyph { width: 1.25em; height: 1.25em; vertical-align: -0.25em; color: var(--accent-2); }
.glyph-text { font-weight: 800; color: var(--accent-2); padding: 0 2px; }
.version { text-align: center; }
.version .link { min-height: 0; padding: 0 4px; }

.update-notice {
    position: sticky;
    top: 0;
    z-index: 6;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: calc(6px + env(safe-area-inset-top)) 16px 6px;
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 600;
    font-size: 0.9rem;
}
.update-notice + .bar { top: 0; }
.small-button { min-height: 32px; padding: 4px 12px; font-size: 0.85rem; background: var(--accent-text); color: var(--accent); border: none; }

.avatar { display: inline-grid; place-items: center; flex: none; border-radius: 50%; object-fit: cover; background: var(--surface-2); color: #fff; font-weight: 700; overflow: hidden; }
.avatar.s { width: 28px; height: 28px; font-size: 0.7rem; }
.avatar.m { width: 40px; height: 40px; font-size: 0.9rem; }
.avatar.l { width: 96px; height: 96px; font-size: 2rem; box-shadow: var(--shadow); }
.who { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.big-who { margin: 0; }
.card.invite.who { display: flex; }
.tone-0 { background: hsl(0 55% 42%); }
.tone-1 { background: hsl(30 55% 42%); }
.tone-2 { background: hsl(60 55% 42%); }
.tone-3 { background: hsl(90 55% 42%); }
.tone-4 { background: hsl(120 55% 42%); }
.tone-5 { background: hsl(150 55% 42%); }
.tone-6 { background: hsl(180 55% 42%); }
.tone-7 { background: hsl(210 55% 42%); }
.tone-8 { background: hsl(240 55% 42%); }
.tone-9 { background: hsl(270 55% 42%); }
.tone-10 { background: hsl(300 55% 42%); }
.tone-11 { background: hsl(330 55% 42%); }
.card.news { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.card.news p { margin: 0; white-space: pre-line; }
.card.news .link { justify-self: start; }

.smileys { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; margin: 0 -4px; padding: 2px 4px; }
.smileys::-webkit-scrollbar { display: none; }
.smileys button { flex: none; min-height: 40px; min-width: 40px; padding: 0; font-size: 1.35rem; background: none; border: none; border-radius: 10px; }
.smileys button:active { background: var(--surface-2); transform: scale(1.15); }
.comment-form { display: grid; gap: 6px; }

.recipients { border: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.recipients legend { font-weight: 600; font-size: 0.92rem; padding: 0; margin-bottom: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 40px; padding: 4px 12px 4px 4px; gap: 8px; font-weight: 500; opacity: 0.55; }
.chip.on { opacity: 1; border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, var(--surface-2)); }
.chip.on::after { content: "✓"; color: var(--accent); font-weight: 800; }
