/*
 * Quartet synth window: layout only. Colours, panel, knobs and LEDs come from the
 * shared analog look (../analog.css) and the app's role tokens, so it follows every
 * skin and theme. 15px text floor, 44px touch targets on touch screens, no sideways
 * page scroll. Compatibility: no @layer, color-mix(), oklch(), :has(), container
 * queries or nesting (Chrome 95 / Safari 14).
 */

.qrt-window {
  position: fixed;
  top: 8px;
  left: 50%;
  z-index: 150;
  display: flex;
  flex-direction: column;
  width: 1080px;
  width: min(1080px, calc(100vw - 16px));
  max-height: calc(100vh - 16px);
  transform: translateX(-50%);
  background: var(--surface-1, #242538);
  color: var(--text-primary, #f6f8fc);
  border-radius: var(--r-xl, 16px);
  font-size: 15px;
  line-height: 1.25;
  overflow: hidden;
}

.qrt-window[hidden] {
  display: none !important;
}

.qrt-window:focus {
  outline: none;
}

.qrt-window *,
.qrt-window *::before,
.qrt-window *::after {
  box-sizing: border-box;
}

.qrt-titlebar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  padding: 8px 10px 8px 14px;
}

.qrt-brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex: 1 1 220px;
  min-width: 0;
}

.qrt-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary, #a6aac0);
  font-weight: 600;
}

.qrt-btn,
.qrt-select {
  font: inherit;
  font-size: 15px;
  color: var(--text-primary, #f6f8fc);
  background-color: var(--surface-3, #353a51);
  border-radius: 6px;
  min-height: 34px;
}

.qrt-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 12px;
  cursor: pointer;
}

.qrt-close {
  width: 34px;
  padding: 0;
}

.qrt-select {
  min-width: 0;
  max-width: 100%;
  padding: 0 8px;
}

.qrt-preset {
  min-width: 180px;
}

.qrt-status {
  padding: 0 14px;
  color: var(--text-secondary, #a6aac0);
}

.qrt-status:not(:empty) {
  padding: 6px 14px;
}

/* The panel: four columns of sections, the master strip across the bottom. */
.qrt-body {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.qrt-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 0 10px 10px;
  transition: opacity 120ms ease-out;
}

.qrt-card.is-off > :not(.qrt-card-head) {
  opacity: 0.4;
}

.qrt-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 36px;
}

.qrt-card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
}

.qrt-led-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 0 8px;
  border-radius: 5px;
  font: inherit;
  font-size: 15px;
  color: #f2efe6;
  cursor: pointer;
}

.qrt-led {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.qrt-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.qrt-label {
  flex: none;
  width: 58px;
  color: var(--an-ink-dim, var(--text-secondary));
}

.qrt-row .qrt-select {
  flex: 1 1 auto;
}

.qrt-knobs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 2px;
}

.qrt-knob {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.qrt-dial {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  cursor: ns-resize;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.qrt-dial svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.qrt-knob-label,
.qrt-knob-value {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  font-size: 15px;
}

.qrt-knob-value {
  font-variant-numeric: tabular-nums;
}

.qrt-knob-label,
.qrt-knob-value {
  line-height: 1.12;
}

/* Centre display row (lcd.js / analog.css) across the top of the panel, a little
   shorter here so every section fits above the keyboard on a 900px-tall screen. */
.qrt-main {
  grid-column: 1 / -1;
  min-width: 0;
  padding: 0 0 4px;
}

.qrt-main .an-lcd {
  padding: 7px 16px 6px;
  gap: 3px;
}

.qrt-main .an-lcd-name {
  font-size: 22px;
}

.qrt-main .an-lcd-vis {
  height: 44px;
}

.qrt-main .an-vu {
  height: 68px;
}

.qrt-main .an-wing {
  gap: 2px;
}

.qrt-root {
  margin-left: auto;
  flex: 0 1 220px;
}

.qrt-root .qrt-label {
  width: auto;
  white-space: nowrap;
}

/* Section screens */
.qrt-wave {
  height: 36px;
}

.qrt-curve,
.qrt-env,
.qrt-lfo {
  height: 44px;
}

/* Preset stepping in the title bar */
.qrt-presetbar {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.qrt-step {
  width: 34px;
  padding: 0;
}

/* Dock: the master section and the keyboard, always in view under the panel. */
.qrt-dock {
  display: flex;
  gap: 10px;
  align-items: stretch;
  padding: 8px 12px 10px;
  border-top: 2px solid rgba(0, 0, 0, 0.7);
  /* A dark keybed in every look, with light print on it */
  background: linear-gradient(180deg, #202124, #121214);
  --an-ink: #f0eadd;
  --an-ink-dim: #c9c3b5;
  --text-primary: #f0eadd;
  --text-secondary: #c9c3b5;
  --surface-3: #34363b;
}

.qrt-dock .qrt-master {
  flex: 0 0 auto;
  width: 190px;
  gap: 6px;
}

.qrt-master-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.qrt-master-row .qrt-knobs {
  grid-template-columns: repeat(2, 66px);
}

/* Keyboard */
.qrt-kb {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.qrt-kb-bar {
  display: flex;
  align-items: center;
  gap: 6px;
}

.qrt-oct {
  flex: none;
  width: 34px;
  padding: 0;
}

.qrt-head-select {
  flex: 0 1 160px;
  min-width: 0;
  min-height: 28px;
}

.qrt-oct-label {
  min-width: 70px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--an-ink-dim, var(--text-secondary));
}

.qrt-keys {
  --qrt-bk: 4.2%;
  --whites: 15;
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-height: 80px;
  padding: 0 2px 2px;
  border-radius: 4px;
  background: #0a0a0b;
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.85);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.qrt-key-w {
  position: relative;
  flex: 1 1 0;
  margin: 0 1px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 4px;
  border-radius: 0 0 5px 5px;
  background: linear-gradient(180deg, #d9d2bf 0%, #fbf8ef 8%, #f2ede0 86%, #d4ccb8 100%);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.08), 0 1px 1px rgba(0, 0, 0, 0.6);
  color: #4a4438;
  cursor: pointer;
}

.qrt-key-lbl {
  font-size: 15px;
  font-weight: 700;
}

.qrt-key-b {
  position: absolute;
  top: 0;
  left: calc(var(--wi) * 100% / var(--whites) - var(--qrt-bk) / 2);
  z-index: 2;
  width: var(--qrt-bk);
  height: 60%;
  border-radius: 0 0 4px 4px;
  background: linear-gradient(180deg, #2c2c2f, #0b0b0c 78%, #26262a);
  box-shadow: inset 0 -4px 0 rgba(255, 255, 255, 0.07), 0 3px 4px rgba(0, 0, 0, 0.6);
  cursor: pointer;
}

.qrt-key-w.down {
  background: linear-gradient(180deg, #cfc6ae 0%, #e9e2cf 60%, #d6cdb5 100%);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.35);
}

.qrt-key-b.down {
  background: linear-gradient(180deg, #1a1a1c, #050506);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.8);
}

.qrt-key.down::after {
  content: "";
  position: absolute;
  left: 30%;
  right: 30%;
  bottom: 8px;
  height: 3px;
  border-radius: 2px;
  background: var(--an-ring, #ff8a4c);
  box-shadow: 0 0 6px var(--an-ring, #ff8a4c);
}

@media (pointer: coarse), (hover: none) {
  .qrt-btn,
  .qrt-select,
  .qrt-led-btn {
    min-height: 44px;
  }

  .qrt-close,
  .qrt-step,
  .qrt-oct {
    width: 44px;
  }
}

@media (max-width: 1000px) {
  .qrt-body {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

}

@media (max-width: 860px) {
  .qrt-dock {
    flex-direction: column;
  }

  .qrt-dock .qrt-master {
    width: auto;
  }

  .qrt-oct2 {
    display: none !important;
  }

  .qrt-keys {
    --qrt-bk: 8.4%;
    --whites: 7;
  }
}

/* Phones and short landscapes: the window fills the screen, one section per row. */
@media (max-width: 760px), (max-width: 900px) and (max-height: 520px) {
  .qrt-window {
    top: 0;
    left: 0;
    width: 100%;
    max-height: 100%;
    height: 100%;
    transform: none;
    border-radius: 0;
  }

  .qrt-body {
    grid-template-columns: minmax(0, 1fr);
    flex: 1 1 auto;
  }

  .qrt-preset {
    flex: 1 1 auto;
    min-width: 0;
  }

  .qrt-presetbar {
    flex: 1 1 100%;
  }

}

@media (max-width: 760px) and (min-width: 520px), (max-width: 900px) and (max-height: 520px) and (min-width: 520px) {
  .qrt-body {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* The Synth button's menu: each synth with what kind it is. */
.synth-choice-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  text-align: left;
}

.synth-choice-text small {
  font-size: 15px;
  color: var(--text-secondary, #a6aac0);
}

.synth-menu .ctx-btn {
  min-height: 56px;
}

/* Touch tablets: two columns, so every switch and knob keeps a full-size target. */
@media (pointer: coarse) and (max-width: 1366px), (hover: none) and (max-width: 1366px) {
  .qrt-body {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .an-sw {
    min-width: 44px;
  }

  .qrt-head-select {
    min-height: 44px;
  }
}

@media (max-width: 760px), (max-width: 900px) and (max-height: 520px) {
  .qrt-body {
    grid-template-columns: minmax(0, 1fr);
  }

  .qrt-master {
    width: auto;
  }
}
