/* ============================================================
   CONDITION VISUALIZATIONS
   Mini-illustrations rendered inside each condition's expanded
   form (and a static version on the show page). Driven by CSS
   custom properties that Stimulus controllers write on input:
     --fill-low / --fill-high  (thermometer band, 0..100%)
     --wind-intensity          (wind streaks, 0..1)
     --wind-fill-low / --wind-fill-high (wind band, 0..100%)
     --needle-angle            (compass needle, degrees)
   ============================================================ */

/* ---- Shared condition-form scaffolding ---- */
.condition-form {
  background: var(--color-white);
  border-radius: var(--radius-2xl);
  padding: 1.6rem 1.5rem;
  box-shadow:
    var(--shadow-panel),
    0 0 0 1px rgba(0, 0, 0, 0.04);
}

.condition-form-head {
  margin-bottom: 1.2rem;
  padding-right: 2.5rem; /* leave room for the collapse × */
}

.condition-form-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: var(--color-dark);
}

.condition-form-sub {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
  color: var(--color-gray-500);
  line-height: 1.45;
}

.condition-form-body {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  align-items: stretch;
}

.condition-form-body--thermo {
  grid-template-columns: 110px 1fr;
}

@media (max-width: 540px) {
  .condition-form-body--thermo {
    grid-template-columns: 80px 1fr;
  }
}

.condition-form-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem;
  align-content: start;
}

@media (max-width: 480px) {
  .condition-form-inputs {
    grid-template-columns: 1fr;
  }
}

/* ============================================================
   RANGE INPUT (paired slider + number)
   ============================================================ */

.range-input {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.range-input__slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--color-surface), #e0e6f4);
  outline: none;
  margin: 0.25rem 0;
  cursor: grab;
}

.range-input__slider:active { cursor: grabbing; }

/* WebKit thumb */
.range-input__slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--gradient-primary);
  border: 3px solid var(--color-white);
  box-shadow: 0 3px 10px rgba(255, 107, 53, 0.4);
  cursor: grab;
  transition: transform 0.2s var(--ease-spring), box-shadow 0.15s;
}

.range-input__slider::-webkit-slider-thumb:hover {
  transform: scale(1.12);
  box-shadow: 0 5px 14px rgba(255, 107, 53, 0.55);
}

.range-input__slider:active::-webkit-slider-thumb { cursor: grabbing; }

/* Firefox thumb */
.range-input__slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-primary);
  border: 3px solid var(--color-white);
  box-shadow: 0 3px 10px rgba(255, 107, 53, 0.4);
  cursor: grab;
}

/* Max slider gets a teal thumb to distinguish from min */
.range-input__slider--max::-webkit-slider-thumb {
  background: linear-gradient(135deg, var(--color-accent), #2e9a91);
  box-shadow: 0 3px 10px rgba(78, 205, 196, 0.45);
}
.range-input__slider--max::-moz-range-thumb {
  background: var(--color-accent);
  box-shadow: 0 3px 10px rgba(78, 205, 196, 0.45);
}

.range-input__number-wrap {
  position: relative;
}

.range-input__number {
  font-feature-settings: "tnum" 1;
  font-variant-numeric: tabular-nums;
  text-align: left;
}

/* ============================================================
   THERMOMETER VIZ
   ============================================================ */

.thermo-viz {
  --fill-low: 0%;
  --fill-high: 100%;
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  position: relative;
}

.thermo-viz__track {
  position: relative;
  width: 38px;
  border-radius: var(--radius-full);
  background: var(--gradient-thermo);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.5),
    0 6px 14px rgba(5, 10, 50, 0.18);
  overflow: hidden;
  min-height: 200px;
}

/* The thermometer renders vertically with HOT at the top of the track
   (--gradient-thermo goes 180deg = top→bottom, hot→cold). The Stimulus
   controller writes --fill-low / --fill-high as fractions along the
   axis from MIN (-10°C, bottom) to MAX (+40°C, top), so a higher
   fraction sits closer to the top. We dim the bands outside [min, max]
   by layering two semi-opaque masks. */
.thermo-viz__track::before,
.thermo-viz__track::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.78);
  pointer-events: none;
  transition: top 0.25s var(--ease-out-soft), bottom 0.25s var(--ease-out-soft);
}

/* Top mask: dims everything above the max */
.thermo-viz__track::before {
  top: 0;
  bottom: var(--fill-high);
}

/* Bottom mask: dims everything below the min */
.thermo-viz__track::after {
  top: calc(100% - var(--fill-low));
  bottom: 0;
}

/* Handle indicators (rendered on top of the masks) */
.thermo-viz__handle {
  position: absolute;
  left: -8px;
  right: -8px;
  height: 4px;
  background: var(--color-dark);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  border-radius: var(--radius-full);
  pointer-events: none;
  transition: bottom 0.25s var(--ease-out-soft), top 0.25s var(--ease-out-soft);
  z-index: 2;
}

.thermo-viz__handle span {
  position: absolute;
  right: -2.5rem;
  top: -0.55rem;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-gray-500);
}

.thermo-viz__handle--max {
  bottom: var(--fill-high);
}

.thermo-viz__handle--min {
  bottom: var(--fill-low);
}

.thermo-viz--max-empty .thermo-viz__handle--max,
.thermo-viz--max-empty .thermo-viz__track::before {
  opacity: 0;
}

.thermo-viz--min-empty .thermo-viz__handle--min,
.thermo-viz--min-empty .thermo-viz__track::after {
  opacity: 0;
}

.thermo-viz__legend {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--color-gray-400);
  letter-spacing: 0.04em;
  padding: 0.25rem 0;
}

/* Mini thermometer for show-page summary */
.thermo-viz--mini .thermo-viz__track {
  min-height: 100px;
  width: 24px;
}

.thermo-viz--mini .thermo-viz__handle {
  height: 3px;
}

.thermo-viz--mini .thermo-viz__handle span { display: none; }

.thermo-viz--mini .thermo-viz__legend { font-size: 0.65rem; }

@media (prefers-reduced-motion: reduce) {
  .thermo-viz__track::before,
  .thermo-viz__track::after,
  .thermo-viz__handle {
    transition: none;
  }
}

/* ============================================================
   WIND VIZ
   ============================================================ */

.wind-viz {
  --wind-intensity: 0.3;
  --wind-fill-low: 0%;
  --wind-fill-high: 100%;
  position: relative;
  height: 110px;
  border-radius: var(--radius-xl);
  background: linear-gradient(160deg, #0d1b6e 0%, #1a3a8f 60%, #2d6abf 100%);
  overflow: hidden;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.12),
    0 8px 18px rgba(5, 10, 50, 0.25);
}

.wind-viz__sky {
  position: absolute;
  inset: 0;
}

.wind-viz__streak {
  position: absolute;
  height: 2px;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.85) 40%, transparent);
  /* duration shrinks as intensity grows: 4s at 0, 0.6s at 1 */
  animation: wind-streak calc(0.6s + (1 - var(--wind-intensity)) * 3.4s) linear infinite;
  opacity: calc(0.35 + var(--wind-intensity) * 0.55);
  width: calc(60px + var(--wind-intensity) * 140px);
}

.wind-viz__streak--1 { top: 16%; left: -40%; animation-delay: 0.0s; }
.wind-viz__streak--2 { top: 30%; left: -50%; animation-delay: 0.4s; }
.wind-viz__streak--3 { top: 46%; left: -35%; animation-delay: 0.9s; }
.wind-viz__streak--4 { top: 62%; left: -55%; animation-delay: 0.2s; }
.wind-viz__streak--5 { top: 76%; left: -30%; animation-delay: 0.7s; }
.wind-viz__streak--6 { top: 88%; left: -45%; animation-delay: 1.1s; }

@keyframes wind-streak {
  0%   { transform: translateX(0); }
  100% { transform: translateX(220%); }
}

.wind-viz__readout {
  position: absolute;
  right: 1.1rem;
  bottom: 0.8rem;
  display: inline-flex;
  align-items: baseline;
  gap: 0.4rem;
  color: var(--color-white);
  background: rgba(0, 0, 0, 0.32);
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-full);
  backdrop-filter: blur(8px);
  z-index: 2;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.wind-viz__readout-value {
  font-size: 1.4rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  font-feature-settings: "tnum" 1;
  font-variant-numeric: tabular-nums;
}

.wind-viz__readout-unit {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.78;
}

/* Mini wind viz for show-page summary */
.wind-viz--mini {
  height: 70px;
}

.wind-viz--mini .wind-viz__readout {
  right: 0.7rem;
  bottom: 0.5rem;
  padding: 0.25rem 0.65rem;
}

.wind-viz--mini .wind-viz__readout-value { font-size: 1rem; }

@media (prefers-reduced-motion: reduce) {
  .wind-viz__streak {
    animation: none;
    transform: translateX(60%);
    opacity: 0.4;
  }
}

/* ============================================================
   COMPASS NEEDLE (center of the existing wind-direction compass)
   ============================================================ */

.compass {
  --needle-angle: 0deg;
}

.compass-needle {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 78px;
  margin-top: -52px;     /* needle pivots near its base */
  margin-left: -2px;
  transform-origin: 50% calc(100% - 26px);
  transform: rotate(var(--needle-angle));
  background: linear-gradient(180deg, var(--color-primary) 0%, var(--color-primary-end) 55%, rgba(255, 217, 61, 0) 100%);
  border-radius: var(--radius-full);
  pointer-events: none;
  transition: transform 0.35s var(--ease-spring);
  filter: drop-shadow(0 2px 6px rgba(255, 107, 53, 0.45));
  z-index: 3;
}

.compass-needle::before {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-white);
  box-shadow:
    0 0 0 3px var(--color-primary),
    0 2px 8px rgba(0, 0, 0, 0.2);
}

.compass--no-direction .compass-needle {
  opacity: 0;
}

/* ============================================================
   WIND DRIFT
   Streaks blowing across the compass face, away from the selected
   directions — so "W" reads as wind coming FROM the west rather than
   an arrow pointing at it. Driven by --wind-angle (needle angle + 90),
   written by wind_compass_controller.js on the picker and inline by
   Ruby on the show-page summary.
   ============================================================ */

.compass-wind {
  --streak-peak: 0.85;
  position: absolute;
  inset: 0;
  /* circular window: rotation-invariant, so the square field inside can
     spin without ever showing a corner */
  border-radius: 50%;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.compass-wind__field {
  position: absolute;
  inset: 0;
  transform: rotate(var(--wind-angle, 0deg));
  /* plain ease — the needle's overshoot easing makes streaks look wobbly */
  transition: transform 0.45s ease;
}

.compass-wind__streak {
  position: absolute;
  left: -35%;
  width: 45%;
  height: 2px;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, transparent, var(--color-accent) 50%, transparent);
  opacity: 0;
  animation: compass-wind-drift 3.8s linear infinite;
}

.compass-wind__streak--1 { top: 24%; animation-delay: 0s; }
.compass-wind__streak--2 { top: 38%; animation-delay: 1.4s; }
.compass-wind__streak--3 { top: 50%; animation-delay: 0.6s; }
.compass-wind__streak--4 { top: 62%; animation-delay: 2.1s; }
.compass-wind__streak--5 { top: 76%; animation-delay: 1.0s; }

/* translateX is relative to the streak's own width, so 0 → 300% carries it
   clear across the circle at any rotation */
@keyframes compass-wind-drift {
  0%       { transform: translateX(0);    opacity: 0; }
  18%, 82% { opacity: var(--streak-peak); }
  100%     { transform: translateX(300%); opacity: 0; }
}

.compass--no-direction .compass-wind {
  opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
  .compass-needle {
    transition: none;
  }

  .compass-wind__field {
    transition: none;
  }

  .compass-wind__streak {
    animation: none;
    transform: translateX(150%);
    opacity: calc(var(--streak-peak) * 0.6);
  }
}

/* ============================================================
   SKY STRIPS (timing)
   A week of miniature days: seven 0–24 h tracks painted with the
   night→gold→night sky (the --gradient-night stops mirrored around
   noon). The allowed window is the lit slice between --window-start
   and --window-end (each a % of the track); night shrouds dim the
   hours outside it. In the form the two range inputs overlaid on
   each strip ARE the from/to fields — only their thumbs are
   interactive. The show-page summary reuses the same markup without
   inputs (.sky-week--mini), properties inlined by Ruby.
   ============================================================ */

.sky-week {
  --day-col: 3.6rem;
  --readout-col: 3.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sky-day {
  display: grid;
  grid-template-columns: var(--day-col) 1fr var(--readout-col);
  align-items: center;
  gap: 0.7rem;
}

.sky-strip {
  --window-start: 33.33%;
  --window-end: 75%;
  position: relative;
  height: 34px;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg,
    #050d2e 0%, #0d1b6e 12%, #1a3a8f 26%, #2d6abf 36%, #74b3e0 44%,
    #f7c94b 50%,
    #74b3e0 56%, #2d6abf 64%, #1a3a8f 74%, #0d1b6e 88%, #050d2e 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.14),
    0 4px 10px rgba(5, 10, 50, 0.22);
  overflow: hidden;
}

/* Night shrouds over the hours outside the window */
.sky-strip::before,
.sky-strip::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(5, 13, 46, 0.78);
  pointer-events: none;
  transition: width 0.3s var(--ease-out-soft), left 0.3s var(--ease-out-soft);
  z-index: 1;
}

.sky-strip::before {
  left: 0;
  width: var(--window-start);
}

.sky-strip::after {
  left: var(--window-end);
  right: 0;
}

/* A day with no window stays night-dark: the shrouds meet in the middle */
.sky-day--off .sky-strip::before { width: 100%; }
.sky-day--off .sky-strip::after  { left: 100%; }

/* ---- The strip as input: transparent ranges, interactive thumbs ---- */

.sky-strip__range {
  -webkit-appearance: none;
  appearance: none;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  background: transparent;
  pointer-events: none;
  z-index: 2;
}

.sky-strip__range--to { z-index: 3; }

.sky-strip__range:disabled { visibility: hidden; }

.sky-strip__range::-webkit-slider-runnable-track {
  height: 100%;
  background: transparent;
  border: none;
}

.sky-strip__range::-moz-range-track {
  background: transparent;
  border: none;
}

.sky-strip__range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  pointer-events: auto;
  width: 12px;
  height: 26px;
  margin-top: 4px; /* (34px strip − 26px thumb) / 2 */
  border-radius: var(--radius-full);
  background: var(--color-white);
  border: none;
  box-shadow:
    0 0 0 2px rgba(5, 13, 46, 0.35),
    0 2px 6px rgba(5, 10, 50, 0.4);
  cursor: grab;
  transition: transform 0.25s var(--ease-spring);
}

.sky-strip__range::-webkit-slider-thumb:hover { transform: scale(1.12); }
.sky-strip__range:active::-webkit-slider-thumb { cursor: grabbing; }

.sky-strip__range::-moz-range-thumb {
  pointer-events: auto;
  width: 12px;
  height: 26px;
  border-radius: var(--radius-full);
  background: var(--color-white);
  border: none;
  box-shadow:
    0 0 0 2px rgba(5, 13, 46, 0.35),
    0 2px 6px rgba(5, 10, 50, 0.4);
  cursor: grab;
}

.sky-strip__range:focus-visible::-webkit-slider-thumb {
  box-shadow:
    0 0 0 3px var(--color-accent),
    0 2px 6px rgba(5, 10, 50, 0.4);
}

.sky-strip__range:focus-visible::-moz-range-thumb {
  box-shadow:
    0 0 0 3px var(--color-accent),
    0 2px 6px rgba(5, 10, 50, 0.4);
}

/* ---- Day toggle chip (checkbox stays focusable, chip is the visual) ---- */

.day-toggle {
  position: relative;
  display: block;
  cursor: pointer;
}

.day-toggle__box {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.day-toggle__chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 0.35rem 0;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.6);
  box-shadow: inset 0 0 0 1px rgba(75, 63, 160, 0.15);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--color-gray-500);
  user-select: none;
  transition:
    background 0.2s,
    color 0.2s,
    box-shadow 0.2s,
    transform 0.25s var(--ease-spring);
}

.day-toggle__box:checked + .day-toggle__chip {
  background: var(--gradient-primary);
  color: var(--color-dark);
  box-shadow: 0 2px 8px rgba(255, 107, 53, 0.35);
  transform: scale(1.06);
}

.day-toggle__box:focus-visible + .day-toggle__chip {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* ---- Labels, readouts, hour scale ---- */

.sky-day__label {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-gray-500);
}

.sky-day__readout {
  font-size: 0.8rem;
  font-weight: 800;
  font-feature-settings: "tnum" 1;
  font-variant-numeric: tabular-nums;
  color: var(--color-gray-500);
  text-align: right;
}

.sky-day--off .sky-day__label,
.sky-day--off .sky-day__readout,
.sky-day--off .day-toggle__chip {
  color: var(--color-gray-400);
}

.sky-scale {
  display: grid;
  grid-template-columns: var(--day-col) 1fr var(--readout-col);
  gap: 0.7rem;
}

.sky-scale__marks {
  grid-column: 2;
  display: flex;
  justify-content: space-between;
  padding: 0 0.15rem;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--color-gray-400);
  font-feature-settings: "tnum" 1;
  font-variant-numeric: tabular-nums;
}

/* ---- Min-session chip ---- */

.session-chip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.7rem 1rem;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
}

.session-chip .form-label { margin: 0; }

.session-chip__input { width: 5.5rem; }

.session-chip__hint {
  flex-basis: 100%;
  margin: 0;
}

/* Read-only variant on the show page */
.session-chip--readout {
  display: inline-flex;
  align-items: center;
  margin-top: 0.8rem;
  padding: 0.35rem 0.9rem;
  background: var(--gradient-primary);
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--color-dark);
  box-shadow: 0 2px 8px rgba(255, 107, 53, 0.25);
}

/* ---- Mini week for the show-page summary ---- */

.sky-week--mini {
  --day-col: 2.6rem;
  --readout-col: 3.2rem;
  gap: 0.35rem;
}

.sky-week--mini .sky-strip { height: 16px; }

.sky-week--mini .sky-day__readout { font-size: 0.7rem; }

@media (max-width: 480px) {
  .sky-week {
    --day-col: 3rem;
    --readout-col: 3rem;
  }

  .sky-day { gap: 0.45rem; }
  .sky-scale { gap: 0.45rem; }
}

@media (prefers-reduced-motion: reduce) {
  .sky-strip::before,
  .sky-strip::after,
  .sky-strip__range::-webkit-slider-thumb,
  .day-toggle__chip {
    transition: none;
  }
}
