/* Swarpeti — the instrument case, its finishes, and the control panel. */

/* ------------------------------------------------------------------ *
 * Instrument case
 * ------------------------------------------------------------------ */

.instrument {
  /* The panel stacks by this box's own width (see the @container rule), so it
     also reacts when the Settings drawer takes space from the page. */
  container: instrument / inline-size;
  position: relative;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: linear-gradient(180deg, var(--case-1), var(--case-2));
  box-shadow:
    0 30px 60px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    inset 0 -2px 0 rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

[data-finish='wood'] .instrument {
  background:
    repeating-linear-gradient(91deg, rgba(0, 0, 0, 0.07) 0 2px, transparent 2px 9px),
    repeating-linear-gradient(89deg, rgba(255, 255, 255, 0.04) 0 1px, transparent 1px 13px),
    repeating-linear-gradient(90.4deg, rgba(0, 0, 0, 0.05) 0 1px, transparent 1px 23px),
    linear-gradient(180deg, var(--case-1), var(--case-2));
}

[data-finish='lacquer'] .instrument::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(118deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.02) 34%, transparent 35%);
  pointer-events: none;
}

[data-finish='neon'] .instrument {
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent),
    0 0 38px color-mix(in srgb, var(--accent) 22%, transparent),
    0 30px 60px rgba(0, 0, 0, 0.55);
}

[data-finish='satin'] .instrument {
  background:
    radial-gradient(90% 120% at 50% 0%, rgba(255, 255, 255, 0.09), transparent 60%),
    linear-gradient(180deg, var(--case-1), var(--case-2));
}

/* ---- more finishes (each is only a surface treatment; colours stay tokens) ---- */

/* paper: sandstone with a fine grain, lighter shadows for a light instrument */
[data-finish='paper'] .instrument {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.75' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .32 0 0 0 0 .22 0 0 0 0 .12 0 0 0 .22 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    radial-gradient(90% 120% at 50% 0%, rgba(255, 255, 255, 0.35), transparent 60%),
    linear-gradient(180deg, var(--case-1), var(--case-2));
  box-shadow:
    0 22px 44px rgba(70, 45, 20, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.6),
    inset 0 -2px 0 rgba(0, 0, 0, 0.1);
}

/* marble: pale stone with soft grey veins */
[data-finish='marble'] .instrument {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='520' height='320'%3E%3Cfilter id='v' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='turbulence' baseFrequency='.004 .011' numOctaves='5' seed='11'/%3E%3CfeColorMatrix values='0 0 0 0 .3 0 0 0 0 .32 0 0 0 0 .4 -3.2 0 0 0 1.35'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23v)' opacity='.5'/%3E%3C/svg%3E") center / cover,
    radial-gradient(80% 100% at 15% 0%, rgba(255, 255, 255, 0.5), transparent 60%),
    linear-gradient(180deg, var(--case-1), var(--case-2));
  box-shadow:
    0 22px 44px rgba(30, 35, 55, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    inset 0 -2px 0 rgba(0, 0, 0, 0.1);
}

/* gradient: the sky at dusk */
[data-finish='gradient'] .instrument {
  background:
    linear-gradient(168deg, color-mix(in srgb, var(--accent) 34%, var(--case-1)) 0%, var(--case-1) 34%, var(--case-2) 100%);
}

/* glass: cool sheen, faint rain streaks, an aqua rim */
[data-finish='glass'] .instrument {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  background:
    repeating-linear-gradient(102deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 15px),
    linear-gradient(180deg, color-mix(in srgb, #ffffff 9%, var(--case-1)), var(--case-2));
  box-shadow:
    0 0 32px color-mix(in srgb, var(--accent) 14%, transparent),
    0 30px 60px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    inset 0 0 40px rgba(255, 255, 255, 0.04);
}

[data-finish='glass'] .instrument::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(112deg, rgba(255, 255, 255, 0.09) 0%, rgba(255, 255, 255, 0.015) 40%, transparent 41%);
  pointer-events: none;
}

/* glow: a lamp burning low inside a dark bronze case */
[data-finish='glow'] .instrument {
  background:
    radial-gradient(75% 95% at 50% 112%, color-mix(in srgb, var(--accent) 34%, transparent), transparent 70%),
    linear-gradient(180deg, var(--case-1), var(--case-2));
  box-shadow:
    0 0 44px color-mix(in srgb, var(--accent) 16%, transparent),
    0 30px 60px rgba(0, 0, 0, 0.55),
    inset 0 -1px 0 color-mix(in srgb, var(--accent) 50%, transparent);
}

/* flat: no gloss, no shadows, strong outlines (the High Contrast theme) */
[data-finish='flat'] .instrument {
  border: 2px solid var(--text);
  background: var(--case-1);
  box-shadow: none;
}

[data-finish='flat'] .panel,
[data-finish='flat'] .keybed-frame,
[data-finish='flat'] .drawer {
  border: 2px solid var(--text);
  box-shadow: none;
}

[data-finish='flat'] .key {
  border-width: 2px;
  border-top: 0;
  border-color: var(--text);
  box-shadow: none;
}

[data-finish='flat'] .key-white {
  background: var(--key-white-1);
}

[data-finish='flat'] .key-black {
  background: var(--key-black-2);
}

[data-finish='flat'] .key-white.active,
[data-finish='flat'] .key-black.active {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: none;
}

[data-finish='flat'] .key-cap {
  opacity: 0.9;
}

/* ---- control panel ----
 *
 * Four groups used while playing (Air, Reeds, Drone, Pitch), then one quiet row
 * set once (Volume, Reverb). Orange means "live": lit stops, the air in the
 * gauge and the chosen air source. Everything else is neutral, and only the air
 * switch has a border, so the eye goes to what is sounding.
 */

.panel {
  display: grid;
  grid-template-columns: auto auto auto auto;
  justify-content: space-between;
  align-items: stretch;
  gap: 14px 24px;
  padding: 16px 26px 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.35);
}

.group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

/* Headings share one line across the panel; the controls sit centred in the
   height that is left, so a shorter group looks balanced, not top-heavy. */
.group-head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 22px;
}

.group-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

/* Without the drone group, three columns. */
.panel:has(> .group-drone[hidden]) {
  grid-template-columns: auto auto auto;
}

/* The four group headings are the only uppercase labels. */
.group-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
}

/* Everything else is plain small text: no tracking, so English is no wider than Hindi. */
.field-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---- air: source switch, then the meter (or the Auto-air slider) and its reading ---- */

.group-air {
  width: 172px;
}

.group-air .group-body {
  width: 100%;
  gap: 12px;
}

.air-switch {
  display: flex;
  width: 100%;
}

.segmented.air-switch button {
  flex: 1;
  padding: 4px 6px;
  font-size: 0.78rem;
  white-space: nowrap;
}

/* The chosen air source is live, so it keeps the accent. */
.segmented.air-switch button[aria-pressed='true'] {
  background: var(--accent);
  color: var(--accent-ink);
}

/* The lid can't be used right now: a small warning dot on its button. */
.air-switch button.unavailable::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 4px;
  vertical-align: 0.45em;
  border-radius: 50%;
  background: #e5604d;
}

/* One row: the meter or the slider (same spot), then the reading. */
.air-meter {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 22px;
}

.air-meter > .air-bar,
.air-meter > .slider-air {
  grid-area: 1 / 1;
}

.air-bar {
  position: relative;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background:
    repeating-linear-gradient(90deg, transparent 0 calc(25% - 1px), color-mix(in srgb, var(--text-dim) 35%, transparent) calc(25% - 1px) 25%),
    var(--well);
  box-shadow: inset 0 0 0 1px var(--border);
}

.air-bar-fill {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--accent);
  box-shadow: 0 0 8px var(--glow);
  transform: scaleX(0);
  transform-origin: left center;
}

.slider-air {
  min-width: 0;
}

.slider-air input[type='range'] {
  flex: 1 1 0;
  width: 0;
  min-width: 0;
}

.air-meter[data-mode='auto'] .air-bar,
.air-meter:not([data-mode='auto']) .slider-air {
  visibility: hidden;
}

/* Settings > Air meter: Bar (above), Off (no meter, just the reading and the
   Auto-air slider), or Dial (the round gauge, reading and slider inside it). */
.air-dial {
  display: none;
}

.group-air[data-meter='off'] .air-bar {
  display: none;
}

.group-air[data-meter='off'] .air-meter {
  grid-template-columns: auto;
  justify-content: center;
}

.group-air[data-meter='off'] .air-meter[data-mode='auto'] {
  grid-template-columns: 1fr auto;
  justify-content: stretch;
}

.group-air[data-meter='off'] .air-meter:not([data-mode='auto']) .slider-air {
  display: none;
}

.group-air[data-meter='dial'] .air-meter {
  position: relative;
  display: block;
  width: 150px;
}

.group-air[data-meter='dial'] .air-dial {
  display: block;
  width: 100%;
  overflow: visible;
}

.group-air[data-meter='dial'] .air-bar {
  display: none;
}

.group-air[data-meter='dial'] .air-reading {
  position: absolute;
  left: 50%;
  bottom: 4px; /* under the hub, below where the needle sweeps at low air */
  justify-items: center;
  transform: translateX(-50%);
}

.group-air[data-meter='dial'] .air-meter[data-mode='auto'] .air-reading {
  bottom: 17px; /* room for the pressure slider underneath */
}

.group-air[data-meter='dial'] .slider-air {
  position: absolute;
  left: 50%;
  bottom: -5px;
  width: 92px;
  transform: translateX(-50%);
}

.gauge-track,
.gauge-fill {
  fill: none;
  stroke-width: 7;
  stroke-linecap: round;
}

.gauge-track {
  stroke: color-mix(in srgb, var(--border) 55%, var(--well));
}

.gauge-fill {
  stroke: var(--accent);
  stroke-dasharray: 0 100;
  filter: drop-shadow(0 0 4px var(--glow));
}

#gauge-ticks line {
  stroke: var(--text-dim);
  stroke-width: 1.2;
  opacity: 0.5;
}

.needle {
  stroke: var(--text);
  stroke-width: 2;
  stroke-linecap: round;
}

.needle-pivot {
  fill: var(--text);
}

.air-reading {
  display: grid;
  justify-items: end;
  min-width: 42px;
}

.air-reading > * {
  grid-area: 1 / 1;
  visibility: hidden;
  white-space: nowrap;
}

.air-aside[data-mode='lid'] .aside-lid,
.air-aside[data-mode='space'] .aside-space,
.air-aside[data-mode='auto'] .aside-auto {
  visibility: visible;
}

.lid-readout,
.aside-auto {
  font: 600 0.95rem var(--font-display);
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.lid-readout.is-warning {
  font: 0.76rem var(--font-ui);
  color: var(--accent-fg);
}

.aside-space kbd {
  font-size: 0.72rem;
}

/* ---- segmented switch (air source here; language and labels elsewhere) ---- */

.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--well);
}

.segmented button {
  padding: 5px 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

/* A choice, not a live state: a neutral highlight. */
.segmented button[aria-pressed='true'] {
  background: color-mix(in srgb, var(--text) 16%, transparent);
  color: var(--text);
  font-weight: 600;
}

.segmented button:not([aria-pressed='true']):hover {
  color: var(--text);
}

.segmented button.nudge:not([aria-pressed='true']) {
  color: var(--accent-fg);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.segmented-compact button {
  padding: 4px 11px;
  font-size: 0.8rem;
}

/* ---- stops: reeds and drone, one knob size, names engraved on the panel ---- */

.reeds {
  display: flex;
  gap: 8px;
}

.drone-tuning {
  display: flex;
  gap: 8px;
}

.stop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  min-width: 50px;
  padding: 2px 2px 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.stop-knob {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--case-1), var(--well) 78%);
  border: 1px solid var(--border);
  box-shadow: inset 0 -3px 5px rgba(0, 0, 0, 0.4), 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: transform 0.18s cubic-bezier(0.3, 1.4, 0.5, 1), box-shadow 0.18s, background 0.18s;
  transform: translateY(4px);
}

.stop-knob::after {
  content: '';
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  border: 1px solid var(--border);
  opacity: 0.6;
}

.stop[aria-pressed='true'] .stop-knob {
  transform: translateY(-2px);
  border-color: var(--accent);
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--accent) 70%, white), var(--accent) 60%, color-mix(in srgb, var(--accent) 60%, black));
  box-shadow: 0 7px 12px rgba(0, 0, 0, 0.5), 0 0 14px var(--glow);
}

.stop[aria-pressed='true'] .stop-knob::after {
  border-color: rgba(0, 0, 0, 0.3);
}

/* Engraved: no box, just the name cut into the panel. */
.stop-name {
  position: relative;
  font: 600 0.82rem var(--font-display);
  letter-spacing: 0.03em;
  white-space: nowrap;
  color: var(--text-dim);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.45);
}

.stop[aria-pressed='true'] .stop-name {
  color: var(--text);
}

/* With the drone silent, the chosen companion is not lit: a small dot under its name says which. */
.drone-stops[data-on='false'] .drone-tuning .stop[aria-pressed='true'] .stop-knob {
  transform: translateY(4px);
  border-color: var(--border);
  background: radial-gradient(circle at 35% 30%, var(--case-1), var(--well) 78%);
  box-shadow: inset 0 -3px 5px rgba(0, 0, 0, 0.4);
}

.drone-stops[data-on='false'] .drone-tuning .stop[aria-pressed='true'] .stop-name {
  color: var(--text);
}

.drone-stops[data-on='false'] .drone-tuning .stop[aria-pressed='true'] .stop-name::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 4px;
  height: 4px;
  margin-left: -2px;
  border-radius: 50%;
  background: currentColor;
}

.stop.refused .stop-knob {
  animation: nudge 0.35s ease;
}

@keyframes nudge {
  25% { translate: -3px 0; }
  75% { translate: 3px 0; }
}

/* ---- drone: shown (and playing) when ticked in Settings ---- */

.drone-stops {
  align-items: flex-start;
}

.drone-sa {
  align-self: center;
  margin: -18px 2px 0 0;
  font: 600 0.82rem var(--font-display);
  color: var(--text);
  white-space: nowrap;
}

/* ---- drone settings, under its stops ---- */

.drone-settings {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 2px;
}

.select {
  padding: 4px 26px 4px 10px;
  border: 0;
  border-radius: 8px;
  background:
    linear-gradient(45deg, transparent 50%, var(--text-dim) 50%) right 13px center / 5px 5px no-repeat,
    linear-gradient(-45deg, transparent 50%, var(--text-dim) 50%) right 9px center / 5px 5px no-repeat,
    var(--well);
  color: var(--text);
  font: 0.8rem var(--font-ui);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

/* ---- pitch: two menus (compact) or two faders (Dial in Settings brings the faders) ---- */

.group-pitch[data-style='menus'] .faders,
.group-pitch[data-style='faders'] .pitch-menus {
  display: none;
}

/* The Scale menu already names the scale; the line below need not repeat it. */
.group-pitch[data-style='menus'] .sa-scale {
  display: none;
}

.pitch-menus {
  display: grid;
  gap: 8px;
}

.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.menu-row .select {
  min-width: 64px;
}

/* ---- pitch faders, like an equaliser ---- */

.faders {
  display: flex;
  gap: 26px;
}

.fader-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.fader {
  --at: 0.5;
  position: relative;
  width: 44px;
  height: 108px;
  cursor: pointer;
  touch-action: none;
  border-radius: 6px;
}

.fader-track {
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: 50%;
  width: 6px;
  margin-left: -3px;
  border-radius: 3px;
  background: var(--well);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.6), 0 0 0 1px var(--border);
}

/* A mark per step on both sides of the track; a full-width one at the centre of Scale. */
.fader-tick {
  position: absolute;
  left: calc(50% - 15px);
  bottom: calc(10px + var(--at) * (100% - 20px));
  width: 30px;
  height: 1px;
  background: linear-gradient(90deg, var(--text-dim) 0 8px, transparent 8px 22px, var(--text-dim) 22px);
  opacity: 0.55;
}

.fader-tick-centre {
  left: calc(50% - 19px);
  width: 38px;
  background: var(--text-dim);
  opacity: 0.9;
}

/* The cap shows the value, like a fader on a desk. */
.fader-thumb {
  position: absolute;
  left: 50%;
  bottom: calc(10px + var(--at) * (100% - 20px));
  display: grid;
  place-items: center;
  width: 40px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--case-1) 85%, white), var(--well));
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.45);
  transform: translate(-50%, 50%);
  transition: bottom 0.12s ease-out;
}

.fader-thumb output {
  font: 600 0.82rem var(--font-ui);
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.fader:hover .fader-thumb {
  border-color: var(--text-dim);
}

.steppers-hint {
  text-align: center;
  white-space: nowrap;
}

.steppers-hint strong {
  color: var(--text);
  font-weight: 600;
}

/* Changed from the keyboard: a short pulse so the eye catches it. */
.fader output.bump {
  animation: bump 0.35s ease;
}

@keyframes bump {
  40% {
    color: var(--accent-fg);
  }
}

/* ---- set once: volume and reverb ---- */

.sound-row {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 48px;
  padding-top: 10px;
  border-top: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}

.slider {
  display: flex;
  align-items: center;
  gap: 10px;
}

.slider output {
  min-width: 3.2ch;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}

.slider-compact {
  gap: 8px;
}

.slider-compact input[type='range'] {
  width: 64px;
}

/* Sliders are settings, not live state: neutral track and thumb. */
input[type='range'] {
  --fill: 50%;
  --range-fill: color-mix(in srgb, var(--text) 55%, transparent);
  width: 130px;
  height: 22px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

input[type='range']::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--range-fill) var(--fill), var(--well) var(--fill));
  box-shadow: inset 0 0 0 1px var(--border);
}

input[type='range']::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: var(--well);
  box-shadow: inset 0 0 0 1px var(--border);
}

input[type='range']::-moz-range-progress {
  height: 4px;
  border-radius: 999px;
  background: var(--range-fill);
}

input[type='range']::-webkit-slider-thumb {
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border: 0;
  border-radius: 50%;
  background: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  -webkit-appearance: none;
  appearance: none;
}

input[type='range']::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 50%;
  background: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
