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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0d0d0d;
  color: #e0e0e0;
  min-height: 100vh;
  min-height: 100dvh;
  /* Safe area for notched devices */
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* --- Login Page --- */

.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 2rem;
}

.login-container h1 {
  font-size: 2rem;
  margin-bottom: 2rem;
  color: #fff;
}

.login-error {
  display: none;
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: #e50914;
  text-align: center;
}

/* --- Home Page --- */

.home-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 2rem;
}

.home-container h1 {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
  color: #fff;
}

.home-container .subtitle {
  color: #888;
  margin-bottom: 3rem;
  font-size: 1.1rem;
  text-align: center;
}

.card {
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 500px;
  margin-bottom: 1.5rem;
}

.card h2 {
  font-size: 1.2rem;
  margin-bottom: 1rem;
  color: #fff;
}

.input-group {
  display: flex;
  gap: 0.75rem;
}

.input-group input {
  flex: 1;
  min-width: 0; /* prevent input from overflowing flex container */
  padding: 0.75rem 1rem;
  border-radius: 8px;
  border: 1px solid #333;
  background: #111;
  color: #fff;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none; /* remove iOS input styling */
}

.input-group input:focus {
  border-color: #e50914;
}

.input-group input::placeholder {
  color: #555;
}

.btn {
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent; /* remove tap highlight on mobile */
}

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

.btn-primary {
  background: #e50914;
  color: #fff;
}

.btn-primary:hover {
  background: #f40612;
}

.btn-secondary {
  background: #333;
  color: #fff;
}

.btn-secondary:hover {
  background: #444;
}

.divider {
  text-align: center;
  color: #555;
  font-size: 0.9rem;
}

/* --- Library Card --- */

.media-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.media-empty {
  color: #666;
  font-size: 0.9rem;
  text-align: center;
  padding: 1rem 0;
}

.media-empty code {
  background: #222;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.85rem;
}

.media-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem 0.5rem 0.5rem;
  background: #111;
  border: 1px solid #2a2a2a;
  border-radius: 8px;
}

.media-thumb {
  width: 96px;
  height: 54px;
  object-fit: cover;
  border-radius: 4px;
  background: #1e1e1e;
  flex-shrink: 0;
}

.media-info {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
  min-width: 0;
}

.media-name {
  font-size: 0.9rem;
  color: #e0e0e0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.media-size {
  font-size: 0.75rem;
  color: #666;
}

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

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  border-radius: 6px;
}

.btn-danger {
  background: transparent;
  color: #888;
  border: 1px solid #333;
}

.btn-danger:hover {
  color: #e50914;
  border-color: #e50914;
}

/* --- Download Progress --- */

.download-progress {
  margin-top: 1rem;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
}

.progress-filename {
  color: #ccc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 0.5rem;
}

.progress-percent {
  color: #e50914;
  flex-shrink: 0;
}

.progress-bar-track {
  width: 100%;
  height: 6px;
  background: #222;
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: #e50914;
  border-radius: 3px;
  transition: width 0.3s ease;
}

.progress-speed {
  font-size: 0.75rem;
  color: #666;
}

.progress-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.progress-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

.btn-icon {
  background: transparent;
  color: #aaa;
  border: 1px solid #333;
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.btn-icon:hover {
  color: #fff;
  border-color: #555;
}

.btn-icon-danger:hover {
  color: #e50914;
  border-color: #e50914;
}

/* --- Room Page --- */

.room-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.video-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  position: relative;
  overflow: hidden;
  min-height: 0; /* allow flex child to shrink below content size */
}

.video-wrapper .video-js {
  width: 100%;
  height: 100%;
}

.room-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
  background: #1a1a1a;
  border-top: 1px solid #2a2a2a;
  flex-shrink: 0;
}

.room-bar .room-info {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.room-bar .user-count {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: #aaa;
  font-size: 0.95rem;
}

.room-bar .user-count .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4caf50;
  display: inline-block;
}

.room-bar .share-btn {
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 1px solid #333;
  background: transparent;
  color: #ccc;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.room-bar .share-btn:hover {
  border-color: #e50914;
  color: #fff;
}

/* --- Toast Notifications --- */

.toast-container {
  position: fixed;
  top: 1.5rem;
  top: calc(1.5rem + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  pointer-events: none;
  width: 90%;
  max-width: 400px;
}

.toast {
  background: rgba(30, 30, 30, 0.92);
  color: #fff;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  font-size: 0.9rem;
  backdrop-filter: blur(8px);
  border: 1px solid #333;
  opacity: 0;
  animation: toast-in 0.3s forwards, toast-out 0.3s 2s forwards;
}

@keyframes toast-in {
  to { opacity: 1; }
}

@keyframes toast-out {
  to { opacity: 0; }
}

/* --- Error state --- */

.error-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  height: 100dvh;
  gap: 1rem;
  padding: 2rem;
  text-align: center;
}

.error-container h2 {
  color: #e50914;
}

.error-container a {
  color: #e50914;
  text-decoration: none;
}

.error-container a:hover {
  text-decoration: underline;
}

/* --- Mobile (< 600px) --- */

@media (max-width: 600px) {
  .home-container {
    padding: 1.5rem 1rem;
    justify-content: flex-start;
    padding-top: 15vh;
  }

  .home-container h1 {
    font-size: 1.8rem;
  }

  .home-container .subtitle {
    margin-bottom: 2rem;
    font-size: 1rem;
  }

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

  .input-group {
    flex-direction: column;
  }

  .input-group input {
    font-size: 16px; /* prevents iOS auto-zoom on focus */
  }

  .btn {
    width: 100%;
    padding: 0.85rem;
    font-size: 1rem;
  }

  .btn-sm {
    width: auto;
    padding: 0.35rem 0.6rem;
    font-size: 0.75rem;
  }

  .media-thumb {
    width: 80px;
    height: 45px;
  }

  .room-bar {
    padding: 0.6rem 1rem;
    padding-bottom: calc(0.6rem + env(safe-area-inset-bottom));
  }

  .room-bar .user-count {
    font-size: 0.85rem;
  }

  .room-bar .share-btn {
    padding: 0.45rem 0.75rem;
    font-size: 0.8rem;
  }
}

/* --- Tablet (601px - 1024px) --- */

@media (min-width: 601px) and (max-width: 1024px) {
  .card {
    max-width: 450px;
  }
}

/* --- Landscape mobile --- */

@media (max-height: 500px) and (orientation: landscape) {
  .home-container {
    padding-top: 1rem;
    justify-content: flex-start;
  }

  .home-container h1 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
  }

  .home-container .subtitle {
    margin-bottom: 1rem;
  }

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

  /* Hide the bar in landscape to maximize video space */
  .room-bar {
    padding: 0.4rem 1rem;
    padding-bottom: calc(0.4rem + env(safe-area-inset-bottom));
  }
}
