/* Ours web (docs/ui.md): always dark, one accent (sand), red only for destroying, green for a
   check that passed. No shadows or gradients. System fonts only (font-src 'self', none loaded). */

:root {
  color-scheme: dark;
  --bg: #0e0e0f;
  --surface: #1a1a1c;
  --surface-2: #232326;
  --line: #2c2c30;
  --text: #eceae6;
  --muted: #8e8c87;
  --sand: #d9b68c;
  --sand-ink: #2b2116;
  --red: #e5675c;
  --green: #7fbf8e;
  --radius: 14px;
  --radius-small: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { overflow: hidden; -webkit-font-smoothing: antialiased; }
#root { height: 100%; }
h1 { font-size: 1.5rem; font-weight: 600; margin: 0.5rem 0; }
h2 { font-size: 1.15rem; font-weight: 600; margin: 0.25rem 0 0.75rem; }
h3 { font-size: 0.95rem; font-weight: 600; margin: 1rem 0 0.5rem; color: var(--muted); }
p { margin: 0.4rem 0; }
a { color: var(--sand); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--red); }
.warn { color: var(--sand); }
.spacer { flex: 1; }
.center { display: grid; place-items: center; height: 100%; }

/* ---- Content protection (docs/web-leakage.md §5.5) ---- */
.secure, .secure * { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.secure img, .secure canvas, .secure video { -webkit-user-drag: none; }
.secure textarea, .secure input { -webkit-user-select: text; user-select: text; }
.media-shield { position: absolute; inset: 0; }
html.veiled #root, html.veiled #overlays { visibility: hidden; }
#veil { display: none; }
html.veiled #veil { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; align-content: center; gap: 1rem; background: var(--bg); color: var(--muted); }
@media print { html, body { display: none !important; } }

/* ---- Icons and logo ---- */
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon-play { fill: currentColor; }
.logo .ring-sand { fill: none; stroke: var(--sand); stroke-width: 3.5; }
.logo .ring-white { fill: none; stroke: var(--text); stroke-width: 3.5; }

/* ---- Buttons and inputs ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; min-height: 44px; padding: 0.6rem 1.2rem;
  border-radius: 999px; border: 1px solid transparent; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--sand); color: var(--sand-ink); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--line); }
.btn-danger { background: transparent; color: var(--red); border-color: var(--red); }
.btn-link { background: none; color: var(--sand); min-height: 36px; padding: 0.3rem 0.6rem; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; border: 0; background: none; color: var(--text); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }
.input, .composer-input { font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.6rem 0.9rem; }
.input:focus, .composer-input:focus, button:focus-visible { outline: 2px solid var(--sand); outline-offset: 1px; }
.tag { display: inline-block; margin-left: 0.5rem; padding: 0 0.5rem; border-radius: 999px; background: var(--surface-2); color: var(--sand); font-size: 0.75rem; font-weight: 600; }
.row { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 1rem; }

/* ---- Full screens (welcome, link, locked, …) ---- */
.screen { height: 100%; overflow: auto; display: grid; place-items: center; padding: 24px 16px; }
.screen-card { width: min(460px, 100%); display: flex; flex-direction: column; gap: 0.75rem; align-items: stretch; text-align: left; }
.screen-card .logo { align-self: center; margin-bottom: 0.5rem; }
.screen-card h1 { text-align: center; }
.notice { display: flex; gap: 0.6rem; align-items: flex-start; padding: 0.75rem 0.9rem; border-radius: var(--radius); background: var(--surface); font-size: 0.9rem; color: var(--muted); }
.notice .icon { margin-top: 2px; color: var(--sand); }
.notice-warn { border: 1px solid var(--line); }
.steps { margin: 0; padding-left: 1.25rem; color: var(--muted); }
.check-code { text-align: center; font-size: 1.6rem; font-weight: 600; letter-spacing: 0.08em; color: var(--sand); margin: 0; font-variant-numeric: tabular-nums; }
.qr-frame { align-self: center; padding: 10px; background: #fff; border-radius: var(--radius); }
.qr { display: block; width: min(300px, 70vw); height: auto; image-rendering: pixelated; }
.qr.expired { opacity: 0.15; }
.status { min-height: 1.4em; text-align: center; }
.choice { display: flex; flex-direction: column; gap: 0.3rem; text-align: left; padding: 1rem; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.choice:hover { border-color: var(--sand); }
.choice:disabled { opacity: 0.5; cursor: default; }
.choice-title { font-weight: 600; }
.choice-body { color: var(--muted); font-size: 0.9rem; }
.choice-warn { color: var(--sand); font-size: 0.85rem; }
.spinner { width: 28px; height: 28px; margin: 1rem auto; border-radius: 50%; border: 3px solid var(--surface-2); border-top-color: var(--sand); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* ---- App layout ---- */
.app { display: flex; flex-direction: column; height: 100%; }
.topbar { display: flex; align-items: center; gap: 0.75rem; padding: 0 12px 0 16px; height: 56px; border-bottom: 1px solid var(--line); background: var(--bg); }
.vault-title { font: inherit; font-weight: 600; font-size: 1.05rem; color: var(--text); background: none; border: 0; cursor: pointer; padding: 0.3rem 0.5rem; border-radius: var(--radius-small); max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vault-title:disabled { cursor: default; }
.tabs { display: flex; gap: 0.25rem; }
.tab { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.45rem 0.9rem; border-radius: 999px; border: 0; background: none; color: var(--muted); font: inherit; cursor: pointer; }
.tab.active { background: var(--surface-2); color: var(--sand); }
.session-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.session-dot.low { background: var(--sand); }
.content { flex: 1; min-height: 0; overflow: hidden; position: relative; }
.empty { text-align: center; color: var(--muted); padding: 3rem 1rem; max-width: 520px; margin: 0 auto; }
.empty h2 { color: var(--text); }
.drop-layer { position: fixed; inset: 0; display: none; place-items: center; align-content: center; gap: 1rem; background: rgba(14, 14, 15, 0.92); border: 2px dashed var(--sand); color: var(--sand); z-index: 30; pointer-events: none; }
.drop-layer.show { display: grid; }
.drop-layer .icon { width: 48px; height: 48px; }
@media (max-width: 640px) {
  .tab span { display: none; }
  .vault-title { max-width: 40vw; }
}

/* ---- Chat ---- */
.chat { display: flex; flex-direction: column; height: 100%; max-width: 860px; margin: 0 auto; }
.banners .banner { display: flex; gap: 0.5rem; align-items: center; margin: 8px 12px 0; padding: 0.5rem 0.8rem; border-radius: var(--radius-small); background: var(--sand); color: var(--sand-ink); font-size: 0.9rem; }
.messages { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 4px; }
.older { text-align: center; }
.system-line { align-self: center; color: var(--muted); font-size: 0.85rem; margin: 0.5rem 0; }
.bubble-wrap { display: flex; flex-direction: column; }
.bubble-row { display: flex; align-items: center; gap: 4px; max-width: 78%; }
.bubble-row.mine { align-self: flex-end; flex-direction: row-reverse; }
.bubble-row.theirs { align-self: flex-start; }
.bubble { position: relative; padding: 0.5rem 0.75rem 0.35rem; border-radius: 18px; background: var(--surface-2); min-width: 64px; }
.bubble.mine { background: var(--sand); color: var(--sand-ink); border-bottom-right-radius: 6px; }
.bubble.theirs { border-bottom-left-radius: 6px; }
.bubble.muted-bubble { background: var(--surface); color: var(--muted); font-style: italic; }
.bubble.failed { outline: 1px solid var(--red); cursor: pointer; }
.bubble .text { white-space: pre-wrap; overflow-wrap: anywhere; display: block; }
.bubble .sender { display: block; color: var(--sand); font-size: 0.8rem; font-weight: 600; margin-bottom: 2px; }
.bubble .deleted { display: inline-flex; gap: 0.4rem; align-items: center; }
.bubble .meta { display: flex; gap: 0.4rem; justify-content: flex-end; align-items: center; font-size: 0.72rem; opacity: 0.75; margin-top: 2px; }
.bubble .meta .icon { width: 14px; height: 14px; }
.bubble .unverified { display: inline-flex; align-items: center; gap: 2px; color: var(--sand); }
.bubble.mine .unverified { color: var(--sand-ink); }
.tick { display: inline-flex; align-items: center; gap: 2px; }
.tick.some { opacity: 0.6; }
.tick.read { opacity: 1; font-weight: 700; }
.bubble-more { opacity: 0; width: 32px; height: 32px; }
.bubble-row:hover .bubble-more, .bubble-more:focus-visible { opacity: 1; }
.quote { display: block; width: 100%; text-align: left; font: inherit; font-size: 0.85rem; color: inherit; opacity: 0.8; background: rgba(0, 0, 0, 0.12); border: 0; border-left: 3px solid currentColor; border-radius: 6px; padding: 0.25rem 0.5rem; margin-bottom: 0.3rem; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reactions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: -2px; }
.reactions.mine { justify-content: flex-end; }
.pill { display: inline-flex; gap: 4px; align-items: center; padding: 0.1rem 0.5rem; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-size: 0.85rem; cursor: pointer; }
.pill.own { border-color: var(--sand); color: var(--sand); }
.read-at { align-self: flex-end; margin: 0 4px; }
.media-grid { display: grid; gap: 2px; border-radius: 12px; overflow: hidden; margin-bottom: 0.25rem; width: min(264px, 60vw); }
.media-grid.n2, .media-grid.n3, .media-grid.n4 { grid-template-columns: 1fr 1fr; }
.media-tile { position: relative; aspect-ratio: 1; padding: 0; border: 0; background: var(--surface); color: var(--muted); display: grid; place-items: center; cursor: pointer; overflow: hidden; }
.media-grid.n1 .media-tile { aspect-ratio: 4 / 3; }
.media-tile .thumb, .tile .thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-tile .missing { padding: 0.5rem; text-align: center; }
.more-count { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 1.3rem; font-weight: 600; }
.badge { position: absolute; right: 6px; bottom: 6px; display: inline-flex; gap: 3px; align-items: center; padding: 1px 6px; border-radius: 999px; background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 0.72rem; font-weight: 600; }
.badge .icon { width: 12px; height: 12px; }
.attachments { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; padding: 0 16px; }
.attachments:not(:empty) { padding: 8px 16px 0; }
.chip { display: inline-flex; gap: 0.3rem; align-items: center; max-width: 220px; padding: 0.15rem 0.6rem; border-radius: 999px; background: var(--surface-2); font-size: 0.82rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chip .icon { width: 14px; height: 14px; }
.chip.ready { color: var(--green); }
.composer-bar:not(:empty) { display: flex; align-items: center; gap: 0.5rem; margin: 8px 16px 0; padding: 0.4rem 0.6rem; border-left: 3px solid var(--sand); background: var(--surface); border-radius: var(--radius-small); }
.bar-text { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.bar-text span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.composer { display: flex; align-items: flex-end; gap: 0.4rem; padding: 10px 12px 14px; }
.composer-input { flex: 1; resize: none; max-height: 160px; line-height: 1.4; }
.composer .send { background: var(--sand); color: var(--sand-ink); }
.composer-off { margin: 10px 16px; }

/* ---- Dialogs, menus, toast ---- */
.dialog-layer { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, 0.6); z-index: 40; padding: 16px; }
.dialog { width: min(440px, 100%); max-height: 90vh; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; display: flex; flex-direction: column; gap: 0.6rem; }
.list { display: flex; flex-direction: column; gap: 2px; }
.list-item { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; padding: 0.6rem 0.75rem; border-radius: var(--radius-small); background: var(--surface-2); color: var(--text); border: 0; font: inherit; text-align: left; cursor: pointer; }
.list-item.static { cursor: default; flex-wrap: wrap; }
.list-item.selected { color: var(--sand); }
.menu { display: flex; flex-direction: column; gap: 2px; }
.menu-item { display: flex; align-items: center; gap: 0.7rem; padding: 0.6rem 0.75rem; border-radius: var(--radius-small); border: 0; background: none; color: var(--text); font: inherit; cursor: pointer; text-align: left; }
.menu-item:hover { background: var(--surface-2); }
.menu-item.danger { color: var(--red); }
.quick-reactions { display: flex; gap: 0.25rem; justify-content: space-between; }
.emoji { font-size: 1.4rem; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--surface-2); cursor: pointer; display: grid; place-items: center; color: var(--text); }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 0.3rem; }
.toggle { display: flex; gap: 0.6rem; align-items: center; }
.version { text-align: center; overflow-wrap: anywhere; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); max-width: min(520px, calc(100% - 32px)); padding: 0.7rem 1rem; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--line); color: var(--text); opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 50; }
#toast.show { opacity: 1; transform: translateX(-50%); }

/* ---- Media ---- */
.media { height: 100%; overflow-y: auto; position: relative; }
.gallery { padding: 0 0 96px; }
.day { padding: 0 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 2px; }
.tile { position: relative; aspect-ratio: 1; padding: 0; border: 0; background: var(--surface); cursor: pointer; overflow: hidden; display: block; }
.tile.locked { display: grid; place-items: center; color: var(--muted); cursor: default; }
.tile .shield { position: absolute; left: 6px; top: 6px; color: var(--sand); background: rgba(0, 0, 0, 0.6); border-radius: 50%; padding: 3px; display: grid; }
.tile .shield .icon { width: 14px; height: 14px; }
.fab { position: absolute; right: 24px; bottom: 24px; width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--sand); color: var(--sand-ink); display: grid; place-items: center; cursor: pointer; }
.fab .icon { width: 26px; height: 26px; }
.uploads:not(:empty) { margin: 12px; padding: 0.75rem; border-radius: var(--radius); background: var(--surface); display: flex; flex-direction: column; gap: 0.4rem; }
.uploads h3 { margin: 0; }
.upload-row { display: grid; grid-template-columns: 1fr auto; gap: 0.2rem 0.75rem; align-items: center; }
.upload-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-row progress { grid-column: 1 / -1; width: 100%; height: 4px; accent-color: var(--sand); }
.upload-row.failed .muted { color: var(--red); }

/* ---- Viewer ---- */
.viewer { position: fixed; inset: 0; background: #000; z-index: 35; display: grid; place-items: center; }
.viewer-stage { position: relative; width: 100%; height: 100%; display: grid; place-items: center; }
.viewer-image { max-width: 100vw; max-height: 100vh; width: auto; height: auto; object-fit: contain; }
.viewer-video { max-width: 100vw; max-height: 100vh; width: 100%; }
.viewer-top { position: absolute; top: 0; left: 0; right: 0; padding: 14px 64px 14px 16px; display: flex; gap: 1rem; align-items: center; color: #ddd; font-size: 0.9rem; z-index: 2; }
.viewer-top .unverified { display: inline-flex; gap: 0.3rem; color: var(--sand); }
.viewer-close { position: absolute; top: 8px; right: 8px; color: #fff; z-index: 3; }
.viewer-nav { position: absolute; top: 50%; transform: translateY(-50%); color: #fff; background: rgba(255, 255, 255, 0.08); z-index: 3; }
.viewer-nav.prev { left: 12px; }
.viewer-nav.next { right: 12px; }
.viewer-msg { color: var(--muted); }

/* ---- Members ---- */
.members { height: 100%; overflow-y: auto; max-width: 720px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 0.6rem; }
.members-list { display: flex; flex-direction: column; gap: 0.5rem; }
.member { display: flex; flex-direction: column; gap: 0.15rem; padding: 0.75rem 0.9rem; border-radius: var(--radius); background: var(--surface); }
.member .warn { display: inline-flex; gap: 0.3rem; align-items: center; }
.member .code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85rem; color: var(--muted); }
.invites:not(:empty) { display: flex; flex-direction: column; gap: 0.3rem; }
.invite { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; padding: 0.5rem 0.9rem; border-radius: var(--radius); background: var(--surface); }
.invite-form { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.invite-form .input { flex: 1; min-width: 0; }
.link-text { overflow-wrap: anywhere; color: var(--muted); }
