/* ============================================================
   APPLICATION MODERNIZATION LABS — RETRO 8-BIT GALLERY
   A love letter to NES, Game Boy, and classic arcade aesthetics
   ============================================================ */

/* Google Fonts — authentic pixel typography */
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=VT323&display=swap');

/* ── 1. CSS Custom Properties ───────────────────────────────── */

:root {
  /* Light theme (default) */
  --bg-primary:    #f0e6d3;
  --bg-secondary:  #e6d9c3;
  --card-bg:       #ffffff;
  --text-primary:  #2d2d2d;
  --text-secondary:#5a5a5a;
  --border-color:  #4a4a8a;
  --header-bg:     #e8dcc8;
  --sidebar-bg:    #e8dcc8;
  --footer-bg:     #e8dcc8;
  --shadow-color:  rgba(74, 74, 138, 0.25);
  --overlay-bg:    rgba(0, 0, 0, 0.5);
  --input-bg:      #ffffff;
  --scanline-alpha: 0.03;

  /* Shared palette */
  --primary:       #00d4aa;
  --primary-dark:  #00b894;
  --secondary:     #ff6b9d;
  --accent:        #ffd93d;
  --error:         #ff4757;
  --success:       #2ed573;
  --card-border:   #4a4a8a;

  /* Typography */
  --font-heading:  'Press Start 2P', cursive;
  --font-body:     'VT323', monospace;

  /* Sizing */
  --header-height: 80px;
  --sidebar-width: 280px;
  --pixel:         4px;
  --radius:        0px; /* no rounded corners — pixels are squares! */

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-base: 0.25s ease;
}

[data-theme="dark"] {
  --bg-primary:    #0f0f23;
  --bg-secondary:  #16163a;
  --card-bg:       #1a1a3e;
  --text-primary:  #e8e8e8;
  --text-secondary:#a0a0c0;
  --border-color:  #4a4a8a;
  --header-bg:     #12122e;
  --sidebar-bg:    #12122e;
  --footer-bg:     #12122e;
  --shadow-color:  rgba(0, 212, 170, 0.15);
  --overlay-bg:    rgba(0, 0, 0, 0.75);
  --input-bg:      #1a1a3e;
  --scanline-alpha: 0.05;
}

/* ── 2. Reset & Base ────────────────────────────────────────── */

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: var(--font-body);
  font-size: 20px;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  line-height: 1.5;
  min-height: 100vh;
  transition: background-color var(--transition-base),
              color var(--transition-base);
  image-rendering: pixelated;
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: unset;
}

/* Pixel grid background pattern */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(rgba(74, 74, 138, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(74, 74, 138, 0.04) 1px, transparent 1px);
  background-size: 16px 16px;
}

/* CRT scanline overlay */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, var(--scanline-alpha)) 2px,
    rgba(0, 0, 0, var(--scanline-alpha)) 4px
  );
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--secondary);
}

img {
  max-width: 100%;
  display: block;
  image-rendering: pixelated;
}

ul, ol { list-style: none; }

/* ── 3. Scrollbar Styling ───────────────────────────────────── */

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-left: 2px solid var(--border-color);
}

::-webkit-scrollbar-thumb {
  background: var(--primary);
  border: 2px solid var(--border-color);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--secondary);
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--primary) var(--bg-secondary);
}

/* ── 4. Animations ──────────────────────────────────────────── */

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

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

@keyframes slideInLeft {
  from { transform: translateX(-100%); }
  to   { transform: translateX(0); }
}

@keyframes typewriter {
  0%   { width: 0; }
  100% { width: 100%; }
}

@keyframes pixelPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0, 212, 170, 0.4); }
  50%      { box-shadow: 0 0 0 6px rgba(0, 212, 170, 0); }
}

@keyframes pressStart {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Card entrance cascade */
.lab-card {
  animation: fadeInUp 0.4s ease both;
}
.lab-card:nth-child(1)  { animation-delay: 0.05s; }
.lab-card:nth-child(2)  { animation-delay: 0.10s; }
.lab-card:nth-child(3)  { animation-delay: 0.15s; }
.lab-card:nth-child(4)  { animation-delay: 0.20s; }
.lab-card:nth-child(5)  { animation-delay: 0.25s; }
.lab-card:nth-child(6)  { animation-delay: 0.30s; }
.lab-card:nth-child(7)  { animation-delay: 0.35s; }
.lab-card:nth-child(8)  { animation-delay: 0.40s; }
.lab-card:nth-child(9)  { animation-delay: 0.45s; }

/* ── 5. Header ──────────────────────────────────────────────── */

.header {
  position: sticky;
  top: 0;
  z-index: 100;
  width: 100%;
  background-color: var(--header-bg);
  border-bottom: var(--pixel) solid var(--border-color);
  box-shadow:
    0 var(--pixel) 0 0 rgba(0, 0, 0, 0.2),
    0 calc(var(--pixel) * 2) 0 0 rgba(0, 0, 0, 0.1);
  transition: background-color var(--transition-base);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1600px;
  margin: 0 auto;
  padding: 12px 24px;
  min-height: var(--header-height);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-left .logo {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
}

.header-left .title-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.header-left .site-title {
  font-family: var(--font-heading);
  font-size: 14px;
  color: var(--primary);
  text-shadow:
    2px 2px 0 var(--border-color),
    4px 4px 0 rgba(0, 0, 0, 0.2);
  letter-spacing: 1px;
}

.header-left .tagline {
  font-family: var(--font-body);
  font-size: 18px;
  color: var(--text-secondary);
  overflow: hidden;
  white-space: nowrap;
}

.header-left .tagline .cursor {
  animation: blink 1s step-end infinite;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ── 6. Buttons ─────────────────────────────────────────────── */

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-heading);
  font-size: 9px;
  padding: 10px 18px;
  color: #0f0f23;
  background-color: var(--primary);
  border: 3px solid var(--border-color);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: transform var(--transition-fast),
              box-shadow var(--transition-fast),
              background-color var(--transition-fast);
  box-shadow:
    4px 4px 0 0 var(--border-color);
  position: relative;
}

.btn-primary:hover {
  background-color: var(--accent);
  transform: translateY(-2px);
  box-shadow:
    4px 6px 0 0 var(--border-color),
    0 0 12px rgba(0, 212, 170, 0.4);
}

.btn-primary:active {
  transform: translateY(2px);
  box-shadow:
    2px 2px 0 0 var(--border-color);
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-heading);
  font-size: 8px;
  padding: 8px 14px;
  color: var(--text-primary);
  background-color: var(--bg-secondary);
  border: 2px solid var(--border-color);
  cursor: pointer;
  text-transform: uppercase;
  transition: transform var(--transition-fast),
              box-shadow var(--transition-fast);
  box-shadow:
    3px 3px 0 0 var(--border-color);
}

.btn-secondary:hover {
  background-color: var(--primary);
  color: #0f0f23;
  transform: translateY(-2px);
  box-shadow:
    3px 5px 0 0 var(--border-color);
}

.btn-secondary:active {
  transform: translateY(2px);
  box-shadow:
    1px 1px 0 0 var(--border-color);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  font-size: 20px;
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  color: var(--text-primary);
  cursor: pointer;
  transition: background-color var(--transition-fast),
              transform var(--transition-fast),
              box-shadow var(--transition-fast);
  box-shadow:
    3px 3px 0 0 var(--border-color);
}

.btn-icon:hover {
  background-color: var(--accent);
  color: #0f0f23;
  transform: translateY(-2px);
  box-shadow:
    3px 5px 0 0 var(--border-color);
}

.btn-icon:active {
  transform: translateY(2px);
  box-shadow:
    1px 1px 0 0 var(--border-color);
}

/* Theme toggle */
#theme-toggle {
  font-size: 18px;
  line-height: 1;
}

/* ── 7. Dropdown ────────────────────────────────────────────── */

.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: var(--card-bg);
  border: 3px solid var(--border-color);
  box-shadow:
    4px 4px 0 0 var(--border-color),
    8px 8px 0 0 rgba(0, 0, 0, 0.1);
  z-index: 200;
  padding: 4px 0;
  transition: background-color var(--transition-base);
}

.dropdown-menu.open,
.dropdown-menu.show {
  display: block;
  animation: fadeInUp 0.15s ease;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  font-family: var(--font-body);
  font-size: 20px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background-color var(--transition-fast),
              color var(--transition-fast);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.dropdown-item:hover {
  background-color: var(--primary);
  color: #0f0f23;
}

.dropdown-item .icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

/* ── 8. Gallery Layout ──────────────────────────────────────── */

.gallery-section {
  position: relative;
  z-index: 1;
  min-height: calc(100vh - var(--header-height));
}

.gallery-container {
  display: flex;
  max-width: 1600px;
  margin: 0 auto;
}

/* ── 9. Filter Sidebar ──────────────────────────────────────── */

.sidebar {
  position: sticky;
  top: var(--header-height);
  width: var(--sidebar-width);
  height: calc(100vh - var(--header-height));
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: var(--pixel) solid var(--border-color);
  overflow-y: auto;
  padding: 20px 16px;
  transition: background-color var(--transition-base),
              transform var(--transition-base);
  z-index: 50;
}

.sidebar-header {
  font-family: var(--font-heading);
  font-size: 10px;
  color: var(--primary);
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 2px dashed var(--border-color);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.filter-group {
  margin-bottom: 20px;
}

.filter-group label,
.filter-group-label {
  display: block;
  font-family: var(--font-heading);
  font-size: 7px;
  color: var(--accent);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.filter-group select,
.filter-group input[type="text"],
.filter-group input[type="search"] {
  width: 100%;
  padding: 8px 10px;
  font-family: var(--font-body);
  font-size: 18px;
  color: var(--text-primary);
  background: var(--input-bg);
  border: 2px solid var(--border-color);
  box-shadow: 2px 2px 0 0 var(--border-color);
  outline: none;
  transition: border-color var(--transition-fast),
              box-shadow var(--transition-fast);
  appearance: none;
  -webkit-appearance: none;
}

.filter-group select:focus,
.filter-group input:focus {
  border-color: var(--primary);
  box-shadow:
    2px 2px 0 0 var(--primary),
    0 0 8px rgba(0, 212, 170, 0.3);
}

/* Custom select arrow */
.filter-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M0 0h12L6 8z' fill='%234a4a8a'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  cursor: pointer;
}

/* Custom pixel checkboxes */
.filter-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 18px;
  color: var(--text-primary);
  transition: color var(--transition-fast);
}

.filter-checkbox:hover {
  color: var(--primary);
}

.filter-checkbox input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-color);
  background: var(--input-bg);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: background-color var(--transition-fast),
              border-color var(--transition-fast);
}

.filter-checkbox input[type="checkbox"]:checked {
  background-color: var(--primary);
  border-color: var(--primary-dark);
}

/* Pixel checkmark */
.filter-checkbox input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 10px;
  height: 10px;
  background: #0f0f23;
  clip-path: polygon(
    10% 50%, 0% 60%, 35% 100%, 100% 20%, 90% 10%, 35% 75%
  );
}

.filter-clear-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-heading);
  font-size: 7px;
  padding: 6px 12px;
  color: var(--error);
  background: transparent;
  border: 2px solid var(--error);
  cursor: pointer;
  text-transform: uppercase;
  transition: background-color var(--transition-fast),
              color var(--transition-fast);
  margin-top: 10px;
}

.filter-clear-btn:hover {
  background: var(--error);
  color: #ffffff;
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  z-index: 40;
}

.sidebar-overlay.show {
  display: block;
}

/* ── 10. Search, Sort & Results Count ───────────────────────── */

.gallery-main {
  flex: 1;
  padding: 20px 24px;
  min-width: 0;
}

.gallery-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 400px;
}

.search-box input {
  width: 100%;
  padding: 10px 14px 10px 36px;
  font-family: var(--font-body);
  font-size: 20px;
  color: var(--text-primary);
  background: var(--input-bg);
  border: 3px solid var(--border-color);
  box-shadow: 3px 3px 0 0 var(--border-color);
  outline: none;
  transition: border-color var(--transition-fast),
              box-shadow var(--transition-fast);
  caret-color: var(--primary);
}

.search-box input:focus {
  border-color: var(--primary);
  box-shadow:
    3px 3px 0 0 var(--primary),
    0 0 12px rgba(0, 212, 170, 0.25);
}

.search-box input::placeholder {
  color: var(--text-secondary);
  opacity: 0.7;
}

.search-box .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  font-size: 16px;
  pointer-events: none;
}

/* Blinking pixel cursor effect for empty search */
.search-box input:focus:placeholder-shown::after {
  animation: blink 0.8s step-end infinite;
}

.sort-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sort-group label {
  font-family: var(--font-heading);
  font-size: 7px;
  color: var(--text-secondary);
  text-transform: uppercase;
  white-space: nowrap;
}

.sort-group select {
  padding: 8px 30px 8px 10px;
  font-family: var(--font-body);
  font-size: 18px;
  color: var(--text-primary);
  background: var(--input-bg);
  border: 2px solid var(--border-color);
  box-shadow: 2px 2px 0 0 var(--border-color);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M0 0h12L6 8z' fill='%234a4a8a'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color var(--transition-fast);
}

.sort-group select:focus {
  border-color: var(--primary);
}

.results-count {
  font-family: var(--font-body);
  font-size: 20px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.results-count strong {
  color: var(--primary);
}

/* ── 11. Gallery Grid ───────────────────────────────────────── */

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

/* ── 12. Lab Cards ──────────────────────────────────────────── */

.lab-card {
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border: 3px solid var(--border-color);
  box-shadow:
    4px 4px 0 0 var(--border-color),
    8px 8px 0 0 rgba(0, 0, 0, 0.08);
  transition: transform var(--transition-fast),
              box-shadow var(--transition-fast),
              border-color var(--transition-fast);
  overflow: hidden;
  position: relative;
}

.lab-card:hover {
  transform: translateY(-4px);
  border-color: var(--primary);
  box-shadow:
    4px 8px 0 0 var(--primary),
    0 0 20px rgba(0, 212, 170, 0.2);
}

.lab-card-thumbnail {
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background:
    linear-gradient(135deg, var(--bg-secondary) 25%, transparent 25%),
    linear-gradient(225deg, var(--bg-secondary) 25%, transparent 25%),
    linear-gradient(315deg, var(--bg-secondary) 25%, transparent 25%),
    linear-gradient(45deg,  var(--bg-secondary) 25%, transparent 25%);
  background-size: 16px 16px;
  background-color: var(--card-bg);
  position: relative;
  border-bottom: 2px solid var(--border-color);
}

.lab-card-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Pixel-art placeholder pattern when no thumbnail */
.lab-card-thumbnail::before {
  content: '🎮';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  opacity: 0.3;
  z-index: 0;
}

.lab-card-thumbnail img ~ ::before {
  display: none;
}

.lab-card-body {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lab-card-title {
  font-family: var(--font-heading);
  font-size: 10px;
  line-height: 1.6;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lab-card-title a {
  color: inherit;
  text-decoration: none;
}

.lab-card-title a:hover {
  color: var(--primary);
}

.lab-card-description {
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.4;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lab-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
}

.lab-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-top: 2px solid var(--border-color);
  gap: 8px;
}

.lab-card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── 13. Badges ─────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-heading);
  font-size: 7px;
  padding: 4px 8px;
  border: 1px solid var(--border-color);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  transition: transform var(--transition-fast);
}

.badge:hover {
  transform: scale(1.05);
}

.badge-category {
  background-color: var(--primary);
  color: #0f0f23;
  border-color: var(--primary-dark);
}

.badge-language {
  background-color: var(--secondary);
  color: #ffffff;
  border-color: #e0547e;
}

.badge-framework {
  background-color: var(--accent);
  color: #0f0f23;
  border-color: #e6c435;
}

.badge-level {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  border-color: var(--border-color);
}

/* ── 14. Action Buttons (Card) ──────────────────────────────── */

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-heading);
  font-size: 7px;
  padding: 5px 10px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 2px solid var(--border-color);
  cursor: pointer;
  text-transform: uppercase;
  transition: background-color var(--transition-fast),
              color var(--transition-fast),
              transform var(--transition-fast),
              box-shadow var(--transition-fast);
  box-shadow: 2px 2px 0 0 var(--border-color);
}

.action-btn:hover {
  background: var(--primary);
  color: #0f0f23;
  transform: translateY(-1px);
  box-shadow: 2px 3px 0 0 var(--border-color);
}

.action-btn:active {
  transform: translateY(1px);
  box-shadow: 1px 1px 0 0 var(--border-color);
}

.action-btn .icon {
  font-size: 12px;
}

/* Start Lab dropdown within card */
.start-lab-dropdown {
  position: relative;
}

.start-lab-dropdown .dropdown-menu {
  right: auto;
  left: 0;
  min-width: 180px;
}

/* ── 15. Avatar / Author ────────────────────────────────────── */

.avatar {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border-color);
  overflow: hidden;
  flex-shrink: 0;
}

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

.avatar-group {
  display: flex;
  align-items: center;
}

.avatar-group .avatar {
  margin-left: -8px;
  transition: transform var(--transition-fast);
}

.avatar-group .avatar:first-child {
  margin-left: 0;
}

.avatar-group .avatar:hover {
  transform: scale(1.15);
  z-index: 2;
}

/* ── 16. Theme Toggle ───────────────────────────────────────── */

#theme-toggle .icon-sun,
#theme-toggle .icon-moon {
  transition: opacity var(--transition-base),
              transform var(--transition-base);
}

[data-theme="dark"] #theme-toggle .icon-sun {
  display: none;
}

:root #theme-toggle .icon-moon {
  display: none;
}

[data-theme="dark"] #theme-toggle .icon-moon {
  display: inline;
}

/* ── 17. Mobile Filter Toggle ───────────────────────────────── */

.mobile-filter-toggle {
  display: none;
  align-items: center;
  gap: 6px;
  font-family: var(--font-heading);
  font-size: 8px;
  padding: 8px 14px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 2px solid var(--border-color);
  cursor: pointer;
  text-transform: uppercase;
  box-shadow: 2px 2px 0 0 var(--border-color);
}

.mobile-filter-toggle:active {
  transform: translateY(2px);
  box-shadow: 0 0 0 0 var(--border-color);
}

/* ── 18. Footer ─────────────────────────────────────────────── */

.footer {
  background: var(--footer-bg);
  border-top: var(--pixel) solid var(--border-color);
  box-shadow:
    0 calc(var(--pixel) * -1) 0 0 rgba(0, 0, 0, 0.1);
  padding: 20px 24px;
  text-align: center;
  transition: background-color var(--transition-base);
}

.footer p {
  font-family: var(--font-body);
  font-size: 18px;
  color: var(--text-secondary);
}

.footer a {
  color: var(--primary);
  border-bottom: 1px dashed var(--primary);
}

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

.footer .pixel-hearts {
  font-size: 12px;
  animation: float 2s ease-in-out infinite;
  display: inline-block;
}

/* ── 19. Modal ──────────────────────────────────────────────── */

.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 500;
  align-items: center;
  justify-content: center;
  background: var(--overlay-bg);
}

.modal.open,
.modal.show {
  display: flex;
}

.modal-content {
  background: var(--card-bg);
  border: 4px solid var(--border-color);
  box-shadow:
    6px 6px 0 0 var(--border-color),
    12px 12px 0 0 rgba(0, 0, 0, 0.15);
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
  position: relative;
  animation: fadeInUp 0.2s ease;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-heading);
  font-size: 10px;
  background: var(--error);
  color: #ffffff;
  border: 2px solid var(--border-color);
  cursor: pointer;
  box-shadow: 2px 2px 0 0 var(--border-color);
  transition: transform var(--transition-fast),
              box-shadow var(--transition-fast);
}

.modal-close:hover {
  transform: translateY(-1px);
  box-shadow: 2px 3px 0 0 var(--border-color);
}

.modal-close:active {
  transform: translateY(1px);
  box-shadow: 1px 1px 0 0 var(--border-color);
}

.modal-title {
  font-family: var(--font-heading);
  font-size: 12px;
  color: var(--primary);
  margin-bottom: 16px;
  padding-right: 40px;
}

.modal-body {
  font-family: var(--font-body);
  font-size: 20px;
  color: var(--text-primary);
  line-height: 1.5;
}

/* ── 20. No Results / Empty State ───────────────────────────── */

.no-results {
  text-align: center;
  padding: 60px 20px;
  grid-column: 1 / -1;
}

.no-results .game-over {
  font-family: var(--font-heading);
  font-size: 20px;
  color: var(--error);
  margin-bottom: 16px;
  text-shadow:
    2px 2px 0 rgba(0, 0, 0, 0.3);
  animation: pressStart 1.5s ease-in-out infinite;
}

.no-results .message {
  font-family: var(--font-body);
  font-size: 24px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.no-results .pixel-face {
  font-size: 48px;
  margin-bottom: 16px;
  display: block;
}

.no-results .retry-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-heading);
  font-size: 8px;
  padding: 10px 20px;
  color: #0f0f23;
  background: var(--accent);
  border: 3px solid var(--border-color);
  cursor: pointer;
  box-shadow: 4px 4px 0 0 var(--border-color);
  text-transform: uppercase;
}

.no-results .retry-btn:hover {
  background: var(--primary);
  transform: translateY(-2px);
  box-shadow: 4px 6px 0 0 var(--border-color);
}

.no-results .retry-btn:active {
  transform: translateY(2px);
  box-shadow: 2px 2px 0 0 var(--border-color);
}

/* ── 21. Loading State ──────────────────────────────────────── */

.loading {
  text-align: center;
  padding: 60px 20px;
  grid-column: 1 / -1;
}

.loading .loading-text {
  font-family: var(--font-heading);
  font-size: 12px;
  color: var(--primary);
  animation: pressStart 1s ease-in-out infinite;
}

.loading .loading-bar {
  width: 200px;
  height: 16px;
  border: 2px solid var(--border-color);
  margin: 20px auto 0;
  background: var(--bg-secondary);
  position: relative;
  overflow: hidden;
}

.loading .loading-bar::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 30%;
  background: var(--primary);
  animation: loadingSlide 1.5s ease-in-out infinite;
}

@keyframes loadingSlide {
  0%   { left: -30%; }
  100% { left: 100%; }
}

/* ── 22. Utility Classes ────────────────────────────────────── */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.text-primary { color: var(--primary) !important; }
.text-secondary-color { color: var(--secondary) !important; }
.text-accent { color: var(--accent) !important; }
.text-error { color: var(--error) !important; }
.text-success { color: var(--success) !important; }

.pixel-border {
  border: 3px solid var(--border-color);
  box-shadow: 4px 4px 0 0 var(--border-color);
}

.hidden { display: none !important; }

/* ── 23. Responsive — Tablet ────────────────────────────────── */

@media (max-width: 1024px) {
  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
  }

  .sidebar {
    width: 240px;
  }
}

/* ── 24. Responsive — Mobile ────────────────────────────────── */

@media (max-width: 768px) {
  :root {
    --header-height: auto;
    --sidebar-width: 280px;
  }

  .header-content {
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 16px;
  }

  .header-left {
    flex: 1;
    min-width: 0;
  }

  .header-left .site-title {
    font-size: 11px;
  }

  .header-left .tagline {
    font-size: 16px;
  }

  .header-right {
    flex-wrap: wrap;
    gap: 8px;
  }

  .mobile-filter-toggle {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    transform: translateX(-100%);
    z-index: 200;
    padding-top: 20px;
    box-shadow: none;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.3);
  }

  .gallery-main {
    padding: 16px;
  }

  .gallery-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .search-box {
    max-width: 100%;
  }

  .sort-group {
    justify-content: space-between;
  }

  .gallery-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .dropdown-menu {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    min-width: 100%;
    border-left: none;
    border-right: none;
    border-bottom: none;
    box-shadow: 0 -4px 0 0 var(--border-color);
  }
}

/* ── 25. Responsive — Small Mobile ──────────────────────────── */

@media (max-width: 480px) {
  .header-left .site-title {
    font-size: 9px;
  }

  .header-left .logo {
    width: 36px;
    height: 36px;
  }

  .lab-card-title {
    font-size: 9px;
  }

  .btn-primary {
    font-size: 8px;
    padding: 8px 12px;
  }
}

/* ── 26. Print Styles ───────────────────────────────────────── */

@media print {
  body::before,
  body::after,
  .sidebar,
  .header-right,
  .mobile-filter-toggle,
  .lab-card-footer {
    display: none !important;
  }

  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .lab-card {
    box-shadow: none;
    border: 1px solid #ccc;
    break-inside: avoid;
  }
}

/* ── 27. Focus Visible (Accessibility) ──────────────────────── */

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ── 28. Selection Color ────────────────────────────────────── */

::selection {
  background: var(--primary);
  color: #0f0f23;
}

::-moz-selection {
  background: var(--primary);
  color: #0f0f23;
}

/* ── END ─ INSERT COIN TO CONTINUE ──────────────────────────── */
