:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #eef0f3;
  --text: #15171b;
  --muted: #5d646e;
  --line: #e1e4e9;
  --accent: #2f6bff;
  --accent-text: #ffffff;
  --accent-soft: rgba(47, 107, 255, 0.12);
  --danger: #d4351c;
  --ok: #1a7f37;
  --warn: #a15c00;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 10px 30px rgba(16, 24, 40, 0.10);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --panel: #161920;
    --panel-2: #1e222b;
    --text: #e8eaed;
    --muted: #9aa1ab;
    --line: #2a2f39;
    --accent: #6b93ff;
    --accent-text: #0b1020;
    --accent-soft: rgba(107, 147, 255, 0.16);
    --danger: #ff7a66;
    --ok: #4cc26b;
    --warn: #e5a23a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 14px 36px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body.drawer-open { overflow: hidden; }

button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.center { text-align: center; }
.sr-only { position: fixed; left: -9999px; top: 0; opacity: 0; }

.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }

/* ------------------------------------------------------------ brand */
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 16px; letter-spacing: -0.01em; }
.logo {
  width: 22px; height: 22px; border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

/* ------------------------------------------------------------ buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  font-weight: 550; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
}
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); border-color: var(--danger); }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type="text"], input[type="email"], input[type="password"], input[type="search"], select {
  height: 36px; padding: 0 11px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--panel); min-width: 0;
}
input:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); }
.seg button {
  height: 28px; padding: 0 11px; border: 0; border-radius: 7px;
  background: transparent; color: var(--muted); font-weight: 550; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }

/* ------------------------------------------------------------ sign in */
.login { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-card {
  width: 100%; max-width: 360px; padding: 28px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  display: grid; gap: 14px;
}
.login-card h1 { margin: 6px 0 2px; font-size: 20px; }
.field { display: grid; gap: 6px; }
.field span { font-size: 13px; color: var(--muted); font-weight: 550; }
.form-error { margin: 0; color: var(--danger); font-size: 13px; }

/* ------------------------------------------------------------ layout */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 24px; background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--line);
}
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 16px 24px 4px; }
.search { flex: 1 1 240px; max-width: 360px; }
.count { margin-left: auto; }

.content { padding: 14px 24px 48px; }

/* ------------------------------------------------------------ uploads */
.uploads { margin: 12px 24px 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.uploads-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.up-list { max-height: 220px; overflow: auto; }
.up-row { display: grid; grid-template-columns: minmax(0, 1fr) auto 140px minmax(0, 220px); align-items: center; gap: 12px; padding: 9px 14px; border-top: 1px solid var(--line); }
.up-row:first-child { border-top: 0; }
.up-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-status { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-row[data-state="done"] .up-status { color: var(--ok); }
.up-row[data-state="error"] .up-status { color: var(--danger); white-space: normal; }
progress { width: 100%; height: 6px; appearance: none; border: 0; border-radius: 99px; background: var(--panel-2); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--panel-2); }
progress::-webkit-progress-value { background: var(--accent); border-radius: 99px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 99px; }

/* ------------------------------------------------------------ grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.card {
  display: block; width: 100%; padding: 0; text-align: left; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
}
.card:hover { transform: translateY(-1px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.thumb { position: relative; aspect-ratio: 1 / 1; background: var(--panel-2); display: grid; place-items: center; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph { color: var(--muted); font-size: 12px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; }
.ph-icon { display: block; width: 34px; height: 34px; margin: 0 auto 8px; border-radius: 9px; border: 2px solid currentColor; position: relative; opacity: 0.7; }
.ph-icon.video::after { content: ""; position: absolute; left: 12px; top: 8px; border-left: 11px solid currentColor; border-top: 7px solid transparent; border-bottom: 7px solid transparent; }
.badges { position: absolute; left: 8px; top: 8px; display: flex; gap: 5px; flex-wrap: wrap; }
.badge { display: inline-block; font-size: 11px; font-weight: 650; line-height: 1; padding: 5px 7px; border-radius: 99px; background: rgba(12, 14, 18, 0.72); color: #fff; }
.card-body { padding: 9px 11px 11px; }
.card-name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.up-row .badge.public { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.up-row .badge.private { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }

.empty { text-align: center; padding: 72px 16px; border: 2px dashed var(--line); border-radius: 16px; }
.empty-title { font-size: 17px; font-weight: 650; margin: 0 0 6px; }
#more-btn { margin-top: 22px; }

/* ------------------------------------------------------------ drawer */
.scrim { position: fixed; inset: 0; z-index: 30; background: rgba(8, 10, 14, 0.45); }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 40;
  width: min(480px, 100vw); display: flex; flex-direction: column;
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: var(--shadow);
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { width: 34px; height: 34px; flex: none; border: 0; border-radius: 8px; background: transparent; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.drawer-body { flex: 1; overflow: auto; padding: 16px 18px; }
.preview { border-radius: var(--radius); background: var(--panel-2); min-height: 120px; display: grid; place-items: center; overflow: hidden; }
.preview img, .preview video { display: block; max-width: 100%; max-height: 52vh; }
.preview video { width: 100%; background: #000; }
.preview p { padding: 24px; margin: 0; text-align: center; }

.meta { display: grid; grid-template-columns: max-content 1fr; gap: 7px 16px; margin: 18px 0; font-size: 13px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; }

.links h3 { font-size: 13px; margin: 20px 0 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.links .row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.links .row > select { flex: 1 1 140px; }
.link-out { flex: 1 1 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.note { font-size: 13px; color: var(--muted); background: var(--panel-2); border-radius: 10px; padding: 11px 12px; margin: 0; }

.drawer-actions { display: flex; justify-content: space-between; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }

/* ------------------------------------------------------------ drop & toast */
.dropzone { position: fixed; inset: 0; z-index: 60; pointer-events: none; padding: 16px; background: color-mix(in srgb, var(--accent) 10%, transparent); }
.dropzone-inner { height: 100%; display: grid; place-items: center; border: 3px dashed var(--accent); border-radius: 20px; font-size: 22px; font-weight: 650; color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 70; transform: translateX(-50%);
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 10px;
  background: var(--text); color: var(--bg); font-weight: 550; box-shadow: var(--shadow);
}
.toast[data-kind="error"] { background: var(--danger); color: #fff; }

/* ------------------------------------------------------------ small screens */
@media (max-width: 640px) {
  .topbar, .toolbar, .content { padding-left: 14px; padding-right: 14px; }
  .uploads { margin-left: 14px; margin-right: 14px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .count { margin-left: 0; width: 100%; }
  .up-row { grid-template-columns: minmax(0, 1fr) auto; }
  .up-row progress, .up-row .up-status { grid-column: 1 / -1; }
}
