/*
 * Studio Bass Boost — faceplate layout and bespoke visuals.
 * Region map (container queries on .device):
 *   ≥ 64rem   display (analyzer window + IN/OUT meters) across the top;
 *             contour | psycho | club underneath
 *   ≥ 44rem   display; contour full width (hero knob beside its three satellites); psycho | club
 *   narrower  display, contour, psycho, club stacked in reading order (= DOM order)
 */

@layer effect {
  body {
    background:
      radial-gradient(90rem 40rem at 50% -10rem, var(--page-glow), var(--transparent)),
      var(--color-chassis);
  }

  /* ── the cabinet: low, heavy faceplate between walnut cheeks ── */
  .device {
    position: relative;
    background-image: linear-gradient(180deg, var(--plate-top) 0, var(--color-panel) 4rem, var(--color-panel) 75%, var(--plate-bottom) 100%);
    border-block-end-width: 0.375rem;

    @media (width >= 60rem) {
      padding-inline: calc(1.5rem + var(--space-5));
    }

    /* oiled walnut side cheeks (decorative) */
    &::before,
    &::after {
      content: "";
      position: absolute;
      inset-block: -1px;
      inline-size: 1.5rem;
      display: none;
      background:
        linear-gradient(90deg, var(--plate-sheen), var(--transparent) 40%, var(--hero-shadow)),
        repeating-linear-gradient(177deg, var(--cheek-dark) 0 0.3rem, var(--cheek-mid) 0.3rem 0.45rem, var(--cheek-light) 0.45rem 0.55rem, var(--cheek-mid) 0.55rem 0.9rem);

      @media (width >= 60rem) {
        display: block;
      }
    }

    &::before {
      inset-inline-start: -1px;
      border-start-start-radius: var(--radius-lg);
      border-end-start-radius: var(--radius-lg);
    }

    &::after {
      inset-inline-end: -1px;
      border-start-end-radius: var(--radius-lg);
      border-end-end-radius: var(--radius-lg);
    }
  }

  .device-header {
    padding-block-end: var(--space-3);
    border-block-end: 1px solid var(--color-border);

    /* the power (Effect in) switch stays beside the brand; presets get their own row … */
    @container device (inline-size >= 30rem) {
      display: grid;
      grid-template-columns: minmax(0, 1fr) auto;
      grid-template-areas:
        "brand   power"
        "presets presets";
      align-items: center;

      .brand { grid-area: brand; }
      #preset-bar { grid-area: presets; }
      [data-toggle="bypass"] { grid-area: power; }
    }

    /* … until there is room for all three on one line */
    @container device (inline-size >= 64rem) {
      grid-template-columns: auto minmax(0, 1fr) auto;
      grid-template-areas: "brand presets power";
      column-gap: var(--space-4);

      #preset-bar { justify-content: flex-end; }
    }
  }

  .brand-name {
    font-weight: 500;
    letter-spacing: 0.04em;
  }

  .section {
    box-shadow: 0 1px 0 var(--plate-sheen) inset;
  }

  /* engraved section titles with a hairline rule */
  .section-title {
    display: flex;
    align-items: center;
    gap: var(--space-3);

    &::after {
      content: "";
      flex: 1 1 auto;
      border-block-start: 1px solid var(--color-border);
    }
  }

  /* ── faceplate grid ── */
  .faceplate {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "display" "contour" "psycho" "club";
    gap: var(--space-4);

    @container device (inline-size >= 44rem) {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      grid-template-areas:
        "display display"
        "contour contour"
        "psycho  club";
    }

    @container device (inline-size >= 64rem) {
      grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr);
      grid-template-areas:
        "display display display"
        "contour psycho  club";
    }
  }

  .analyzer { grid-area: display; }
  .contour { grid-area: contour; }
  .psycho { grid-area: psycho; }
  .club { grid-area: club; }

  /* ── analyzer: oxblood glass window lit from below, meters beside it ── */
  .analyzer {
    --viz-block: clamp(13rem, 27cqi, 21rem);
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "title" "legend" "window" "readout" "meters";

    @container device (inline-size >= 36rem) {
      grid-template-columns: minmax(0, 1fr) auto;
      grid-template-areas:
        "title   title"
        "legend  legend"
        "window  meters"
        "readout readout";
    }

    .section-title { grid-area: title; }

    .meters {
      grid-area: meters;
      block-size: 9rem;

      /* beside the window: exactly its height (a definite size — an auto-height row would let the
         meter canvas' percentage height keep the previous layout's size after the page narrows) */
      @container device (inline-size >= 36rem) {
        block-size: var(--viz-block);
      }
    }
  }

  /* canvases take their size from CSS only: size containment stops the ResizeObserver →
     backing-store → intrinsic-size feedback from growing them in auto-height rows on HiDPI screens */
  .meter-canvas,
  .gauge-canvas,
  .viz-window canvas {
    contain: size;
  }

  .viz-window {
    grid-area: window;
    block-size: var(--viz-block);
    min-inline-size: 0;
    background: radial-gradient(70% 85% at 50% 115%, var(--window-glow), var(--window-glass) 75%);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-inset), 0 0 0 0.25rem var(--window-bezel);

    canvas {
      inline-size: 100%;
      block-size: 100%;
    }
  }

  .viz-legend {
    grid-area: legend;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-4);
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: var(--text-xs);
    color: var(--color-text-muted);
  }

  .legend-item {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);

    &::before {
      content: "";
      inline-size: 1rem;
      block-size: 0.625rem;
    }
  }

  .legend-pre::before {
    background: var(--viz-pre);
    opacity: 0.6;
  }

  .legend-post::before {
    block-size: 0;
    border-block-start: 2px solid var(--viz-post);
  }

  .legend-curve::before {
    block-size: 0;
    border-block-start: 3px solid var(--viz-curve);
  }

  .legend-mono::before {
    background: repeating-linear-gradient(135deg, var(--viz-mono) 0 1.5px, var(--transparent) 1.5px 4px);
    outline: 1px solid var(--viz-mono);
  }

  .legend-gen::before {
    inline-size: 0.5rem;
    block-size: 0.5rem;
    margin-inline: 0.25rem;
    background: var(--viz-sub);
    rotate: 45deg;
  }

  .viz-readout {
    grid-area: readout;
    font: 500 var(--text-xs) / 1.4 var(--font-mono);
    font-variant-numeric: tabular-nums;
    color: var(--color-text-muted);
    min-block-size: 1.05rem;
  }

  /* ── contour: one dominant Punch knob and its three satellites ── */
  .contour-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "hero" "row";
    justify-items: center;
    gap: var(--space-4);
    padding-block: var(--space-2);

    @container device (inline-size >= 44rem) and (inline-size < 64rem) {
      grid-template-columns: auto auto;
      grid-template-areas: "hero row";
      justify-content: center;
      align-items: center;
      column-gap: var(--space-7);
    }
  }

  /* the contour group sits in the middle of its (often taller) grid cell */
  .contour {
    grid-template-rows: auto minmax(0, 1fr);
    align-content: stretch;

    .contour-controls { align-content: center; }
  }

  .contour-row {
    grid-area: row;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-4) var(--space-3);
  }

  .hero {
    grid-area: hero;
    --knob-size: var(--hero-size);
    --knob-cap: var(--hero-cap);
    --knob-cap-edge: var(--hero-cap-edge);
    --knob-arc-width: 5;
    padding-block-start: var(--space-3);

    .knob-dial {
      position: relative;
      background: radial-gradient(closest-side, var(--hero-skirt) 0 90%, var(--transparent) 92%);
      box-shadow: 0 0.6rem 1.2rem var(--hero-shadow);

      /* engraved tick ring: 21 ticks over the 270° travel, gap at the bottom */
      &::before {
        content: "";
        position: absolute;
        inset: -0.75rem;
        border-radius: var(--radius-full);
        background: repeating-conic-gradient(from -135.4deg, var(--hero-tick) 0 0.8deg, var(--transparent) 0.8deg 13.5deg);
        mask:
          radial-gradient(closest-side, var(--transparent) 87%, currentColor 88%),
          conic-gradient(from 136deg, var(--transparent) 0 88deg, currentColor 88deg);
        mask-composite: intersect;
        pointer-events: none;
      }

      &:focus-visible { outline-offset: 0.9rem; }
    }

    .knob-label {
      font-size: var(--text-xs);
      color: var(--color-text);
    }

    .knob-value { font-size: var(--text-sm); }
  }

  /* ── backlit needle gauges ── */
  .gauges {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
  }

  .gauge {
    display: grid;
    gap: var(--space-1);
    min-inline-size: 0;
  }

  .gauge-face {
    aspect-ratio: 16 / 9;
    background: radial-gradient(90% 95% at 50% 95%, var(--gauge-face) 0 40%, var(--gauge-face-edge) 100%);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-inset), 0 0 0 0.1875rem var(--gauge-bezel);
    overflow: hidden;

    canvas {
      inline-size: 100%;
      block-size: 100%;
    }
  }

  .gauge-caption {
    display: grid;
    justify-items: center;
    text-align: center;
  }

  .gauge-title {
    font: 600 var(--text-2xs) / 1.3 var(--font-display);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-text-muted);
  }

  .gauge-readout {
    font: 500 var(--text-xs) / 1.3 var(--font-mono);
    font-variant-numeric: tabular-nums;
    color: var(--color-text);
  }

  /* ── knob rows in the two smaller sections ── */
  .psycho,
  .club {
    .controls {
      justify-content: space-around;
      column-gap: var(--space-1);
    }

    .knob { inline-size: 5.5rem; }
  }

  .character {
    display: grid;
    justify-items: center;
  }

  .character-scale {
    display: flex;
    justify-content: space-between;
    inline-size: 100%;
    font: 600 var(--text-2xs) / 1.2 var(--font-display);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-text-muted);
  }

  .switches {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-2) var(--space-3);
  }

  .page-foot {
    display: grid;
    gap: var(--space-2);
  }
}
