/*
 * Video Downloader – shared theme
 * Dark gothic palette: deep charcoal, forest green, luminous green accent.
 */

:root {
  /* Primary background – deep charcoal / black */
  --bg: #0a0a0c;
  /* Secondary – dark forest / moss */
  --surface: #1a2420;
  /* Cards / elevated – misty green-gray */
  --surface-elevated: #243028;
  /* Borders – mid green-gray */
  --border: #2f4a3a;
  --border-subtle: #263830;

  /* Text */
  --text: #d8e4dc;
  --text-muted: #6b8a78;
  --text-dim: #5a7268;

  /* Accent – luminous green */
  --accent: #39ff14;
  --accent-hover: #5fff3a;
  --accent-glow: rgba(57, 255, 20, 0.35);
  --accent-glow-strong: rgba(57, 255, 20, 0.5);
  --accent-subtle: rgba(57, 255, 20, 0.12);

  /* Feedback */
  --error: #c95c5c;
  --success: #5cb85c;

  --radius: 8px;
  --radius-sm: 4px;
}

* {
  box-sizing: border-box;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  min-height: 100vh;
  padding: 2rem;
  /* Subtle misty gradient for depth */
  background-image: radial-gradient(ellipse 120% 80% at 50% 0%, rgba(28, 58, 44, 0.4) 0%, transparent 55%),
    radial-gradient(ellipse 80% 50% at 80% 80%, rgba(47, 79, 63, 0.15) 0%, transparent 50%);
}

/* ----- Layout ----- */
.container {
  max-width: 720px;
  margin: 0 auto;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.page-header h1 {
  margin: 0;
}

.page-header .header-link {
  font-size: 0.875rem;
}

.guest-banner {
  position: sticky;
  top: 0;
  z-index: 100;
  margin: -2rem -2rem;
  margin-bottom: 1rem;
  padding: 0.6rem 2rem;
  background: var(--surface);
  border-bottom: 2px solid var(--accent);
  color: var(--text-muted);
  font-size: 0.875rem;
  text-align: center;
}

.auth-layout {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-container {
  max-width: 400px;
  width: 100%;
}

.auth-container h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  text-align: center;
}

/* ----- Typography ----- */
h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
}

/* ----- Cards ----- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.card:last-child {
  margin-bottom: 0;
}

/* ----- Forms ----- */
.form-row {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.url-drop-zone {
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  border-radius: var(--radius);
  padding: 0;
}

.url-drop-zone.drop-zone-active {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 12px var(--accent-glow);
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

input[type="url"],
input[type="text"],
input[type="email"],
input[type="password"] {
  width: 100%;
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.6rem 0.75rem;
  font-size: 0.9375rem;
}

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

input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

/* ----- Buttons ----- */
button,
button[type="submit"] {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  padding: 0.6rem 1.25rem;
  font-weight: 600;
  font-size: 0.9375rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

button:hover,
button[type="submit"]:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 16px var(--accent-glow);
}

button:disabled,
button[type="submit"]:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
}

.form-group + button[type="submit"],
.form-group + .message + button[type="submit"] {
  margin-top: 0.25rem;
}

button[type="submit"] {
  width: 100%;
  padding: 0.75rem 1.25rem;
}

.file-input-hidden {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
}

.button-secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.button-secondary:hover {
  background: var(--accent-subtle);
  box-shadow: none;
}

/* ----- Messages ----- */
.message {
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

.message.error {
  color: var(--error);
}

.message.success {
  color: var(--success);
}

/* ----- Links ----- */
a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s ease, text-shadow 0.2s ease;
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
  text-shadow: 0 0 12px var(--accent-glow);
}

/* ----- Auth pages ----- */
.auth-footer {
  text-align: center;
  font-size: 0.9375rem;
  color: var(--text-muted);
  margin-top: 1rem;
}

.auth-footer a {
  color: var(--accent);
}

.auth-container .button-link {
  display: inline-block;
  margin-top: 1rem;
  padding: 0.6rem 1.25rem;
  font-weight: 600;
  font-size: 0.9375rem;
  background: var(--accent);
  color: var(--bg);
  border-radius: var(--radius);
  text-decoration: none;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.auth-container .button-link:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 16px var(--accent-glow);
}

.verify-link-box {
  margin-top: 1rem;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
}

.verify-link-box a {
  color: var(--accent);
  word-break: break-all;
}

/* ----- Home page: section title ----- */
.section-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

/* ----- Tabs ----- */
.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.tabs [role="tab"] {
  padding: 0.5rem 1rem;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.tabs [role="tab"]:hover {
  color: var(--text);
}

.tabs [role="tab"][aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.search-wrap {
  margin-bottom: 1rem;
}

/* ----- Limits card ----- */
.limits-card {
  font-size: 0.875rem;
  color: var(--text-muted);
  border-left: 3px solid var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.limits-card strong {
  color: var(--text);
}

.limits-card .limits-stats {
  margin-top: 0.35rem;
}

/* ----- Video list ----- */
.video-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.video-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem;
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  background: var(--surface-elevated);
  border: 1px solid var(--border-subtle);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.video-item:hover {
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.video-thumb-wrap {
  position: relative;
  display: inline-block;
  flex-shrink: 0;
}

.video-thumb {
  width: 120px;
  height: 68px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.video-delete-btn {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 28px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.6);
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s ease;
}

.video-delete-btn:hover {
  background: var(--error);
}

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

.video-title {
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.video-title-editable {
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 0.15rem 0.25rem;
  margin: -0.15rem -0.25rem;
}

.video-title-editable:hover {
  background: var(--accent-subtle);
}

.video-title-input {
  width: 100%;
  font: inherit;
  font-weight: 500;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.2rem 0.35rem;
  margin: -0.2rem -0.35rem;
  box-sizing: border-box;
}

.video-title-input:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.video-meta {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.video-actions {
  display: flex;
  gap: 0.5rem;
}

.video-actions a,
.video-actions button {
  font-size: 0.8125rem;
  padding: 0.35rem 0.65rem;
  text-decoration: none;
  color: var(--accent);
  background: transparent;
  border: none;
  cursor: pointer;
}

.video-actions a:hover,
.video-actions button:hover {
  text-decoration: underline;
}

.video-actions .download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem;
}

.video-actions .download-link:hover {
  text-decoration: none;
}

.video-actions .video-action-icon {
  display: block;
  flex-shrink: 0;
}

.share-toggle-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.share-toggle-label {
  white-space: nowrap;
}

.share-toggle {
  width: 2.25rem;
  height: 1.2rem;
  margin: 0;
  appearance: none;
  background: var(--border);
  border-radius: 999px;
  cursor: pointer;
  position: relative;
  transition: background 0.2s ease;
}

.share-toggle::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: calc(1.2rem - 4px);
  height: calc(1.2rem - 4px);
  background: var(--text-dim);
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.share-toggle:checked {
  background: var(--accent);
}

.share-toggle:checked::before {
  transform: translateX(1.05rem);
  background: var(--bg);
}

/* ----- Delete confirmation modal ----- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(4px);
  background: rgba(0, 0, 0, 0.5);
}

.modal-backdrop:not([hidden]) {
  display: flex;
}

.modal-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

.modal-title {
  margin: 0 0 0.5rem;
  font-size: 1.125rem;
  font-weight: 600;
}

.modal-text {
  margin: 0 0 1.25rem;
  font-size: 0.9375rem;
  color: var(--text-muted);
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

.modal-actions button {
  padding: 0.5rem 1rem;
  font-size: 0.9375rem;
}

.modal-actions #delete-modal-confirm {
  background: var(--error);
  color: var(--bg);
}

.modal-actions #delete-modal-confirm:hover {
  filter: brightness(1.1);
}

.empty {
  color: var(--text-muted);
  font-size: 0.9375rem;
  padding: 1rem 0;
}

/* ----- Toasts ----- */
.toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  color: var(--error);
  max-width: 320px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translateY(0.5rem);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: auto;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.fade-out {
  opacity: 0;
  transform: translateY(0.25rem);
}

/* ----- Watch page (shared link preview + inline play) ----- */
.watch-page {
  max-width: 720px;
  margin: 0 auto;
}

.watch-card {
  overflow: hidden;
}

.watch-title {
  margin: 0 0 1rem;
  font-size: 1.25rem;
  font-weight: 600;
  word-break: break-word;
}

.watch-player-wrap {
  position: relative;
  background: var(--bg);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1rem;
}

.watch-video {
  width: 100%;
  display: block;
  max-height: 70vh;
}

.watch-video[hidden] {
  display: none;
}

.watch-no-access {
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
}

.watch-no-access p {
  margin: 0 0 1rem;
}

/* ----- Responsive ----- */
@media (max-width: 640px) {
  body {
    padding: 1rem;
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }

  .guest-banner {
    margin-left: calc(-1 * max(1rem, env(safe-area-inset-left)));
    margin-right: calc(-1 * max(1rem, env(safe-area-inset-right)));
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }

  .container {
    max-width: 100%;
  }

  h1 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
  }

  .card {
    padding: 1rem;
    margin-bottom: 1rem;
  }

  input[type="url"],
  input[type="text"],
  input[type="email"],
  input[type="password"] {
    font-size: 16px; /* prevents iOS zoom on focus */
  }

  .form-row {
    flex-direction: column;
    gap: 0.5rem;
  }

  .form-row button {
    width: 100%;
    min-height: 44px;
  }

  .limits-card .limits-stats {
    display: block;
    word-wrap: break-word;
  }

  .video-item {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .video-item > div:first-child {
    width: 100%;
  }

  .video-thumb {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    max-height: 180px;
  }

  .video-info {
    min-width: 0;
  }

  .video-title {
    word-break: break-word;
    overflow-wrap: break-word;
  }

  .video-item .video-actions {
    align-self: flex-start;
  }

  .video-actions a {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 0.75rem;
  }

  .toast-container {
    left: max(1rem, env(safe-area-inset-left));
    right: max(1rem, env(safe-area-inset-right));
    bottom: max(1rem, env(safe-area-inset-bottom));
    max-width: none;
  }

  .toast {
    max-width: none;
  }

  .auth-layout {
    padding: 1rem;
  }
}
