:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #ece7dc;
  --ink: #1d1b17;
  --ink-2: #4a453c;
  --muted: #847c6e;
  --line: #e2dccf;
  --accent: #e2552b;
  --accent-ink: #ffffff;
  --accent-soft: #fbe3d8;
  --ok: #3f8a5a;
  --danger: #c23b2b;
  --folder: #d9a441;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 8px 24px rgba(40, 30, 10, .08);
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141310; --surface: #1c1a16; --surface-2: #26231e; --ink: #f2eee6; --ink-2: #cfc8bb;
    --muted: #8f8778; --line: #2e2a24; --accent: #f0683c; --accent-soft: #3a2117; --folder: #d6a347;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.45 var(--sans); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; min-height: 100dvh; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
a { color: inherit; }
svg.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 30px 26px; box-shadow: var(--shadow); }
.login-card form { margin: 0; }
.or { text-align: center; color: var(--muted); font-size: 12.5px; margin: 14px 0 2px; }
.brand { display: flex; align-items: center; gap: 8px; font: 600 12px/1 var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }
.brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); animation: ping 2.4s ease-out infinite; }
@keyframes ping { 0% { box-shadow: 0 0 0 0 var(--accent-soft); } 70%, 100% { box-shadow: 0 0 0 7px transparent; } }
@media (prefers-reduced-motion: reduce) { .brand .dot { animation: none; } }
.login h1 { font-size: 22px; margin: 22px 0 4px; letter-spacing: -.01em; }
.login p { color: var(--muted); margin: 0 0 22px; font-size: 14px; }
.field { width: 100%; height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); padding: 0 14px; outline: none; }
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 999px; font-weight: 600; font-size: 14px; background: var(--surface-2); color: var(--ink); text-decoration: none; white-space: nowrap; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.block { width: 100%; height: 46px; margin-top: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 10px; }

/* Shell */
.top { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px); border-bottom: 1px solid var(--line); padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px; }
.top-row { display: flex; align-items: center; gap: 12px; max-width: 1080px; margin: 0 auto; }
.top .host { color: var(--muted); font: 500 12px/1 var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search { flex: 1; position: relative; min-width: 0; }
.search input { width: 100%; height: 38px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); padding: 0 14px 0 38px; outline: none; }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search svg { position: absolute; left: 12px; top: 9px; color: var(--muted); width: 19px; height: 19px; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: var(--ink-2); flex: none; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.on { color: var(--accent); }
main { max-width: 1080px; margin: 0 auto; padding: 14px 16px calc(110px + var(--safe-b)); }

.crumbs { display: flex; align-items: center; gap: 2px; overflow-x: auto; scrollbar-width: none; margin: 4px 0 10px; white-space: nowrap; }
.crumbs::-webkit-scrollbar { display: none; }
.crumbs button { padding: 6px 8px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.crumbs button:last-child { color: var(--ink); font-weight: 650; }
.crumbs button:hover { background: var(--surface-2); }
.crumbs .sep { color: var(--line); font-size: 18px; }

.toolbar { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }
.toolbar .count { color: var(--muted); font: 500 12px/1 var(--mono); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.seg button { height: 30px; padding: 0 11px; border-radius: 999px; color: var(--muted); font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 5px; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.seg svg.i { width: 17px; height: 17px; }

.section-title { font: 600 11px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 18px 2px 10px; }
.quick { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.quick button { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); text-align: left; font-weight: 600; }
.quick button:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.quick svg { color: var(--accent); }

/* List */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 9px 12px; min-height: 58px; border-top: 1px solid var(--line); cursor: pointer; position: relative; user-select: none; -webkit-user-select: none; }
.row:first-child { border-top: 0; }
.row:hover { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.row.sel { background: var(--accent-soft); }
.thumb { width: 40px; height: 40px; border-radius: 9px; flex: none; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-2); overflow: hidden; }
.thumb > *, .tile .pic > * { grid-area: 1 / 1; }
.tile .pic img { position: absolute; inset: 0; }
.thumb img, .tile .pic img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .2s; }
.thumb img.ok, .tile .pic img.ok { opacity: 1; }
.thumb.folder { background: color-mix(in srgb, var(--folder) 20%, transparent); color: var(--folder); }
.thumb svg.i { width: 22px; height: 22px; }
.row .meta { flex: 1; min-width: 0; }
.row .name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .more { color: var(--muted); }
.check { width: 22px; height: 22px; border-radius: 50%; border: 1.6px solid var(--muted); flex: none; display: grid; place-items: center; }
.row.sel .check { background: var(--accent); border-color: var(--accent); color: #fff; }
.check svg.i { width: 14px; height: 14px; stroke-width: 2.6; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; position: relative; user-select: none; -webkit-user-select: none; }
.tile .pic { aspect-ratio: 1; display: grid; place-items: center; position: relative; overflow: hidden; background: var(--surface-2); color: var(--ink-2); }
.tile .pic.folder { color: var(--folder); background: color-mix(in srgb, var(--folder) 14%, var(--surface)); }
.tile .pic svg.i { width: 38px; height: 38px; stroke-width: 1.3; }
.tile .cap { padding: 8px 10px 9px; }
.tile .name { font-size: 13px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .sub { font-size: 11.5px; color: var(--muted); }
.tile.sel { outline: 2.5px solid var(--accent); outline-offset: -2.5px; }
.tile .check { position: absolute; top: 8px; left: 8px; background: rgba(255,255,255,.85); }

.empty { text-align: center; padding: 56px 16px; color: var(--muted); }
.empty svg.i { width: 34px; height: 34px; stroke-width: 1.3; margin-bottom: 8px; }
.skeleton { height: 58px; border-top: 1px solid var(--line); background: linear-gradient(90deg, transparent, var(--surface-2), transparent); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.notice { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--accent-soft); color: var(--ink); font-size: 13.5px; margin-bottom: 12px; }
.notice svg { color: var(--accent); margin-top: 1px; }

/* Bottom action bar */
.actionbar { position: fixed; left: 50%; bottom: calc(16px + var(--safe-b)); transform: translateX(-50%); z-index: 20; display: flex; align-items: center; gap: 6px; background: var(--ink); color: var(--bg); border-radius: 999px; padding: 6px 6px 6px 18px; box-shadow: 0 10px 30px rgba(0,0,0,.25); max-width: calc(100% - 32px); }
.actionbar .lbl { font-weight: 600; font-size: 14px; margin-right: 6px; white-space: nowrap; }
.actionbar .btn { background: color-mix(in srgb, var(--bg) 14%, transparent); color: var(--bg); height: 36px; }
.actionbar .btn.primary { background: var(--accent); color: #fff; }
@media (min-width: 561px) { .fab { display: none !important; } }
.fab { position: fixed; right: 18px; bottom: calc(18px + var(--safe-b)); z-index: 15; width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 45%, transparent); }
.fab svg.i { width: 26px; height: 26px; stroke-width: 2; }

/* Upload tray */
.tray { position: fixed; right: 16px; bottom: calc(86px + var(--safe-b)); z-index: 16; width: min(340px, calc(100% - 32px)); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 12px 14px; }
.tray .t-head { display: flex; justify-content: space-between; align-items: center; font-weight: 650; font-size: 13.5px; margin-bottom: 6px; }
.tray .t-item { font-size: 12.5px; padding: 5px 0; }
.tray .t-name { display: flex; justify-content: space-between; gap: 8px; }
.tray .t-name span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tray .bar { height: 4px; border-radius: 4px; background: var(--surface-2); margin-top: 4px; overflow: hidden; }
.tray .bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.tray .done { color: var(--ok); }
.tray .fail { color: var(--danger); }

/* Sheets & viewer */
.scrim { position: fixed; inset: 0; z-index: 30; background: rgba(15, 12, 8, .45); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease-out; }
@media (min-width: 700px) { .scrim { align-items: center; } }
@keyframes fade { from { opacity: 0; } }
.sheet { width: min(460px, 100%); background: var(--surface); border-radius: 22px 22px 0 0; padding: 20px 20px calc(20px + var(--safe-b)); box-shadow: var(--shadow); animation: up .2s cubic-bezier(.2,.8,.2,1); max-height: 90dvh; overflow: auto; }
@media (min-width: 700px) { .sheet { border-radius: 22px; } }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.sheet h2 { font-size: 17px; margin: 0 0 4px; word-break: break-word; }
.sheet p { color: var(--muted); font-size: 13.5px; margin: 0 0 16px; }
.sheet .menu button, .sheet .menu a { display: flex; align-items: center; gap: 12px; width: 100%; padding: 13px 4px; border-top: 1px solid var(--line); text-align: left; font-weight: 550; text-decoration: none; }
.sheet .menu > :first-child { border-top: 0; }
.sheet .row-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chips button { height: 34px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); font-size: 13.5px; font-weight: 600; }
.chips button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.linkbox { display: flex; gap: 6px; align-items: center; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 6px 6px 6px 12px; font: 12.5px/1.3 var(--mono); word-break: break-all; }
.linkbox span { flex: 1; }

.viewer { position: fixed; inset: 0; z-index: 40; background: #0d0c0a; color: #f2eee6; display: flex; flex-direction: column; animation: fade .15s; }
.viewer header { display: flex; align-items: center; gap: 8px; padding: calc(env(safe-area-inset-top, 0px) + 8px) 10px 8px; }
.viewer header .title { flex: 1; min-width: 0; }
.viewer header .title b { display: block; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer header .title span { font-size: 12px; color: #9a9284; }
.viewer .icon-btn { color: #f2eee6; }
.viewer .icon-btn:hover { background: rgba(255,255,255,.08); }
.viewer .stage { flex: 1; min-height: 0; display: grid; place-items: center; position: relative; overflow: hidden; }
.viewer .stage img, .viewer .stage video { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer .stage audio { width: min(520px, 90%); }
.viewer .stage iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.viewer .stage pre { width: 100%; height: 100%; margin: 0; overflow: auto; padding: 16px; font: 12.5px/1.55 var(--mono); white-space: pre-wrap; word-break: break-word; color: #e8e2d6; }
.viewer .nav { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; border-radius: 50%; background: rgba(0,0,0,.4); display: grid; place-items: center; color: #fff; }
.viewer .nav.prev { left: 10px; } .viewer .nav.next { right: 10px; }
.viewer footer { display: flex; gap: 8px; justify-content: center; padding: 10px 12px calc(12px + var(--safe-b)); flex-wrap: wrap; }
.viewer footer .btn { background: rgba(255,255,255,.1); color: #f2eee6; }
.viewer footer .btn.primary { background: var(--accent); color: #fff; }
.viewer .fallback { text-align: center; color: #9a9284; }
.viewer .fallback svg.i { width: 56px; height: 56px; stroke-width: 1.2; margin-bottom: 10px; }

.toast { position: fixed; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 66px); transform: translateX(-50%); z-index: 50; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow); animation: up .2s; max-width: calc(100% - 32px); }
.drop { position: fixed; inset: 10px; z-index: 60; border: 2.5px dashed var(--accent); border-radius: 24px; background: color-mix(in srgb, var(--accent-soft) 70%, transparent); display: grid; place-items: center; font-weight: 700; color: var(--accent); pointer-events: none; font-size: 18px; }
.share-row { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); }
.share-row:first-child { border-top: 0; }
.share-row .meta { flex: 1; min-width: 0; }
.share-row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-row .sub { font-size: 12.5px; color: var(--muted); }
@media (max-width: 560px) {
  .top .host, .hide-sm { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
}

/* v2 additions */
.top-row .grow, .toolbar .grow { flex: 1; }
.chip { display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600; }
.chip svg.i { width: 14px; height: 14px; }
.chip.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.badge { color: var(--muted); display: grid; place-items: center; }
.badge svg.i { width: 17px; height: 17px; }
.quick button.accent { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: var(--accent-soft); }
.bar.big { height: 6px; border-radius: 6px; background: var(--surface-2); overflow: hidden; margin: 6px 0 4px; }
.bar.big i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.sheet .menu .danger { color: var(--danger); }
.sheet .menu p { color: var(--muted); font-size: 13.5px; margin: 8px 0; }
.sheet .err { color: var(--danger); margin: 8px 0 0; min-height: 0; }
.toggle-row { display: flex; align-items: center; gap: 12px; padding: 13px 4px; border-top: 1px solid var(--line); cursor: pointer; }
.toggle-row span { flex: 1; display: flex; flex-direction: column; }
.toggle-row small { color: var(--muted); font-size: 12.5px; }
.toggle-row input { width: 22px; height: 22px; accent-color: var(--accent); }
.picker { max-height: 46dvh; overflow: auto; }
.tray .t-dest { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.tray .t-dest svg.i { width: 15px; height: 15px; }
.actionbar .btn { padding: 0 12px; }
.actionbar .lbl { min-width: 14px; text-align: center; }
