/* Touch receiver: the instrument fits the viewport; panels scroll internally. */
.mobile-motion,
.mobile-help {
  display: none;
}
@media (pointer: coarse),
  (max-width: 600px),
  (max-width: 950px) and (max-height: 500px) {
  html,
  body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }
  body {
    min-height: 0;
    padding: max(8px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
    height: 100dvh;
  }
  .stage {
    width: min(900px, 100%);
    height: 100%;
    max-height: 660px;
    min-height: 0;
    position: relative;
  }
  .radio {
    height: 100%;
    min-height: 0;
    padding: 12px;
    border-radius: 24px;
    display: grid;
    grid-template-rows: auto minmax(160px, 1fr) auto auto auto;
    align-content: start;
    gap: 8px;
    overflow: hidden;
  }
  .radio > header {
    margin: 0;
    gap: 4px;
    flex-direction: row;
    align-items: center;
  }
  .brand {
    font-size: 21px;
    letter-spacing: 0.25em;
  }
  .edition {
    font-size: 8px;
    letter-spacing: 0.13em;
  }
  .radio .double-dial {
    height: 100%;
    min-height: 0;
    padding: 0 15px;
    border-radius: 14px;
  }
  .radio .track {
    inset: 0 7px;
  }
  .radio .loaded-idea {
    top: 22px;
    font-size: 11px;
    line-height: 1.2;
    padding: 0;
    white-space: nowrap;
    display: block;
    text-overflow: ellipsis;
  }
  .radio .upper .graduations {
    top: auto;
    bottom: 24px;
    height: 14px;
  }
  .radio .upper .scale-tick.major-tick {
    height: 14px;
  }
  .radio .upper .printed-numbers {
    top: auto;
    bottom: 6px;
    height: 11px;
  }
  .radio .lower-scale .graduations {
    top: 16%;
  }
  .radio .lower-scale .printed-numbers {
    top: calc(16% + 25px);
  }
  .radio .scale-row .graduations {
    height: 18px;
  }
  .radio .scale-tick.major-tick {
    height: 18px;
  }
  .radio .scale-tick.middle-tick {
    height: 12px;
  }
  .radio .scale-tick.minor-tick {
    height: 7px;
  }
  .radio .printed-numbers {
    font-size: 9px;
  }
  .radio .printed-numbers span:nth-child(even) {
    visibility: hidden;
  }
  .radio .scale-heading {
    font-size: 8px;
    line-height: 10px;
  }
  .radio .upper .scale-heading {
    top: 7px;
  }
  .radio .lower-scale .scale-heading {
    bottom: 7px;
  }
  .radio .needle-down {
    bottom: 5px;
  }
  .radio .needle-up {
    top: 5px;
  }
  .mobile-motion {
    display: flex;
    gap: 8px;
    align-items: center;
    min-width: 0;
  }
  .mobile-motion .night-switch {
    margin: 0;
    padding: 8px;
    min-height: 34px;
    font-size: 9px;
    flex-shrink: 0;
  }
  .mobile-motion .night-switch::before {
    display: none;
  }
  #tilt-toggle[aria-pressed="true"] {
    border-color: #ac703d;
    background: #ddae72;
    color: #392a19;
    box-shadow:
      inset 0 1px 3px #8d582b33,
      0 0 8px #df9b4433;
  }
  #tilt-status {
    font:
      9px/1.3 Arial,
      sans-serif;
    color: #806c4f;
  }
  .radio .lower {
    padding: 0;
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;
  }
  .radio .speaker {
    height: 28px;
  }
  .radio .controls {
    width: 100%;
    grid-column: 1;
  }
  .radio .controls .knob-wrap {
    grid-template-rows: auto 14px;
    gap: 2px;
    min-width: 0;
  }
  .radio .rotary-unit {
    width: min(calc(100% - 12px), 110px);
    height: auto;
    aspect-ratio: 1;
  }
  .radio .controls .knob {
    width: 63%;
    height: 63%;
  }
  .radio .controls .label {
    font-size: 9px;
    line-height: 14px;
  }
  .radio-bottom-row {
    margin: 0;
    padding-top: 8px;
    gap: 6px;
  }
  .power-reception {
    width: 100%;
    justify-content: space-between;
    gap: 5px;
  }
  .power-reception > .power {
    flex: 0 1 66px;
    height: 34px;
  }
  .power-reception .library-key {
    min-width: 64px;
    height: 34px;
  }
  .power-reception .night-switch {
    font-size: 8px;
    padding: 8px 6px;
    min-height: 34px;
  }
  .power-reception .night-switch::before {
    width: 4px;
    height: 4px;
    margin-right: 4px;
  }
  .radio-bottom-row .site-note {
    flex-basis: 100%;
    gap: 2px 10px;
    font-size: 8px;
    line-height: 1.4;
  }
  .explore-mode {
    position: absolute;
    bottom: 0;
    margin: 0;
  }
  .mobile-help {
    display: block;
    font:
      13px/1.6 Arial,
      sans-serif;
  }
  #help-dialog .help-grid,
  #help-dialog .help-notes {
    display: none;
  }
  #help-dialog,
  #library {
    max-height: calc(100dvh - 24px);
    overflow: auto;
    overscroll-behavior: contain;
  }
}
@media (pointer: coarse) and (max-height: 600px) and (orientation: portrait),
  (max-width: 600px) and (max-height: 600px) and (orientation: portrait),
  (max-width: 950px) and (max-height: 500px) and (max-height: 600px) and (orientation: portrait) {
  .radio {
    padding: 10px;
    gap: 6px;
  }
  .radio .rotary-unit {
    max-width: 86px;
  }
  .radio .speaker {
    height: 14px;
  }
  .brand {
    font-size: 17px;
  }
}
@media (pointer: coarse) and (orientation: landscape) and (max-height: 600px),
  (max-width: 600px) and (orientation: landscape) and (max-height: 600px),
  (max-width: 950px) and (max-height: 500px) and (orientation: landscape) and (max-height: 600px) {
  .radio {
    padding: 10px 14px;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto minmax(110px, 1fr) auto auto;
    gap: 7px 16px;
  }
  .radio > header {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
  }
  .radio .double-dial {
    grid-column: 1;
    grid-row: 2 / 4;
  }
  .radio .lower {
    grid-column: 2;
    grid-row: 2;
    align-self: center;
  }
  .radio .rotary-unit {
    max-width: 96px;
  }
  .mobile-motion {
    grid-column: 2;
    grid-row: 3;
  }
  .radio-bottom-row {
    grid-column: 1 / -1;
    grid-row: 4;
  }
  .power-reception {
    width: auto;
    gap: 8px;
  }
  .radio-bottom-row .site-note {
    flex-basis: auto;
    max-width: 45%;
  }
}

/* The same field-note card, illustrated for phone gestures. */
.mobile-help-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 16px;
}
.mobile-help-card {
  border-top: 1px solid #b9a98e55;
  padding-top: 7px;
}
.mobile-help-card h3 {
  margin: 0 0 4px;
  font:
    500 12px Arial,
    sans-serif;
  color: inherit;
}
.mobile-help-card p {
  margin: 0;
  font:
    11px/1.45 Arial,
    sans-serif;
}
.mobile-demo {
  height: 56px;
  display: grid;
  place-items: center;
  color: #947952;
  perspective: 160px;
}
.mobile-demo svg {
  width: 80px;
  height: 56px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
}
.mobile-demo .phone-shape {
  transform-origin: 40px 28px;
}
.mobile-demo.sideways svg {
  animation: phone-y 4s ease-in-out infinite;
}
.mobile-demo.forwards svg {
  animation: phone-forwards 4s ease-in-out infinite;
}
.mobile-demo.centre .phone-shape {
  animation: phone-centre 4s ease-in-out infinite;
}
.mobile-demo .touch-needle {
  transform-origin: 40px 28px;
  animation: phone-sideways 4s ease-in-out infinite;
}
.demo-key {
  border: 1px solid #b7a484;
  border-radius: 7px;
  padding: 6px 9px;
  font:
    9px Arial,
    sans-serif;
  letter-spacing: 0.1em;
}
.mobile-help-footnote {
  margin: 10px 0 0;
  font:
    10px/1.45 Arial,
    sans-serif;
}
@keyframes phone-sideways {
  0%,
  50%,
  100% {
    transform: rotate(0deg);
  }
  25% {
    transform: rotate(-18deg);
  }
  75% {
    transform: rotate(18deg);
  }
}
@keyframes phone-forwards {
  0%,
  50%,
  100% {
    transform: rotateX(0deg);
  }
  25% {
    transform: rotateX(35deg);
  }
  75% {
    transform: rotateX(-35deg);
  }
}
@keyframes phone-centre {
  0% {
    transform: rotate(-15deg);
  }
  30%,
  85% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(-15deg);
  }
}
@media (pointer: coarse),
  (max-width: 600px),
  (max-width: 950px) and (max-height: 500px) {
  #help-dialog .help-intro {
    display: none;
  }
  #help-dialog .help-shell {
    padding: 15px;
  }
  #help-dialog .help-header {
    margin-bottom: 12px;
  }
  #help-dialog .help-header h2 {
    font-size: 22px;
  }
}
@media (pointer: coarse) and (orientation: landscape),
  (max-width: 600px) and (orientation: landscape),
  (max-width: 950px) and (max-height: 500px) and (orientation: landscape) {
  .mobile-help-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .mobile-demo {
    height: 42px;
  }
  .mobile-demo svg {
    height: 42px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .mobile-demo * {
    animation: none !important;
  }
}

/* Shared control geometry: complete rows instead of accidental wrapping. */
@media (pointer: coarse),
  (max-width: 600px),
  (max-width: 950px) and (max-height: 500px) {
  .radio .power-reception {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: 100%;
    min-width: 0;
    gap: 8px;
  }
  .radio .power-reception > button {
    width: 100%;
    min-width: 0;
    height: 44px;
    min-height: 44px;
    margin: 0;
    font-size: 9px;
    letter-spacing: 0.08em;
    white-space: nowrap;
  }
  .radio .power-reception .night-switch {
    border-radius: 9px;
    padding: 6px;
  }
  .radio .power-reception .library-key span {
    padding: 0 4px;
    font-size: 9px;
    letter-spacing: 0.08em;
  }
  .radio .power-reception .power-word {
    font-size: 9px;
    letter-spacing: 0.08em;
  }
  .radio-bottom-row .site-note {
    max-width: none;
    width: 100%;
    justify-content: center;
    text-align: center;
  }
}
@media (max-width: 480px) {
  .radio .power-reception {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .radio .power-reception > button,
  .radio .power-reception .library-key span,
  .radio .power-reception .power-word {
    font-size: 10px;
  }
}
@media (pointer: coarse) and (max-height: 600px) and (orientation: portrait),
  (max-width: 600px) and (max-height: 600px) and (orientation: portrait),
  (max-width: 950px) and (max-height: 500px) and (max-height: 600px) and (orientation: portrait) {
  .radio {
    gap: 5px;
  }
  .radio .rotary-unit {
    max-width: 78px;
  }
  .radio .speaker {
    height: 14px;
  }
  .radio .edition {
    font-size: 7px;
  }
}

/* Keep the instrument designation opposite the brand at every width. */
.radio > header {
  flex-direction: row;
  align-items: center;
  min-width: 0;
}
.radio > header .edition {
  margin-left: auto;
  text-align: right;
  justify-content: flex-end;
  min-width: 0;
  text-wrap: balance;
}
@media (max-width: 480px) {
  .radio > header {
    gap: 10px;
  }
  .radio > header .brand {
    font-size: clamp(16px, 4.8vw, 21px);
    letter-spacing: 0.2em;
  }
  .radio > header .edition {
    font-size: 7px;
    letter-spacing: 0.08em;
    white-space: nowrap;
  }
}

#tilt-centre:disabled {
  opacity: 0.45;
  cursor: default;
}

/* On phones the handset is the enclosure, including its safe-area edges. */
@media (pointer: coarse),
  (max-width: 600px),
  (max-width: 950px) and (max-height: 500px) {
  body,
  body.night-mode {
    padding: 0;
    background: #eee8dc;
  }
  body.night-mode {
    background: #b8aa8e;
  }
  .stage {
    width: 100%;
    height: 100dvh;
    max-height: none;
  }
  .stage .radio {
    width: 100%;
    height: 100%;
    max-height: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: max(12px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(12px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }
}

@keyframes phone-y {
  0%,
  50%,
  100% {
    transform: perspective(180px) rotateY(0deg);
  }
  25% {
    transform: perspective(180px) rotateY(-30deg);
  }
  75% {
    transform: perspective(180px) rotateY(30deg);
  }
}
@media (pointer: coarse),
  (max-width: 600px),
  (max-width: 950px) and (max-height: 500px) {
  #tilt-centre:disabled {
    display: none;
  }
  .scale-row .spectrum {
    touch-action: none;
  }
}
.scale-drag .drag-finger {
  animation: scale-finger 4s ease-in-out infinite;
}
@keyframes scale-finger {
  0%,
  50%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-15px);
  }
  75% {
    transform: translateX(15px);
  }
}
@media (prefers-reduced-motion: reduce) {
  .scale-drag .drag-finger {
    animation: none;
  }
}

/* Fit the desktop instrument, while dialogs keep their own scrollable panels. */
@media (pointer: fine) and (min-width: 951px),
  (pointer: fine) and (min-width: 601px) and (min-height: 501px) {
  body:has(.stage) {
    height: 100dvh;
    min-height: 0;
    padding: 16px;
    overflow: hidden;
  }
  .stage {
    width: min(1220px, 100%);
  }
  .stage .radio {
    transform-origin: top center;
  }
}
.gesture.scale-drag {
  fill: none;
  stroke: #88785f;
  stroke-width: 1.4;
}
