@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

:root {
  --bg: #000000;
  --bg-grad: radial-gradient(ellipse at 50% 0%, #0d1117 0%, #000000 70%);
  --surface: rgba(255, 255, 255, 0.04);
  --surface-hover: rgba(255, 255, 255, 0.07);
  --surface-solid: #111318;
  --glass: rgba(255, 255, 255, 0.06);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-strong: rgba(255, 255, 255, 0.1);
  --text: #f0f0f5;
  --text-secondary: rgba(255, 255, 255, 0.55);
  --text-dim: rgba(255, 255, 255, 0.3);
  --accent: #e31937;
  --accent-glow: rgba(227, 25, 55, 0.25);
  --accent-soft: rgba(227, 25, 55, 0.1);
  --success: #00d26a;
  --warning: #ffb800;
  --danger: #ff3b5c;
  --radius: 16px;
  --radius-sm: 10px;
  --font: 'Outfit', -apple-system, sans-serif;
  --mono: 'JetBrains Mono', monospace;
  --header-h: 72px;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  background-image: var(--bg-grad);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
}

body.is-tesla {
  cursor: none;
}

.hidden { display: none !important; }

/* ===== AMBIENT BACKGROUND ===== */
.ambient-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  pointer-events: none;
  z-index: 0;
  opacity: 0.4;
}

.orb-1 {
  width: 600px;
  height: 600px;
  background: var(--accent);
  top: -200px;
  right: -100px;
  opacity: 0.07;
}

.orb-2 {
  width: 400px;
  height: 400px;
  background: #1a3a8a;
  bottom: -100px;
  left: -100px;
  opacity: 0.06;
}

/* ===== SCREENS ===== */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

/* ===== LOGIN / QR ===== */
.login-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 64px;
  padding: 56px 64px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 28px;
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  max-width: 780px;
  animation: cardIn 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes cardIn {
  from { opacity: 0; transform: scale(0.96) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.login-brand {
  flex-shrink: 0;
  text-align: center;
  min-width: 200px;
}

.brand-mark {
  width: 72px;
  height: 72px;
  background: var(--accent);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  box-shadow: 0 8px 32px var(--accent-glow);
  position: relative;
}

.brand-mark::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 24px;
  background: linear-gradient(135deg, var(--accent), transparent 60%);
  opacity: 0.3;
  z-index: -1;
}

.brand-mark svg {
  width: 28px;
  height: 28px;
  fill: white;
  margin-left: 3px;
}

.brand-name {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}

.brand-tag {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 400;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.login-divider {
  width: 1px;
  height: 220px;
  background: linear-gradient(transparent, var(--glass-border), transparent);
  flex-shrink: 0;
}

.qr-section {
  text-align: center;
  flex-shrink: 0;
}

.qr-label {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  font-weight: 400;
  line-height: 1.5;
}

.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.qr-frame {
  position: relative;
  padding: 16px;
  background: white;
  border-radius: 16px;
}

.qr-frame img {
  display: block;
  width: 180px;
  height: 180px;
  border-radius: 4px;
}

.qr-loading {
  width: 180px;
  height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 14px;
}

.qr-direct-link {
  color: var(--accent);
  font-size: 13px;
  text-decoration: none;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 8px;
  transition: background 0.2s;
}

.qr-direct-link:active {
  background: var(--accent-soft);
}

.qr-hint {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
  margin-top: 4px;
}

.pass-login {
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--glass-border);
}

.pass-toggle {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 4px;
}

.pass-toggle:active {
  color: var(--text);
}

.pass-form {
  margin-top: 14px;
}

.pass-form .input-group {
  margin-bottom: 10px;
}

.pass-form .btn {
  width: 100%;
}

.pass-error {
  margin-top: 10px;
  font-size: 12px;
  color: var(--danger);
}

.qr-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 24px;
  padding: 14px 20px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  animation: pulse-soft 2s ease infinite;
}

@keyframes pulse-soft {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--glass-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.qr-expired {
  text-align: center;
  margin-top: 24px;
}

.qr-expired p {
  color: var(--text-secondary);
  margin-bottom: 16px;
  font-size: 14px;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 28px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, background 0.2s, opacity 0.2s;
  -webkit-appearance: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-primary:active {
  background: #c4152f;
}

.btn-glass {
  background: var(--glass-strong);
  color: var(--text);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(12px);
}

.btn-glass:active {
  background: rgba(255,255,255,0.14);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 14px 16px;
}

.btn-ghost:active {
  color: var(--text);
}

.btn-icon {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 12px;
  font-size: 18px;
}

/* ===== HEADER ===== */
header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--glass-border);
  z-index: 50;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-logo {
  width: 40px;
  height: 40px;
  background: var(--accent);
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-logo svg {
  width: 16px;
  height: 16px;
  fill: white;
  margin-left: 2px;
}

.header-title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-greeting {
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 400;
  margin-right: 8px;
}

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

#dashboard-screen.hidden { display: none !important; }

main {
  flex: 1;
  padding: calc(var(--header-h) + 24px) 32px 24px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

main::-webkit-scrollbar {
  width: 6px;
}

main::-webkit-scrollbar-track {
  background: transparent;
}

main::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
}

/* ===== VIDEO GRID ===== */
.videos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 20px;
}

.is-tesla .videos-grid {
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 24px;
}

.video-card {
  position: relative;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.2s;
  animation: cardFadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.video-card:nth-child(1)  { animation-delay: 0.05s; }
.video-card:nth-child(2)  { animation-delay: 0.1s; }
.video-card:nth-child(3)  { animation-delay: 0.15s; }
.video-card:nth-child(4)  { animation-delay: 0.2s; }
.video-card:nth-child(5)  { animation-delay: 0.25s; }
.video-card:nth-child(6)  { animation-delay: 0.3s; }
.video-card:nth-child(7)  { animation-delay: 0.35s; }
.video-card:nth-child(8)  { animation-delay: 0.4s; }

@keyframes cardFadeIn {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.video-card:active {
  transform: scale(0.98);
  border-color: var(--accent);
}

.video-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  background: var(--surface-solid);
  overflow: hidden;
}

.video-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s;
}

.video-card:active .video-thumb img {
  transform: scale(1.03);
}

.video-thumb::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: linear-gradient(transparent, rgba(0,0,0,0.6));
  pointer-events: none;
}

.play-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.2s;
}

.video-card:active .play-overlay {
  opacity: 1;
}

.play-overlay-circle {
  width: 56px;
  height: 56px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 24px var(--accent-glow);
}

.play-overlay-circle svg {
  width: 22px;
  height: 22px;
  fill: white;
  margin-left: 2px;
}

.duration-badge {
  position: absolute;
  bottom: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  padding: 4px 10px;
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  z-index: 3;
  letter-spacing: 0.5px;
}

.status-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 5px 12px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  z-index: 3;
}

.status-downloading {
  background: rgba(255, 184, 0, 0.9);
  color: #1a1a1a;
  animation: pulse-soft 1.5s ease infinite;
}

.status-error {
  background: rgba(255, 59, 92, 0.9);
  color: white;
}

.status-ready {
  background: rgba(0, 210, 106, 0.9);
  color: #1a1a1a;
}

.video-info {
  padding: 16px 18px;
}

.video-info h3 {
  font-size: 15px;
  font-weight: 500;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  letter-spacing: -0.1px;
}

.video-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 400;
}

.video-actions {
  display: flex;
  gap: 2px;
}

.delete-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}

.delete-btn:active {
  background: rgba(255, 59, 92, 0.15);
  color: var(--danger);
}

/* ===== EMPTY STATE ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 80px 20px;
  animation: cardFadeIn 0.5s ease;
}

.empty-visual {
  width: 120px;
  height: 120px;
  border-radius: 32px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
}

.empty-visual svg {
  width: 48px;
  height: 48px;
  stroke: var(--text-dim);
  fill: none;
  stroke-width: 1.5;
}

.empty-state h3 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 14px;
  color: var(--text-secondary);
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px;
  color: var(--text-dim);
  font-size: 14px;
}

.loading .spinner {
  width: 20px;
  height: 20px;
}

/* ===== MODAL ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-content {
  background: var(--surface-solid);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  padding: 36px;
  width: 100%;
  max-width: 480px;
  margin: 20px;
  animation: cardIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-content h3 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 6px;
}

.modal-hint {
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 20px;
}

.input-group {
  margin-bottom: 16px;
}

.input-group input {
  width: 100%;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}

.input-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input-group input::placeholder {
  color: var(--text-dim);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 8px;
}

#download-status {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  text-align: center;
  font-weight: 500;
}

/* ===== PLAYER ===== */
.player-body {
  background: #000;
  overflow: hidden;
}

#player-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.player-top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  background: linear-gradient(rgba(0,0,0,0.8), transparent);
  z-index: 20;
  transition: opacity 0.3s;
}

.back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  background: rgba(255,255,255,0.1);
  backdrop-filter: blur(12px);
  border: none;
  border-radius: 14px;
  color: white;
  font-size: 20px;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}

.back-btn:active {
  background: rgba(255,255,255,0.2);
}

.video-title {
  font-family: var(--font);
  font-size: 16px;
  font-weight: 500;
  color: rgba(255,255,255,0.9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#player-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  overflow: hidden;
}

#player-canvas {
  width: 100% !important;
  height: 100% !important;
  object-fit: contain;
  display: block;
}

/* Player Controls */
.controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 40px 24px 20px;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 10;
  transition: opacity 0.3s;
}

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

.progress-bar {
  /* Direct child of the column-flex .controls: `flex: 1` here grows the bar
     along the vertical axis, and since .controls has no fixed height there is
     no free space to grow into, so the bar collapses to zero and vanishes.
     A fixed height with full width is what a seek bar actually needs. */
  width: 100%;
  flex: none;
  height: 10px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 5px;
  cursor: pointer;
  position: relative;
  touch-action: none;
}

.is-tesla .progress-bar {
  height: 16px;
  border-radius: 8px;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
  width: 0%;
  position: relative;
  z-index: 2;
  transition: width 0.1s linear;
}

.progress-fill::after {
  content: '';
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  opacity: 0;
  transition: opacity 0.15s;
}

.progress-bar:active .progress-fill::after {
  opacity: 1;
}

.is-tesla .progress-fill::after {
  opacity: 1;
  width: 18px;
  height: 18px;
  right: -9px;
}

.progress-buffered {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: rgba(255, 255, 255, 0.1);
  border-radius: inherit;
  width: 0%;
  z-index: 1;
}

.ctrl-btn {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
  backdrop-filter: blur(8px);
}

.is-tesla .ctrl-btn {
  width: 60px;
  height: 60px;
  border-radius: 16px;
  font-size: 22px;
}

.ctrl-btn:active {
  background: rgba(255, 255, 255, 0.2);
}

.ctrl-btn.play-main {
  width: 64px;
  height: 52px;
  background: var(--accent);
  box-shadow: 0 4px 20px var(--accent-glow);
}

.is-tesla .ctrl-btn.play-main {
  width: 72px;
  height: 60px;
}

.ctrl-btn.play-main:active {
  background: #c4152f;
}

.time-display {
  font-family: var(--mono);
  font-size: 13px;
  color: rgba(255, 255, 255, 0.65);
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: 0.5px;
  min-width: 100px;
}

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

.volume-slider {
  width: 100px;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
  outline: none;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: white;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.controls-spacer {
  flex: 1;
}

/* Always show controls on Tesla (no hover) */
.is-tesla .controls,
.is-tesla .player-top-bar {
  opacity: 1 !important;
}

/* Loading overlay for player */
.player-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(0,0,0,0.6);
  z-index: 30;
}

.player-loading .spinner {
  width: 32px;
  height: 32px;
  border-width: 3px;
}

.player-loading span {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ===== RESPONSIVE / TESLA ===== */
@media (max-width: 768px) {
  .login-card {
    flex-direction: column;
    gap: 32px;
    padding: 36px 28px;
  }

  .login-divider {
    width: 100%;
    height: 1px;
  }

  .videos-grid {
    grid-template-columns: 1fr;
  }

  header {
    padding: 0 20px;
    height: 60px;
  }

  main {
    padding: calc(60px + 16px) 16px 16px;
  }

  .volume-group {
    display: none;
  }
}

/* Tesla landscape mode */
@media (min-width: 1200px) and (max-height: 900px) {
  .videos-grid {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  }
}
