/* Anatomical iPad overlay — restrained, exhibition-friendly controls */

:root {
  --ipad-joy-size: 60px;
  --ipad-joy-inset: 24px;
  --ipad-ctrl-z: 40;
  --ipad-overlay-z: 50;
  --ipad-panel-bg: rgba(18, 22, 28, 0.78);
  --ipad-panel-border: rgba(255, 255, 255, 0.18);
  --ipad-text: #f2f4f6;
  --ipad-muted: rgba(242, 244, 246, 0.72);
  --ipad-accent: #c8d4de;
  --ipad-danger: #e8b4b4;
  --ipad-ok: #b6d7b9;
}

html.anatomical-ipad,
html.anatomical-ipad body {
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  background: #000;
}

#ipad-ui-root {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: var(--ipad-ctrl-z);
  font-family: "Franklin Gothic Book", "Segoe UI", "Helvetica Neue", sans-serif;
  color: var(--ipad-text);
}

#ipad-ui-root * {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

#ipad-ui-root button,
#ipad-ui-root .ipad-joystick,
#ipad-ui-root .ipad-panel,
#ipad-ui-root a {
  pointer-events: auto;
}

/* —— Joysticks —— */
.ipad-joystick {
  position: fixed;
  width: var(--ipad-joy-size);
  height: var(--ipad-joy-size);
  bottom: calc(var(--ipad-joy-inset) + env(safe-area-inset-bottom, 0px));
  border-radius: 50%;
  background: rgba(20, 24, 30, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.28);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  touch-action: none;
  z-index: var(--ipad-ctrl-z);
}

.ipad-joystick--move {
  left: calc(var(--ipad-joy-inset) + env(safe-area-inset-left, 0px));
}

.ipad-joystick--look {
  right: calc(var(--ipad-joy-inset) + env(safe-area-inset-right, 0px));
}

.ipad-joystick__thumb {
  position: absolute;
  width: 42%;
  height: 42%;
  left: 50%;
  top: 50%;
  border-radius: 50%;
  background: rgba(235, 240, 245, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.35);
  transform: translate(-50%, -50%);
  will-change: transform;
  pointer-events: none;
}

.ipad-joystick__label {
  position: absolute;
  left: 50%;
  top: -16px;
  transform: translateX(-50%);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
  pointer-events: none;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

/* —— Top chrome —— */
.ipad-topbar {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
  left: calc(12px + env(safe-area-inset-left, 0px));
  display: flex;
  justify-content: flex-end;
  align-items: flex-start;
  gap: 8px;
  z-index: var(--ipad-ctrl-z);
  pointer-events: none;
}

.ipad-topbar > * {
  pointer-events: auto;
}

.ipad-icon-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(18, 22, 28, 0.55);
  color: var(--ipad-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
}

.ipad-icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ipad-icon-btn:active {
  background: rgba(18, 22, 28, 0.8);
}

.ipad-status-chip {
  align-self: center;
  max-width: min(52vw, 280px);
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(18, 22, 28, 0.55);
  font-size: 11px;
  color: var(--ipad-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: auto;
}

.ipad-status-chip[data-tone="ok"] {
  color: var(--ipad-ok);
}

.ipad-status-chip[data-tone="warn"] {
  color: #e6d5a8;
}

.ipad-status-chip[data-tone="err"] {
  color: var(--ipad-danger);
}

.ipad-status-chip[hidden] {
  display: none !important;
}

/* —— Panels / overlays —— */
.ipad-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: var(--ipad-overlay-z);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + env(safe-area-inset-top, 0px))
    calc(20px + env(safe-area-inset-right, 0px))
    calc(16px + env(safe-area-inset-bottom, 0px))
    calc(20px + env(safe-area-inset-left, 0px));
  pointer-events: auto;
}

.ipad-backdrop[hidden] {
  display: none !important;
}

.ipad-panel {
  width: min(440px, 100%);
  max-height: min(86vh, 640px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--ipad-panel-bg);
  border: 1px solid var(--ipad-panel-border);
  border-radius: 14px;
  padding: 22px 22px 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.ipad-panel h1,
.ipad-panel h2 {
  margin: 0 0 10px;
  font-weight: 600;
  font-size: 1.35rem;
  letter-spacing: 0.01em;
}

.ipad-panel p,
.ipad-panel li {
  margin: 0 0 8px;
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--ipad-muted);
}

.ipad-panel ul {
  margin: 0 0 16px;
  padding-left: 1.15rem;
}

.ipad-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.ipad-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.12);
  color: var(--ipad-text);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.92rem;
  cursor: pointer;
  min-height: 40px;
}

.ipad-btn--primary {
  background: rgba(232, 238, 244, 0.92);
  color: #1a1f26;
  border-color: transparent;
  font-weight: 600;
}

.ipad-btn--ghost {
  background: transparent;
}

.ipad-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.ipad-progress {
  margin-top: 12px;
}

.ipad-progress__track {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.ipad-progress__bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #9eb0bd, #d7e1e8);
  transition: width 0.15s ease-out;
}

.ipad-progress__meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--ipad-muted);
}

.ipad-note {
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--ipad-muted);
}

.ipad-hidden {
  display: none !important;
}

/* Keep joysticks usable but smaller on very narrow landscape */
@media (max-height: 500px) {
  :root {
    --ipad-joy-size: 54px;
    --ipad-joy-inset: 16px;
  }
}

@media (min-width: 1100px) {
  :root {
    --ipad-joy-size: 64px;
  }
}
