/* Import modern, clean typeface */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  /* Flat UI Color Palette */
  --bg-primary: #f4f6f8;
  --card-bg: #ffffff;
  --text-primary: #2c3e50;
  --text-secondary: #7f8c8d;
  
  --color-primary: #3498db;
  --color-primary-hover: #2980b9;
  --color-primary-light: #ebf5fb;
  
  --color-success: #2ecc71;
  --color-success-hover: #27ae60;
  --color-success-light: #eafaf1;
  
  --color-danger: #e74c3c;
  --color-danger-hover: #c0392b;
  --color-danger-light: #fdedec;
  
  --color-neutral: #bdc3c7;
  --border-color: #bdc3c7;
  --border-width: 2px;
  
  --radius-lg: 8px;
  --radius-md: 6px;
  
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
}

/* Global Reset */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  padding: 20px;
  -webkit-font-smoothing: antialiased;
}

/* App Layout */
.app-container {
  max-width: 800px;
  margin: 0 auto;
  padding-bottom: 60px;
}

.app-header {
  text-align: center;
  margin-bottom: 30px;
  padding: 10px 0;
}

.logo {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.5px;
  margin-bottom: 8px;
}

.subtitle {
  font-size: 1.1rem;
  color: var(--text-secondary);
}

/* Cards (Flat styling: no shadow, solid borders) */
.card {
  background-color: var(--card-bg);
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
}

.card h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 20px;
  border-bottom: var(--border-width) solid var(--bg-primary);
  padding-bottom: 10px;
}

/* Form Styles */
.form-group {
  margin-bottom: 24px;
}

.step-label {
  display: block;
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.help-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 6px;
}

.help-text-block {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

/* Inputs and Buttons */
input[type="url"] {
  width: 100%;
  font-family: var(--font-sans);
  font-size: 1.05rem;
  padding: 12px 16px;
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 0.15s ease-in-out;
  background-color: var(--bg-primary);
}

input[type="url"]:focus {
  border-color: var(--color-primary);
  background-color: var(--card-bg);
}

.url-input-wrapper {
  display: flex;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 600;
  padding: 12px 20px;
  border: var(--border-width) solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s, border-color 0.15s;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background-color: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
  width: 100%;
  font-size: 1.1rem;
  padding: 16px;
}

.btn-primary:hover {
  background-color: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

.btn-secondary {
  background-color: transparent;
  color: var(--text-primary);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  background-color: var(--bg-primary);
}

.btn-danger {
  background-color: var(--color-danger);
  color: white;
  border-color: var(--color-danger);
}

.btn-danger:hover {
  background-color: var(--color-danger-hover);
  border-color: var(--color-danger-hover);
}

/* Format Choice Radio Buttons Styled as Cards */
.format-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 600px) {
  .format-options {
    grid-template-columns: 1fr;
  }
}

.format-card {
  position: relative;
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
  background-color: var(--card-bg);
}

.format-card input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.format-card-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.format-card-content .icon {
  font-size: 2rem;
  margin-bottom: 6px;
}

.format-card-content .title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.format-card-content .desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Format Card Selected State */
.format-card.active {
  border-color: var(--color-primary);
  background-color: var(--color-primary-light);
}

.format-card.active .title {
  color: var(--color-primary-hover);
}

/* Cookie Options Radio Groups */
.cookie-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cookie-option {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}

.cookie-option input[type="radio"] {
  margin-right: 12px;
  width: 18px;
  height: 18px;
  accent-color: var(--color-primary);
}

.cookie-option:hover {
  background-color: var(--bg-primary);
}

.cookie-option.active {
  border-color: var(--color-primary);
  background-color: var(--color-primary-light);
}

.cookie-label-text {
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  border: var(--border-width) solid transparent;
}

.badge-gray {
  background-color: #e2e8f0;
  color: #4a5568;
  border-color: #cbd5e0;
}

.badge-green {
  background-color: var(--color-success-light);
  color: var(--color-success-hover);
  border-color: var(--color-success);
}

.badge-red {
  background-color: var(--color-danger-light);
  color: var(--color-danger);
  border-color: var(--color-danger);
}

/* Active Downloads Card */
.active-download-card {
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
  background-color: var(--bg-primary);
}

.active-download-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
  gap: 12px;
}

.active-download-title {
  font-size: 1rem;
  font-weight: 700;
  word-break: break-word;
}

.progress-bar-container {
  height: 16px;
  background-color: #e2e8f0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  margin-bottom: 10px;
}

.progress-bar-fill {
  height: 100%;
  background-color: var(--color-primary);
  width: 0%;
  transition: width 0.2s ease-out;
}

.active-download-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.active-download-meta .status {
  font-weight: 700;
}

.active-download-meta .status.completed {
  color: var(--color-success-hover);
}

.active-download-meta .status.failed {
  color: var(--color-danger);
}

.active-download-error {
  margin-top: 10px;
  font-size: 0.85rem;
  background-color: var(--color-danger-light);
  border: 1px solid var(--color-danger);
  color: var(--color-danger);
  padding: 8px 12px;
  border-radius: 4px;
  white-space: pre-wrap;
  word-break: break-all;
}

/* History List */
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.history-header h2 {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.no-downloads {
  text-align: center;
  padding: 30px;
  color: var(--text-secondary);
  background-color: var(--bg-primary);
  border: var(--border-width) dashed var(--border-color);
  border-radius: var(--radius-md);
  font-size: 1rem;
}

.download-list {
  list-style: none;
}

.download-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--bg-primary);
  gap: 16px;
}

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

.download-item-info {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 0; /* Prevents overflow */
}

.file-icon {
  font-size: 1.8rem;
  user-select: none;
}

.file-details {
  min-width: 0; /* Prevents text overflow */
}

.file-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  word-break: break-all;
  margin-bottom: 2px;
}

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

.download-item-actions {
  display: flex;
  gap: 8px;
}

/* Player Overlay Modal */
.player-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(44, 62, 80, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease-out;
}

.player-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.player-modal {
  background-color: var(--card-bg);
  border: var(--border-width) solid var(--text-primary);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 760px;
  padding: 20px;
  transform: scale(0.95);
  transition: transform 0.25s ease-out;
}

.player-overlay.open .player-modal {
  transform: scale(1);
}

.player-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.player-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 75%;
}

.player-body {
  background-color: black;
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 16 / 9;
}

#web-video-player {
  width: 100%;
  height: 100%;
  display: block;
}

#web-audio-player {
  width: 80%;
  margin: 40px auto;
  display: block;
}

.app-footer {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 30px;
  padding: 10px;
  border-top: var(--border-width) solid var(--border-color);
}

/* System-detected Dark Mode */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #121212;
    --card-bg: #1e1e1e;
    --text-primary: #f5f6f7;
    --text-secondary: #a0aec0;
    --border-color: #333333;
    --color-primary-light: #1a2f42;
    --color-success-light: #162f1c;
    --color-danger-light: #2d1918;
  }
  
  input[type="url"], select {
    background-color: #2b2b2b;
    color: #ffffff;
  }
  
  input[type="url"]:focus {
    background-color: #1e1e1e;
  }
  
  .btn-secondary {
    color: #f5f6f7;
    border-color: #444;
  }
  
  .btn-secondary:hover {
    background-color: #2b2b2b;
  }
  
  .format-card {
    background-color: #1e1e1e;
  }
  
  .format-card.active {
    background-color: var(--color-primary-light);
  }
  
  .cookie-option {
    background-color: #1e1e1e;
  }
  
  .cookie-option:hover {
    background-color: #252525;
  }
  
  .cookie-option.active {
    background-color: var(--color-primary-light);
  }
  
  .badge-gray {
    background-color: #2d2d2d;
    color: #cbd5e0;
    border-color: #4a5568;
  }
  
  .active-download-card {
    background-color: #222222;
  }
  
  .progress-bar-container {
    background-color: #2d2d2d;
  }
  
  .no-downloads {
    background-color: #222222;
    border-color: #333333;
  }
  
  .download-item {
    border-bottom: 1px solid #2d2d2d;
  }
  
  .player-modal {
    background-color: #1e1e1e;
    border-color: #444444;
  }
}

