:root {
  --bg: #000;
  --fg: #fff;
  --dim: #888;
  --dim2: #555;
  --line: #2a2a2a;
  --panel: #0a0a0a;
  --panel2: #111;
  --accent: #fff;
  --danger: #ddd;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Courier New', ui-monospace, Menlo, monospace;
  min-height: 100%;
  overscroll-behavior: none;
}

body {
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

#stars {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1px 1px at 10% 20%, #fff 0, transparent 100%),
    radial-gradient(1px 1px at 80% 10%, #fff 0, transparent 100%),
    radial-gradient(1.5px 1.5px at 30% 70%, #fff 0, transparent 100%),
    radial-gradient(1px 1px at 60% 85%, #fff 0, transparent 100%),
    radial-gradient(1px 1px at 90% 60%, #fff 0, transparent 100%),
    radial-gradient(1.5px 1.5px at 45% 35%, #fff 0, transparent 100%),
    radial-gradient(1px 1px at 15% 55%, #fff 0, transparent 100%),
    radial-gradient(1px 1px at 70% 40%, #fff 0, transparent 100%);
  background-size: 100% 100%;
  opacity: 0.5;
}

.icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
  flex-shrink: 0;
}
.icon-sm { width: 14px; height: 14px; }
.icon-lg { width: 40px; height: 40px; }

.view { min-height: 100vh; }

/* ---------- LOGIN ---------- */
#view-login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 32px 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  font-size: 22px;
  letter-spacing: 0.15em;
  text-transform: lowercase;
  margin-bottom: 6px;
}
.brand.small { font-size: 16px; gap: 8px; }

.sub {
  text-align: center;
  color: var(--dim);
  font-size: 12px;
  margin: 0 0 24px;
  letter-spacing: 0.05em;
}

.field {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 12px;
  background: var(--panel2);
}
.field:focus-within { border-color: var(--fg); }
.field .icon { color: var(--dim); }
.field input {
  background: none;
  border: none;
  outline: none;
  color: var(--fg);
  font-family: inherit;
  font-size: 14px;
  width: 100%;
}

#login-btn, #upload-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  background: var(--fg);
  color: #000;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 0.05em;
  cursor: pointer;
  margin-top: 6px;
  transition: opacity 0.15s;
}
#login-btn:hover, #upload-btn:hover { opacity: 0.85; }
#login-btn:disabled, #upload-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.error {
  color: var(--danger);
  font-size: 12px;
  text-align: center;
  margin: 12px 0 0;
  border: 1px solid var(--line);
  padding: 8px;
  border-radius: 6px;
  background: #1a0000;
}

.live-stats {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--dim);
}
.stat { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.stat b { color: var(--fg); }
.ip-log {
  margin-top: 10px;
  max-height: 110px;
  overflow-y: auto;
  font-size: 10.5px;
  line-height: 1.7;
}
.ip-log .ip-row { display: flex; justify-content: space-between; gap: 8px; color: var(--dim2); }
.ip-log .ip-row.fail { color: #c77; }
.ip-log .ip-row.ok { color: #7c7; }
.ip-log .ip-addr { font-weight: bold; }

/* ---------- TOPBAR / MENU ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: rgba(0,0,0,0.9);
  backdrop-filter: blur(6px);
  z-index: 20;
}

.menu { display: flex; align-items: center; gap: 6px; }

.menu-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid transparent;
  color: var(--dim);
  padding: 8px 12px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  letter-spacing: 0.03em;
}
.menu-btn.active, .menu-btn:hover { color: var(--fg); border-color: var(--line); }
.menu-btn span { display: inline; }
.menu-btn.logout { color: var(--dim); padding: 8px; }

.online-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--dim);
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 20px;
}
.online-pill .icon { color: #7c7; }
.online-pill b { color: var(--fg); }

/* ---------- CATALOG ---------- */
.tab { padding: 20px; max-width: 1200px; margin: 0 auto; }

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

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.card:hover { border-color: var(--fg); transform: translateY(-2px); }

.card-thumb {
  aspect-ratio: 16/9;
  background: var(--panel2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--dim2);
  position: relative;
}
.card-thumb .icon-lg { width: 36px; height: 36px; }
.card-duration {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0,0,0,0.75);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
}

.card-info { padding: 10px 12px; }
.card-title {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 6px;
}
.card-meta {
  display: flex;
  gap: 8px;
  font-size: 10.5px;
  color: var(--dim);
}
.card-meta .badge {
  border: 1px solid var(--line);
  padding: 1px 6px;
  border-radius: 4px;
}

.empty {
  text-align: center;
  color: var(--dim2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 60px 0;
  font-size: 13px;
}

/* ---------- UPLOAD ---------- */
.upload-card {
  max-width: 480px;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  background: var(--panel);
}
.upload-card h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  margin: 0 0 18px;
}
.upload-card .field {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  background: none;
  border: none;
  padding: 0;
}
.upload-card .field span { font-size: 11px; color: var(--dim); }
.upload-card .field input[type="text"] {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: var(--panel2);
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 30px 16px;
  margin: 14px 0;
  cursor: pointer;
  color: var(--dim);
  text-align: center;
  font-size: 12px;
}
.dropzone:hover, .dropzone.drag { border-color: var(--fg); color: var(--fg); }

.progress-wrap {
  height: 6px;
  border-radius: 4px;
  background: var(--panel2);
  overflow: hidden;
  margin-top: 12px;
}
.progress-bar { height: 100%; width: 0%; background: var(--fg); transition: width 0.1s; }

.msg { font-size: 12px; color: var(--dim); text-align: center; margin-top: 10px; min-height: 16px; }
.msg.ok { color: #9f9; }
.msg.err { color: #f99; }

/* ---------- PLAYER ---------- */
.back-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: 1px solid var(--line);
  color: var(--dim);
  padding: 8px 14px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  margin-bottom: 14px;
}
.back-btn:hover { color: var(--fg); border-color: var(--fg); }

.player-title { font-size: 15px; margin: 0 0 12px; word-break: break-word; }

.player {
  position: relative;
  width: 100%;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  aspect-ratio: 16/9;
  touch-action: manipulation;
}

#video-el {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
}

.player-overlay {
  position: absolute;
  inset: 0;
  cursor: pointer;
}

.player-controls {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, rgba(0,0,0,0.85), transparent);
}

.seekbar {
  position: relative;
  height: 14px;
  display: flex;
  align-items: center;
  cursor: pointer;
  margin-bottom: 6px;
}
.seekbar::before {
  content: '';
  position: absolute;
  left: 0; right: 0;
  height: 4px;
  background: rgba(255,255,255,0.25);
  border-radius: 2px;
}
.seekbar-buffered {
  position: absolute;
  height: 4px;
  background: rgba(255,255,255,0.4);
  border-radius: 2px;
  width: 0%;
}
.seekbar-fill {
  position: absolute;
  height: 4px;
  background: #fff;
  border-radius: 2px;
  width: 0%;
}
.seekbar-handle {
  position: absolute;
  width: 12px; height: 12px;
  background: #fff;
  border-radius: 50%;
  left: 0%;
  transform: translateX(-50%);
}

.controls-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ctrl-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
}
.ctrl-btn:hover { background: rgba(255,255,255,0.1); }
.ctrl-btn .ctrl-label {
  position: absolute;
  font-size: 8px;
  bottom: 2px;
  pointer-events: none;
}

.time { font-size: 11px; color: #ddd; }
.time-sep { font-size: 11px; color: #777; }
.spacer { flex: 1; }

.player-meta { font-size: 11px; color: var(--dim); margin-top: 10px; }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 640px) {
  .login-card { padding: 24px 18px; }
  .menu-btn span { display: none; }
  .menu-btn { padding: 8px; }
  .topbar { padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top, 0px)); }
  .tab { padding: 14px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .card-title { font-size: 12px; }
  .ctrl-btn .icon { width: 18px; height: 18px; }
  .online-pill span { display: none; }
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
