*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-base: #f0f2f5;
  --glass-bg: rgba(255, 255, 255, 0.52);
  --glass-bg-hover: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(255, 255, 255, 0.72);
  --glass-shadow: 0 2px 16px rgba(0, 0, 0, 0.06), 0 0 1px rgba(0, 0, 0, 0.08);
  --glass-blur: blur(24px) saturate(180%);
  --accent: #007AFF;
  --accent-light: rgba(0, 122, 255, 0.10);
  --accent-hover: #0068e0;
  --danger: #FF3B30;
  --danger-light: rgba(255, 59, 48, 0.10);
  --danger-hover: #e0332a;
  --success: #34C759;
  --success-light: rgba(52, 199, 89, 0.10);
  --text-primary: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-muted: #aeaeb2;
  --border: rgba(0, 0, 0, 0.06);
  --input-bg: rgba(120, 120, 128, 0.08);
  --radius: 20px;
  --radius-sm: 12px;
  --radius-pill: 100px;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Inter', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 60% 50% at 15% 20%, rgba(120, 180, 255, 0.25) 0%, transparent 70%),
    radial-gradient(ellipse 50% 60% at 85% 25%, rgba(200, 140, 255, 0.18) 0%, transparent 70%),
    radial-gradient(ellipse 55% 45% at 50% 80%, rgba(100, 220, 255, 0.15) 0%, transparent 70%),
    radial-gradient(ellipse 40% 35% at 80% 75%, rgba(255, 180, 200, 0.12) 0%, transparent 70%);
}

.container {
  max-width: 520px;
  margin: 0 auto;
  padding: 12px;
}

/* Header */
.header {
  text-align: center;
  padding: 20px 0 12px;
}

.header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text-primary);
}

.header p {
  color: var(--text-secondary);
  font-size: 0.8rem;
  margin-top: 2px;
}

/* Network badge */
.network-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 8px;
  padding: 3px 12px;
  border-radius: var(--radius-pill);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--success-light);
  color: var(--success);
  border: 1px solid rgba(52, 199, 89, 0.2);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: all 0.3s ease;
}

.network-badge.offline {
  background: var(--danger-light);
  color: var(--danger);
  border-color: rgba(255, 59, 48, 0.2);
}

.network-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  transition: background 0.3s ease;
}

.network-badge.offline .network-dot {
  background: var(--danger);
}

/* Cards */
.card {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--glass-shadow);
}

.card-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

/* Storage Info */
.storage-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.stat {
  text-align: center;
  padding: 8px 4px;
  background: var(--input-bg);
  border-radius: var(--radius-sm);
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-top: 1px;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--input-bg);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 6px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #007AFF, #5AC8FA);
  border-radius: 3px;
  transition: width 0.5s ease;
  min-width: 0;
}

.progress-fill.warning {
  background: linear-gradient(90deg, #FF9500, #FF3B30);
}

.progress-label {
  text-align: right;
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px 18px;
  border: none;
  border-radius: var(--radius-pill);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

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

.btn-primary {
  background: rgba(0, 122, 255, 0.82);
  color: #fff;
  box-shadow: 0 1px 8px rgba(0, 122, 255, 0.2);
}

.btn-primary:hover {
  background: rgba(0, 104, 224, 0.9);
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn-danger {
  background: rgba(255, 59, 48, 0.82);
  color: #fff;
  box-shadow: 0 1px 8px rgba(255, 59, 48, 0.15);
}

.btn-danger:hover {
  background: rgba(224, 51, 42, 0.9);
}

.btn-outline {
  background: rgba(120, 120, 128, 0.08);
  color: var(--text-secondary);
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.btn-outline:hover {
  background: rgba(120, 120, 128, 0.14);
  color: var(--text-primary);
}

.btn-sm {
  padding: 5px 12px;
  font-size: 0.7rem;
}

.btn-block {
  width: 100%;
}

/* Input groups */
.input-group {
  margin-bottom: 10px;
}

.input-group label {
  display: block;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.input-row {
  display: flex;
  gap: 6px;
}

.input-row input {
  flex: 1;
}

input[type="text"],
input[type="url"] {
  width: 100%;
  padding: 9px 12px;
  background: var(--input-bg);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-family: inherit;
  transition: all 0.2s ease;
}

input[type="text"]:focus,
input[type="url"]:focus {
  outline: none;
  border-color: rgba(0, 122, 255, 0.4);
  background: rgba(255, 255, 255, 0.7);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
}

input[type="text"]::placeholder,
input[type="url"]::placeholder {
  color: var(--text-muted);
}

input[type="text"]:disabled,
input[type="url"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* File input */
.file-drop {
  border: 1.5px dashed rgba(0, 0, 0, 0.12);
  border-radius: var(--radius-sm);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  background: var(--input-bg);
}

.file-drop:hover,
.file-drop.dragover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.file-drop input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-drop-text {
  color: var(--text-secondary);
  font-size: 0.8rem;
}

.file-drop-text strong {
  color: var(--accent);
}

/* Divider */
.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
  color: var(--text-muted);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Cached files list */
.file-list {
  list-style: none;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.file-item:last-child {
  border-bottom: none;
}

.file-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--accent);
  font-size: 0.65rem;
  font-weight: 700;
}

.file-info {
  flex: 1;
  min-width: 0;
}

.file-name {
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

.file-size {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.file-actions {
  flex-shrink: 0;
}

.empty-state {
  text-align: center;
  padding: 20px 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* Toast notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
}

.toast {
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  padding: 8px 20px;
  font-size: 0.78rem;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  pointer-events: auto;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
  max-width: 90vw;
  color: var(--text-primary);
}

.toast.error {
  color: var(--danger);
}

.toast.success {
  color: var(--accent);
}

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

@keyframes toastOut {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(0.96); }
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* Progress overlay for downloads */
.download-progress {
  margin-top: 10px;
  display: none;
}

.download-progress.active {
  display: block;
}

.download-progress-text {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
  font-weight: 500;
}

/* Footer */
.footer {
  text-align: center;
  padding: 12px 0 28px;
  color: var(--text-muted);
  font-size: 0.65rem;
}

/* Clear all row */
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-header .card-title {
  margin-bottom: 0;
}

/* Video modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(32px) saturate(200%);
  -webkit-backdrop-filter: blur(32px) saturate(200%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.12), 0 0 1px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 560px;
  overflow: hidden;
  transform: scale(0.95) translateY(8px);
  transition: transform 0.25s ease;
}

.modal-overlay.active .modal {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
  margin-right: 12px;
}

.modal-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--input-bg);
  color: var(--text-secondary);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.modal-close:hover {
  background: rgba(120, 120, 128, 0.16);
  color: var(--text-primary);
}

.modal-close:active {
  transform: scale(0.92);
}

.modal-body {
  padding: 0;
  background: #000;
}

.modal-video {
  display: block;
  width: 100%;
  max-height: 60vh;
  outline: none;
}

/* Clickable file items */
.file-item-clickable {
  cursor: pointer;
  border-radius: var(--radius-sm);
  margin: 0 -8px;
  padding: 10px 8px;
  transition: background 0.15s ease;
}

.file-item-clickable:hover {
  background: var(--input-bg);
}

.file-item-clickable:active {
  background: rgba(120, 120, 128, 0.12);
}

/* Responsive */
@media (max-width: 400px) {
  .storage-stats {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .stat {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    text-align: left;
    padding: 6px 10px;
  }

  .stat-label {
    order: -1;
    margin-top: 0;
  }
}
