/* Design Tokens & Theme Setup */
:root {
  --bg-primary: #09090b;
  --bg-secondary: #121215;
  --card-bg: rgba(20, 20, 28, 0.55);
  --card-hover: rgba(30, 30, 42, 0.7);
  --border-color: rgba(255, 255, 255, 0.07);
  --border-focus: rgba(6, 182, 212, 0.5);
  
  /* Color Palette */
  --accent-cyan: #06b6d4;
  --accent-purple: #8b5cf6;
  --accent-pink: #d946ef;
  --text-primary: #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-muted: #52525b;
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  
  /* Layout Dimensions */
  --header-height: 70px;
  --border-radius-lg: 16px;
  --border-radius-md: 12px;
  --border-radius-sm: 8px;
  
  /* Typography */
  --font-main: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Base Styles & Reset */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body, html {
  font-family: var(--font-main);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100%;
  overflow-x: hidden;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Typography Utilities */
h1 {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin-bottom: 0.5rem;
}

h2 {
  font-size: 1.3rem;
  font-weight: 600;
}

p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.gradient-text {
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Animations */
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.05); opacity: 0.8; }
}

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

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

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

.pulse {
  animation: pulse 2.5s infinite ease-in-out;
}

.spin-animation {
  animation: spin 0.8s linear infinite;
}

/* Component Layout & Containers */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: relative;
}

/* App Header */
.app-header {
  height: var(--header-height);
  padding: 0 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  background: rgba(9, 9, 11, 0.85);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-image {
  width: 32px;
  height: 32px;
  border-radius: var(--border-radius-sm);
  box-shadow: 0 0 12px rgba(6, 182, 212, 0.4);
}

.logo-text {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.015em;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: fadeIn 0.3s ease-out;
}

.user-name {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  object-fit: cover;
}

/* View Sections */
.app-main {
  flex: 1;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  position: relative;
}

.view-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  animation: slideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.hidden {
  display: none !important;
}

/* Glassmorphism Cards */
.glass-card {
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 1.5rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
}

/* Login View Styling */
#view-login {
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.card-icon-header {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.15), rgba(139, 92, 246, 0.15));
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.5rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--accent-cyan);
}

.large-icon {
  width: 32px;
  height: 32px;
}

.small-icon {
  width: 16px;
  height: 16px;
  vertical-align: middle;
}

.auth-code-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 0;
  gap: 1rem;
}

.auth-instructions {
  margin-top: 1.5rem;
  text-align: left;
  border-top: 1px solid var(--border-color);
  padding-top: 1.5rem;
}

.instruction-label {
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
  font-size: 0.9rem;
}

.instruction-label:not(:first-of-type) {
  margin-top: 1.25rem;
}

.user-code-display {
  font-family: monospace;
  font-size: 2.2rem;
  font-weight: 700;
  text-align: center;
  background: rgba(0, 0, 0, 0.4);
  border: 1px dashed var(--border-color);
  border-radius: var(--border-radius-md);
  padding: 0.75rem;
  letter-spacing: 0.1em;
  color: #fff;
  text-shadow: 0 0 10px rgba(6, 182, 212, 0.3);
  margin: 0.75rem 0 1.25rem;
}

.poll-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: center;
}

.indicator {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.indicator.green {
  background-color: var(--success);
  box-shadow: 0 0 8px var(--success);
  animation: pulse 1.5s infinite;
}

/* Button UI */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  font-family: var(--font-main);
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--border-radius-md);
  border: none;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  text-decoration: none;
  width: 100%;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
  color: white;
  box-shadow: 0 4px 16px rgba(139, 92, 246, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(139, 92, 246, 0.45);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-link {
  text-decoration: none;
  color: var(--accent-cyan);
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
}

.icon-btn-text {
  width: auto;
}

/* Toolbar & Filter Options */
.directory-toolbar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  align-items: center;
  flex-shrink: 0;
}

.toolbar-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-shrink: 0;
}

.toolbar-select {
  background: rgba(20, 20, 25, 0.85);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  padding-right: 1.8rem;
  transition: border-color 0.2s;
}

.toolbar-select:hover,
.toolbar-select:focus {
  border-color: var(--accent-primary);
  outline: none;
}


.search-wrapper {
  position: relative;
  flex: 1;
}

.search-icon {
  position: absolute;
  left: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 18px;
  height: 18px;
  pointer-events: none;
}

.search-wrapper input {
  width: 100%;
  background: rgba(20, 20, 25, 0.8);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  padding: 0.75rem 1rem 0.75rem 2.5rem;
  font-family: var(--font-main);
  font-size: 0.95rem;
  color: white;
  transition: all 0.2s ease;
}

.search-wrapper input:focus {
  outline: none;
  border-color: var(--accent-cyan);
  box-shadow: 0 0 10px rgba(6, 182, 212, 0.15);
  background: rgba(30, 30, 38, 0.9);
}

.clear-btn {
  position: absolute;
  right: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.25rem;
  cursor: pointer;
}

#refresh-btn {
  flex-shrink: 0;
  width: auto;
}

/* Torrent list / Grid cards */
.torrent-grid {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.torrent-card {
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  padding: 1rem;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
}

.torrent-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(to bottom, var(--accent-cyan), var(--accent-purple));
  opacity: 0;
  transition: opacity 0.2s ease;
}

.torrent-card:hover {
  background: var(--card-hover);
  transform: scale(1.01);
  border-color: rgba(255, 255, 255, 0.12);
}

.torrent-card:hover::before {
  opacity: 1;
}

.torrent-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}

.torrent-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.torrent-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.75rem;
  align-items: center;
}

.badge {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

.bg-blur {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}

.badge.status-ready {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.25);
  color: var(--success);
}

.torrent-info-text {
  font-size: 0.75rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

/* Spinner / Loader */
.loading-state, .empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  text-align: center;
  gap: 1rem;
}

.empty-state i {
  color: var(--text-muted);
  width: 48px;
  height: 48px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(6, 182, 212, 0.15);
  border-top-color: var(--accent-cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Torrent Info details view */
.info-header {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-shrink: 0;
}

.info-header-actions {
  display: flex;
  gap: 0.5rem;
  align-self: flex-start;
}

.torrent-meta-info {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.torrent-title {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.4;
  color: white;
}

.torrent-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  word-break: break-all;
  font-family: monospace;
  line-height: 1.4;
  margin-top: -0.25rem;
}

.torrent-badges {
  display: flex;
  gap: 0.5rem;
}

/* Files Structure / Folders list */
.files-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Group/Folder Card */
.folder-card {
  background: rgba(20, 20, 25, 0.35);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  margin-bottom: 0.5rem;
  overflow: hidden;
}

.folder-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1rem;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  user-select: none;
}

.folder-header:hover {
  background: rgba(255, 255, 255, 0.04);
}

.folder-title-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.folder-header i {
  color: var(--accent-cyan);
}

.folder-header .folder-chevron {
  color: var(--text-secondary);
  transition: transform 0.2s ease;
}

.folder-card.open .folder-chevron {
  transform: rotate(180deg);
}

.folder-content {
  display: none;
  padding: 0.5rem;
  border-top: 1px solid var(--border-color);
  flex-direction: column;
  gap: 0.25rem;
}

.folder-card.open .folder-content {
  display: flex;
}

/* File Entry Card */
.file-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-radius: var(--border-radius-sm);
  background: transparent;
  cursor: pointer;
  transition: background 0.2s ease;
  gap: 1rem;
}

.file-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.file-title-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.file-item i {
  color: var(--accent-purple);
  flex-shrink: 0;
}

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

.file-size-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  flex-shrink: 0;
}

/* Playback Modal overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn 0.2s ease forwards;
}

.modal-content {
  width: 100%;
  max-width: 580px;
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.25rem;
  gap: 1rem;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.35;
  color: white;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.close-modal-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
}

.close-modal-btn:hover {
  color: white;
}

/* In-Browser Web Player style */
.web-player-container {
  width: 100%;
  margin-bottom: 1.5rem;
  background: black;
  border-radius: var(--border-radius-md);
  overflow: hidden;
  border: 1px solid var(--border-color);
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.web-player-container video {
  width: 100%;
  aspect-ratio: 16/9;
  display: block;
}

.player-disclaimer {
  font-size: 0.75rem;
  color: var(--text-secondary);
  padding: 0.6rem 0.9rem;
  background: rgba(255, 255, 255, 0.02);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.player-disclaimer i {
  color: var(--accent-cyan);
  flex-shrink: 0;
}

/* Handoff Buttons */
.playback-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.btn-vlc {
  background: linear-gradient(135deg, #f15a24, #f7931e);
  color: white;
  box-shadow: 0 4px 16px rgba(241, 90, 36, 0.25);
  font-size: 1.05rem;
  padding: 0.9rem 1.5rem;
}

.btn-vlc:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 22px rgba(241, 90, 36, 0.4);
}

.alternative-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

/* Toast Alerts */
.toast-container {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
  width: calc(100% - 2rem);
  max-width: 320px;
}

.toast {
  background: rgba(20, 20, 25, 0.9);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  color: white;
  border-radius: var(--border-radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: slideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  pointer-events: auto;
}

.toast.toast-error {
  border-left: 3px solid var(--error);
}

.toast.toast-success {
  border-left: 3px solid var(--success);
}

.toast.toast-warning {
  border-left: 3px solid var(--warning);
}

/* Responsive Scaling details */
@media (min-width: 600px) {
  body {
    background-color: #050507;
  }
  
  .app-container {
    max-width: 800px;
    margin: 0 auto;
    box-shadow: 0 0 40px rgba(0,0,0,0.5);
    background-color: var(--bg-primary);
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
  }
  
  .app-main {
    padding: 2rem;
  }
}

/* Play/Download Split Choices Layout */
.modal-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.choice-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.25rem 1rem;
  height: 100px;
  border-radius: var(--border-radius-md);
  font-size: 1.05rem;
  width: 100%;
}

.choice-btn i {
  width: 24px;
  height: 24px;
}

.btn-vlc-mini {
  background: rgba(241, 90, 36, 0.1) !important;
  border: 1px solid rgba(241, 90, 36, 0.3) !important;
  color: #f15a24 !important;
}

.btn-vlc-mini:hover {
  background: rgba(241, 90, 36, 0.25) !important;
  border-color: rgba(241, 90, 36, 0.5) !important;
}

/* Header Player Select styling */
.player-select-wrapper {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  padding: 0.3rem 0.5rem;
  margin-right: 0.75rem;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.player-select-wrapper:hover {
  border-color: rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.08);
}

.player-select-wrapper i {
  color: var(--accent-cyan);
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.player-select {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  padding-right: 0.25rem;
}

.player-select option {
  background: #09090b;
  color: var(--text-primary);
}
