/* Tablet controls adapted from the native iPad simulator. */
/* Native iPad persistent slit-lamp joystick: the centre stick sets lateral
   and forward/back position; swiping around the outer rim raises or lowers
   the beam. Always visible in the corner, like the focus dial in laser mode,
   so it never disappears while the other hand is holding the lens. */
.touch-joystick-ui {
  display: none;
}

body.touchscreen .touch-joystick-ui {
  display: block;
  position: absolute;
  right: 12px;
  bottom: 14px;
  z-index: 46;
  color: var(--text);
}

body.touchscreen .touch-joystick-ui.is-os {
  right: auto;
  left: 12px;
}

.touch-joystick-card {
  padding: 8px 10px 10px;
  border-radius: 8px;
  background: var(--surface-1);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
}

.touch-joystick-card .info-row {
  justify-content: space-between;
  margin-bottom: 8px;
}

.touch-joystick-reset {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1;
  touch-action: manipulation;
}

.touch-joystick-reset:active {
  color: var(--text);
  border-color: var(--accent-strong);
}

.touch-joystick-pad-wrap {
  position: relative;
  width: 208px;
  height: 208px;
  margin: 0 auto;
}

.touch-joystick-rim {
  --elevation-angle: 0deg;
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid var(--line-soft);
  background: radial-gradient(circle, rgb(255 255 255 / 3%) 0 58%, rgb(0 0 0 / 24%) 78% 100%);
  box-shadow: inset 0 1px 8px rgb(0 0 0 / 35%);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.touch-joystick-rim-track {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  transform: rotate(var(--elevation-angle));
  pointer-events: none;
}

.touch-joystick-rim-index {
  position: absolute;
  top: 6px;
  left: 50%;
  width: 4px;
  height: 14px;
  margin-left: -2px;
  border-radius: 2px;
  background: #8fd7ff;
  box-shadow: 0 0 6px rgb(75 185 241 / 60%);
}

.touch-joystick-rim.is-dragging,
.touch-joystick-rim:focus-visible {
  border-color: #83d1ff;
  box-shadow: inset 0 1px 8px rgb(0 0 0 / 35%), 0 0 0 3px rgb(48 174 255 / 20%);
  outline: none;
}

.touch-joystick-rim-label {
  position: absolute;
  bottom: 12px;
  color: var(--text-dim);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  pointer-events: none;
}

.touch-joystick-rim-label.is-lower { left: 16px; }
.touch-joystick-rim-label.is-raise { right: 16px; }

.touch-joystick-pad {
  --joystick-x: 0;
  --joystick-depth: 0;
  --joystick-travel: 42px;
  position: absolute;
  top: 50%;
  left: 50%;
  width: 160px;
  height: 160px;
  margin: -80px 0 0 -80px;
  overflow: hidden;
  border-radius: 50%;
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at center, rgb(97 142 163 / 16%) 0 2px, transparent 3px),
    linear-gradient(var(--surface-2), var(--surface-1));
  box-shadow: inset 0 1px 10px rgb(0 0 0 / 40%);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.touch-joystick-crosshair::before,
.touch-joystick-crosshair::after {
  content: "";
  position: absolute;
  background: rgb(142 174 190 / 14%);
  pointer-events: none;
}

.touch-joystick-crosshair::before {
  top: 18px;
  bottom: 18px;
  left: 50%;
  width: 1px;
}

.touch-joystick-crosshair::after {
  top: 50%;
  right: 18px;
  left: 18px;
  height: 1px;
}

.touch-joystick-direction {
  position: absolute;
  left: 50%;
  z-index: 1;
  color: var(--text-dim);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transform: translateX(-50%);
  pointer-events: none;
}

.touch-joystick-direction.is-forward { top: 12px; }
.touch-joystick-direction.is-back { bottom: 12px; }

.touch-joystick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 48px;
  height: 48px;
  border: 2px solid #84959d;
  border-radius: 50%;
  background:
    radial-gradient(circle at 38% 34%, #66747a 0 8%, #3c474b 30%, #20282b 70%, #121719 100%);
  box-shadow:
    inset 0 3px 5px rgb(255 255 255 / 15%),
    inset 0 -8px 12px rgb(0 0 0 / 48%),
    0 0 0 4px rgb(0 0 0 / 22%),
    0 6px 12px rgb(0 0 0 / 45%);
  transform: translate(
    calc(-50% + var(--joystick-x) * var(--joystick-travel)),
    calc(-50% - var(--joystick-depth) * var(--joystick-travel))
  );
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.touch-joystick-knob::after {
  content: "";
  position: absolute;
  inset: 11px;
  border: 1px solid rgb(214 226 231 / 20%);
  border-radius: 50%;
}

.touch-joystick-knob.is-dragging {
  cursor: grabbing;
  border-color: #83d1ff;
  box-shadow:
    inset 0 3px 5px rgb(255 255 255 / 15%),
    inset 0 -8px 12px rgb(0 0 0 / 48%),
    0 0 0 4px rgb(72 180 236 / 18%),
    0 6px 12px rgb(0 0 0 / 45%);
}

/* iPad touch joystick: use the same light instrument-panel language as the
   sidebars, while retaining the mechanical finish of the illumination dials. */
.touch-joystick-launcher,
.touch-joystick-reset,
.touch-joystick-close {
  border: 1px solid #bbb8ae;
  background: #fff;
  color: #171715;
  box-shadow: 0 1px 2px rgb(0 0 0 / 12%);
}

.touch-joystick-launcher {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 13px;
  border-radius: 8px;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  touch-action: manipulation;
}

.touch-joystick-launcher-icon {
  width: 19px;
  height: 19px;
  border: 1px solid #53554f;
  border-radius: 50%;
  background:
    radial-gradient(circle at 39% 32%, #fff 0 5%, transparent 17%),
    radial-gradient(circle, #d8d5ca 0 13%, #8b8d86 15% 24%, #4f514d 26% 31%, transparent 33%),
    repeating-conic-gradient(from -2deg, #e1ded3 0deg 5deg, #777970 5deg 9deg, #b7b4a9 9deg 13deg);
  box-shadow: 0 2px 3px rgb(0 0 0 / 32%);
}

.touch-joystick-card {
  width: 230px;
  padding: 10px 10px 12px;
  border: 1px solid #c7c4ba;
  border-radius: 10px;
  background: #fff;
  color: #171715;
  box-shadow: 0 10px 30px rgb(0 0 0 / 24%);
}

.touch-joystick-card[hidden] { display: none; }
.touch-joystick-ui.is-open .touch-joystick-launcher { display: none; }

.touch-joystick-card .joystick-label,
.touch-joystick-card .info-pill { color: #171715; }

.touch-joystick-actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.touch-joystick-reset,
.touch-joystick-close {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 6px;
  font-size: 17px;
  line-height: 1;
  touch-action: manipulation;
}

.touch-joystick-pad-wrap {
  width: 208px;
  height: 208px;
  margin-bottom: 17px;
}

.touch-joystick-rim {
  z-index: 1;
  border: 2px solid #4f514d;
  background:
    radial-gradient(circle, transparent 0 61%, #a7a69f 62% 66%, #d9d6cc 67% 75%, #85877f 77% 86%, #c8c5ba 88% 100%);
  box-shadow:
    inset 0 0 0 2px rgb(255 255 255 / 54%),
    inset 0 -5px 8px rgb(0 0 0 / 20%),
    0 3px 7px rgb(0 0 0 / 30%);
}

.touch-joystick-rim.is-dragging {
  border-color: #55564f;
  background:
    radial-gradient(circle, transparent 0 61%, #d8d6ce 62% 66%, #f2efe5 67% 75%, #a8aaa1 77% 86%, #e8e4d9 88% 100%);
  box-shadow:
    inset 0 0 0 2px rgb(255 255 255 / 78%),
    inset 0 -3px 6px rgb(0 0 0 / 16%),
    0 0 0 3px rgb(0 0 0 / 8%),
    0 4px 9px rgb(0 0 0 / 28%);
}

.touch-joystick-rim-track { transform: rotate(var(--elevation-angle)); }

.touch-joystick-rim-index {
  top: 5px;
  width: 3px;
  height: 11px;
  background: #171715;
  box-shadow: none;
}

.touch-joystick-rotation-guide {
  position: absolute;
  inset: 5px;
  z-index: 4;
  width: calc(100% - 10px);
  height: calc(100% - 10px);
  fill: none;
  stroke: #292927;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.touch-joystick-rotation-guide .rotation-arrowhead {
  fill: #292927;
  stroke: none;
}

.touch-joystick-rim-label {
  z-index: 3;
  bottom: -16px;
  color: #292927;
}

.touch-joystick-rim-label.is-lower { left: 24px; }
.touch-joystick-rim-label.is-raise { right: 24px; }

.touch-joystick-pad {
  z-index: 2;
  --joystick-travel: 22px;
  width: 140px;
  height: 140px;
  margin: -70px 0 0 -70px;
  border: 2px solid #51534e;
  background:
    radial-gradient(circle at 39% 32%, rgb(255 255 255 / 90%) 0 5%, transparent 17%),
    repeating-conic-gradient(from -2deg, #e1ded3 0deg 5deg, #777970 5deg 9deg, #b7b4a9 9deg 13deg);
  box-shadow:
    inset 0 0 0 5px rgb(238 235 224 / 22%),
    inset 0 -10px 15px rgb(0 0 0 / 27%),
    0 2px 7px rgb(0 0 0 / 38%);
  transform: translate(
    calc(var(--joystick-x) * var(--joystick-travel)),
    calc(var(--joystick-depth) * var(--joystick-travel) * -1)
  );
  overflow: visible;
}

.touch-joystick-pad.is-dragging {
  background:
    radial-gradient(circle at 39% 32%, #fff 0 5%, transparent 17%),
    repeating-conic-gradient(from -2deg, #f1eee3 0deg 5deg, #83857c 5deg 9deg, #c7c4b8 9deg 13deg);
  box-shadow:
    inset 0 0 0 5px rgb(255 255 255 / 36%),
    inset 0 -8px 12px rgb(0 0 0 / 20%),
    0 0 0 3px rgb(255 255 255 / 50%),
    0 3px 8px rgb(0 0 0 / 34%);
}

.touch-joystick-crosshair::before,
.touch-joystick-crosshair::after { background: rgb(22 22 20 / 18%); }

.touch-joystick-direction { color: #242421; text-shadow: 0 1px rgb(255 255 255 / 55%); }

.touch-joystick-knob {
  inset: 0;
  width: auto;
  height: auto;
  border: 0;
  background: transparent;
  box-shadow: none;
  transform: none;
  z-index: 5;
}

.touch-joystick-knob::after {
  inset: 34%;
  border: 1px solid rgb(30 30 28 / 24%);
  box-shadow: inset 0 1px 2px rgb(255 255 255 / 45%);
}

.touch-joystick-knob.is-dragging {
  background: transparent;
  box-shadow: none;
}

@media (max-height: 760px) {
  body.touchscreen .touch-joystick-ui { bottom: 8px; }
  .touch-joystick-pad-wrap { width: 176px; height: 176px; }
  .touch-joystick-pad {
    width: 116px;
    height: 116px;
    margin: -58px 0 0 -58px;
    --joystick-travel: 19px;
  }
}


/* Control selection is a dialog, so focus and taps stay within the choice. */
.control-method-dialog {
  width: min(860px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  margin: auto;
  border: 0;
  border-radius: 26px;
  padding: 30px 24px 24px;
  background: #f5f5f4;
  color: #1b1e20;
  box-shadow: 0 24px 100px #0008;
}
.control-method-dialog::backdrop { background: rgb(0 0 0 / 62%); backdrop-filter: blur(5px); }
.control-method-dialog h2 { margin: 0 0 15px; text-align: center; font-size: clamp(22px, 3vw, 28px); font-weight: 600; }
.control-method-dialog p { margin: 0 0 18px; text-align: center; font-size: 23px; color: #6b6b6b; }
.control-method-options { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.control-method-option { position: relative; display: flex; align-items: center; flex-direction: column; gap: 18px; padding: 24px 12px; border: 2px solid transparent; border-radius: 24px; background: #fff; cursor: pointer; }
.control-method-option:has(input:checked) { border-color: #667f69; box-shadow: 0 0 0 1px #667f69; }
.control-method-option:has(input:focus-visible) { outline: 3px solid #213e60; outline-offset: 5px; }
.control-method-option input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.control-method-option svg { width: 48px; height: 48px; fill: #fff; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.control-method-option strong { font-size: 26px; font-weight: 600; }
.control-method-option span { font-size: 20px; color: #6b6b6b; }
.control-method-continue { display: block; width: 100%; min-height: 62px; margin: 18px 0 0; border: 0; border-radius: 999px; background: #191d20; color: white; font-size: 24px; cursor: pointer; }
.control-method-cancel { display: block; margin: 12px auto 0; border: 0; padding: 10px 20px; background: transparent; color: #464b47; font-size: 15px; cursor: pointer; }
.control-method-cancel[hidden] { display: none; }
.change-control-method { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; background: transparent; color: inherit; cursor: pointer; font-size: 11px; }
.change-control-method .control-method-current { font-weight: 700; }
.tablet-focus-slot, .tablet-help, .tutorial-touch-demo { display: none; }
.phone-preview .change-control-method { display: none; }

/* Keep tablet controls in the full simulator at every width. Canvas coordinates
   stay 880×550; only the displayed size changes, so touch maps consistently. */
body.touchscreen { --tablet-control-font: clamp(12px, calc(0.5vw + 6.88px), 14px); display: block; overflow: auto; overscroll-behavior: none; }
body.touchscreen .sim-root { width: 100%; max-width: none; height: 100dvh; padding: 8px; gap: 0; }
/* Keep the 1024px layout intact, then give each sidebar a quarter of the
   additional width while the examination receives the remaining half. */
body.touchscreen .app { display: grid; grid-template-columns: clamp(190px, calc(25vw - 66px), 320px) minmax(0, 1fr) clamp(222px, calc(25vw - 34px), 360px); gap: 8px; width: 100%; max-width: none; height: 100%; max-height: none; padding: 0; }
body.touchscreen .app.is-hidden { display: none; }
body.touchscreen .controls, body.touchscreen .slit-panel { width: auto; min-width: 0; height: 100%; max-height: none; padding: clamp(12px, calc(1vw + 1.76px), 16px); margin: 0; overflow: hidden; }
body.touchscreen .controls-scroll { min-height: 0; overflow-y: auto; gap: 8px; }
body.touchscreen .controls h1 { font-size: clamp(15px, calc(0.8vw + 6.808px), 18px); padding-bottom: 12px; }
body.touchscreen .controls h2, body.touchscreen .slit-panel h2 { font-size: var(--tablet-control-font); }
body.touchscreen .controls p, body.touchscreen .controls label { font-size: var(--tablet-control-font); }
body.touchscreen .controls .pill-btn, body.touchscreen .slit-panel .pill-btn { min-height: 44px; font-size: var(--tablet-control-font); }
body.touchscreen .slit-panel .lesson-title { font-size: var(--tablet-control-font); }
body.touchscreen .controls .fixation-toggle { --fixation-button-size: 44px; }
body.touchscreen .fixation-layout { flex-wrap: wrap; gap: 6px; }
body.touchscreen .fixation-shortcuts { display: none; }
body.touchscreen .select-control { min-height: 44px; font-size: var(--tablet-control-font); }
body.touchscreen .controls .slit-controls input[type=range] { min-height: 28px; background-size: 100% 6px; background-repeat: no-repeat; background-position: center; }
body.touchscreen .controls .slit-controls input[type=range]::-webkit-slider-thumb { width: 26px; height: 26px; }
body.touchscreen .canvas-wrapper { width: 100%; height: 100%; min-height: 0; display: flex; }
body.touchscreen .sim-view { --view-title-height: 28px; height: 100%; min-height: 0; padding: 28px 10px 12px; gap: 12px; flex-direction: column; justify-content: flex-start; }
body.touchscreen #simCanvas { flex: 0 0 auto; width: min(100%, calc((100dvh - 360px) * 1.6)); height: auto; max-width: 100%; aspect-ratio: 1.6; touch-action: none; user-select: none; -webkit-user-select: none; }
body.touchscreen .overview-cluster { flex: 1; width: 100%; min-height: 230px; margin: 0; justify-content: center; }
body.touchscreen .overview-shell { width: min(65%, 380px); min-width: 0; transition: width 260ms ease, transform 260ms ease; }
body.touchscreen #overviewCanvas { width: 100%; height: auto; aspect-ratio: 36 / 23; }
body.touchscreen .overview-label { font-size: 11px; line-height: 1.35; }
body.touchscreen .joystick-open .overview-shell { width: min(65%, calc(100% - 246px)); transform: translateX(-120px); }
body.touchscreen .joystick-open.joystick-on-left .overview-shell { transform: translateX(120px); }
body.touchscreen #joystickIndicator { display: none; }
body.touchscreen .touch-joystick-ui { display: block; position: absolute; top: var(--overview-center-y, 75%); bottom: auto; right: 10px; left: auto; width: 230px; transform: translateY(-50%); z-index: 20; }
body.touchscreen .touch-joystick-ui.is-os { right: auto; left: 10px; }
body.touchscreen .touch-joystick-ui:not(.is-open) { top: auto; bottom: 12px; width: auto; transform: none; }
body.touchscreen .touch-joystick-card { width: 230px; }
body.touchscreen .touch-joystick-card .info-row { min-height: 44px; }
body.touchscreen .touch-joystick-close, body.touchscreen .touch-joystick-reset { width: 44px; height: 44px; }
body.touchscreen .touch-joystick-launcher { min-height: 44px; }
body.touchscreen .touch-joystick-knob:focus-visible, body.touchscreen .touch-joystick-rim:focus-visible { outline: 3px solid #19609a; outline-offset: 3px; }
body.touchscreen .slit-panel .tablet-focus-slot { display: flex; flex-direction: column-reverse; gap: 4px; flex: 0 0 auto; padding: 12px 0; border-top: 1px solid var(--line); }
body.touchscreen .tablet-focus-slot > p { margin: 0; font-size: 11px; line-height: 1.4; color: var(--text-muted); }
body.touchscreen .focus-indicator { position: relative; right: auto; top: auto; transform: none; width: 100%; min-height: 0; padding: 0; border: 0; background: none; display: grid; grid-template-columns: 65px 1fr; grid-template-rows: auto 1fr; gap: 6px 12px; }
body.touchscreen .focus-indicator-label { grid-column: 2; grid-row: 1; font-size: 12px; }
body.touchscreen .focus-joystick { grid-column: 1; grid-row: 1 / 3; touch-action: none; user-select: none; height: 122px; }
body.touchscreen .focus-indicator-text { grid-column: 2; grid-row: 2; font-size: 12px; align-self: center; }
body.touchscreen .focus-indicator.is-adjusting { outline: 2px solid #43795b; outline-offset: 4px; border-radius: 4px; }
body.touchscreen .focus-indicator.is-hidden { display: none; }
body.touchscreen .slit-panel.is-tutorial-active .tablet-focus-slot { display: none; }
body.touchscreen .slit-panel .challenge-section { padding: 16px 0; }
body.touchscreen .slit-panel > .slit-controls.right-card { min-height: 0; flex: 1; order: 3; overflow-y: auto; }
body.touchscreen .slit-panel .tutorial-card { order: 1; min-height: 0; }
body.touchscreen .slit-panel > .panel-footer { order: 4; }
body.touchscreen .slit-panel.is-tutorial-active .tutorial-card { display: flex; flex: 1; }
body.touchscreen .tutorial-content { min-height: 0; overflow: auto; }
body.touchscreen .tutorial-btn, body.touchscreen .tutorial-close-btn { min-width: 44px; min-height: 44px; }
body.touchscreen .tablet-help { display: block; flex-shrink: 0; order: 3; margin-top: 12px; }
body.touchscreen .right-card > .feedback-launcher { order: 4; margin-top: 12px; }
.tablet-help-button { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 56px; padding: 12px 10px; border: 0; background: transparent; color: var(--text); font: inherit; font-size: var(--tablet-control-font); font-weight: 600; line-height: 1.4; text-align: left; cursor: pointer; }
.tablet-help-button + .tablet-help-button { border-top: 1px solid var(--line); }
.tablet-help-button:first-child { border-radius: 7px 7px 0 0; }
.tablet-help-button:last-child { border-radius: 0 0 7px 7px; }
.tablet-help-button:hover { background: #eaf0e9; }
.tablet-help-button:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }
.tablet-help-button > .panel-icon:first-child { color: var(--text-muted); flex-shrink: 0; }
.tablet-help-button .disclosure-chevron { margin-left: auto; width: 16px; height: 16px; flex-shrink: 0; color: var(--text-muted); }
.tablet-panel-dialog { width: min(560px, calc(100vw - 48px)); max-height: calc(100dvh - 48px); box-sizing: border-box; padding: 0 24px 24px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface-1); color: var(--text); box-shadow: 0 20px 70px #0004; overflow-y: auto; overscroll-behavior: contain; }
.tablet-panel-dialog::backdrop { background: #14241e88; }
.tablet-panel-heading { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 0 12px; background: var(--surface-1); z-index: 1; }
.tablet-panel-heading h2 { margin: 0; font-size: 22px; line-height: 1.3; }
.tablet-panel-close { flex: 0 0 44px; width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 50%; background: transparent; color: inherit; font-size: 26px; cursor: pointer; }
.tablet-panel-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tablet-panel-list { margin: 4px 0 0; padding-left: 22px; font-size: 16px; line-height: 1.5; }
.tablet-panel-list li + li { margin-top: 16px; }
.tablet-panel-list strong, .tablet-panel-list span { display: block; }
.tablet-panel-list span { margin-top: 4px; color: var(--text-muted); }
.tablet-panel-note { margin: 20px 0 0; font-size: 14px; color: var(--text-muted); }
.tablet-panel-dialog .upload-section h2 { display: none; }
.tablet-panel-dialog .upload-card { position: relative; display: flex; justify-content: center; align-items: center; gap: 12px; min-height: 72px; margin: 12px 0; padding: 12px; border: 1px dashed var(--accent); border-radius: 8px; font-size: 16px; cursor: pointer; }
.tablet-panel-dialog .upload-card:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.tablet-panel-dialog .upload-card input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.tablet-panel-dialog .upload-note { font-size: 14px; line-height: 1.5; color: var(--text-muted); }
body.touchscreen .desktop-help, body.touchscreen .fullscreen-tip, body.touchscreen #layoutBanner { display: none !important; }
body.touchscreen .tutorial-input-demo.is-touch-demo .tutorial-key-cluster { display: none; }
body.touchscreen .tutorial-touch-demo { display: flex; align-items: start; justify-content: space-around; gap: 10px; width: 100%; }
.tutorial-touch-demo > div { flex: 1; text-align: center; font-size: 11px; line-height: 1.4; }
.tutorial-touch-demo > div > span:last-child { display: block; margin-top: 10px; }
.touch-demo-lens, .touch-demo-joystick { display: block; position: relative; width: 42px; height: 42px; border-radius: 50%; margin: 15px auto; }
.touch-demo-lens { border: 3px solid #be9a48; background: #d0e4dd; transform: translate(var(--demo-lens-x, 0), var(--demo-lens-y, 0)); }
.touch-demo-lens i { position: absolute; width: 14px; height: 22px; border: 1px solid #527d90; border-radius: 8px; background: #acc8d5; left: 11px; }
.touch-demo-lens i:first-child { top: -17px; }
.touch-demo-lens i:last-child { bottom: -17px; }
.touch-demo-joystick { border: 5px solid #9a9b93; background: #deded7; }
.touch-demo-joystick i { position: absolute; inset: 6px; border-radius: 50%; background: #454b47; transform: translate(var(--demo-joystick-x, 0), var(--demo-joystick-y, 0)); }
body.touchscreen .phone-gesture-coach.is-active { display: block; position: absolute; pointer-events: none; z-index: 10; }
body.touchscreen .phone-focus-coach { display: none; }
body.touchscreen .phone-lens-label { display: block; position: absolute; left: 50%; top: 7%; transform: translateX(-50%); width: max-content; max-width: 90%; padding: 8px 12px; border-radius: 8px; background: #07131bd9; color: #d9f1ff; text-align: center; font-size: 12px; }
body.touchscreen .phone-lens-target { position: absolute; display: block; left: var(--lens-x); width: 40px; height: 40px; border: 2px solid #8bd8ff; border-radius: 50%; background: #2ca9ed33; transform: translate(-50%, -50%); }
body.touchscreen .phone-lens-target.is-top { top: var(--lens-top); }
body.touchscreen .phone-lens-target.is-bottom { top: var(--lens-bottom); }
body.touchscreen .is-lens-complete .phone-lens-target, body.touchscreen .is-lens-complete .phone-lens-label { opacity: 0; transition: opacity 400ms ease; }
body.touchscreen .sim-view.challenge-mode .overview-cluster { display: flex; visibility: hidden; }

/* Compact fallback underneath the portrait rotation prompt, and for small
   landscape viewports. Tablet use resumes only in landscape. */
@media (max-width: 1000px) and (orientation: portrait), (max-width: 800px) {
  body.touchscreen .sim-root { height: auto; min-height: 100dvh; }
  body.touchscreen .app { grid-template-columns: minmax(0, 1fr) 210px; grid-template-rows: auto auto; height: auto; }
  body.touchscreen .canvas-wrapper { grid-column: 1; grid-row: 1; height: auto; min-height: max(710px, calc(100dvh - 16px)); }
  body.touchscreen .slit-panel { grid-column: 2; grid-row: 1; height: calc(100dvh - 16px); position: sticky; top: 8px; }
  body.touchscreen .controls { grid-column: 1 / -1; grid-row: 2; height: auto; max-height: none; }
  body.touchscreen .controls-scroll { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: visible; }
  body.touchscreen .controls h1 { grid-column: 1 / -1; }
  body.touchscreen .sim-view { padding: 28px 8px 12px; height: auto; }
  body.touchscreen #simCanvas { width: 100%; }
  body.touchscreen .overview-cluster { flex: 0 0 auto; min-height: 0; justify-content: flex-start; padding-top: 18px; }
  body.touchscreen .joystick-open .overview-shell,
  body.touchscreen .joystick-open.joystick-on-left .overview-shell { width: min(85%, 360px); transform: none; }
  body.touchscreen .touch-joystick-ui.is-open { position: relative; align-self: flex-end; flex-shrink: 0; margin-top: auto; top: auto; bottom: auto; left: auto; right: auto; transform: none; }
  body.touchscreen .touch-joystick-ui.is-open.is-os { align-self: flex-start; }
}
@media (max-width: 540px) {
  body.touchscreen .app { grid-template-columns: 1fr; grid-template-rows: 690px auto auto; }
  body.touchscreen .slit-panel { grid-column: 1; grid-row: 2; position: static; min-height: 500px; max-height: 80dvh; }
  body.touchscreen .controls { grid-row: 3; }
  .control-method-dialog { padding: 24px 16px; }
  .control-method-dialog p { font-size: 18px; }
  .control-method-option { gap: 12px; padding: 20px 8px; }
  .control-method-option strong { font-size: 20px; }
  .control-method-option span { font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  body.touchscreen .overview-shell, body.touchscreen .phone-lens-target, body.touchscreen .phone-lens-label { transition: none; }
}

body.touchscreen .touch-joystick-ui:not(.is-open) .touch-joystick-card { display: none; }
body.touchscreen .touch-joystick-ui.is-open .touch-joystick-card { display: block; }

body.touchscreen :is(#simCanvas, .touch-joystick-knob, .touch-joystick-rim, .focus-joystick) { -webkit-touch-callout: none; }

.control-method-option small { padding: 5px 10px; border-radius: 999px; background: #edf1ec; color: #465b48; font-size: 13px; font-weight: 600; }
.tablet-orientation-dialog { width: min(440px, calc(100vw - 40px)); max-height: calc(100dvh - 40px); overflow: auto; margin: auto; padding: 32px; border: 1px solid #d5ddd3; border-radius: 24px; background: #f5f5f1; color: #232923; text-align: center; box-shadow: 0 24px 80px #0006; }
.tablet-orientation-dialog::backdrop { background: #0b100ef2; }
.tablet-orientation-dialog svg { display: block; width: 96px; height: 78px; margin: 0 auto 18px; fill: none; stroke: #526d58; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.tablet-orientation-dialog h2 { margin: 0 0 16px; font-size: 26px; line-height: 1.2; }
.tablet-orientation-dialog p { margin: 0 0 14px; font-size: 17px; line-height: 1.5; }
.tablet-orientation-dialog .tablet-rotation-help { color: #63705f; font-size: 14px; }
.tablet-orientation-dialog button { min-height: 44px; margin-top: 8px; padding: 10px 18px; border: 1px solid #a3b09d; border-radius: 8px; background: transparent; color: inherit; font: inherit; cursor: pointer; }
.tablet-orientation-dialog button:focus-visible { outline: 3px solid #213e60; outline-offset: 4px; }
