:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --text: #17181c;
  --muted: #5d6270;
  --line: #e3e5ea;
  --accent: #d9731a;
  --accent-strong: #b85d0f;
  --accent-soft: #fdf0e3;
  --on-accent: #ffffff;
  --danger: #c42b1c;
  --shadow: 0 1px 2px rgba(16, 18, 24, .06), 0 8px 24px rgba(16, 18, 24, .06);
  --radius: 14px;
  --k-video: #fde8e6; --k-video-fg: #c42b1c;
  --k-audio: #efe6fb; --k-audio-fg: #7a3db8;
  --k-image: #e2f3ea; --k-image-fg: #10793f;
  --k-folder: #fdf0d9; --k-folder-fg: #b86b00;
  --k-archive: #e7eef9; --k-archive-fg: #2a5bb8;
  --k-text: #eef0f4; --k-text-fg: #4a5160;
  --k-pdf: #fde7ec; --k-pdf-fg: #b4233f;
  color-scheme: light;
}
/* Modos: sin data-theme = el del sistema; data-theme = light | dark | amoled (lo elige la persona y se recuerda). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #111215;
    --surface: #1b1c21;
    --surface-2: #24262c;
    --text: #eef0f4;
    --muted: #a3a8b5;
    --line: #2e3038;
    --accent: #f0943d;
    --accent-strong: #ffad5c;
    --accent-soft: #3a2614;
    --on-accent: #1a1006;
    --danger: #ff7b6b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --k-video: #3b1d1a; --k-video-fg: #ff8f80;
    --k-audio: #2c2140; --k-audio-fg: #c9a6f5;
    --k-image: #17302a; --k-image-fg: #6fd19c;
    --k-folder: #3a2c12; --k-folder-fg: #f5c06a;
    --k-archive: #1b2a42; --k-archive-fg: #8fb3f0;
    --k-text: #23272f; --k-text-fg: #b9c2d3;
    --k-pdf: #3b1a22; --k-pdf-fg: #ff8fa3;
    color-scheme: dark;
  }
}
:root[data-theme="dark"], :root[data-theme="amoled"] {
  --bg: #111215;
  --surface: #1b1c21;
  --surface-2: #24262c;
  --text: #eef0f4;
  --muted: #a3a8b5;
  --line: #2e3038;
  --accent: #f0943d;
  --accent-strong: #ffad5c;
  --accent-soft: #3a2614;
  --on-accent: #1a1006;
  --danger: #ff7b6b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  --k-video: #3b1d1a; --k-video-fg: #ff8f80;
  --k-audio: #2c2140; --k-audio-fg: #c9a6f5;
  --k-image: #17302a; --k-image-fg: #6fd19c;
  --k-folder: #3a2c12; --k-folder-fg: #f5c06a;
  --k-archive: #1b2a42; --k-archive-fg: #8fb3f0;
  --k-text: #23272f; --k-text-fg: #b9c2d3;
  --k-pdf: #3b1a22; --k-pdf-fg: #ff8fa3;
  color-scheme: dark;
}
/* Negro AMOLED: fondo negro puro, superficies casi negras, bordes muy sutiles */
:root[data-theme="amoled"] {
  --bg: #000000;
  --surface: #0a0a0b;
  --surface-2: #141416;
  --line: #1e1f23;
  --accent-soft: #2a1a0b;
  --shadow: none;
  --k-video: #1d0d0c; --k-audio: #160f21; --k-image: #0b1813; --k-folder: #1d160a; --k-archive: #0d1521; --k-text: #121418; --k-pdf: #1d0c11;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
a { color: inherit; }

.top {
  display: flex;
  align-items: center;
  padding: 14px max(16px, env(safe-area-inset-left));
  max-width: 920px;
  width: 100%;
  margin: 0 auto;
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-size: 16px; letter-spacing: -.01em; }
.brand b { font-weight: 650; }
.top-actions { margin-left: auto; }
.theme-btn { color: var(--muted); }
.theme-btn:hover { color: var(--text); }
.top-actions .menu-item small { color: var(--accent); font-weight: 600; }

main {
  flex: 1;
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: 8px 16px 32px;
}
.foot { text-align: center; color: var(--muted); font-size: 12.5px; padding: 0 16px 24px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* Estados: cargando, error, contraseña */
.state { display: grid; justify-items: center; gap: 10px; text-align: center; padding: 64px 16px; color: var(--muted); }
.state h1 { color: var(--text); font-size: 20px; margin: 6px 0 0; font-weight: 650; }
.state p { margin: 0; max-width: 420px; }
.state .big-icon { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); }
.state .big-icon svg { width: 28px; height: 28px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.lock { max-width: 400px; margin: 48px auto 0; padding: 28px 24px; display: grid; gap: 14px; }
.lock h1 { margin: 0; font-size: 20px; font-weight: 650; }
.lock p { margin: 0; color: var(--muted); }
.field { display: grid; gap: 6px; }
.field input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  outline: none;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.error-text { color: var(--danger); font-size: 13.5px; min-height: 1.2em; margin: 0; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--accent-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: default; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn.ghost { background: var(--surface-2); color: var(--text); border-color: var(--line); }
.btn.ghost:hover { background: var(--line); }
.btn.small { padding: 7px 12px; font-size: 13.5px; }
.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center; flex: none;
  border-radius: 10px; border: 0; background: transparent; cursor: pointer; color: inherit;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 20px; height: 20px; }

/* Cabecera del enlace */
.share-head { padding: 20px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.share-head .thumb { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; flex: none; }
.share-head .thumb svg { width: 26px; height: 26px; }
.share-head .meta { flex: 1; min-width: 200px; }
.share-head h1 { margin: 0; font-size: 19px; font-weight: 650; word-break: break-word; line-height: 1.3; }
.share-head .sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.share-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.crumbs { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; padding: 4px 4px 12px; font-size: 14px; color: var(--muted); }
.crumbs button { border: 0; background: none; padding: 4px 6px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.crumbs button:hover { background: var(--surface-2); color: var(--text); }
.crumbs .here { color: var(--text); font-weight: 600; padding: 4px 6px; }

/* Lista de archivos */
.list { margin-top: 14px; }
.list:not(.view-grid) .row:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.list:not(.view-grid) .row:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.list:not(.view-grid) .row:only-child { border-radius: var(--radius); }
.row-actions .menu-pop { z-index: 31; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px 10px 14px;
  border-top: 1px solid var(--line);
  min-height: 60px;
}
.row:first-child { border-top: 0; }
.row.clickable { cursor: pointer; }
.row.clickable:hover { background: var(--surface-2); }
.row .ico { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.row .ico svg { width: 20px; height: 20px; }
.row .name { flex: 1; min-width: 0; }
.row .name strong { display: block; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .name span { color: var(--muted); font-size: 12.5px; }
.row .row-actions { display: flex; gap: 6px; flex: none; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

.k-video { background: var(--k-video); color: var(--k-video-fg); }
.k-audio { background: var(--k-audio); color: var(--k-audio-fg); }
.k-image { background: var(--k-image); color: var(--k-image-fg); }
.k-folder { background: var(--k-folder); color: var(--k-folder-fg); }
.k-archive { background: var(--k-archive); color: var(--k-archive-fg); }
.k-text { background: var(--k-text); color: var(--k-text-fg); }
.k-pdf { background: var(--k-pdf); color: var(--k-pdf-fg); }
.k-other { background: var(--surface-2); color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: 14px; box-shadow: var(--shadow); z-index: 50;
}

/* Reproductor a pantalla completa */
.player { position: fixed; inset: 0; z-index: 40; background: #000; display: flex; flex-direction: column; color: #fff; }
.player[hidden] { display: none; }
.player-bar { display: flex; align-items: center; gap: 8px; padding: 8px max(10px, env(safe-area-inset-left)); background: #0b0b0d; }
.player-bar .icon-btn:hover { background: #222; }
.player-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.player-bar .btn.ghost { background: #1d1e22; border-color: #2c2d33; color: #fff; }
.player-stage { flex: 1; min-height: 0; display: flex; }
.player-stage movi-player { flex: 1; width: 100%; height: 100%; display: block; }
.player-note { margin: 0; padding: 10px 16px; background: #0b0b0d; color: #c9ccd4; font-size: 13.5px; text-align: center; }

.i { display: inline-grid; place-items: center; }
.i svg { width: 18px; height: 18px; }
.lock-icon { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.lock-icon svg { width: 24px; height: 24px; }
.share-head .thumb-img { width: 96px; height: 64px; object-fit: cover; border-radius: 12px; flex: none; background: var(--surface-2); }
.btn.icon-only { padding: 10px 12px; }
.btn.icon-only .lbl { display: none; }
select {
  font: inherit; color: inherit; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 7px 10px; cursor: pointer;
}

/* Menú desplegable */
.menu { position: relative; display: inline-flex; }
.menu-pop {
  position: absolute; top: calc(100% + 6px); z-index: 30; min-width: 270px; max-width: min(340px, calc(100vw - 32px));
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  padding: 6px; display: grid; gap: 2px;
}
.menu-pop.right { right: 0; }
.menu-pop.left { left: 0; }
.menu-pop.up { top: auto; bottom: calc(100% + 6px); }
.menu-pop[hidden] { display: none; }
.menu-item {
  display: flex; gap: 12px; align-items: center; text-align: left; width: 100%;
  border: 0; background: none; padding: 9px 10px; border-radius: 8px; cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); outline: none; }
.menu-item .i { color: var(--accent); }
.menu-item strong { display: block; font-weight: 550; font-size: 14px; }
.menu-item small { display: block; color: var(--muted); font-size: 12.5px; }
.menu-sep { height: 1px; background: var(--line); margin: 4px 6px; }

/* Barra de herramientas */
.toolbar { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.toolbar .search {
  flex: 1; min-width: 180px; display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 0 12px;
}
.toolbar .search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.toolbar .search .i { color: var(--muted); }
.toolbar .search input { flex: 1; min-width: 0; border: 0; background: none; padding: 9px 0; outline: none; }
.tools-right { display: flex; align-items: center; gap: 4px; }
.toolbar .check.all { padding-left: 14px; }

/* Casillas */
.check { position: relative; display: inline-grid; place-items: center; flex: none; cursor: pointer; padding: 6px; margin: -6px; }
.check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.check .box {
  width: 20px; height: 20px; border-radius: 6px; border: 1.5px solid var(--muted); display: grid; place-items: center;
  color: transparent; background: var(--surface); transition: background .12s, border-color .12s;
}
.check .box svg { width: 14px; height: 14px; stroke-width: 2.6; }
.check input:checked + .box { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.check input:indeterminate + .box { background: var(--accent); border-color: var(--accent); }
.check input:indeterminate + .box svg { display: none; }
.check input:indeterminate + .box::after { content: ""; width: 10px; height: 2px; border-radius: 1px; background: var(--on-accent); }
.check input:focus-visible + .box { box-shadow: 0 0 0 3px var(--accent-soft); }

.row.selected { background: var(--accent-soft); }
.row.selected:hover { background: var(--accent-soft); }
.row .ico.has-img { overflow: hidden; background: var(--surface-2); }
.row .ico img { width: 100%; height: 100%; object-fit: cover; display: block; }
.row .go { color: var(--muted); }
.row.seen .name strong { color: var(--muted); }
.seen-tag {
  font-style: normal; margin-left: 8px; font-size: 11.5px; padding: 1px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.list-foot { color: var(--muted); font-size: 13px; text-align: center; padding-top: 10px; min-height: 1em; }

/* Vista de cuadrícula */
.list.view-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 10px; padding: 10px; background: transparent; border: 0; box-shadow: none; overflow: visible; }
.view-grid .row {
  position: relative; flex-direction: column; align-items: stretch; gap: 8px; padding: 10px; min-height: 0;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
.view-grid .row:first-child { border-top: 1px solid var(--line); }
.view-grid .row.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.view-grid .row .check { position: absolute; top: 16px; left: 16px; z-index: 2; margin: 0; }
.view-grid .row .ico { width: 100%; height: auto; aspect-ratio: 4 / 3; border-radius: 9px; }
.view-grid .row .ico svg { width: 36px; height: 36px; }
.view-grid .row .name strong { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.3; font-size: 14px; }
.view-grid .row .row-actions { justify-content: flex-start; }
.view-grid .row .row-actions .btn .lbl { display: none; }
.view-grid .row .row-actions .btn { padding: 6px 9px; }
.view-grid .row .go { display: none; }
.view-grid .empty { grid-column: 1 / -1; background: var(--surface); border-radius: 12px; border: 1px solid var(--line); }

/* Barra de selección */
.selbar {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 35;
  width: min(720px, calc(100vw - 24px)); display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
  padding: 8px 10px;
}
.selbar[hidden] { display: none; }
.sel-count { flex: 1; font-weight: 600; min-width: 140px; }
.sel-actions { display: flex; gap: 8px; }
body.has-selbar main { padding-bottom: 110px; }
.toast { display: flex; align-items: center; gap: 14px; max-width: calc(100vw - 32px); }
.toast span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast button { border: 0; background: none; color: var(--accent); font-weight: 650; cursor: pointer; padding: 0; }
body.has-selbar .toast { bottom: 96px; }

/* Visores */
.player-bar .icon-btn:disabled { opacity: .35; cursor: default; }
.player-bar .icon-btn[hidden] { display: none; }
.player-bar .btn svg { width: 16px; height: 16px; }
/* Visor de imágenes */
.player-stage.kind-image { flex-direction: column; position: relative; background: #0b0b0d; }
.iv { position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: none; cursor: zoom-in; user-select: none; -webkit-user-select: none; }
.iv.zoomed { cursor: grab; }
.iv.dragging { cursor: grabbing; }
.iv-img { position: absolute; left: 50%; top: 50%; max-width: none; transform-origin: center center; will-change: transform; image-rendering: auto; -webkit-user-drag: none; }
.iv-spin { position: absolute; right: 16px; top: 16px; }
.iv-spin .spinner { width: 22px; height: 22px; border-width: 2.5px; border-color: rgba(255,255,255,.15); border-top-color: #f0943d; }
.iv-spin[hidden] { display: none; }
.iv-info {
  position: absolute; left: 12px; top: 12px; z-index: 2; max-width: min(320px, calc(100% - 24px));
  background: rgba(17, 18, 21, .82); backdrop-filter: blur(12px); border: 1px solid #2e3038; border-radius: 12px;
  padding: 12px 14px; color: #eef0f4; font-size: 13px;
}
.iv-info[hidden] { display: none; }
.iv-info strong { display: block; margin-bottom: 8px; word-break: break-word; }
.iv-info dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; }
.iv-info dt { color: #a3a8b5; }
.iv-info dd { margin: 0; }
.iv-bar {
  display: flex; align-items: center; justify-content: center; gap: 6px 14px; flex-wrap: wrap;
  padding: 8px max(10px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-bottom)); background: #0b0b0d; color: #eef0f4;
}
.iv-group { display: flex; align-items: center; gap: 2px; background: #1b1c21; border: 1px solid #2c2d33; border-radius: 12px; padding: 3px; }
.iv-btn { width: 38px; height: 36px; display: grid; place-items: center; border: 0; border-radius: 9px; background: none; color: inherit; cursor: pointer; }
.iv-btn:hover { background: #2a2b31; }
.iv-btn svg { width: 20px; height: 20px; }
.iv-zoom { min-width: 64px; height: 36px; border: 0; border-radius: 9px; background: none; color: inherit; font: inherit; font-size: 13px; font-variant-numeric: tabular-nums; cursor: pointer; }
.iv-zoom:hover { background: #2a2b31; }
.iv-count { color: #a3a8b5; font-size: 13px; font-variant-numeric: tabular-nums; min-width: 56px; text-align: center; }
.iv-strip {
  display: flex; gap: 6px; overflow-x: auto; padding: 8px 12px 2px; background: #0b0b0d; scrollbar-width: thin;
  scroll-behavior: smooth;
}
.iv-strip[hidden] { display: none; }
.iv-thumb { flex: none; width: 64px; height: 48px; padding: 0; border: 2px solid transparent; border-radius: 8px; overflow: hidden; background: #1b1c21; cursor: pointer; opacity: .6; transition: opacity .15s, border-color .15s; }
.iv-thumb:hover { opacity: .9; }
.iv-thumb.on { border-color: #f0943d; opacity: 1; }
.iv-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.player:fullscreen .player-bar { position: absolute; left: 0; right: 0; top: 0; z-index: 3; background: linear-gradient(#000a, transparent); }
@media (max-width: 560px) {
  .iv-bar { gap: 6px; }
  .iv-count { width: 100%; order: -1; min-width: 0; }
  .iv-btn { width: 34px; }
  .iv-zoom { min-width: 54px; }
}
.player-stage.kind-text { overflow: auto; background: #111215; }
.viewer-text {
  margin: 0; padding: 20px max(16px, env(safe-area-inset-left)); width: 100%; max-width: 980px; margin-inline: auto;
  white-space: pre-wrap; word-break: break-word; color: #e6e8ee; font: 13.5px/1.6 ui-monospace, "Cascadia Mono", Consolas, monospace;
}
.native-media { width: 100%; height: 100%; background: #000; }

@media (max-width: 560px) {
  .share-head { padding: 16px; }
  .share-head .actions { width: 100%; }
  .share-head .actions > .btn { flex: 1; }
  .row .btn .lbl { display: none; }
  .row .btn { padding: 8px 10px; }
  .row { gap: 10px; padding-left: 12px; }
  .list:not(.view-grid) .row .name strong { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.3; word-break: break-word; }
  .toolbar .search { order: -1; flex-basis: 100%; }
  .toolbar .check.all { padding-left: 12px; }
  .tools-right { margin-left: auto; }
  .list.view-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 0; }
  .sel-actions { width: 100%; }
  .sel-actions .btn { flex: 1; }
  .player-bar .btn .lbl { display: none; }
}
