:root {
  --ink: #0f0d0b;
  --ink-soft: #1c1813;
  --cream: #f4ede0;
  --cream-soft: #ede3d2;
  --paper: #faf6ee;
  --umber: #5c3a21;
  --sienna: #8b4513;
  --cadmium: #e8821e;
  --crimson: #9b2c2c;
  --viridian: #1f5f4f;
  --ochre: #c9a227;
  --white: #faf7f0;
  --muted: #8b7e6b;
  --line: #2a2118;
}

* {
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--cream);
  color: var(--ink);
  overflow-x: hidden;
}

.font-display {
  font-family: 'Fraunces', serif;
  font-optical-sizing: auto;
}
.font-hand {
  font-family: 'Caveat', cursive;
}

/* Canvas texture overlay */
.canvas-texture {
  background-image:
    url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.1 0 0 0 0 0.08 0 0 0 0 0.06 0 0 0 0.35 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg width='40' height='40' viewBox='0 0 40 40' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 10h40M0 30h40M10 0v40M30 0v40' stroke='%23000' stroke-opacity='0.04' stroke-width='0.5'/%3E%3C/svg%3E");
  background-size: 200px 200px, 40px 40px;
}

.paper-texture {
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='p'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.4 0 0 0 0 0.3 0 0 0 0 0.2 0 0 0 0.08 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23p)'/%3E%3C/svg%3E");
}

/* Hero atmosphere */
.hero-bg {
  background:
    radial-gradient(ellipse at 20% 30%, rgba(232, 130, 30, 0.18) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 70%, rgba(155, 44, 44, 0.15) 0%, transparent 55%),
    radial-gradient(ellipse at 50% 100%, rgba(31, 95, 79, 0.12) 0%, transparent 60%),
    linear-gradient(180deg, #0f0d0b 0%, #1c1813 100%);
}

/* Brush stroke animation */
.brush-stroke {
  stroke-dasharray: 2000;
  stroke-dashoffset: 2000;
  animation: paintStroke 3s ease-out forwards;
}
.brush-stroke-2 {
  animation-delay: 0.5s;
}
.brush-stroke-3 {
  animation-delay: 1s;
}
@keyframes paintStroke {
  to {
    stroke-dashoffset: 0;
  }
}

/* Floating paint particles */
.paint-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(1px);
  opacity: 0.6;
  animation: float 20s infinite ease-in-out;
}
@keyframes float {
  0%,
  100% {
    transform: translate(0, 0) rotate(0deg);
  }
  33% {
    transform: translate(30px, -40px) rotate(120deg);
  }
  66% {
    transform: translate(-20px, 30px) rotate(240deg);
  }
}

@keyframes scroll {
  to {
    transform: translateX(-50%);
  }
}

/* Palette swatch */
.paint-swatch {
  position: relative;
  background:
    radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.4) 0%, transparent 40%),
    var(--swatch-color, #888);
  box-shadow:
    inset 0 -8px 16px rgba(0, 0, 0, 0.3),
    inset 0 4px 8px rgba(255, 255, 255, 0.2),
    0 4px 12px rgba(0, 0, 0, 0.25);
  border-radius: 50%;
}
.paint-swatch::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 70% 70%, rgba(0, 0, 0, 0.4) 0%, transparent 30%);
}

/* Card hover */
.style-card {
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
}
.style-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 0%, rgba(232, 130, 30, 0) 100%);
  transition: background 0.4s;
  pointer-events: none;
}
.style-card:hover::before {
  background: linear-gradient(135deg, rgba(232, 130, 30, 0.08) 0%, rgba(155, 44, 44, 0.05) 100%);
}
/* Selection state is driven by the native radio inside each card, so the
   form serializes without any JS bookkeeping. */
.style-card.active,
.style-card:has(input:checked) {
  border-color: var(--cadmium);
  background: linear-gradient(135deg, rgba(232, 130, 30, 0.08) 0%, rgba(155, 44, 44, 0.04) 100%);
}
.style-card:has(input:focus-visible) {
  outline: 2px solid var(--cadmium);
  outline-offset: 2px;
}
.style-card.active::after,
.style-card:has(input:checked)::after {
  content: '';
  position: absolute;
  top: 12px;
  right: 12px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--cadmium);
  box-shadow: 0 0 12px var(--cadmium);
}

/* Upload zone */
.upload-zone {
  background:
    repeating-linear-gradient(45deg, transparent 0 12px, rgba(92, 58, 33, 0.03) 12px 24px),
    var(--paper);
  transition: all 0.3s;
}
.upload-zone.dragging {
  background:
    repeating-linear-gradient(45deg, transparent 0 12px, rgba(232, 130, 30, 0.08) 12px 24px),
    var(--paper);
  border-color: var(--cadmium);
  transform: scale(1.01);
}
.upload-zone-dark {
  background: repeating-linear-gradient(
    45deg,
    transparent 0 12px,
    rgba(244, 237, 224, 0.03) 12px 24px
  );
}
.upload-zone-dark.dragging {
  border-color: var(--cadmium);
}

/* Custom range slider */
input[type='range'].level-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: linear-gradient(90deg, var(--umber) 0%, var(--cadmium) 50%, var(--crimson) 100%);
  border-radius: 3px;
  outline: none;
}
input[type='range'].level-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
input[type='range'].level-slider::-moz-range-thumb {
  width: 28px;
  height: 28px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 50%;
  cursor: pointer;
}

/* Stage timeline */
.stage-node {
  transition: all 0.4s;
}
.stage-node.completed {
  background: var(--viridian);
  border-color: var(--viridian);
}
.stage-node.active {
  background: var(--cadmium);
  border-color: var(--cadmium);
  box-shadow: 0 0 0 6px rgba(232, 130, 30, 0.2);
}

/* Reveal animation */
.reveal {
  opacity: 0;
  transform: translateY(24px);
  transition:
    opacity 0.9s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.9s cubic-bezier(0.16, 1, 0.3, 1);
}
.reveal.in {
  opacity: 1;
  transform: translateY(0);
}

/* Loading brush */
.brush-loader {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: var(--cadmium);
  border-right-color: var(--crimson);
  animation: spin 1s linear infinite;
}
.brush-loader-sm {
  width: 24px;
  height: 24px;
  border-width: 2px;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Toast */
.toast {
  transform: translateY(160%);
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.toast.show {
  transform: translateY(0);
}

html {
  scroll-behavior: smooth;
}

.palette-list::-webkit-scrollbar {
  width: 6px;
}
.palette-list::-webkit-scrollbar-thumb {
  background: var(--umber);
  border-radius: 3px;
}

/* Decorative underline */
.paint-underline {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 12'%3E%3Cpath d='M2 8 Q 75 2, 150 6 T 298 5' stroke='%23E8821E' stroke-width='3' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: bottom left;
  background-size: 100% 8px;
  padding-bottom: 12px;
}

/* Feedback card variants */
.feedback-good {
  border-left-color: var(--viridian);
}
.feedback-warn {
  border-left-color: var(--ochre);
}
.feedback-fix {
  border-left-color: var(--crimson);
}

.canvas-area {
  cursor: crosshair;
}

/* htmx request states.
   htmx adds .htmx-request to whichever element hx-indicator points at, so these
   rules are scoped to that element's subtree rather than applied globally. */
.htmx-indicator {
  display: none;
}
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: flex;
}

/* Reference zone: swap the drop-zone and prompt box for a loader while busy.
   Used by htmx (generate) and by the upload path, which sets .htmx-request
   manually because it must resize the file before sending. */
.reference-busy {
  display: none;
}
#referenceZone.htmx-request .hide-while-loading {
  display: none;
}
#referenceZone.htmx-request .reference-busy {
  display: flex;
}

/* Per-stage critique zone busy state */
[data-critique-zone] [data-critique-loading] {
  display: none;
}
[data-critique-zone].htmx-request {
  pointer-events: none;
}
[data-critique-zone].htmx-request [data-critique-prompt] {
  display: none;
}
[data-critique-zone].htmx-request [data-critique-loading] {
  display: flex;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Canvas-proportion picker — selection driven by the native radio */
.format-card:has(input:checked) {
  border-color: var(--cadmium);
  background: rgba(232, 130, 30, 0.08);
}
.format-card:has(input:checked) span[style] {
  border-color: var(--cadmium);
}
.format-card:has(input:focus-visible) {
  outline: 2px solid var(--cadmium);
  outline-offset: 2px;
}
