/**
 * STORMSCAPE — control rail components.
 *
 * The slider is the app's signature control, so it gets the most attention:
 * a recessed rail, a fill that carries the accent, and a thumb that lifts on
 * hover and compresses on press. The whole thing is 22px tall but has a 34px
 * hit area, because a control this important must not be fiddly.
 */

.rail-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.rail-section--grow {
  flex: 1;
}

.rail-section__title {
  color: var(--text-tertiary);
}

/* --------------------------------------------------------------------------
   Presets
   -------------------------------------------------------------------------- */

.presets {
  display: flex;
  gap: var(--space-1);
  padding: var(--space-1);
  border-radius: var(--radius-md);
  background: var(--bg-inset);
  border: 1px solid var(--border-soft);
}

.preset {
  flex: 1 1 0;
  min-width: 0;
  padding: var(--space-2) var(--space-1);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-tertiary);
  /* Four presets plus a reset button in a 280px rail leaves very little room;
     truncating beats letting the last label run off the panel edge. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition:
    background var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out);
}

.preset:hover {
  color: var(--text-primary);
  background: var(--bg-control-hover);
}

.preset[data-active='true'] {
  background: var(--bg-control-active);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm), inset 0 1px 0 var(--edge-highlight);
}

.preset--reset {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 30px;
  padding: 0;
}

.preset--reset svg {
  width: 15px;
  height: 15px;
}

/* --------------------------------------------------------------------------
   Control groups
   -------------------------------------------------------------------------- */

.control-groups {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.control-group__title {
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border-soft);
}

.control-group__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.control-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    'slider info'
    'help help';
  align-items: start;
  gap: var(--space-2);
}

.control-row .slider {
  grid-area: slider;
}

.control-row__info {
  grid-area: info;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-top: 1px;
  border-radius: var(--radius-full);
  color: var(--text-disabled);
  transition:
    color var(--duration-fast) var(--ease-out),
    background var(--duration-fast) var(--ease-out);
}

.control-row__info:hover,
.control-row[data-open] .control-row__info {
  color: var(--accent-text);
  background: var(--accent-muted);
}

.control-row__info svg {
  width: 14px;
  height: 14px;
}

.control-row__help {
  grid-area: help;
  display: none;
  margin-top: var(--space-1);
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  border-left: 2px solid var(--accent-border);
  background: color-mix(in srgb, var(--accent) 6%, transparent);
  font-size: var(--text-xs);
  line-height: var(--leading-normal);
}

.control-row[data-open] .control-row__help {
  display: block;
  animation: help-in var(--duration-normal) var(--ease-out) both;
}

@keyframes help-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

/* --------------------------------------------------------------------------
   Slider
   -------------------------------------------------------------------------- */

.slider {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}

.slider__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
}

.slider__label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  letter-spacing: var(--tracking-tight);
}

.slider__readout {
  display: flex;
  align-items: baseline;
  gap: 3px;
  flex: 0 0 auto;
}

.slider__value {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.slider__unit {
  font-size: var(--text-2xs);
  color: var(--text-tertiary);
}

/* A generous invisible hit area around a visually slim track. */
.slider__control {
  position: relative;
  padding: 7px 0;
  cursor: grab;
  touch-action: none;
  border-radius: var(--radius-sm);
}

.slider[data-dragging] .slider__control {
  cursor: grabbing;
}

.slider__track {
  position: relative;
  display: block;
  height: 20px;
}

.slider__rail {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 4px;
  margin-top: -2px;
  border-radius: var(--radius-full);
  background: var(--bg-inset);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4);
}

.slider__fill {
  position: absolute;
  top: 50%;
  left: 0;
  height: 4px;
  margin-top: -2px;
  border-radius: var(--radius-full);
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--accent) 55%, transparent),
    var(--accent)
  );
  transition: width var(--duration-instant) linear;
}

.slider__thumb {
  position: absolute;
  top: 50%;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: var(--radius-full);
  background: var(--slate-50);
  border: 1px solid rgba(0, 0, 0, 0.28);
  box-shadow: var(--shadow-md);
  transition:
    transform var(--duration-fast) var(--ease-spring),
    box-shadow var(--duration-fast) var(--ease-out),
    left var(--duration-instant) linear;
}

.slider__control:hover .slider__thumb {
  transform: scale(1.14);
}

.slider[data-dragging] .slider__thumb {
  transform: scale(1.24);
  box-shadow: var(--shadow-lg), 0 0 0 6px var(--accent-muted);
}

.slider[data-focused] .slider__thumb {
  box-shadow: var(--shadow-md), 0 0 0 3px var(--focus-halo), 0 0 0 5px var(--focus-ring);
}

/* The control itself owns focus; suppress the generic ring in favour of the
   thumb treatment above, which is far more legible at this size. */
.slider__control:focus-visible {
  outline: none;
  box-shadow: none;
}

/* --------------------------------------------------------------------------
   Compare
   -------------------------------------------------------------------------- */

.compare {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-soft);
  background: var(--bg-inset);
}

.compare__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.compare__label {
  font-size: var(--text-xs);
  line-height: var(--leading-normal);
}

.compare__active,
.compare__empty {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  align-items: flex-start;
}

.button {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-control);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  transition:
    background var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out);
}

.button:hover {
  background: var(--bg-control-hover);
  border-color: var(--border-strong);
}

.button--ghost {
  background: none;
  color: var(--text-tertiary);
}

.button--ghost:hover {
  color: var(--text-primary);
}

/* --------------------------------------------------------------------------
   Mobile sheet chrome
   -------------------------------------------------------------------------- */

.sheetgrip,
.sheettabs {
  display: none;
}

@media (max-width: 720px) {
  .sheetgrip {
    display: grid;
    place-items: center;
    height: 26px;
    flex: 0 0 auto;
    cursor: grab;
    touch-action: none;
  }

  .sheetgrip__bar {
    width: 38px;
    height: 4px;
    border-radius: var(--radius-full);
    background: var(--border-strong);
  }

  .sheettabs {
    display: flex;
    gap: var(--space-1);
    flex: 0 0 auto;
    margin: 0 var(--space-4) var(--space-1);
    padding: var(--space-1);
    border-radius: var(--radius-md);
    background: var(--bg-inset);
  }

  .sheettab {
    flex: 1;
    padding: var(--space-2);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    color: var(--text-tertiary);
  }

  .sheettab[data-active='true'] {
    background: var(--bg-control-active);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
  }

  /* Touch targets grow; a 14px thumb is not usable with a thumb. */
  .slider__thumb {
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
  }

  .slider__control {
    padding: 11px 0;
  }

  .control-group__body {
    gap: var(--space-6);
  }
}
