:root {
  --bg: #0b1020;
  --panel: #121a33;
  --text: #eaf1ff;
  --muted: #a7b3d7;
  --accent: #5cc8ff;
  --visited: #2ecc71;
  --top: #ffc107;
  --border: #253158;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
  background: var(--bg); /* Dark background by default */
}

.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 64px;
  padding: 8px 16px;
  display: flex; /* Always visible when main-app is shown */
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  backdrop-filter: blur(8px);
  background: linear-gradient(180deg, rgba(10,16,32,0.85), rgba(10,16,32,0.35) 80%, rgba(10,16,32,0));
  border-bottom: 1px solid var(--border);
  z-index: 500;
}

.title { display: flex; align-items: center; gap: 12px; }
.title h2 { margin: 0; font-size: 18px; font-weight: 600; color: var(--text); }
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 999px;
  background: linear-gradient(135deg, #ff4d4d, #ff9a62);
  color: white; font-weight: 800; box-shadow: 0 6px 20px rgba(255,120,80,0.35);
}

.legend { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.legend .key { display:inline-block; width:16px; height:16px; border-radius: 4px; border: 1px solid var(--border); }
.legend .visited { background: var(--visited); }
.legend .top { background: var(--top); }
.legend .circle { border-radius: 999px; }
.legend .cat-view { background: #4cc9f0; border-color: #2a6f97; }
.legend .cat-xc { background: #b5e48c; border-color: #52796f; }
.legend .cat-wc { background: #ff8fab; border-color: #9d4edd; }
.legend .cat-emerging { background: #ffd166; border-color: #ef476f; }
.legend .legend-text { margin-right: 6px; }

.right-panel { display: flex; align-items: center; gap: 18px; }
.scoreboard {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px;
  background: rgba(10,16,32,0.55); border: 1px solid var(--border); border-radius: 12px;
  cursor: pointer;
}
.scoreboard .ratio { font-weight: 700; color: var(--text); }
.scoreboard .pct { color: var(--muted); font-size: 12px; }
.scoreboard .units { display: flex; align-items: center; gap: 4px; margin-left: 6px; }
.scoreboard .unit {
  width: 18px; height: 18px; border-radius: 50%; overflow: hidden; border: 1px solid var(--border);
  background: linear-gradient(135deg, #182248, #0c1430);
  display: grid; place-items: center;
}
.scoreboard .unit img { width: 100%; height: 100%; object-fit: cover; display: block; }
.scoreboard .unit.dim { opacity: 0.25; filter: grayscale(0.8); }

.media-browser-btn {
  background: linear-gradient(135deg, #4cc9f0, #7b8bff);
  color: #041026;
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(76, 201, 240, 0.3);
}

.media-browser-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(76, 201, 240, 0.4);
}

/* Media Browser Modal */
.media-browser {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  backdrop-filter: blur(4px);
}

.media-browser[hidden] {
  display: none !important;
}

.media-browser-content {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: min(95vw, 900px);
  max-height: 90vh;
  overflow: hidden;
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
}

.media-browser-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.media-browser-header h3 {
  margin: 0;
  font-size: 1.4rem;
  color: var(--text);
}

.browser-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

#browser-counter {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
}

.browser-close {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: background-color 0.2s;
}

.browser-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.media-browser-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px;
  gap: 20px;
  overflow: hidden;
}

.media-display {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
  overflow: hidden;
  min-height: 400px;
  position: relative;
}

.media-display img,
.media-display video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

.media-display img {
  display: block;
}

.media-display video {
  display: none;
}

.media-info {
  text-align: center;
  padding: 16px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.media-info h4 {
  margin: 0 0 8px 0;
  font-size: 1.2rem;
  color: var(--text);
}

.media-info p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.4;
}

.media-browser-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.browser-nav-btn {
  background: linear-gradient(135deg, #5cc8ff, #7b8bff);
  color: #041026;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 100px;
}

.browser-nav-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(92, 200, 255, 0.3);
}

.browser-nav-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--border);
  color: var(--muted);
}

.app-main { 
  position: absolute; 
  inset: 64px 0 40px 0; 
  display: block; /* Always visible when main-app is shown */
}
#map { height: 100%; width: 100%; }

.celebrate {
  position: fixed; inset: 0; display: grid; place-items: start center; padding-top: 100px;
  background: radial-gradient(900px 600px at 50% 10%, rgba(28,35,72,0.35), rgba(11,16,32,0.7));
  z-index: 4000; backdrop-filter: blur(2px);
}
.celebrate[hidden] { display: none !important; }
.confetti-canvas, #confetti-canvas {
  position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 3500;
}

/* Gallery overlay */
.gallery { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(5,10,20,0.75); z-index: 3800; backdrop-filter: blur(2px); }
.gallery[hidden] { display:none !important; }
.gallery-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; width: min(95vw, 980px); max-height: 85vh; overflow: hidden; box-shadow: 0 30px 100px rgba(0,0,0,0.6); }
.gallery-header { display: flex; align-items:center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.gallery-header h3 { margin: 0; font-size: 18px; }
.gallery-controls { display: flex; align-items: center; gap: 12px; }
.toggle-group { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.toggle-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 14px;
}

.toggle-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.toggle-btn.active {
  background: var(--accent);
  color: #041026;
  font-weight: 600;
}

/* Add indicator for All Destinations button */
#toggle-all::after {
  content: " (" attr(data-count) ")";
  font-size: 12px;
  opacity: 0.8;
}
.btn-close { background: transparent; color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; cursor: pointer; }
.btn-export { background: transparent; color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 16px; transition: all 0.2s; }
.btn-export:hover { background: var(--accent); color: #041026; border-color: var(--accent); }
.gallery-body { overflow: auto; padding: 12px; background: #0f1631; max-height: 60vh; }
.grid { width: 100%; border-collapse: collapse; table-layout: fixed; }
.grid th, .grid td { border-bottom: 1px solid var(--border); padding: 8px; text-align: left; word-wrap: break-word; }
.grid th:nth-child(1) { width: 15%; } /* Country */
.grid th:nth-child(2) { width: 20%; } /* Title */
.grid th:nth-child(3) { width: 20%; } /* Exact Location */
.grid th:nth-child(4) { width: 15%; } /* Media */
.grid th:nth-child(5) { width: 12%; } /* Date */
.grid th:nth-child(6) { width: 18%; } /* Notes */

/* Table container with horizontal scroll */
.table-container {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 60vh;
  border-radius: 8px;
  background: #0f1631;
}

.table-container::-webkit-scrollbar {
  height: 8px;
  width: 8px;
}

.table-container::-webkit-scrollbar-track {
  background: #0a1020;
  border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}
.grid img { width: 80px; height: 50px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.grid input, .grid textarea { 
  width: 100%; 
  background: #0e1530; 
  color: var(--text); 
  border: 1px solid var(--border); 
  border-radius: 6px; 
  padding: 6px; 
  transition: border-color 0.3s, background-color 0.3s;
}

.grid input:focus, .grid textarea:focus { 
  outline: none; 
  border-color: var(--accent); 
  background: #0f1631;
}

.grid input.saving, .grid textarea.saving {
  border-color: #4CAF50;
  background: rgba(76, 175, 80, 0.1);
}

.grid input.saved, .grid textarea.saved {
  border-color: #4CAF50;
  background: rgba(76, 175, 80, 0.05);
}

/* Save indicator */
.save-indicator {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: #4CAF50;
  opacity: 0;
  transition: opacity 0.3s;
}

.save-indicator.show {
  opacity: 1;
}

/* Input container for positioning save indicator */
.input-container {
  position: relative;
}

.input-container input,
.input-container textarea {
  padding-right: 60px;
}
.grid tr.not-visited { opacity: 0.6; background: rgba(15,22,49,0.3); }
.grid tr.not-visited input, .grid tr.not-visited textarea { background: #0a1020; color: var(--muted); }
.celebrate-card{
  background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 28px; width: min(92vw, 680px);
  box-shadow: 0 28px 80px rgba(0,0,0,0.55); text-align: center;
}
.celebrate-card h3{ margin: 0 0 12px; font-size: 32px; letter-spacing: 0.3px; }
.celebrate-card p{ margin: 0; color: var(--muted); font-size: 18px; line-height: 1.45; }

/* Champagne pop micro-animation */
@keyframes pop-burst {
  0% { transform: translateY(8px) scale(0.8); opacity: 0; }
  30% { transform: translateY(-6px) scale(1.05); opacity: 1; }
  70% { transform: translateY(-18px) scale(1); opacity: 1; }
  100% { transform: translateY(-28px) scale(0.9); opacity: 0; }
}
.popper {
  position: absolute; top: 80px; right: min(5vw, 24px); font-size: 28px; filter: drop-shadow(0 6px 12px rgba(0,0,0,0.45));
}
.cork { position: absolute; top: 60px; right: calc(min(5vw, 24px) + 24px); font-size: 22px; animation: pop-burst 1.4s ease-out forwards; }

.credits {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 40px;
  display: flex; /* Always visible when main-app is shown */
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: linear-gradient(0deg, rgba(10,16,32,0.85), rgba(10,16,32,0.35) 80%, rgba(10,16,32,0));
  border-top: 1px solid var(--border);
  letter-spacing: 0.3px;
  font-size: 14px;
}

.password-screen {
  position: fixed; 
  inset: 0; 
  display: grid; 
  place-items: center; 
  background: #000000; /* Pure black background */
  z-index: 1000;
}

.password-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 40px;
  width: min(90vw, 400px);
  text-align: center;
  backdrop-filter: blur(10px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.duck-icon {
  font-size: 4rem;
  margin-bottom: 20px;
  filter: drop-shadow(0 4px 8px rgba(255, 255, 0, 0.3));
}

.password-card h1 { 
  margin: 0 0 16px 0; 
  font-size: 1.8rem; 
  color: #ffffff;
  font-weight: 600;
}

.password-card p { 
  margin: 0 0 24px 0; 
  color: rgba(255, 255, 255, 0.7); 
  font-size: 1rem;
  line-height: 1.5;
}

.password-card form { 
  display: flex; 
  flex-direction: column;
  gap: 16px;
  align-items: center; 
}

.password-card input {
  width: 100%;
  padding: 12px 16px; 
  border-radius: 12px; 
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.1); 
  color: #ffffff;
  font-size: 1rem;
  backdrop-filter: blur(5px);
}

.password-card input::placeholder {
  color: rgba(255, 255, 255, 0.5);
}

.password-card input:focus {
  outline: none;
  border-color: #ffd700;
  box-shadow: 0 0 0 2px rgba(255, 215, 0, 0.2);
}

.password-card button {
  padding: 12px 24px; 
  border-radius: 12px; 
  border: none;
  background: linear-gradient(135deg, #ffd700, #ffed4e);
  color: #000000; 
  font-weight: 700; 
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(255, 215, 0, 0.3);
}

.password-card button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(255, 215, 0, 0.4);
}

.error { 
  margin-top: 8px; 
  color: #ff6b6b; 
  min-height: 1.2em; 
  font-size: 0.9rem;
}

/* Leaflet theming tweaks */
.leaflet-container { background: #0c1228; }
.leaflet-popup-content-wrapper { background: #0f1836; color: var(--text); border: 1px solid var(--border); border-radius: 12px; }
.leaflet-popup-tip { background: #0f1836; }
.leaflet-control-zoom a { background: #101a39; color: var(--text); border: 1px solid var(--border); }

.media {
  max-width: 320px;
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}
.media video, .media img, .media iframe { width: 100%; height: auto; border: 0; border-radius: 10px; display: block; }

/* Media gallery for multiple files */
.media-gallery {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 400px;
  overflow-y: auto;
}
.media-gallery .media {
  max-width: 280px;
}

/* Grid media display */
.grid-media {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-width: 200px;
}
.grid-media img, .grid-media video {
  width: 60px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
}

/* Circular map marker icons for cat/dad */
.leaflet-marker-icon.cat-icon,
.leaflet-marker-icon.dad-icon {
  border-radius: 50% !important;
  border: 2px solid #ffffffaa;
  background: #ffffff;
  box-shadow: 0 8px 20px rgba(0,0,0,0.35);
  object-fit: cover;
}

/* Image Modal */
.image-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  backdrop-filter: blur(4px);
}

.image-modal[hidden] {
  display: none !important;
}

.image-modal-content {
  position: relative;
  max-width: 95vw;
  max-height: 95vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.image-modal-close {
  position: absolute;
  top: -40px;
  right: 0;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  backdrop-filter: blur(4px);
  transition: background-color 0.2s;
}

.image-modal-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

#modal-image {
  max-width: 100%;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

#modal-video {
  max-width: 100%;
  max-height: 85vh;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  display: none;
}

.image-modal-caption {
  margin-top: 16px;
  color: white;
  text-align: center;
  font-size: 14px;
  max-width: 80%;
  line-height: 1.4;
}

/* Make grid images and videos clickable */
.grid-media img,
.grid-media video {
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.grid-media img:hover,
.grid-media video:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Export Popup */
.export-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10001;
  backdrop-filter: blur(4px);
}

.export-content {
  background: #0f1631;
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.export-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: #0a1020;
}

.export-header h4 {
  margin: 0;
  color: var(--text);
}

.export-close {
  background: transparent;
  color: var(--text);
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.export-close:hover {
  background: rgba(255, 255, 255, 0.1);
}

.export-body {
  padding: 20px;
  overflow-y: auto;
  max-height: 60vh;
  flex: 1;
}

.export-body pre {
  margin: 0;
  color: var(--text);
  font-family: 'Courier New', monospace;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.export-footer {
  display: flex;
  gap: 12px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: #0a1020;
}

.btn-copy, .btn-download {
  background: var(--accent);
  color: #041026;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.btn-copy:hover, .btn-download:hover {
  background: #ffd54f;
  transform: translateY(-1px);
}

/* Mobile export popup adjustments */
@media (max-width: 680px) {
  .export-content {
    max-width: 95vw;
    max-height: 95vh;
  }
  
  .export-header {
    padding: 12px 16px;
  }
  
  .export-body {
    padding: 16px;
    max-height: 50vh;
  }
  
  .export-footer {
    padding: 12px 16px;
    flex-direction: column;
  }
  
  .btn-copy, .btn-download {
    width: 100%;
    padding: 12px;
  }
}

@media (max-width: 680px) {
  .title h2 { font-size: 16px; }
  
  /* Mobile header adjustments */
  .app-header {
    height: 56px;
    padding: 6px 12px;
    flex-direction: column;
    height: auto;
    min-height: 56px;
  }
  
  .title {
    margin-bottom: 4px;
  }
  
  .right-panel {
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .legend {
    font-size: 12px;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .legend .legend-text {
    margin-right: 4px;
  }
  
  .scoreboard {
    padding: 4px 8px;
    gap: 6px;
    font-size: 12px;
  }
  
  .scoreboard .units {
    gap: 2px;
  }
  
  .scoreboard .unit {
    width: 14px;
    height: 14px;
  }
  
  /* Mobile map adjustments */
  .app-main {
    inset: auto 0 40px 0;
    top: 80px;
  }
  
  /* Mobile gallery adjustments */
  .gallery-card {
    width: 95vw;
    max-height: 90vh;
    margin: 10px;
  }
  
  .gallery-header {
    padding: 12px;
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
  }
  
  .gallery-controls {
    justify-content: space-between;
  }
  
  .toggle-group {
    flex: 1;
    margin-right: 8px;
  }
  
  .toggle-btn {
    padding: 8px 12px;
    font-size: 12px;
  }
  
  .gallery-body {
    padding: 8px;
    max-height: 70vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Mobile table adjustments */
  .table-container {
    max-height: 65vh;
    overflow-x: auto;
    overflow-y: auto;
  }
  
  .grid {
    font-size: 12px;
    table-layout: auto;
    min-width: 600px;
  }
  
  .grid th, .grid td {
    padding: 6px 4px;
    white-space: nowrap;
  }
  
  .grid th:nth-child(3), .grid td:nth-child(3) {
    white-space: normal;
    word-wrap: break-word;
  }
  
  .grid-media {
    max-width: 120px;
  }
  
  .grid-media img, .grid-media video {
    width: 40px;
    height: 30px;
  }
  
  /* Mobile media gallery adjustments */
  .media-gallery {
    max-height: 300px;
  }
  
  .media-gallery .media {
    max-width: 240px;
  }
  
  /* Mobile celebration adjustments */
  .celebrate {
    padding-top: 60px;
  }
  
  .celebrate-card {
    width: 90vw;
    padding: 20px;
  }
  
  .celebrate-card h3 {
    font-size: 24px;
  }
  
  .celebrate-card p {
    font-size: 16px;
  }
  
  /* Mobile password screen adjustments */
  .password-card {
    width: 90vw;
    padding: 20px;
  }
  
  .password-card form {
    flex-direction: column;
    gap: 12px;
  }
  
  .password-card input,
  .password-card button {
    width: 100%;
    padding: 12px;
  }
}

@media (max-width: 480px) {
  /* Extra small mobile adjustments */
  .app-header {
    padding: 4px 8px;
  }
  
  .title h2 {
    font-size: 14px;
  }
  
  .badge {
    width: 32px;
    height: 32px;
    font-size: 12px;
  }
  
  .legend {
    font-size: 11px;
  }
  
  .scoreboard {
    font-size: 11px;
    padding: 3px 6px;
  }
  
  .scoreboard .unit {
    width: 12px;
    height: 12px;
  }
  
  .gallery-card {
    width: 98vw;
    margin: 5px;
  }
  
  .grid {
    font-size: 11px;
  }
  
  .grid th, .grid td {
    padding: 4px 2px;
  }
  
  .grid-media {
    max-width: 100px;
  }
  
  .grid-media img, .grid-media video {
    width: 35px;
    height: 25px;
  }
  
  .media-gallery .media {
    max-width: 200px;
  }
  
  .celebrate-card h3 {
    font-size: 20px;
  }
  
  .celebrate-card p {
    font-size: 14px;
  }
}

/* Touch-friendly interactions */
@media (hover: none) and (pointer: coarse) {
  .scoreboard {
    cursor: pointer;
    transition: background-color 0.2s;
  }
  
  .scoreboard:active {
    background: rgba(10,16,32,0.75);
  }
  
  .toggle-btn {
    min-height: 44px;
  }
  
  .btn-close {
    min-height: 44px;
    min-width: 44px;
  }
  
  .grid input, .grid textarea {
    min-height: 44px;
  }
  
  .password-card button {
    min-height: 44px;
  }
}

/* Touch device optimizations */
.touch-device .scoreboard {
  -webkit-tap-highlight-color: transparent;
}

.touch-device .gallery-body {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.touch-device .media-gallery {
  -webkit-overflow-scrolling: touch;
}

/* Prevent text selection on interactive elements */
.scoreboard, .toggle-btn, .btn-close {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Mobile-friendly focus states */
@media (hover: none) and (pointer: coarse) {
  .toggle-btn:focus,
  .btn-close:focus,
  .password-card button:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }
}

/* Landscape mobile adjustments */
@media (max-width: 900px) and (orientation: landscape) {
  .app-header {
    height: 48px;
    padding: 4px 12px;
  }
  
  .app-main {
    top: 48px;
  }
  
  .gallery-card {
    max-height: 85vh;
  }
  
  .celebrate {
    padding-top: 40px;
  }
}

/* Mobile modal adjustments */
@media (max-width: 680px) {
  .image-modal-content {
    max-width: 98vw;
    max-height: 98vh;
  }
  
  .image-modal-close {
    top: -50px;
    right: 10px;
    width: 40px;
    height: 40px;
    font-size: 20px;
  }
  
  #modal-image {
    max-height: 80vh;
  }
  
  .image-modal-caption {
    font-size: 12px;
    margin-top: 12px;
  }
}

/* Loading Animation */
.loading-animation {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #0b1020 0%, #1a1f3a 50%, #0b1020 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  overflow: hidden;
}

.loading-animation[hidden] {
  display: none !important;
}

.loading-content {
  text-align: center;
  z-index: 10;
  position: relative;
}

.loading-title h2 {
  font-size: 2.5rem;
  margin: 0 0 1rem 0;
  background: linear-gradient(45deg, #ff6b6b, #4ecdc4, #45b7d1, #96ceb4, #ffeaa7);
  background-size: 400% 400%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradient-shift 2s ease-in-out infinite;
}

.loading-title p {
  font-size: 1.2rem;
  color: var(--muted);
  margin: 0 0 2rem 0;
}

.loading-gallery {
  width: 600px;
  height: 400px;
  margin: 0 auto 2rem auto;
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  min-height: 400px;
  min-width: 600px;
}

.loading-gallery img {
  position: absolute;
  width: 120px;
  height: 80px;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transform: scale(0.5) rotate(-10deg);
  transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  z-index: 1;
}

.loading-gallery img.show {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

.loading-gallery img.hide {
  opacity: 0;
  transform: scale(1.2) rotate(10deg);
}

.loading-progress {
  display: flex;
  align-items: center;
  gap: 1rem;
  justify-content: center;
}

.progress-bar {
  width: 300px;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #ff6b6b, #4ecdc4, #45b7d1, #96ceb4);
  background-size: 200% 100%;
  border-radius: 4px;
  width: 0%;
  transition: width 0.3s ease;
  animation: progress-glow 2s ease-in-out infinite;
}

.progress-text {
  color: var(--text);
  font-weight: 600;
  font-size: 1.1rem;
  min-width: 50px;
}

.fireworks-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

@keyframes gradient-shift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

@keyframes progress-glow {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

@keyframes pop-in {
  0% {
    opacity: 0;
    transform: scale(0.3) rotate(-180deg);
  }
  50% {
    opacity: 1;
    transform: scale(1.1) rotate(5deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
}

@keyframes pop-out {
  0% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: scale(0.8) rotate(10deg);
  }
}

/* Floating celebration elements */
.celebration-emoji {
  position: absolute;
  font-size: 2rem;
  animation: float 3s ease-in-out infinite;
  z-index: 15;
}

@keyframes float {
  0%, 100% { transform: translateY(0px) rotate(0deg); }
  50% { transform: translateY(-20px) rotate(180deg); }
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .loading-title h2 {
    font-size: 1.8rem;
  }
  
  .loading-gallery {
    width: 90vw;
    height: 300px;
  }
  
  .loading-gallery img {
    width: 80px;
    height: 60px;
  }
  
  .progress-bar {
    width: 200px;
  }
}

@media (max-width: 768px) {
  .media-browser-content {
    width: 95vw;
    max-height: 95vh;
  }
  
  .media-browser-header {
    padding: 12px 16px;
  }
  
  .media-browser-header h3 {
    font-size: 1.2rem;
  }
  
  .media-browser-body {
    padding: 16px;
    gap: 16px;
  }
  
  .media-display {
    min-height: 300px;
  }
  
  .browser-nav-btn {
    padding: 8px 12px;
    font-size: 0.9rem;
  }
}

/* Main App Container */
.main-app {
  position: fixed;
  inset: 0;
  background: radial-gradient(1200px 800px at 20% 0%, #131c3b, var(--bg));
}

.main-app[hidden] {
  display: none !important;
}

