:root {
  --accent: #fbbf24;
  --bg-base: #0f172a;
  --bg-surface: rgba(15, 23, 42, 0.65);
  --bg-panel: rgba(15, 23, 42, 0.8);
  --header-bg: rgba(15, 23, 42, 0.7);
  --text-primary: #e2e8f0;
  --text-muted: #94a3b8;
  --border-soft: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.1);
  --chip-bg: rgba(255, 255, 255, 0.06);
  --chip-border: rgba(255, 255, 255, 0.08);
  --chip-active-text: #111827;
  --chip-active-gradient-start: rgba(251, 191, 36, 0.25);
  --chip-active-gradient-end: rgba(244, 114, 182, 0.2);
  --shadow-color: rgba(0, 0, 0, 0.35);
  --noise-opacity: 0.25;
  --lightbox-bg: rgba(15, 23, 42, 0.85);
}

body[data-theme="light"],
:root[data-theme="light"] body {
  --bg-base: #f8fafc;
  --bg-surface: rgba(255, 255, 255, 0.9);
  --bg-panel: rgba(255, 255, 255, 0.92);
  --header-bg: rgba(255, 255, 255, 0.88);
  --text-primary: #0f172a;
  --text-muted: #475569;
  --border-soft: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.12);
  --chip-bg: rgba(15, 23, 42, 0.05);
  --chip-border: rgba(15, 23, 42, 0.1);
  --chip-active-text: #0f172a;
  --chip-active-gradient-start: rgba(251, 191, 36, 0.3);
  --chip-active-gradient-end: rgba(244, 114, 182, 0.28);
  --shadow-color: rgba(15, 23, 42, 0.12);
  --noise-opacity: 0.15;
  --lightbox-bg: rgba(15, 23, 42, 0.4);
}

* {
  box-sizing: border-box;
}

body {
  font-family: 'Space Grotesk', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-base);
  color: var(--text-primary);
  transition: none;
}

body[data-theme-ready="true"] {
  transition: background-color 0.3s ease, color 0.3s ease;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.75rem;
  border-radius: 9999px;
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  color: var(--text-primary);
  font-size: 0.85rem;
}

.nav-button {
  text-align: left;
  padding: 0.9rem 1rem;
  border-radius: 0.9rem;
  border: 1px solid var(--border-soft);
  background: var(--bg-surface);
  transition: all 0.2s ease;
  color: var(--text-primary);
}

.nav-button:hover,
.nav-button.active {
  border-color: rgba(251, 191, 36, 0.4);
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.08), rgba(244, 114, 182, 0.08));
  color: var(--text-primary);
}

.filter-button {
  padding: 0.55rem 0.95rem;
  border-radius: 9999px;
  border: 1px solid var(--chip-border);
  background: var(--chip-bg);
  color: var(--text-primary);
  font-size: 0.95rem;
  transition: all 0.2s ease;
}

.filter-button:hover {
  border-color: rgba(251, 191, 36, 0.5);
  color: var(--text-primary);
}

.filter-button.active {
  background: linear-gradient(135deg, var(--chip-active-gradient-start), var(--chip-active-gradient-end));
  border-color: rgba(251, 191, 36, 0.6);
  color: var(--chip-active-text);
  font-weight: 600;
}

.noise-overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 20% 20%, rgba(251, 191, 36, 0.12), transparent 35%),
    radial-gradient(circle at 80% 10%, rgba(244, 114, 182, 0.18), transparent 30%),
    radial-gradient(circle at 10% 70%, rgba(56, 189, 248, 0.14), transparent 28%),
    #0f172a;
  opacity: 0.9;
  pointer-events: none;
  z-index: 0;
}

.noise-overlay::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url('https://grainy-gradients.vercel.app/noise.svg');
  opacity: var(--noise-opacity);
  mix-blend-mode: soft-light;
}

.card {
  border: 1px solid var(--border-strong);
  border-radius: 1rem;
  background: var(--bg-surface);
  backdrop-filter: blur(6px);
  transition: transform 0.18s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 15px 45px var(--shadow-color);
}

.card:hover {
  transform: translateY(-3px);
  border-color: var(--card-hover-border);
  box-shadow: 0 15px 45px var(--shadow-color);
}

.card img {
  border-radius: 0.9rem;
  object-fit: cover;
}

.tab-section {
  scroll-margin-top: 96px;
}

#lightbox {
  z-index: 15;
  backdrop-filter: blur(4px);
  background: var(--lightbox-bg);
}

#lightbox.hidden {
  display: none;
  pointer-events: none;
}

#lightbox-dialog {
  position: relative;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 2rem);
}

#lightbox-panel {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 100%;
}

.lightbox-image-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  line-height: 0;
}

#lightbox-image {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(70vh, calc(100vh - 12rem));
}

#lightbox-panel > div:last-child {
  flex: 0 0 auto;
}

.lightbox-graph-overlay {
  --grid-color: #ffffff;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.graph-grid-border {
  fill: none;
  stroke: color-mix(in srgb, var(--grid-color) 85%, transparent);
  stroke-width: 0.45;
}

.graph-grid-line {
  stroke: color-mix(in srgb, var(--grid-color) 62%, transparent);
  stroke-width: 0.32;
}

.drawing-controls {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

.drawing-controls__label {
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.grid-size-select {
  border-radius: 0.6rem;
  border: 1px solid var(--border-strong);
  background: var(--chip-bg);
  color: var(--text-primary);
  padding: 0.3rem 0.45rem;
  font-size: 0.8rem;
}

.grid-size-select:focus-visible {
  outline: 2px solid rgba(251, 191, 36, 0.8);
  outline-offset: 2px;
}

.grid-color-input {
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--border-strong);
  border-radius: 0.45rem;
  background: transparent;
  padding: 0.08rem;
  cursor: pointer;
}

.grid-color-input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.grid-color-input::-webkit-color-swatch {
  border: none;
  border-radius: 0.3rem;
}

.drawing-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--chip-bg);
  color: var(--text-primary);
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.drawing-toggle:hover {
  border-color: rgba(56, 189, 248, 0.65);
}

.drawing-toggle[aria-pressed='true'] {
  border-color: rgba(251, 191, 36, 0.75);
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.28), rgba(56, 189, 248, 0.24));
}

.drawing-toggle:focus-visible {
  outline: 2px solid rgba(251, 191, 36, 0.8);
  outline-offset: 2px;
}

@media (min-width: 1200px) and (min-height: 760px) {
  #lightbox {
    padding: 0.75rem;
  }

  #lightbox-dialog {
    width: min(98vw, 1800px);
    max-width: none;
    height: min(96vh, 1200px);
    max-height: min(96vh, 1200px);
  }

  #lightbox-panel {
    height: 100%;
    display: flex;
    flex-direction: column;
  }

  #lightbox .lightbox-image-wrap {
    flex: 1;
    width: min(100%, 84vw);
    max-width: 1400px;
    max-height: none;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  #lightbox-image {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
  }

  #lightbox-close {
    top: 0.9rem;
    right: 1rem;
    z-index: 2;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: color-mix(in srgb, var(--bg-panel) 92%, transparent);
    padding: 0.2rem 0.7rem;
  }
}

@media (max-width: 767px) {
  .drawing-controls {
    width: 100%;
    justify-content: flex-start;
    gap: 0.4rem;
  }

  .drawing-controls__label {
    font-size: 0.7rem;
  }

  .grid-size-select {
    font-size: 0.75rem;
    padding: 0.25rem 0.4rem;
  }

  .drawing-toggle {
    font-size: 0.78rem;
    padding: 0.3rem 0.65rem;
  }

  #lightbox {
    padding: 1rem 0.75rem;
  }

  #lightbox-dialog {
    width: 100%;
    max-height: calc(100vh - 1.5rem);
    max-height: calc(100dvh - 1.5rem);
  }

  #lightbox-panel {
    max-height: calc(100vh - 2.5rem);
    max-height: calc(100dvh - 2.5rem);
  }

  #lightbox .lightbox-image-wrap {
    padding: 0.85rem 0.5rem 0.4rem;
    align-items: center;
    justify-content: center;
  }

  #lightbox-image {
    margin: 0 auto;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: calc(100vh - 12rem);
    max-height: calc(100dvh - 12rem);
    object-fit: contain;
  }

  #lightbox-close {
    top: -2.1rem;
    right: 0.15rem;
  }
}

.themed-surface {
  background: var(--header-bg) !important;
  border-color: var(--border-strong) !important;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--chip-bg);
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: border-color 0.2s ease, background-color 0.2s ease, transform 0.2s ease;
}

.theme-toggle:hover {
  border-color: rgba(251, 191, 36, 0.6);
  transform: translateY(-1px);
}

.theme-toggle__icon {
  display: inline-flex;
  width: 1.9rem;
  height: 1.9rem;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.15), rgba(244, 114, 182, 0.12));
  border: 1px solid var(--chip-border);
}

.theme-toggle__label {
  font-weight: 600;
  letter-spacing: 0.02em;
}

.left-nav-hide-toggle,
.left-nav-show-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: color-mix(in srgb, var(--bg-panel) 88%, transparent);
  color: var(--text-primary);
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.left-nav-hide-toggle {
  margin-top: 0.5rem;
}

.left-nav-show-toggle {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 35;
  display: none;
  backdrop-filter: blur(8px);
}

.left-nav-hide-toggle:hover,
.left-nav-show-toggle:hover {
  border-color: rgba(251, 191, 36, 0.65);
  transform: translateY(-1px);
}

.left-nav-hide-toggle:focus-visible,
.left-nav-show-toggle:focus-visible {
  outline: 2px solid rgba(251, 191, 36, 0.8);
  outline-offset: 2px;
}

.themed-surface .tab-button {
  color: var(--text-primary);
}

.themed-surface nav .tab-button {
  background: var(--chip-bg);
  border-color: var(--chip-border);
}

/* Prevent nav pop-in jump by reserving space while shared components load. */
#mobile-top-container:empty::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  height: 124px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border-strong);
  backdrop-filter: blur(6px);
}

#left-nav-container:empty {
  display: none;
}

@media (min-width: 768px) {
  body.left-nav-collapsed #left-nav-container {
    display: none;
  }

  body.left-nav-collapsed .left-nav-show-toggle.is-visible {
    display: inline-flex;
  }

  body.left-nav-collapsed main {
    margin-left: 0 !important;
  }

  #mobile-top-container:empty::before {
    display: none;
  }

  #left-nav-container:empty {
    display: block;
    width: 16rem;
    height: 100vh;
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--header-bg);
    border-right: 1px solid var(--border-strong);
    backdrop-filter: blur(6px);
  }
}

body[data-theme="light"] .noise-overlay,
:root[data-theme="light"] body .noise-overlay {
  background: radial-gradient(circle at 20% 20%, rgba(251, 191, 36, 0.18), transparent 35%),
    radial-gradient(circle at 80% 10%, rgba(244, 114, 182, 0.22), transparent 32%),
    radial-gradient(circle at 10% 70%, rgba(56, 189, 248, 0.22), transparent 30%),
    #f8fafc;
}

body[data-theme="light"] .text-slate-300,
body[data-theme="light"] .text-slate-400,
body[data-theme="light"] .text-slate-500,
body[data-theme="light"] .text-slate-600,
:root[data-theme="light"] body .text-slate-300,
:root[data-theme="light"] body .text-slate-400,
:root[data-theme="light"] body .text-slate-500,
:root[data-theme="light"] body .text-slate-600 {
  color: var(--text-muted) !important;
}

body[data-theme="light"] .text-slate-100,
body[data-theme="light"] .text-slate-200,
:root[data-theme="light"] body .text-slate-100,
:root[data-theme="light"] body .text-slate-200 {
  color: var(--text-primary) !important;
}

body[data-theme="light"] .border-slate-800,
body[data-theme="light"] .border-slate-800\/80,
body[data-theme="light"] .border-slate-700\/80,
:root[data-theme="light"] body .border-slate-800,
:root[data-theme="light"] body .border-slate-800\/80,
:root[data-theme="light"] body .border-slate-700\/80 {
  border-color: var(--border-strong) !important;
}

body[data-theme="light"] .bg-slate-900\/60,
body[data-theme="light"] .bg-slate-900\/80,
body[data-theme="light"] .bg-slate-950,
body[data-theme="light"] .bg-slate-950\/60,
:root[data-theme="light"] body .bg-slate-900\/60,
:root[data-theme="light"] body .bg-slate-900\/80,
:root[data-theme="light"] body .bg-slate-950,
:root[data-theme="light"] body .bg-slate-950\/60 {
  background-color: var(--bg-panel) !important;
}

body[data-theme="light"] .shadow-amber-500\/5,
:root[data-theme="light"] body .shadow-amber-500\/5 {
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08) !important;
}

body[data-theme="light"] .rounded-2xl.border-slate-800,
body[data-theme="light"] .rounded-2xl.border-slate-800\/80,
:root[data-theme="light"] body .rounded-2xl.border-slate-800,
:root[data-theme="light"] body .rounded-2xl.border-slate-800\/80 {
  border-color: var(--border-strong) !important;
}

@media (max-width: 767px) {
  .left-nav-hide-toggle,
  .left-nav-show-toggle {
    display: none !important;
  }

  body {
    padding-top: 136px;
  }

  body.lightbox-open {
    padding-top: 0;
    overflow: hidden;
  }

  body.lightbox-open #mobile-top-container {
    display: none;
  }
}
