:root {
  --bg: #fbf6ef;
  --surface: #ffffff;
  --ink: #2b1f16;
  --muted: #7a6a5c;
  --line: #eadfd2;
  --brand: #8a5a2b;
  --brand-ink: #ffffff;
  --honey: #f2b134;
  --chip: #f3eadf;
  --danger: #b3261e;
  --shadow: 0 6px 24px rgba(59, 42, 30, .15);
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17120e; --surface: #221b15; --ink: #f4ece3; --muted: #b3a597;
    --line: #3a2f26; --brand: #d79a52; --brand-ink: #1b130c; --chip: #2e251d;
    --shadow: 0 6px 24px rgba(0,0,0,.5); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
h1 { margin: .2em 0; font-size: 1.9rem; }

.view.center { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.hero { max-width: 380px; text-align: center; }
.logo { font-size: 84px; line-height: 1; }
.sub { color: var(--muted); margin: 0 0 24px; font-size: 1.1rem; }
.hint { color: var(--muted); font-size: .95rem; margin-top: 18px; }
.error { color: var(--danger); font-weight: 600; }

.btn { border: 0; border-radius: 999px; padding: 12px 20px; background: var(--chip); font-weight: 600; }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.danger { background: transparent; color: var(--danger); border: 1.5px solid var(--danger); }
.btn.big { width: 100%; padding: 16px 22px; font-size: 1.1rem; }
.btn:disabled { opacity: .55; }
.link { background: none; border: 0; color: var(--brand); font-weight: 600; padding: 4px; }

/* top bar + controls */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px; background: var(--bg); }
.brand { font-weight: 800; font-size: 1.15rem; }
.logo-sm { font-size: 1.4rem; vertical-align: -2px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--brand); color: var(--brand-ink); font-weight: 700; }
.controls { position: sticky; top: 58px; z-index: 4; background: var(--bg); padding: 0 16px 10px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--chip); border-radius: 999px; padding: 4px; margin-bottom: 10px; }
.seg-btn { border: 0; background: none; border-radius: 999px; padding: 8px; font-weight: 600; color: var(--muted); }
.seg-btn.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1.5px solid transparent; background: var(--chip); border-radius: 999px; padding: 7px 12px; font-size: .92rem; white-space: nowrap; }
.chip .n { color: var(--muted); margin-left: 4px; font-size: .85em; }
.chip.active { background: var(--brand); color: var(--brand-ink); }
.chip.active .n { color: inherit; opacity: .8; }

/* grid */
main { padding: 0 4px calc(110px + var(--safe-b)); }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(5, 1fr); } main { padding: 0 16px 120px; } }
@media (min-width: 1100px) { .grid { grid-template-columns: repeat(7, 1fr); } }
.tile { position: relative; aspect-ratio: 1; border: 0; padding: 0; background: var(--chip); overflow: hidden; border-radius: 4px; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .badge { position: absolute; right: 5px; bottom: 5px; background: rgba(0,0,0,.6); color: #fff; font-size: .75rem; padding: 2px 6px; border-radius: 6px; }
.tile .who { position: absolute; left: 5px; bottom: 5px; background: rgba(0,0,0,.45); color: #fff; font-size: .7rem; padding: 1px 6px; border-radius: 6px; }
.tile .pending { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: var(--muted); font-size: .8rem; padding: 6px; }
.tile .pending.over { background: rgba(0,0,0,.45); color: #fff; }
.spin { width: 22px; height: 22px; border: 3px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--muted); padding: 60px 24px; }
.empty .big { font-size: 56px; }
.sentinel { height: 1px; }

/* fab + upload tray */
.fab { position: fixed; z-index: 6; left: 50%; transform: translateX(-50%); bottom: calc(18px + var(--safe-b));
  border: 0; border-radius: 999px; background: var(--brand); color: var(--brand-ink); padding: 14px 22px;
  font-weight: 700; font-size: 1.05rem; box-shadow: var(--shadow); white-space: nowrap; }
.fab span { font-size: 1.2em; margin-right: 4px; }
.tray { position: fixed; z-index: 7; left: 12px; right: 12px; bottom: calc(80px + var(--safe-b)); max-width: 520px; margin: 0 auto;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; }
.tray-head { display: flex; justify-content: space-between; align-items: center; }
.tray.collapsed .tray-list { display: none; }
.bar { height: 6px; background: var(--chip); border-radius: 3px; margin: 8px 0; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--honey); transition: width .2s; }
.tray-list { list-style: none; margin: 0; padding: 0; max-height: 34vh; overflow: auto; font-size: .88rem; }
.tray-list li { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-top: 1px solid var(--line); }
.tray-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tray-list .st { flex: none; color: var(--muted); }
.tray-list .st.ok { color: #2e7d32; }
.tray-list .st.bad { color: var(--danger); }

/* viewer */
.viewer { position: fixed; inset: 0; z-index: 20; background: #000; color: #fff; display: flex; flex-direction: column; }
.viewer-top { display: flex; justify-content: space-between; align-items: center; padding: calc(8px + env(safe-area-inset-top, 0px)) 8px 8px; z-index: 2; }
.icon-btn { width: 44px; height: 44px; border: 0; border-radius: 50%; background: rgba(255,255,255,.12); color: #fff; font-size: 1.2rem; }
.v-pos { opacity: .7; font-size: .9rem; }
.v-stage { flex: 1; min-height: 0; display: grid; place-items: center; touch-action: pan-y; }
.v-stage img, .v-stage video { max-width: 100%; max-height: 100%; object-fit: contain; }
.v-stage .pending { color: #ccc; text-align: center; }
.v-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 72px; border: 0; background: rgba(255,255,255,.1); color: #fff; font-size: 2rem; border-radius: 10px; }
.v-nav.left { left: 8px; } .v-nav.right { right: 8px; }
@media (hover: none) { .v-nav { display: none; } }
.v-info { background: #111; padding: 12px 16px calc(14px + var(--safe-b)); max-height: 45vh; overflow: auto; }
.v-info.collapsed { display: none; }
.v-meta { color: #bbb; font-size: .9rem; }
.v-caption { font-size: 1.05rem; margin: 6px 0; }
.v-desc { color: #999; font-size: .85rem; font-style: italic; }
.v-cats { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.v-cats .chip { background: #2a2a2a; color: #eee; }
.v-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.v-actions .btn { background: #2a2a2a; color: #fff; padding: 9px 14px; font-size: .92rem; }
.v-note { color: var(--honey); font-size: .85rem; margin-top: 6px; }

/* sheet */
.sheet-back { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.4); }
.sheet { position: fixed; z-index: 31; left: 0; right: 0; bottom: 0; max-width: 560px; margin: 0 auto; max-height: 88dvh; overflow: auto;
  background: var(--surface); color: var(--ink); border-radius: 18px 18px 0 0; padding: 18px 18px calc(18px + var(--safe-b)); box-shadow: var(--shadow); }
.sheet h2 { margin: 0 0 12px; font-size: 1.2rem; }
.sheet .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.sheet .row:first-of-type { border-top: 0; }
.sheet .small { color: var(--muted); font-size: .85rem; }
.sheet textarea { width: 100%; min-height: 72px; border: 1.5px solid var(--line); border-radius: 10px; padding: 10px; font: inherit; background: var(--bg); color: var(--ink); resize: vertical; }
.sheet .counter { text-align: right; color: var(--muted); font-size: .8rem; }
.sheet .cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0 12px; }
.sheet .cat-grid .chip { text-align: left; border-color: var(--line); background: transparent; }
.sheet .cat-grid .chip.active { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.sheet .stack { display: grid; gap: 10px; margin-top: 14px; }
.sheet .linkbox { word-break: break-all; background: var(--bg); border: 1px dashed var(--line); padding: 10px; border-radius: 10px; font-size: .85rem; margin: 8px 0; }
.switch { display: flex; align-items: center; gap: 10px; }
.switch input { width: 22px; height: 22px; accent-color: var(--brand); }

.toast { position: fixed; z-index: 40; left: 50%; transform: translateX(-50%); bottom: calc(90px + var(--safe-b)); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 999px; font-size: .92rem; box-shadow: var(--shadow); max-width: calc(100% - 32px); text-align: center; }
.sheet h2.mt { margin-top: 22px; }
a.btn { text-decoration: none; display: inline-block; }
.key-form { display: grid; gap: 12px; text-align: left; }
.key-label { font-weight: 700; }
.key-form input { font: inherit; font-size: 1.25rem; padding: 14px 16px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); color: var(--ink); }
.key-form input:focus { outline: none; border-color: var(--brand); }
.small-link { margin-top: 22px; font-size: .9rem; color: var(--muted); }
