/* Layout: sticky top bar, one content column (max 1180px), card grid that drops to 2 columns on phones. */
:root {
  --bg: #f2f4f8;
  --surface: #ffffff;
  --surface-2: #e9edf4;
  --line: #d9dfea;
  --ink: #12203a;
  --muted: #5b6880;
  --primary: #0f1c38;
  --primary-ink: #ffffff;
  --accent: #d9970f;
  --accent-soft: #fbefd2;
  --flow: #1f8fd0;
  --danger: #c8372d;
  --danger-soft: #fbe3e1;
  --ok: #23845a;
  --shadow: 0 1px 2px rgba(15, 28, 56, .06), 0 6px 18px rgba(15, 28, 56, .06);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Ubuntu, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1428;
    --surface: #13203b;
    --surface-2: #1b2a49;
    --line: #26375a;
    --ink: #e8edf7;
    --muted: #96a3bd;
    --primary: #f2b230;
    --primary-ink: #13203a;
    --accent: #f2b230;
    --accent-soft: #3a3220;
    --flow: #5fc8ff;
    --danger: #ff7a70;
    --danger-soft: #3d1d22;
    --ok: #5fd49a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-text-size-adjust: 100%;
  min-height: 100vh;
}
[hidden] { display: none !important; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
code { font-family: var(--mono); font-size: .86em; }
h2 { font-size: 1.05rem; margin: 0; text-wrap: balance; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: .45rem; justify-content: center;
  min-height: 40px; padding: 0 .95rem; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:focus-visible, .chip:focus-visible, .card:focus-visible, .icon-btn:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid var(--flow); outline-offset: 2px;
}
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { filter: brightness(1.12); border-color: var(--primary); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn-sm { min-height: 32px; padding: 0 .7rem; font-size: .88rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: wait; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 9px;
  border: 0; background: transparent; color: var(--ink); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }

input[type="text"], input[type="password"], input[type="search"], select {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; min-height: 40px; padding: 0 .75rem; width: 100%;
}
label { font-weight: 600; font-size: .9rem; }
.form-error { color: var(--danger); margin: 0; font-size: .9rem; }

/* Brand */
.brand { display: inline-flex; align-items: center; gap: .6rem; font-weight: 750; letter-spacing: -.01em; color: var(--ink); text-decoration: none; font-size: 1.05rem; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; background: #0f1c38 url("/icon.svg") center/cover no-repeat;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08);
}
.brand-lg { font-size: 1.35rem; }
.brand-lg .brand-mark { width: 36px; height: 36px; border-radius: 10px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left)); }
.login-card {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 28px 24px; box-shadow: var(--shadow); display: grid; gap: .7rem;
}
.login-card p { margin: 0 0 .4rem; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar-inner, .wrap {
  max-width: 1180px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 58px; }
.topbar-right { display: flex; align-items: center; gap: .5rem; }
.disk { font-size: .85rem; font-variant-numeric: tabular-nums; }
.wrap { padding-block: 18px 120px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.wrap > * { min-width: 0; }

/* Breadcrumbs */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: .15rem; font-size: 1.15rem; font-weight: 700; min-width: 0; }
.crumbs a { color: var(--muted); text-decoration: none; padding: .1rem .35rem; border-radius: 6px; }
.crumbs a:hover { background: var(--surface-2); color: var(--ink); }
.crumbs .sep { color: var(--line); }
.crumbs .current { padding: .1rem .35rem; overflow-wrap: anywhere; }

/* Path for Claude */
.claude-path {
  display: flex; align-items: center; gap: .75rem; justify-content: space-between;
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: var(--radius); padding: .6rem .6rem .6rem .9rem;
}
.claude-path-text { display: grid; min-width: 0; }
.claude-path .label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; color: var(--muted); }
.claude-path code { overflow-wrap: anywhere; }

/* Toolbar */
.toolbar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.search { position: relative; flex: 1 1 260px; min-width: 0; }
.search svg { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 2.2rem; }
.chips { display: flex; gap: .35rem; overflow-x: auto; scrollbar-width: none; max-width: 100%; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-size: .88rem; font-weight: 600;
  border-radius: 999px; padding: .35rem .8rem; cursor: pointer; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.sort select { width: auto; min-height: 36px; font-size: .9rem; }
.summary { margin: 0; font-size: .88rem; font-variant-numeric: tabular-nums; }

/* Grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.card {
  position: relative; display: grid; grid-template-rows: auto 1fr; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  cursor: pointer; text-align: left; color: inherit; font: inherit; padding: 0;
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--muted); }
.thumb {
  aspect-ratio: 16 / 10; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; position: relative;
  color: var(--muted);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb svg { width: 40px; height: 40px; stroke-width: 1.4; }
.thumb .badge {
  position: absolute; left: 8px; bottom: 8px; background: rgba(8, 14, 30, .78); color: #fff;
  font-size: .72rem; font-weight: 700; letter-spacing: .04em; padding: .1rem .45rem; border-radius: 6px;
}
.thumb .play {
  position: absolute; width: 40px; height: 40px; border-radius: 50%; background: rgba(8, 14, 30, .62); display: grid; place-items: center;
}
.thumb .play svg { width: 18px; height: 18px; color: #fff; fill: #fff; stroke: none; margin-left: 2px; }
.card.dir .thumb { aspect-ratio: auto; height: 92px; color: var(--accent); background: var(--accent-soft); }
.card.dir .thumb svg { width: 44px; height: 44px; fill: color-mix(in srgb, var(--accent) 22%, transparent); }
.card-body { padding: .6rem .75rem .7rem; display: grid; gap: .1rem; min-width: 0; }
.card-name { font-weight: 650; font-size: .93rem; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-sub { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.card-more {
  position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; border-radius: 8px; border: 0;
  background: rgba(8, 14, 30, .55); color: #fff; display: grid; place-items: center; cursor: pointer;
}
.card.dir .card-more { background: transparent; color: var(--muted); }
.card-more:hover { background: rgba(8, 14, 30, .8); color: #fff; }

.empty { text-align: center; padding: 48px 16px; border: 2px dashed var(--line); border-radius: 16px; }
.empty svg { width: 44px; height: 44px; color: var(--muted); stroke-width: 1.4; }
.empty p { margin: .3rem 0; }

/* Drop overlay */
.drop {
  position: fixed; inset: 0; z-index: 40; background: color-mix(in srgb, var(--bg) 70%, transparent);
  display: grid; place-items: center; padding: 24px; pointer-events: none;
}
.drop-inner {
  border: 3px dashed var(--flow); border-radius: 20px; padding: 40px 28px; background: var(--surface);
  font-size: 1.1rem; text-align: center; box-shadow: var(--shadow); max-width: 520px; overflow-wrap: anywhere;
}

/* Upload queue */
.queue {
  position: fixed; z-index: 30; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom));
  width: min(380px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 12px; display: grid; gap: 8px;
}
.queue-head { display: flex; align-items: center; gap: .5rem; }
.queue-head strong { flex: 1; font-variant-numeric: tabular-nums; }
.queue.collapsed .queue-list { display: none; }
.bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--flow); transition: width .2s; }
.queue-list { list-style: none; margin: 0; padding: 0; max-height: 40vh; overflow: auto; display: grid; gap: 6px; }
.queue-item { display: grid; gap: 3px; font-size: .85rem; padding: 6px 2px; border-top: 1px solid var(--line); }
.queue-item .q-row { display: flex; justify-content: space-between; gap: .5rem; }
.queue-item .q-name { overflow-wrap: anywhere; min-width: 0; }
.queue-item .q-state { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.queue-item.done .q-state { color: var(--ok); }
.queue-item.fail .q-state { color: var(--danger); white-space: normal; text-align: right; }
.queue-item .bar { height: 4px; }
.queue-item.done .bar span { background: var(--ok); }
.queue-item.fail .bar span { background: var(--danger); }

/* Toast */
.toast {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); bottom: max(20px, env(safe-area-inset-bottom));
  background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; font-weight: 600; box-shadow: var(--shadow);
  max-width: calc(100vw - 32px);
}
.toast.error { background: var(--danger); color: #fff; }

/* Dialogs */
dialog {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 16px; padding: 0;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .35); max-width: calc(100vw - 24px);
}
dialog::backdrop { background: rgba(6, 11, 24, .6); }
.viewer { width: min(880px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto; }
.viewer-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: 12px 12px 8px 18px; }
.viewer-head h2 { overflow-wrap: anywhere; min-width: 0; }
.viewer-media { background: #05080f; display: grid; place-items: center; }
.viewer-media:empty { display: none; }
.viewer-media video, .viewer-media img { display: block; max-width: 100%; max-height: 70dvh; width: auto; margin: 0 auto; }
.viewer-media audio { width: calc(100% - 32px); margin: 24px 16px; }
.viewer-media pre {
  margin: 0; width: 100%; max-height: 60dvh; overflow: auto; padding: 16px 18px; background: var(--surface-2); color: var(--ink);
  font: 13px/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere;
}
.viewer-media .file-icon { padding: 36px; color: #8ea0c4; }
.viewer-media .file-icon svg { width: 56px; height: 56px; stroke-width: 1.2; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; padding: 14px 18px 4px; font-size: .9rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; min-width: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.meta code { background: var(--surface-2); padding: .05rem .35rem; border-radius: 5px; }
.viewer-actions { display: flex; flex-wrap: wrap; gap: .5rem; padding: 12px 18px 18px; }
.viewer-actions .spacer { flex: 1; }
.btn-danger-ghost { color: var(--danger); }
.btn-danger-ghost:hover { border-color: var(--danger); }
.confirm { margin: 0 18px 18px; padding: 12px 14px; border-radius: 12px; background: var(--danger-soft); display: grid; gap: .6rem; }
.confirm p { margin: 0; overflow-wrap: anywhere; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; }
.ask { width: min(420px, calc(100vw - 24px)); }
.ask form { display: grid; gap: .6rem; padding: 20px; }

@media (max-width: 560px) {
  body { font-size: 15px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .actions .btn { flex: 1 1 auto; padding: 0 .7rem; }
  .disk { display: none; }
  .claude-path { flex-direction: column; align-items: stretch; }
  .meta { grid-template-columns: 1fr; gap: .1rem; }
  .meta dd { margin-bottom: .45rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
