:root {
  --bg: #0b0d17;
  --bg2: #11142a;
  --panel: #171b36;
  --panel2: #1f2448;
  --line: #2c3263;
  --ink: #e8e9f5;
  --muted: #8a8fbf;
  --accent: #4dffa6;
  --accent-ink: #062016;
  --accent2: #ff5c8a;
  --warn: #ffd23f;
  --shadow: #000;
  --px: 4px;
  --pixel: "Press Start 2P", ui-monospace, monospace;
  --body: "VT323", ui-monospace, "Courier New", monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--bg2) 2px, transparent 2px),
    linear-gradient(90deg, var(--bg2) 2px, transparent 2px);
  background-size: 32px 32px;
  color: var(--ink);
  font-family: var(--body);
  font-size: 22px;
  line-height: 1.15;
  -webkit-font-smoothing: none;
  font-smooth: never;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
/* scanlines */
body::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 100;
  background: repeating-linear-gradient(to bottom, rgba(0,0,0,.18) 0 1px, transparent 1px 3px);
}
img, video, svg { image-rendering: pixelated; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.title { font-family: var(--pixel); letter-spacing: 1px; }

/* ---------- pixel primitives ---------- */
.px-box {
  background: var(--panel);
  border: var(--px) solid var(--line);
  box-shadow: var(--px) var(--px) 0 var(--shadow);
}
.px-btn {
  font-family: var(--pixel); font-size: 10px; line-height: 1;
  color: var(--ink); background: var(--panel2);
  border: var(--px) solid var(--line);
  box-shadow: var(--px) var(--px) 0 var(--shadow);
  padding: 10px 12px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  white-space: nowrap; user-select: none;
  transition: none;
}
.px-btn:hover { border-color: var(--accent); color: var(--accent); }
.px-btn:active { transform: translate(var(--px), var(--px)); box-shadow: 0 0 0 var(--shadow); }
.px-btn:focus-visible, .px-input:focus-visible, .sort:focus-visible, .row:focus-visible {
  outline: var(--px) solid var(--warn); outline-offset: 2px;
}
.px-btn.primary { background: var(--accent); color: var(--accent-ink); border-color: #b8ffd9; }
.px-btn.primary:hover { background: #8dffc7; color: var(--accent-ink); }
.px-btn.danger { background: var(--accent2); color: #2a0612; border-color: #ffb3c8; }
.px-btn.danger:hover { background: #ff8fae; color: #2a0612; }
.px-btn.ghost { background: transparent; box-shadow: none; }
.px-btn.small { font-size: 8px; padding: 7px 9px; }
.px-btn.wide { width: 100%; padding: 16px; font-size: 12px; }
.px-btn:disabled { opacity: .5; cursor: default; }
.px-input {
  font-family: var(--body); font-size: 24px; color: var(--ink);
  background: var(--bg); border: var(--px) solid var(--line);
  padding: 6px 10px; width: 100%; border-radius: 0;
  box-shadow: inset var(--px) var(--px) 0 #05060c;
}
.px-input::placeholder { color: #50557f; }
input[type=checkbox] {
  appearance: none; width: 18px; height: 18px; margin: 0; cursor: pointer;
  background: var(--bg); border: 3px solid var(--muted);
}
input[type=checkbox]:checked { background: var(--accent); border-color: var(--accent);
  box-shadow: inset 0 0 0 3px var(--bg); }

.pix { display: block; width: 100%; height: 100%; shape-rendering: crispEdges; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-box { width: min(380px, 100%); padding: 32px 28px 24px; text-align: center; display: grid; gap: 18px; }
.logo-big { width: 96px; height: 96px; margin: 0 auto; animation: bob 1.2s steps(2) infinite; }
.login .title { font-size: 22px; line-height: 1.5; margin: 0; color: var(--accent);
  text-shadow: var(--px) var(--px) 0 #0d5a37; }
.blink-line { margin: 0; animation: blink 1s steps(1) infinite; }
.msg { min-height: 1.2em; margin: 0; color: var(--accent2); }
@keyframes blink { 50% { opacity: .35; } }
@keyframes bob { 50% { transform: translateY(-4px); } }
.shake { animation: shake .3s steps(3); }
@keyframes shake { 33% { transform: translateX(-8px); } 66% { transform: translateX(8px); } }

/* ---------- app ---------- */
.app { max-width: 1100px; margin: 0 auto; padding: 16px 16px 40px; }
.topbar { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; margin-right: auto; }
.brand .logo { width: 40px; height: 40px; display: block; }
.brand .title { font-size: 14px; color: var(--accent); text-shadow: 3px 3px 0 #0d5a37; }
.search { max-width: 280px; font-size: 22px; }

.toolbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-right: auto; font-size: 24px; min-width: 0; }
.crumbs a { color: var(--ink); text-decoration: none; padding: 0 4px; }
.crumbs a:hover { background: var(--accent); color: var(--accent-ink); }
.crumbs .sep { color: var(--muted); }
.crumbs .here { color: var(--accent); padding: 0 4px; }
.actions { display: flex; gap: 12px; flex-wrap: wrap; }

.selbar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; margin-bottom: 12px; flex-wrap: wrap; }
.selbar span { margin-right: auto; color: var(--warn); }

.list { padding: 0; }
.row {
  display: grid; grid-template-columns: 34px minmax(0, 1fr) 100px 170px 132px;
  align-items: center; gap: 8px; padding: 6px 12px; min-height: 48px;
  border-bottom: 2px dashed var(--line);
}
.row:last-child { border-bottom: 0; }
.row.head { min-height: 40px; background: var(--panel2); border-bottom: var(--px) solid var(--line); }
.sort { all: unset; cursor: pointer; font-family: var(--pixel); font-size: 9px; color: var(--muted); }
.sort:hover, .sort.on { color: var(--accent); }
.sort.on::after { content: " ▼"; }
.sort.on.asc::after { content: " ▲"; }
.item { cursor: pointer; }
.item:hover { background: var(--panel2); }
.item.selected { background: #1d3a3a; }
.item.drop-target { outline: var(--px) dashed var(--accent); outline-offset: -4px; }
.c-name { display: flex; align-items: center; gap: 12px; min-width: 0; }
.c-name .ic { width: 28px; height: 28px; flex: none; }
.c-name .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-size, .c-date { color: var(--muted); font-size: 20px; white-space: nowrap; }
.c-act { display: flex; gap: 6px; justify-content: flex-end; opacity: 0; }
.item:hover .c-act, .item:focus-within .c-act, .item.selected .c-act { opacity: 1; }
.icon-btn {
  width: 34px; height: 34px; padding: 5px; cursor: pointer;
  background: var(--bg); border: 3px solid var(--line); color: var(--ink);
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn.del:hover { border-color: var(--accent2); }

.empty { text-align: center; padding: 48px 16px; }
.empty p:first-of-type { font-family: var(--pixel); font-size: 12px; }
.empty-icon { width: 72px; height: 72px; margin: 0 auto 8px; opacity: .8; }

.footer { display: flex; align-items: center; gap: 16px; margin-top: 20px; }
.meter { width: 220px; height: 20px; border: var(--px) solid var(--line); background: var(--bg); padding: 2px; }
.meter-fill {
  height: 100%; width: 0;
  background: repeating-linear-gradient(90deg, var(--accent) 0 8px, transparent 8px 10px);
}
.meter-fill.full { background: repeating-linear-gradient(90deg, var(--accent2) 0 8px, transparent 8px 10px); }

/* ---------- upload queue ---------- */
.queue {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 30;
  width: min(380px, calc(100vw - 32px)); max-height: 50vh; overflow: auto; padding: 0;
}
.queue-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px;
  background: var(--panel2); font-family: var(--pixel); font-size: 10px; position: sticky; top: 0; }
.q-item { padding: 8px 12px; border-top: 2px dashed var(--line); }
.q-top { display: flex; gap: 8px; justify-content: space-between; font-size: 20px; }
.q-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-pct { color: var(--muted); flex: none; }
.q-bar { height: 14px; margin-top: 4px; border: 3px solid var(--line); background: var(--bg); padding: 1px; }
.q-fill { height: 100%; width: 0;
  background: repeating-linear-gradient(90deg, var(--accent) 0 6px, transparent 6px 8px); }
.q-item.err .q-fill { background: var(--accent2); width: 100% !important; }
.q-item.err .q-pct { color: var(--accent2); }

/* ---------- overlays ---------- */
.drop { position: fixed; inset: 0; z-index: 40; background: rgba(11,13,23,.85);
  display: grid; place-items: center; pointer-events: none; }
.drop-box { padding: 32px 48px; text-align: center; border-color: var(--accent); border-style: dashed; }
.drop-box div { width: 80px; height: 80px; margin: 0 auto 12px; animation: bob .8s steps(2) infinite; }
.drop-box p { font-family: var(--pixel); font-size: 12px; color: var(--accent); margin: 0; }

.modal { position: fixed; inset: 0; z-index: 50; background: rgba(5,6,12,.75); display: grid; place-items: center; padding: 16px; }
.modal-box { width: min(440px, 100%); padding: 24px; display: grid; gap: 14px; }
.modal-box h2 { font-family: var(--pixel); font-size: 12px; margin: 0; color: var(--accent); line-height: 1.5; }
.modal-box p { margin: 0; overflow-wrap: anywhere; }
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 6px; }

.preview { position: fixed; inset: 0; z-index: 45; background: rgba(5,6,12,.94); display: flex; flex-direction: column; }
.preview-bar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--panel); border-bottom: var(--px) solid var(--line); }
.preview-bar #preview-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spacer { flex: 1; }
.preview-body { flex: 1; min-height: 0; display: grid; place-items: center; padding: 16px; overflow: auto; }
.preview-body img, .preview-body video { max-width: 100%; max-height: 100%; image-rendering: auto;
  border: var(--px) solid var(--line); box-shadow: var(--px) var(--px) 0 #000; }
.preview-body iframe { width: 100%; height: 100%; border: var(--px) solid var(--line); background: #fff; }
.preview-body pre { width: 100%; max-width: 1000px; height: 100%; margin: 0; overflow: auto; padding: 16px;
  background: var(--bg); border: var(--px) solid var(--line); font-family: var(--body); font-size: 20px;
  white-space: pre-wrap; overflow-wrap: anywhere; place-self: stretch center; }
.preview-body audio { width: min(500px, 100%); }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 60; padding: 10px 16px; max-width: calc(100vw - 32px); border-color: var(--accent); }
.toast.bad { border-color: var(--accent2); color: #ffc2d3; }

/* ---------- small screens ---------- */
@media (max-width: 720px) {
  body { font-size: 20px; }
  .brand .title { font-size: 11px; }
  .search { max-width: none; order: 3; flex-basis: 100%; }
  .row { grid-template-columns: 30px minmax(0, 1fr) 108px; }
  .c-date { display: none; }
  .c-size { display: none; }
  .row .c-act { grid-column: 3; opacity: 1; }
  .row.head .c-act { display: none; }
  .icon-btn { width: 30px; height: 30px; padding: 4px; }
  .meter { width: 140px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; }
}
