/* ==========================================================================
   Terminal Portfolio - CSS Custom Properties & Theme
   ========================================================================== */

@import '../shared/theme.css';

:root {
  /* Glow utilities (non-color, terminal-specific) */
  --glow-intensity: 0 0 2px;
  --glow-strong: 0 0 4px, 0 0 8px;
  --glow-blur: 0.4px;

  /* Typography */
  --font-primary: 'Science Gothic', monospace;
  --font-terminal: 'Share Tech Mono', monospace;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.25rem;
  --font-size-xl: 1.5rem;
  --font-size-2xl: 2rem;
  --font-size-3xl: 2.5rem;
  --font-size-hero: clamp(2rem, 5vw, 4rem);

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;

  /* Animation Timing */
  --duration-instant: 0ms;
  --duration-fast: 100ms;
  --duration-normal: 200ms;
  --duration-slow: 400ms;
  --duration-boot: 2000ms;
  --duration-typing: 50ms;

  /* CRT / Scanline Effects */
  --scanline-opacity: 0.05;
  --scanline-size: 2px;

  /* Layout */
  --terminal-padding: var(--space-lg);
  --min-touch-target: 44px;

  /* Z-Index Scale */
  --z-base: 0;
  --z-content: 10;
  --z-overlay: 100;
  --z-boot: 200;
  --z-command-bar: 300;
}

/* Reduced Motion Preferences */
@media (prefers-reduced-motion: reduce) {
  :root {
    --duration-boot: 0ms;
    --duration-typing: 0ms;
    --duration-fast: 0ms;
    --duration-normal: 0ms;
    --duration-slow: 0ms;
    --scanline-opacity: 0;
  }

  /* Hide gradient mask immediately for reduced motion */
  .terminal-main::before {
    opacity: 0;
  }
}

/* ==========================================================================
   Base Styles
   ========================================================================== */

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

html {
  font-size: 16px;
  touch-action: manipulation;
}

body {
  font-family: var(--font-primary);
  font-weight: 400;
  font-size: var(--font-size-base);
  line-height: 1.6;
  background-color: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  overflow: hidden;
  /* Text rendering optimizations for Retina displays */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Allow scrolling when page content is visible */
body.has-page-content {
  overflow-y: auto;
}

/* Lock scroll when command bar is open (fixes iOS fixed positioning) */
body.command-bar-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ==========================================================================
   CRT Scanline Overlay
   ========================================================================== */

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, var(--scanline-opacity)) 0px,
    rgba(0, 0, 0, var(--scanline-opacity)) var(--scanline-size),
    transparent var(--scanline-size),
    transparent calc(var(--scanline-size) * 2)
  );
  pointer-events: none;
  z-index: var(--z-overlay);
}

/* ==========================================================================
   Layout Container
   ========================================================================== */

.terminal-container {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  min-height: 100vh;
  padding: var(--terminal-padding);
  position: relative;
}

.terminal-main {
  width: 100%;
  text-align: left;
  position: relative;
}

/* Gradient mask at top of viewport - boot messages fade as they scroll up */
.terminal-main::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 120px;
  background: linear-gradient(to bottom, var(--color-bg) 0%, var(--color-bg) 50%, transparent 100%);
  z-index: var(--z-boot);
  pointer-events: none;
  opacity: 1;
  transition: opacity 300ms ease-out;
}

/* Larger gradient on desktop */
@media (min-width: 768px) {
  .terminal-main::before {
    height: 150px;
  }
}

/* Hide gradient after animation completes */
.terminal-main.animation-complete::before {
  opacity: 0;
}

/* ==========================================================================
   Focus Styles
   ========================================================================== */

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

:focus:not(:focus-visible) {
  outline: none;
}

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

/* ==========================================================================
   Screen Reader Only
   ========================================================================== */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   Mobile-First Responsive Breakpoints
   ========================================================================== */

/* Small devices (landscape phones, 576px and up) */
@media (min-width: 576px) {
  :root {
    --font-size-hero: clamp(2.5rem, 6vw, 4.5rem);
  }
}

/* Medium devices (tablets, 768px and up) */
@media (min-width: 768px) {
  :root {
    --space-lg: 2rem;
    --space-xl: 3rem;
    --terminal-padding: var(--space-lg);
  }
}

/* Large devices (desktops, 1024px and up) */
@media (min-width: 1024px) {
  :root {
    --font-size-hero: clamp(3rem, 5vw, 5rem);
  }
}

/* Extra large devices (large desktops, 1440px and up) */
@media (min-width: 1440px) {
  :root {
    --terminal-padding: var(--space-xl);
  }
}

/* ==========================================================================
   Boot Sequence (integrated with page)
   ========================================================================== */

.boot-messages-wrapper {
  position: relative;
  overflow: visible;
  margin-bottom: var(--space-md);
  transform: translateY(0);
  opacity: 1;
  transition:
    transform 250ms ease-out,
    opacity 250ms ease-out;
}

/* When boot completes, push wrapper up and out */
.boot-messages-wrapper.pushed-up {
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
}

/* Hidden immediately (for hash URL load) */
.boot-messages-wrapper.hidden {
  display: none;
}

.boot-messages {
  font-family: var(--font-terminal);
  font-size: var(--font-size-sm);
  color: var(--color-accent);
  line-height: 1.8;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.boot-messages .boot-line {
  display: block;
  opacity: 0;
  animation: boot-line-appear var(--duration-fast) ease-out forwards;
}

@keyframes boot-line-appear {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Reduced motion: instant appear */
@media (prefers-reduced-motion: reduce) {
  .boot-messages .boot-line {
    opacity: 1;
    animation: none;
  }

  .boot-messages-wrapper {
    transition: none;
  }

  .boot-messages-wrapper.pushed-up {
    display: none;
  }
}

/* ==========================================================================
   Hero Section
   ========================================================================== */

/* Hero section slides up into view after boot */
.hero-section {
  margin-bottom: var(--space-2xl);
  transform: translateY(80px);
  opacity: 0;
  transition:
    transform 250ms ease-out,
    opacity 250ms ease-out;
  /* Note: margin-bottom NOT transitioned - causes jitter when compacting */
}

.hero-section.sliding-up {
  transform: translateY(0);
  opacity: 1;
}

/* Tagline hidden until slide-up phase */
.hero-tagline {
  opacity: 0;
  transform: translateY(15px);
  transition:
    opacity 200ms ease-out,
    transform 200ms ease-out;
}

.hero-tagline.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Compact mode when page content is shown */
.hero-section.compact {
  margin-bottom: var(--space-md);
}

.hero-section.compact .hero-name {
  font-size: clamp(1.5rem, 3vw, 2.5rem);
}

/* Reduced motion: instant appear */
@media (prefers-reduced-motion: reduce) {
  .hero-section {
    transform: none;
    opacity: 1;
    transition: none;
  }

  .hero-section.sliding-up {
    transform: none;
  }

  .hero-name,
  .hero-tagline {
    opacity: 1;
    transform: none;
    transition: none;
  }
}

.hero-name {
  font-size: var(--font-size-hero);
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--color-accent);
  text-shadow: var(--glow-layered);
  filter: blur(var(--glow-blur));
  margin-bottom: var(--space-sm);
  cursor: pointer;
  transition: font-size 400ms ease-in-out;
}

.hero-name.glow-effect {
  text-shadow: var(--glow-layered-strong);
}

.hero-role {
  font-size: var(--font-size-lg);
  color: var(--color-text);
  margin-bottom: var(--space-md);
}

.hero-tagline {
  font-size: var(--font-size-base);
  color: var(--color-text-muted);
  transition: font-size 400ms ease-in-out;
}

/* Hero name text wrapper */
.hero-name-text {
  display: inline;
}

/* Blinking cursor - positioned next to hero name */
.cursor {
  display: inline-block;
  vertical-align: baseline;
  width: 0.5em;
  height: 0.85em;
  background-color: var(--color-accent);
  box-shadow: var(--glow-layered);
  filter: blur(var(--glow-blur));
  margin-left: 0.1em;
  opacity: 1;
  animation: cursor-blink 1s step-end infinite;
  transform: translateY(0.05em);
}

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

/* Reduced motion: static cursor */
@media (prefers-reduced-motion: reduce) {
  .cursor {
    animation: none;
  }
}

/* ==========================================================================
   Navigation Section
   ========================================================================== */

.nav-section {
  opacity: 0;
  transform: translateY(20px);
  transition:
    opacity 300ms ease-out,
    transform 300ms ease-out;
  margin-bottom: 0;
  /* Note: margin-bottom NOT transitioned - causes jitter when compacting */
}

.nav-section.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Compact mode when page content is shown */
.nav-section.compact {
  margin-bottom: var(--space-md);
}

/* Reduced motion: instant appear */
@media (prefers-reduced-motion: reduce) {
  .nav-section {
    opacity: 1;
    transform: none;
    transition: none;
  }
}

.nav-list {
  list-style: none;
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-start;
  gap: var(--space-md);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.nav-list::-webkit-scrollbar {
  display: none;
}

.nav-list li {
  display: inline-block;
  flex-shrink: 0;
}

.nav-link {
  display: inline-flex;
  font-size: var(--font-size-base);
  color: var(--color-text);
  text-decoration: none;
  padding: var(--space-sm) 0;
  min-height: var(--min-touch-target);
  align-items: center;
  justify-content: flex-start;
  border: 1px solid transparent;
  transition:
    color var(--duration-fast),
    border-color var(--duration-fast),
    text-shadow var(--duration-fast);
}

.nav-link::before {
  content: '[';
  color: var(--color-text-muted);
  margin-right: var(--space-xs);
}

.nav-link::after {
  content: ']';
  color: var(--color-text-muted);
  margin-left: var(--space-xs);
}

.nav-link:hover,
.nav-link:focus,
.nav-link.active {
  color: var(--color-accent);
  text-shadow: var(--glow-intensity) var(--glow-color);
}

.nav-link:hover::before,
.nav-link:hover::after,
.nav-link:focus::before,
.nav-link:focus::after,
.nav-link.active::before,
.nav-link.active::after {
  color: var(--color-accent);
}

/* Allow clicks to pass through glitch spans to the parent link (Safari fix) */
.nav-link > span {
  pointer-events: none;
}

/* ==========================================================================
   Command Bar
   ========================================================================== */

.command-bar {
  position: fixed;
  bottom: var(--terminal-padding);
  left: 50%;
  transform: translateX(-50%) translateY(var(--command-bar-translate-y));
  width: clamp(280px, 35vw, 500px);
  max-width: calc(100% - var(--terminal-padding) * 2);
  max-height: 70vh;
  background-color: var(--color-bg-overlay);
  border: 1px solid var(--color-accent-dim);
  border-radius: 4px;
  padding: var(--space-sm) var(--space-md);
  z-index: var(--z-command-bar);
  --command-bar-translate-y: calc(100% + var(--terminal-padding));
  transition: transform var(--duration-normal) ease-out;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  touch-action: pan-y; /* Re-enable vertical touch when body has touch-action:none */
}

.command-bar.visible,
.command-bar[aria-hidden='false'] {
  --command-bar-translate-y: 0px;
  transform: translateX(-50%) translateY(var(--command-bar-translate-y));
  visibility: visible;
}

.command-bar[aria-hidden='true'] {
  --command-bar-translate-y: calc(100% + var(--terminal-padding));
  transform: translateX(-50%) translateY(var(--command-bar-translate-y));
  visibility: hidden;
}

/* Disable transitions during drag for smooth tracking
   Must come AFTER aria-hidden rules to override visibility */
.command-bar.dragging {
  transition: none;
  visibility: visible;
}

.command-prompt {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex: 0 0 auto;
}

/* Separator between output and input when output exists */
.command-output:not(:empty) + .command-prompt {
  border-top: 1px solid var(--color-text-dim);
  padding-top: var(--space-sm);
  margin-top: var(--space-sm);
}

.prompt-symbol {
  color: var(--color-accent-dim);
  font-weight: bold;
}

.command-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--color-text);
  font-family: var(--font-terminal);
  font-size: var(--font-size-base);
  outline: none;
  caret-color: var(--color-accent);
}

.command-input::placeholder {
  color: var(--color-text-dim);
}

.command-enter {
  background: transparent;
  border: none;
  color: var(--color-accent-dim);
  font-family: var(--font-terminal);
  font-size: var(--font-size-sm);
  padding: var(--space-xs);
  cursor: pointer;
  transition:
    color var(--duration-fast) ease,
    text-shadow var(--duration-fast) ease;
  line-height: 1;
}

.command-enter:hover {
  color: var(--color-accent);
  text-shadow: 0 0 8px var(--color-accent-dim);
}

.command-enter:active {
  color: var(--color-accent);
}

.command-enter:disabled {
  color: var(--color-text-dim);
  cursor: not-allowed;
  opacity: 0.5;
  text-shadow: none;
}

.command-output {
  margin-bottom: var(--space-sm);
  font-family: var(--font-terminal);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--color-text-dim) transparent;
}

.command-output:empty {
  display: none;
}

/* Terminal-style scrollbar */
.command-output::-webkit-scrollbar {
  width: 6px;
}

.command-output::-webkit-scrollbar-track {
  background: transparent;
}

.command-output::-webkit-scrollbar-thumb {
  background: var(--color-text-dim);
  border-radius: 3px;
}

.command-output::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-muted);
}

.command-result {
  padding: var(--space-xs) 0;
}

.command-result.success {
  color: var(--color-success);
}

.command-result.error {
  color: var(--color-error);
}

.command-result-input {
  color: var(--color-text-muted);
  margin-bottom: var(--space-xs);
}

.command-result-message {
  white-space: pre-wrap;
}

/* Mobile command bar refinements */
@media (max-width: 767px) {
  .command-bar {
    left: var(--space-md);
    right: var(--space-md);
    width: auto;
    transform: translateY(var(--command-bar-translate-y));
  }

  .command-bar.visible,
  .command-bar[aria-hidden='false'] {
    max-height: 50vh;
    bottom: var(--space-md);
    border-radius: 8px;
    transform: translateY(var(--command-bar-translate-y));
  }

  .command-bar[aria-hidden='true'] {
    transform: translateY(var(--command-bar-translate-y));
  }

  .command-output {
    -webkit-overflow-scrolling: touch;
  }
}

/* ==========================================================================
   Matrix Hover Effect (for hero name)
   ========================================================================== */

.hero-name .char {
  display: inline-block;
  transition: none;
}

.hero-name .char.scrambling {
  color: var(--color-accent-dim);
}

.hero-name .char.resolved {
  color: var(--color-accent);
}

.hero-name .char.locked {
  color: var(--color-accent);
}

/* Reduced motion: no scramble effect */
@media (prefers-reduced-motion: reduce) {
  .hero-name .char.scrambling {
    color: var(--color-accent);
  }
}

/* ==========================================================================
   Page Content Area (SPA Navigation)
   ========================================================================== */

.page-content {
  margin-top: var(--space-lg);
  padding: var(--space-lg) 0;
  min-height: 0;
  opacity: 0;
  transform: translateY(30px);
  transition:
    opacity 300ms ease-out,
    transform 300ms ease-out;
}

.page-content.visible {
  opacity: 1;
  transform: translateY(0);
}

.page-content:empty {
  display: none;
}

.page-content h2 {
  font-size: var(--font-size-xl);
  color: var(--color-accent);
  margin-bottom: var(--space-md);
  font-weight: 600;
}

/* Clickable page heading - collapses section on click */
.page-content .page-heading {
  cursor: pointer;
  transition: color 150ms ease;
}

.page-content .page-heading:hover {
  color: var(--color-text);
}

.page-content p {
  color: var(--color-text-muted);
  line-height: 1.8;
  margin-bottom: var(--space-md);
}

.page-content .coming-soon {
  color: var(--color-text-dim);
  font-style: italic;
}

.page-content .matrix-quote {
  color: var(--color-accent-dim);
  border-left: 2px solid var(--color-accent-dim);
  padding-left: var(--space-md);
  margin: var(--space-lg) 0;
}

.page-content a {
  color: var(--color-accent);
  text-decoration: none;
}

.page-content a:hover {
  text-decoration: underline;
}

/* Under Construction Page */
.construction-btn {
  display: inline-block;
  margin-top: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  background: transparent;
  border: 1px solid var(--color-accent-dim);
  color: var(--color-accent);
  font-family: var(--font-terminal);
  font-size: var(--font-size-sm);
  cursor: pointer;
  transition:
    background var(--duration-normal) ease,
    color var(--duration-normal) ease,
    box-shadow var(--duration-normal) ease;
  letter-spacing: 0.05em;
  -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
  .construction-btn:hover {
    background: var(--color-accent);
    color: var(--color-bg);
    box-shadow: 0 0 12px var(--glow-rgba, rgba(0, 255, 65, 0.3));
  }
}

.construction-btn:active {
  background: var(--color-accent);
  color: var(--color-bg);
}

/* ==========================================================================
   Menu Page (... page)
   ========================================================================== */

.menu-page {
  max-width: 500px;
}

/* Menu Section Structure */
.menu-section {
  margin-bottom: var(--space-xl);
}

.menu-section:last-child {
  margin-bottom: 0;
}

/* URL Row */
.share-url-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--color-text-dim);
  border-radius: 4px;
  padding: var(--space-sm) var(--space-md);
}

.share-url-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--color-text);
  font-family: var(--font-terminal);
  font-size: var(--font-size-sm);
  outline: none;
  min-width: 0;
}

.share-copy-btn {
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  font-family: var(--font-terminal);
  font-size: var(--font-size-sm);
  padding: var(--space-xs) var(--space-sm);
  cursor: pointer;
  transition: color var(--duration-fast);
  white-space: nowrap;
}

.share-copy-btn:hover {
  color: var(--color-accent);
}

.share-copy-btn.copied {
  color: var(--color-accent);
}

/* Theme Color Row */
.theme-color-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-md);
}

/* Theme Preset Dots */
.theme-presets {
  display: flex;
  gap: var(--space-sm);
  overflow-x: auto;
  flex-shrink: 1;
  min-width: 0;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
  /* Padding to prevent outline/glow clipping, negative margin to compensate */
  padding: 6px;
  margin: -6px;
}

.theme-preset {
  background: transparent;
  border: 2px solid transparent;
  border-radius: 50%;
  padding: 2px;
  cursor: pointer;
  flex-shrink: 0;
  transition:
    border-color var(--duration-fast),
    transform var(--duration-fast);
}

.theme-preset:hover {
  transform: scale(1.15);
}

.theme-preset.active {
  border-color: var(--color-text);
}

.preset-dot {
  display: block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: var(--preset-color);
  box-shadow: 0 0 6px var(--preset-color);
  outline: 1px solid rgba(255, 255, 255, 0.3);
  outline-offset: -1px;
}

/* Random Button */
.theme-random-btn {
  width: 5.5rem;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-text-dim);
  border-radius: 4px;
  padding: var(--space-xs) var(--space-sm);
  font-family: var(--font-terminal);
  font-size: var(--font-size-sm);
  flex-shrink: 0;
  cursor: pointer;
  white-space: nowrap;
  /* Custom properties for dynamic hex background */
  background-color: var(--random-btn-bg, rgba(255, 255, 255, 0.03));
  color: var(--random-btn-text, var(--color-text));
  transition:
    border-color var(--duration-fast),
    color var(--duration-fast),
    background-color var(--duration-fast);
}

/* Theme Toggle (random / color) */
.theme-toggle {
  display: inline-flex;
  position: relative;
  border: 1px solid var(--color-text-dim);
  border-radius: 4px;
  margin-bottom: var(--space-md);
  overflow: hidden;
}

.theme-toggle-option {
  position: relative;
  z-index: 1;
  background: transparent;
  border: none;
  padding: var(--space-xs) var(--space-md);
  font-family: var(--font-terminal);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: color var(--duration-fast);
  min-width: 5rem;
  text-align: center;
}

.theme-toggle-option[aria-checked='true'] {
  color: var(--color-bg);
}

.theme-toggle-indicator {
  position: absolute;
  top: 0;
  left: 0;
  width: 50%;
  height: 100%;
  background: var(--color-accent);
  border-radius: 3px;
  transition: transform var(--duration-normal) ease;
  pointer-events: none;
}

.theme-toggle.color-active .theme-toggle-indicator {
  transform: translateX(100%);
}

/* Panel Container (fixed height prevents layout shift) */
.theme-panels {
  position: relative;
  height: 40px;
}

/* Conditional Panels (random / color) */
.theme-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-normal) ease;
}

.theme-panel.active {
  opacity: 1;
  pointer-events: auto;
}

/* Constraint Selector (inside random panel) */
.theme-constraint-selector {
  display: flex;
  gap: var(--space-md);
}

.constraint-word {
  background: transparent;
  border: none;
  padding: 0;
  font-family: var(--font-terminal);
  font-size: var(--font-size-base);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: color var(--duration-fast);
}

.constraint-word:hover {
  color: var(--color-text);
}

.constraint-word.active {
  color: var(--color-accent);
  font-weight: bold;
}

.constraint-prefix {
  color: var(--color-accent);
}

/* Always-visible Hex Input Row */
.theme-hex-input-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-family: var(--font-terminal);
}

.hex-swatch {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  background-color: var(--color-accent);
  border: 1px solid rgba(255, 255, 255, 0.15);
  flex-shrink: 0;
}

.hex-hash {
  color: var(--color-text);
  font-size: var(--font-size-sm);
  margin-right: calc(-1 * var(--space-sm));
}

.hex-input-wrapper {
  position: relative;
  font-size: 16px;
  width: 6.5ch;
}

.hex-input {
  position: relative;
  z-index: 1;
  background: transparent;
  border: none;
  border-bottom: none;
  color: var(--color-text);
  font-family: inherit;
  font-size: inherit; /* inherits 16px from wrapper — prevents iOS zoom */
  width: 100%;
  outline: none;
  padding: 0;
  letter-spacing: 0.05em;
}

.hex-input:focus {
  border-bottom: none;
}

.hex-ghost {
  position: absolute;
  top: 0;
  left: 0;
  color: var(--color-text-dim);
  font-family: inherit;
  font-size: inherit;
  letter-spacing: 0.05em;
  pointer-events: none;
  user-select: none;
}

.theme-hex-input-row.hex-error {
  animation: hex-shake 0.4s ease-out;
}

/* Preset Hover Tooltips */
.theme-preset {
  position: relative;
}

.theme-preset::after {
  content: attr(data-hint);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-bg);
  border: 1px solid var(--color-text-dim);
  border-radius: 4px;
  padding: var(--space-xs) var(--space-sm);
  font-family: var(--font-terminal);
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  white-space: normal;
  max-width: 18rem;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--duration-fast);
  z-index: 10;
}

.theme-preset:hover::after {
  opacity: 1;
}

@media (hover: none) {
  .theme-preset::after {
    display: none;
  }
}

/* Shake animation for error */

@keyframes hex-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-3px);
  }
  40% {
    transform: translateX(3px);
  }
  60% {
    transform: translateX(-2px);
  }
  80% {
    transform: translateX(2px);
  }
}

/* Reduced motion: no shake, no toggle/panel transitions */
@media (prefers-reduced-motion: reduce) {
  .theme-hex-input-row.hex-error {
    animation: none;
  }

  .theme-toggle-indicator {
    transition: none;
  }

  .theme-panel {
    transition: none;
  }
}

.theme-random-btn:hover {
  border-color: var(--color-accent);
}

/* When showing a hex value, button takes on that color */
.theme-random-btn.showing-hex {
  border-color: transparent;
}

/* Fix focus outline when showing hex - use contrasting color based on background */
.theme-random-btn.showing-hex:focus,
.theme-random-btn.showing-hex:focus-visible {
  outline-color: var(--random-btn-text);
}

.theme-random-btn .random-char {
  display: inline-block;
  transition: color 50ms;
}

.theme-random-btn .random-char.scrambling {
  color: var(--color-accent);
}

.theme-random-btn .random-char.resolved {
  color: var(--color-accent);
  text-shadow: 0 0 4px var(--glow-color);
}

/* Adjust character colors when showing hex */
.theme-random-btn.showing-hex .random-char {
  color: var(--random-btn-text, var(--color-text));
}

.theme-random-btn.showing-hex .random-char.scrambling,
.theme-random-btn.showing-hex .random-char.resolved {
  color: var(--random-btn-text);
  text-shadow: none;
}

/* Mobile Responsive */
@media (max-width: 480px) {
  .theme-presets {
    max-width: 100%;
  }

  .theme-toggle-option {
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-size-xs);
    min-width: 4rem;
  }
}

/* ==========================================================================
   Thing List (tree-style project links)
   ========================================================================== */

.thing-list {
  list-style: none;
  margin: var(--space-lg) 0;
  padding: 0;
  font-family: var(--font-terminal);
}

.thing-list li {
  display: flex;
  gap: var(--space-sm);
  line-height: 1.2;
}

.thing-list__tree {
  color: var(--color-text-dim);
  user-select: none;
}

.thing-list a {
  color: var(--color-text);
}

.thing-list a:hover {
  color: var(--color-accent);
}

.thing-list__desc {
  color: var(--color-text-muted);
}

.thing-list__spacer {
  line-height: 0.8;
}

.thing-list__spacer--half {
  line-height: 0.1;
}

/* ==========================================================================
   Matrix Rain Effect (Konami Code Easter Egg)
   ========================================================================== */

.matrix-rain {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
  background: var(--color-bg);
}

.matrix-char {
  position: absolute;
  top: 0;
  font-family: monospace;
  font-size: 16px;
  line-height: 1;
  color: var(--color-accent);
  will-change: transform;
  text-shadow: 0 0 4px var(--glow-color);
}

/* Head character - momentary white flash */
.matrix-char--head {
  color: #ffffff;
  text-shadow:
    0 0 8px #ffffff,
    0 0 16px var(--glow-color),
    0 0 32px var(--glow-color);
}

/* Bright - just after being head */
.matrix-char--bright {
  color: var(--matrix-bright);
  text-shadow:
    0 0 6px var(--glow-color),
    0 0 12px var(--glow-color);
}

/* Medium brightness */
.matrix-char--medium {
  color: var(--matrix-medium);
  text-shadow: 0 0 4px var(--glow-color);
}

/* Trail - uses smooth opacity fade from JS */
.matrix-char--trail {
  color: var(--matrix-trail);
  text-shadow: 0 0 2px var(--glow-color);
  transition: opacity 0.1s ease-out;
}

/* ==========================================================================
   Light Theme (for dark accent colors)
   Automatically applied when accent color luminance < 0.179
   ========================================================================== */

.theme-light {
  /* Invert scanline effect for light background */
  --scanline-opacity: 0.03;
}

/* Adjust scanlines to use light-friendly colors */
.theme-light body::before {
  background: repeating-linear-gradient(
    0deg,
    rgba(255, 255, 255, var(--scanline-opacity)) 0px,
    rgba(255, 255, 255, var(--scanline-opacity)) var(--scanline-size),
    transparent var(--scanline-size),
    transparent calc(var(--scanline-size) * 2)
  );
}

/* Softer glow blur in light mode */
.theme-light .hero-name {
  filter: none;
}

/* Matrix rain adjustments for light mode */
.theme-light .matrix-rain {
  background: var(--color-bg);
}

.theme-light .matrix-char {
  text-shadow: none;
}

.theme-light .matrix-char--head {
  color: var(--color-text);
  filter: none;
}

/* Swatch border in light mode */
.theme-light .hex-swatch {
  border-color: rgba(0, 0, 0, 0.15);
}

/* Command bar in light mode */
.theme-light .command-bar {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}
