/* === Reset & Variables === */

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

:root {
  --text-color: #1a1a1a;
  --text-secondary: #6b6b6b;
  --text-tertiary: #999;
  --border-color: rgba(0, 0, 0, 0.1);
  --bg-color: #fafaf7;
  --surface: rgba(255, 255, 255, 0.85);
  --surface-border: rgba(255, 255, 255, 0.9);

  --font-display: 'Syne', sans-serif;
  --font-mono: 'Space Mono', monospace;
  --font-body: 'Syne', sans-serif;

  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
}

/* === Noise Texture Overlay === */

.noise {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px 256px;
}

/* === Body === */

body {
  font-family: var(--font-body);
  color: var(--text-color);
  background-color: var(--bg-color);
  transition: background-color 0.5s var(--ease-out-expo),
              color 0.4s ease;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection {
  background: rgba(0, 0, 0, 0.15);
}

/* === Layout === */

main {
  max-width: 860px;
  margin: 0 auto;
  padding: 56px 32px 40px;
  display: flex;
  flex-direction: column;
  gap: 72px;
}

/* === Reveal Animations === */

.reveal {
  opacity: 0;
  transform: translateY(24px);
  animation: revealUp 0.8s var(--ease-out-expo) forwards;
  animation-delay: var(--reveal-delay, 0s);
}

@keyframes revealUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* === Section Labels === */

.section-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 24px;
  background: var(--surface);
  display: inline-block;
  padding: 4px 8px;
  border-radius: 2px;
  transition: color 0.4s ease, background 0.4s ease;
}

/* === Hero === */

.hero {
  text-align: center;
  padding: 24px 0 0;
}

.hero-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 16px;
  background: var(--surface);
  display: inline-block;
  padding: 4px 10px;
  border-radius: 2px;
  transition: color 0.4s ease, background 0.4s ease;
}

.hero h1 {
  font-family: var(--font-display);
  font-size: clamp(5rem, 15vw, 10rem);
  font-weight: 800;
  letter-spacing: 0.15em;
  line-height: 0.9;
  margin-bottom: 20px;
  display: flex;
  justify-content: center;
  gap: 0.02em;
}

.hero h1 .letter {
  display: inline-block;
  opacity: 0;
  transform: translateY(40px) rotate(-4deg);
  animation: letterIn 0.7s var(--ease-out-expo) forwards;
  animation-delay: calc(0.1s + var(--i) * 0.08s);
}

@keyframes letterIn {
  to {
    opacity: 1;
    transform: translateY(0) rotate(0deg);
  }
}

.subtitle {
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 400;
  line-height: 1.6;
  background: var(--surface);
  display: inline-block;
  padding: 6px 12px;
  border-radius: 2px;
  transition: color 0.4s ease, background 0.4s ease;
}

/* === Picker Layout === */

.picker-row {
  display: flex;
  gap: 24px;
  align-items: stretch;
}

/* === Y Slider === */

.y-slider {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 52px;
  flex-shrink: 0;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  position: relative;
}

.y-scale {
  position: absolute;
  left: -44px;
  top: 0;
  bottom: 0;
  width: 40px;
  padding-top: 28px; /* offset for label */
}

.y-scale-tick {
  position: absolute;
  right: 0;
  font-family: var(--font-mono);
  font-size: 0.55rem;
  color: var(--text-tertiary);
  transform: translateY(-50%);
  background: var(--surface);
  padding: 1px 3px;
  border-radius: 1px;
  transition: color 0.4s ease, background 0.4s ease;
}

.y-slider-label {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-color);
  text-align: center;
  line-height: 1.2;
  background: var(--surface);
  padding: 4px 8px;
  border-radius: 2px;
  transition: color 0.4s ease, background 0.4s ease;
}

.y-slider-sublabel {
  display: block;
  font-size: 0.55rem;
  font-weight: 400;
  color: var(--text-tertiary);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-top: 2px;
  transition: color 0.4s ease;
}

.y-slider-track {
  flex: 1;
  width: 32px;
  background: linear-gradient(to bottom, #fff, #000);
  border-radius: 4px;
  position: relative;
  border: 1px solid var(--surface-border);
  touch-action: none;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.08),
              0 1px 2px rgba(0,0,0,0.04);
  transition: border-color 0.4s ease, box-shadow 0.4s ease;
}

.y-slider-handle {
  position: absolute;
  left: -6px;
  right: -6px;
  height: 8px;
  background: white;
  border: 2px solid rgba(0,0,0,0.3);
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2),
              0 0 0 1px rgba(255,255,255,0.8) inset;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.y-slider:hover .y-slider-handle,
.y-slider:active .y-slider-handle {
  border-color: rgba(0,0,0,0.5);
  box-shadow: 0 2px 12px rgba(0,0,0,0.3),
              0 0 0 1px rgba(255,255,255,0.8) inset;
}

/* === UV Square === */

.uv-wrap {
  display: flex;
  gap: 6px;
  flex: 1;
  max-width: 540px;
}

.uv-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.uv-container {
  position: relative;
  aspect-ratio: 1;
  width: 100%;
  cursor: crosshair;
  border-radius: 3px;
  overflow: hidden;
  touch-action: none;
}

/* UV Scales */

.uv-scale {
  position: relative;
  font-family: var(--font-mono);
  font-size: 0.55rem;
  color: var(--text-tertiary);
}

.uv-scale-v {
  width: 40px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.uv-scale-v .uv-scale-tick {
  position: absolute;
  right: 0;
  transform: translateY(-50%);
  background: var(--surface);
  padding: 1px 3px;
  border-radius: 1px;
  transition: color 0.4s ease, background 0.4s ease;
}

.uv-scale-v .uv-scale-label {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%) rotate(-90deg);
  font-weight: 700;
  font-size: 0.65rem;
  color: var(--text-secondary);
  transition: color 0.4s ease;
}

.uv-scale-u {
  height: 20px;
  position: relative;
}

.uv-scale-u .uv-scale-tick {
  position: absolute;
  top: 2px;
  transform: translateX(-50%);
  background: var(--surface);
  padding: 1px 3px;
  border-radius: 1px;
  transition: color 0.4s ease, background 0.4s ease;
}

.uv-scale-u .uv-scale-label {
  position: absolute;
  top: 2px;
  right: -24px;
  font-weight: 700;
  font-size: 0.65rem;
  color: var(--text-secondary);
  transition: color 0.4s ease;
}

.uv-container canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: auto;
}

.uv-container::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 3px;
  border: 2px solid var(--surface-border);
  pointer-events: none;
  transition: border-color 0.4s ease;
}

.uv-cursor {
  position: absolute;
  width: 22px;
  height: 22px;
  border: 2.5px solid white;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.25),
              0 2px 12px rgba(0,0,0,0.25),
              inset 0 0 0 1px rgba(0,0,0,0.1);
  pointer-events: none;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: width 0.15s ease, height 0.15s ease;
}

.uv-container:active .uv-cursor {
  width: 18px;
  height: 18px;
}

/* === Info Panel === */

.info-panel {
  width: 152px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.info-swatch {
  width: 100%;
  height: 56px;
  border-radius: 3px;
  background: #808080;
  border: 2px solid var(--surface-border);
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  transition: background-color 0.15s ease,
              box-shadow 0.4s ease,
              border-color 0.4s ease;
}

.info-block {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 3px;
  padding: 10px 12px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.4s ease, border-color 0.4s ease;
}

.info-block-label {
  font-family: var(--font-mono);
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 6px;
  transition: color 0.4s ease;
}

.info-values {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.info-values dt {
  font-weight: 700;
  color: var(--text-secondary);
  transition: color 0.4s ease;
}

.info-values dd {
  font-variant-numeric: tabular-nums;
  text-align: right;
  transition: color 0.4s ease;
}

.info-hex {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
  text-align: center;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 3px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: color 0.4s ease, background 0.4s ease, border-color 0.4s ease;
}

/* === Upload Zone === */

.upload-zone {
  border: 1.5px dashed var(--surface-border);
  border-radius: 3px;
  background: var(--surface);
  padding: 40px 32px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.3s ease, background 0.3s ease, transform 0.2s ease;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.upload-icon {
  opacity: 0.4;
  transition: opacity 0.3s ease, transform 0.3s var(--ease-out-expo);
}

.upload-zone p {
  font-family: var(--font-body);
  font-size: 0.85rem;
  transition: color 0.4s ease;
}

.upload-zone:hover {
  border-color: var(--text-secondary);
  background: rgba(255,255,255,0.04);
}

.upload-zone:hover .upload-icon {
  opacity: 0.7;
  transform: translateY(-2px);
}

.upload-zone.dragover {
  border-color: var(--text-color);
  background: rgba(255,255,255,0.08);
  transform: scale(1.01);
}

/* === Channels === */

.channels {
  display: flex;
  gap: 16px;
  margin-top: 28px;
}

.channel {
  flex: 1;
  text-align: center;
}

.channel canvas {
  width: 100%;
  height: auto;
  border-radius: 3px;
  display: block;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}

.channel-label {
  display: inline-block;
  margin-top: 10px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  background: var(--surface);
  padding: 3px 8px;
  border-radius: 2px;
  transition: color 0.4s ease, background 0.4s ease;
}

.channel-sublabel {
  font-weight: 400;
  color: var(--text-tertiary);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-left: 4px;
  transition: color 0.4s ease;
}

/* === Explanation === */

.explanation-content {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 3px;
  padding: 32px 36px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.4s ease, border-color 0.4s ease;
}

.explanation-content h2 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 16px;
  line-height: 1.3;
}

.explanation-content h3 {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  margin-top: 28px;
  margin-bottom: 10px;
  line-height: 1.3;
}

.explanation-content p {
  font-family: var(--font-body);
  font-size: 0.9rem;
  line-height: 1.75;
  color: var(--text-secondary);
  margin-bottom: 12px;
  transition: color 0.4s ease;
}

.explanation-content p:last-child {
  margin-bottom: 0;
}

.explanation-content strong {
  color: var(--text-color);
  font-weight: 600;
  transition: color 0.4s ease;
}

.explanation-content code {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  background: rgba(0,0,0,0.05);
  padding: 2px 6px;
  border-radius: 2px;
  transition: background 0.4s ease;
}

/* === Footer === */

.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--surface-border);
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-tertiary);
  letter-spacing: 0.05em;
  padding: 24px 32px;
  transition: color 0.4s ease, background 0.4s ease, border-color 0.4s ease;
}

.site-footer a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.3s ease;
}

.site-footer a:hover {
  color: var(--text-color);
}

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

.y-slider:focus-visible {
  outline: 2px solid var(--text-color);
  outline-offset: 4px;
  border-radius: 8px;
}

.uv-container canvas:focus-visible {
  outline: 2px solid white;
  outline-offset: -2px;
}

.upload-zone:focus-visible {
  outline: 2px solid var(--text-color);
  outline-offset: 4px;
}

/* === Responsive === */

@media (max-width: 768px) {
  main {
    padding: 36px 20px 32px;
    gap: 56px;
  }

  .hero h1 {
    font-size: clamp(4rem, 20vw, 7rem);
  }

  .subtitle br {
    display: none;
  }

  .picker-row {
    flex-direction: column;
    align-items: center;
    gap: 20px;
  }

  .y-slider {
    flex-direction: row;
    width: 100%;
    height: 52px;
    gap: 12px;
  }

  .y-slider-label {
    min-width: 40px;
  }

  .y-slider-sublabel {
    display: none;
  }

  .y-slider-track {
    flex: 1;
    height: 32px;
    width: auto;
    border-radius: 4px;
    background: linear-gradient(to right, #000, #fff);
  }

  .y-slider-handle {
    left: 50%;
    right: auto;
    top: -6px;
    bottom: -6px;
    width: 8px;
    height: auto;
    transform: translateX(-50%);
  }

  .uv-wrap {
    width: 100%;
    max-width: 100%;
  }

  .y-scale {
    display: none;
  }

  .uv-scale-v {
    display: none;
  }

  .info-panel {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
    align-items: stretch;
  }

  .info-swatch {
    width: 56px;
    height: 56px;
    flex-shrink: 0;
  }

  .info-block {
    flex: 1;
    min-width: 100px;
  }

  .info-hex {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .channels {
    flex-direction: column;
    gap: 20px;
  }
}

@media (max-width: 480px) {
  .hero h1 {
    font-size: 4rem;
  }

  .section-label {
    font-size: 0.6rem;
  }
}
