:root {
  --bg: #14171c;
  --surface: #1b1f27;
  --surface-2: #232833;
  --surface-hover: #2a3040;
  --border: #2b303a;
  --text: #e8eaed;
  --text-dim: #8b93a1;
  --accent: #5eb1bf;
  --accent-2: #3d8a97;
  --accent-soft: rgba(94, 177, 191, 0.12);
  --danger: #e2726b;
  --danger-soft: rgba(226, 114, 107, 0.12);
  --font-display: 'Sora', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--font-mono); }
.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
}

input {
  font-family: inherit;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  width: 100%;
}
input:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ===== screens ===== */
.screen { min-height: 100vh; }

/* ===== auth ===== */
#screen-setup, #screen-login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 10%, rgba(94,177,191,0.08), transparent 40%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
}

.auth-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0c1013;
  font-family: var(--font-display);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  font-size: 14px;
}

.auth-card h1 {
  font-family: var(--font-display);
  font-size: 22px;
  margin: 0 0 8px;
}

.auth-sub {
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.5;
  margin: 0 0 24px;
}

fieldset {
  border: none;
  padding: 0;
  margin: 0 0 20px;
}
fieldset legend {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 0 0 10px;
}

.auth-card label {
  display: block;
  font-size: 12.5px;
  color: var(--text-dim);
  margin-bottom: 12px;
}
.auth-card label input { margin-top: 6px; }

.auth-warning {
  font-size: 12.5px;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.5;
  margin: 0 0 20px;
}

.auth-error {
  color: var(--danger);
  font-size: 13px;
  margin: 12px 0 0;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  background: var(--accent);
  color: #0c1013;
  border: none;
  border-radius: 8px;
  padding: 11px 16px;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.15s ease;
}
.btn-primary:hover { background: var(--accent-2); }

.btn-ghost {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 13px;
  margin-top: 12px;
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-dim); }

/* ===== app shell ===== */
#screen-app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.brand-mark {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0c1013;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 11px;
  display: flex; align-items: center; justify-content: center;
}
.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
}

.breadcrumb {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  font-size: 13.5px;
  color: var(--text-dim);
  scrollbar-width: none;
}
.breadcrumb::-webkit-scrollbar { display: none; }
.crumb {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 13.5px;
  padding: 4px 6px;
  border-radius: 6px;
  white-space: nowrap;
}
.crumb:hover { color: var(--text); background: var(--surface-2); }
.crumb:last-of-type { color: var(--text); }
.crumb-sep { color: var(--accent); opacity: 0.6; font-family: var(--font-mono); }

.topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 13.5px;
  font-weight: 500;
}
.btn-secondary:hover { background: var(--surface-hover); }

.topbar-actions .btn-primary {
  width: auto;
  padding: 9px 16px;
  font-size: 13.5px;
}
.btn-upload { display: inline-flex; }

.btn-icon {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
}
.btn-icon:hover { color: var(--danger); border-color: var(--danger); }

/* ===== grid / dropzone ===== */
.dropzone {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  position: relative;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 14px;
  position: relative;
  transition: border-color 0.15s ease, background 0.15s ease;
  cursor: default;
}
.card:hover { border-color: var(--accent); background: var(--surface-2); }
.card-folder { cursor: pointer; }

.card-icon { font-size: 30px; line-height: 1; margin-bottom: 10px; }
.card-name {
  font-size: 13.5px;
  font-weight: 500;
  word-break: break-word;
  margin-bottom: 4px;
  padding-right: 60px;
}
.card-meta { font-size: 11px; color: var(--text-dim); }

.card-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.card:hover .card-actions { opacity: 1; }
.card-action {
  width: 24px; height: 24px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 11px;
  display: flex; align-items: center; justify-content: center;
}
.card-action:hover { color: var(--accent); border-color: var(--accent); }

.loading { color: var(--text-dim); font-size: 13.5px; padding: 40px 0; text-align: center; grid-column: 1 / -1; }

.empty-state {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--text-dim);
}
.empty-state p { margin: 4px 0; }
.empty-sub { font-size: 13px; }

.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 23, 28, 0.85);
  border: 2px dashed var(--accent);
  margin: 12px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-family: var(--font-display);
  font-size: 16px;
  pointer-events: none;
  z-index: 50;
}

/* ===== upload tray ===== */
.upload-tray {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 300px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  max-height: 260px;
  overflow-y: auto;
  z-index: 60;
}
.upload-row { margin-bottom: 10px; }
.upload-row:last-child { margin-bottom: 0; }
.upload-name {
  font-size: 12px;
  color: var(--text-dim);
  display: block;
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.upload-bar {
  height: 4px;
  background: var(--surface-2);
  border-radius: 2px;
  overflow: hidden;
}
.upload-bar-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.2s ease;
}
.upload-error .upload-bar-fill { background: var(--danger); }
.upload-pct { font-size: 11px; color: var(--text-dim); font-family: var(--font-mono); }

/* ===== modals ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 12, 15, 0.75);
  backdrop-filter: blur(2px);
}
.modal-body {
  position: relative;
  max-width: 90vw;
  max-height: 88vh;
}
.modal-body img, .modal-body video {
  max-width: 90vw;
  max-height: 88vh;
  border-radius: 10px;
  display: block;
}
.modal-close {
  position: absolute;
  top: -14px; right: -14px;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
}
.preview-fallback {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 40px;
  text-align: center;
  color: var(--text-dim);
}
.preview-fallback .btn-primary { width: auto; margin-top: 12px; text-decoration: none; }

.modal-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 380px;
}
.modal-card h3 {
  font-family: var(--font-display);
  font-size: 16px;
  margin: 0 0 16px;
}
.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.modal-actions .btn-ghost, .modal-actions .btn-primary { width: auto; flex: 1; margin: 0; }

/* ===== toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13.5px;
  z-index: 200;
}
.toast-error { border-color: var(--danger); color: var(--danger); }

/* ===== responsive ===== */
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 12px 16px; }
  .breadcrumb { order: 3; width: 100%; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
