:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #f0f2ef;
  --border: #dfe3de;
  --text: #17201d;
  --muted: #5f6b66;
  --accent: #0f766e;
  --accent-hover: #0b5f58;
  --accent-soft: #d9f0ec;
  --on-accent: #ffffff;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --warn-soft: #fff4d6;
  --warn-text: #7a5300;
  --shadow: 0 1px 2px rgb(16 24 20 / 6%), 0 8px 24px rgb(16 24 20 / 6%);
  --radius: 12px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1412;
    --surface: #151d1a;
    --surface-2: #1c2622;
    --border: #2a3632;
    --text: #e6ece9;
    --muted: #93a19b;
    --accent: #2bb3a3;
    --accent-hover: #3fc7b7;
    --accent-soft: #123a35;
    --on-accent: #06201c;
    --danger: #f2766a;
    --danger-soft: #3a1714;
    --warn-soft: #3a2e10;
    --warn-text: #f4cf72;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 30%);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
p { margin: 0; }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.icon { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); font-size: 14px; min-height: 0; }
.error:empty { display: none; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 14px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  font-weight: 550; white-space: nowrap; text-decoration: none; color: var(--text);
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.block { width: 100%; height: 44px; }
.btn.ghost { background: transparent; border-color: transparent; color: #fff; }
.btn.ghost:hover { background: rgb(255 255 255 / 12%); }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 8px;
  border: 0; background: transparent; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.ghost { color: #fff; }
.icon-btn.ghost:hover { background: rgb(255 255 255 / 12%); }
.link { border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; font-weight: 550; display: inline-flex; align-items: center; gap: 4px; }
.link:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.input {
  width: 100%; height: 42px; padding: 0 12px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field { display: grid; gap: 6px; font-size: 14px; font-weight: 550; }
.check { display: flex; gap: 10px; align-items: center; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.meter { display: grid; gap: 4px; font-weight: 400; }
.meter-track { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--muted); transition: width .2s, background .2s; }
.meter[data-level="1"] .meter-fill { background: var(--danger); }
.meter[data-level="2"] .meter-fill { background: #d29b00; }
.meter[data-level="3"] .meter-fill { background: var(--accent); }
.meter-label { font-size: 13px; color: var(--muted); }

.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- centered pages ---------- */
.center { max-width: 460px; margin: 0 auto; padding: 56px 16px 40px; display: grid; gap: 20px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { width: 48px; height: 48px; border-radius: 12px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.form { display: grid; gap: 16px; }
.back { justify-self: start; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; text-align: center; overflow-wrap: anywhere; }

.library-list { display: grid; gap: 8px; }
.library-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer;
}
.library-item:hover { border-color: var(--accent); background: var(--surface-2); }
.library-item > .icon { color: var(--muted); }
.library-icon { width: 38px; height: 38px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.library-icon.big { width: 52px; height: 52px; border-radius: 12px; }
.library-meta { display: grid; flex: 1; min-width: 0; }
.library-meta .muted { font-size: 13px; }

.notice { display: flex; gap: 10px; padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); font-size: 14px; }
.notice .icon { margin-top: 2px; color: var(--accent); }
.notice.warn { background: var(--warn-soft); color: var(--warn-text); margin: 0 24px 12px; }
.notice.warn .icon { color: currentColor; }

.backup-code { display: flex; gap: 10px; align-items: center; padding: 14px; border-radius: 10px; background: var(--surface-2); border: 1px dashed var(--border); }
.backup-code code { flex: 1; font: 600 17px/1.4 var(--mono); letter-spacing: .04em; overflow-wrap: anywhere; user-select: all; }

.empty { display: grid; justify-items: center; gap: 10px; padding: 48px 16px; color: var(--muted); text-align: center; }

.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* ---------- browser ---------- */
.browser { min-height: 100%; display: flex; flex-direction: column; position: relative; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px; padding: 12px 24px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.title strong { font-size: 16px; }
.user-name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-name::before { content: '· '; }
.search-wrap { flex: 1; max-width: 420px; position: relative; display: flex; align-items: center; margin-left: auto; }
.search-wrap .icon { position: absolute; left: 12px; color: var(--muted); pointer-events: none; }
.search { padding-left: 38px; height: 38px; background: var(--surface-2); border-color: transparent; }
.tools { display: flex; gap: 8px; align-items: center; }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: 42px; z-index: 10; min-width: 240px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
}
.menu-item { display: flex; gap: 10px; align-items: center; width: 100%; padding: 9px 10px; border: 0; background: none; border-radius: 7px; cursor: pointer; text-align: left; }
.menu-item:hover { background: var(--surface-2); }
.menu-item .icon { color: var(--muted); }

.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; padding: 16px 24px 8px; }
.crumb { border: 0; background: none; padding: 4px 8px; border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 16px; }
.crumb:hover { background: var(--surface-2); }
.crumb:last-of-type { color: var(--text); }
.sep { color: var(--muted); display: inline-flex; }
.search-note { margin-left: 6px; font-size: 14px; }

.files { padding: 4px 16px 16px; display: grid; gap: 2px; flex: 1; align-content: start; }
.row { display: flex; align-items: center; border-radius: 10px; }
.row:hover { background: var(--surface); box-shadow: var(--shadow); }
.row-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px; padding: 8px; border: 0; background: none; cursor: pointer; text-align: left; border-radius: 10px; }
.row-icon { width: 44px; height: 44px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); overflow: hidden; flex: none; }
.row.folder .row-icon { background: var(--accent-soft); color: var(--accent); }
.row.video .row-icon { color: #7c3aed; }
.row.audio .row-icon { color: #db2777; }
.row.image .row-icon { color: #2563eb; }
.thumb { width: 100%; height: 100%; object-fit: cover; }
.row-text { display: grid; min-width: 0; }
.row-name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { display: flex; gap: 2px; padding-right: 8px; opacity: 0; transition: opacity .12s; }
.row:hover .row-actions, .row:focus-within .row-actions { opacity: 1; }
@media (hover: none) { .row-actions { opacity: 1; } }

.statusbar { padding: 10px 24px 20px; color: var(--muted); font-size: 13px; }

.drop-overlay {
  position: fixed; inset: 0; z-index: 20; display: none; place-content: center; justify-items: center; gap: 12px;
  background: color-mix(in srgb, var(--accent) 14%, transparent); border: 3px dashed var(--accent);
  color: var(--accent); font-weight: 600; pointer-events: none;
}
.browser.dragging .drop-overlay { display: grid; }

.upload-panel {
  position: fixed; right: 20px; bottom: 20px; z-index: 15; width: min(380px, calc(100vw - 32px));
  padding: 14px 16px; display: grid; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.upload-head, .upload-sub { display: flex; justify-content: space-between; gap: 12px; }
.upload-sub { font-size: 13px; color: var(--muted); }
.upload-panel progress { width: 100%; height: 8px; accent-color: var(--accent); }

/* ---------- preview ---------- */
.preview { position: fixed; inset: 0; z-index: 30; background: rgb(8 12 10 / 92%); display: flex; flex-direction: column; color: #fff; }
.preview-bar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 16px; }
.preview-title { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.preview-title .muted { color: rgb(255 255 255 / 60%); font-size: 13px; flex: none; }
/* One fixed-size cell (minmax(0, 1fr) both ways) so max-height: 100% has a real height to
   resolve against; with auto tracks it is ignored and portrait images overflow. */
.stage {
  flex: 1; min-height: 0; display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center; padding: 8px 72px 24px;
}
.stage img, .stage video { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; background: #000; }
.stage iframe { width: min(1000px, 100%); height: 100%; border: 0; border-radius: 6px; background: #fff; }
.text-preview {
  width: min(1000px, 100%); max-height: 100%; overflow: auto; margin: 0; padding: 20px;
  background: var(--surface); color: var(--text); border-radius: 8px; font: 13px/1.6 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere;
}
.audio-card, .no-preview { display: grid; justify-items: center; gap: 16px; text-align: center; }
.audio-card audio { width: min(420px, 80vw); }
.nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 48px; border-radius: 50%;
  display: grid; place-items: center; border: 0; background: rgb(255 255 255 / 10%); color: #fff; cursor: pointer;
}
.nav:hover { background: rgb(255 255 255 / 20%); }
.nav.prev { left: 12px; }
.nav.next { right: 12px; }

/* ---------- dialogs ---------- */
.dlg {
  width: min(440px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.dlg.wide { width: min(640px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgb(8 12 10 / 45%); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 16px 0 20px; }
.dlg-body { display: grid; gap: 14px; padding: 16px 20px 20px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.stats { display: grid; grid-template-columns: auto 1fr; gap: 8px 20px; margin: 0; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; font-weight: 550; text-align: right; }

/* ---------- toasts ---------- */
#toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast {
  padding: 10px 16px; border-radius: 10px; background: var(--text); color: var(--bg);
  box-shadow: var(--shadow); font-size: 14px; max-width: calc(100vw - 32px); animation: rise .2s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.leaving { opacity: 0; transition: opacity .4s; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .search-wrap { order: 3; max-width: none; flex-basis: 100%; margin-left: 0; }
  .tools { margin-left: auto; }
  .tools .label { display: none; }
  .tools .btn { padding: 0 10px; }
  .crumbs { padding: 12px 16px 6px; }
  .files { padding: 4px 8px 16px; }
  .statusbar { padding: 10px 16px 20px; }
  .notice.warn { margin: 0 16px 12px; }
  .stage { padding: 8px 8px 16px; }
  .nav { display: none; }
  .center { padding-top: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
