:root {
  --bg: #0f1117;
  --surface: #181b24;
  --surface-border: #262b3a;
  --text-main: #f0f3f6;
  --text-muted: #8b949e;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-glow: rgba(59, 130, 246, 0.25);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 1rem;
}

.app-container {
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background-color: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-icon {
  font-size: 1.5rem;
}

.header-brand h1 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--warning);
  display: inline-block;
  transition: background-color 0.2s ease;
}

.status-dot.online {
  background-color: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.status-dot.offline {
  background-color: var(--danger);
}

/* Card Container */
.card {
  background-color: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

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

.subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.4;
}

/* Pairing View */
.pairing-box {
  background: rgba(0, 0, 0, 0.25);
  border: 1px dashed var(--surface-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.pairing-box label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.url-field {
  display: flex;
  gap: 0.5rem;
}

.url-field input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  color: var(--text-main);
  padding: 0.65rem 0.85rem;
  font-family: monospace;
  font-size: 0.95rem;
}

.code-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: rgba(59, 130, 246, 0.1);
  border-radius: 8px;
  border: 1px solid rgba(59, 130, 246, 0.2);
}

.code-banner strong {
  font-family: monospace;
  font-size: 1.5rem;
  letter-spacing: 0.15em;
  color: #60a5fa;
}

.join-existing {
  border-top: 1px solid var(--surface-border);
  padding-top: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Active Rooms Section */
.active-rooms-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.section-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

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

.room-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.room-card:hover {
  background: rgba(59, 130, 246, 0.08);
  border-color: rgba(59, 130, 246, 0.4);
  transform: translateY(-1px);
}

.room-card-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.room-code {
  font-family: monospace;
  font-size: 1.2rem;
  font-weight: 700;
  color: #60a5fa;
  letter-spacing: 0.05em;
}

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

.btn-full {
  width: 100%;
}

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.join-form {
  display: flex;
  gap: 0.5rem;
}

.join-form input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  color: var(--text-main);
  padding: 0.65rem 0.85rem;
  font-size: 1.1rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-family: monospace;
}

/* Device Pill */
.device-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.75rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 20px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.device-pill strong {
  color: var(--text-main);
  margin-left: 0.25rem;
  font-family: monospace;
}

/* Status Alert */
.status-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.25);
  border-radius: 8px;
  font-size: 0.9rem;
  color: #fbbf24;
}

.status-card.connected {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.25);
  color: #34d399;
}

/* Capture Zone (Mobile) */
.capture-zone {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: stretch;
  margin: 1rem 0;
}

.btn-large {
  padding: 1.5rem;
  font-size: 1.25rem;
  border-radius: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  box-shadow: 0 4px 14px var(--accent-glow);
}

.btn-large .btn-icon {
  font-size: 1.6rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.2rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
  text-decoration: none;
  user-select: none;
}

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

.btn-primary {
  background-color: var(--accent);
  color: #ffffff;
}

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

.btn-secondary {
  background-color: #272d3d;
  color: var(--text-main);
  border: 1px solid var(--surface-border);
}

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

.btn-subtle {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--surface-border);
}

.btn-subtle:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

.btn-small {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

/* Upload Status Indicator */
.upload-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem;
  background: rgba(59, 130, 246, 0.1);
  border-radius: 8px;
  font-size: 0.95rem;
  color: #60a5fa;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(96, 165, 250, 0.2);
  border-top-color: #60a5fa;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Receiver View (Computer) */
.computer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.receiver-stage {
  min-height: 380px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px dashed var(--surface-border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.empty-state {
  text-align: center;
  padding: 2.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}

.empty-state h3 {
  font-size: 1.25rem;
  font-weight: 600;
}

.empty-state p {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.pairing-reminder {
  margin-top: 1rem;
  padding: 0.5rem 0.85rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.pairing-reminder code {
  color: #60a5fa;
  font-family: monospace;
}

.latest-photo-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.25rem;
  gap: 1rem;
}

.photo-wrapper {
  max-width: 100%;
  max-height: 520px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
}

.photo-wrapper img {
  max-width: 100%;
  max-height: 520px;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  transition: transform 0.15s ease, filter 0.15s ease;
  animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.photo-wrapper:hover img {
  filter: brightness(1.05);
}

.photo-click-hint {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 17, 23, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 0.35rem 0.85rem;
  border-radius: 20px;
  font-size: 0.8rem;
  color: #fff;
  pointer-events: none;
  opacity: 0.8;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.photo-wrapper:hover .photo-click-hint {
  opacity: 1;
  transform: translateX(-50%) translateY(-2px);
}

.copy-success-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(16, 185, 129, 0.95);
  backdrop-filter: blur(10px);
  color: #ffffff;
  padding: 0.85rem 1.5rem;
  border-radius: 30px;
  font-size: 1.1rem;
  font-weight: 700;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
  z-index: 10;
  pointer-events: none;
  animation: popFade 1.2s forwards;
}

@keyframes popFade {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  30% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.95); }
}

.photo-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-action {
  padding: 0.85rem 1.4rem;
  font-size: 1rem;
  font-weight: 600;
}

.photo-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Gallery Strip & Grid */
.thumbnail-strip {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
}

.thumbnail-strip img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--surface-border);
}

.gallery-section h3, .recent-sent-section h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.75rem;
}

.gallery-item {
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--surface-border);
  position: relative;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.gallery-item:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-item-actions {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.gallery-item:hover .gallery-item-actions {
  opacity: 1;
}

.gallery-btn {
  background: rgba(255, 255, 255, 0.9);
  color: #0f1117;
  border: none;
  border-radius: 6px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}

.gallery-btn:hover {
  background: #ffffff;
  transform: scale(1.1);
}

.gallery-btn:active {
  transform: scale(0.95);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background-color: #1e293b;
  border: 1px solid #334155;
  color: #fff;
  padding: 0.75rem 1.25rem;
  border-radius: 30px;
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 100;
  transition: opacity 0.2s, transform 0.2s;
}

.hidden {
  display: none !important;
}

.small-text {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Responsive tweaks */
@media (max-width: 600px) {
  body {
    padding: 0.5rem;
  }
  .card {
    padding: 1rem;
  }
}
