* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: #111921;
  color: #eaf4f7;
  font: 14px system-ui;
}
canvas {
  display: block;
  width: 100%;
  height: 100vh;
}
header {
  position: absolute;
  top: 22px;
  left: 24px;
  right: 24px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}
h1 {
  margin: 0;
  font-size: 21px;
  letter-spacing: 0.02em;
}
small {
  display: block;
  margin-top: 5px;
  color: #a7c3ce;
}
nav,
.panel {
  pointer-events: auto;
  background: #142530ec;
  border: 1px solid #ffffff20;
  border-radius: 12px;
  padding: 10px;
}
nav {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}
button,
select {
  background: #263c49;
  color: #eefaff;
  border: 1px solid #6e899650;
  border-radius: 7px;
  padding: 9px 12px;
  font: inherit;
  cursor: pointer;
}
button:hover {
  background: #385666;
}
button:disabled,
select:disabled {
  opacity: 0.45;
  cursor: wait;
}
#status {
  position: absolute;
  bottom: 25px;
  left: 24px;
  max-width: 75vw;
}
#metrics {
  position: absolute;
  bottom: 25px;
  right: 24px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.error {
  color: #ffaaaa;
}
@media (max-width: 800px) {
  header {
    flex-direction: column;
    top: 12px;
    left: 12px;
  }
  #metrics {
    font-size: 11px;
    bottom: 12px;
    right: 12px;
  }
  #status {
    bottom: 70px;
    left: 12px;
  }
}
.lab-home {
  display: inline-block;
  pointer-events: auto;
  color: #eaf4f7;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 5px 0;
}
.lab-home:focus-visible {
  outline: 2px solid #b6edff;
  outline-offset: 3px;
}

/* Two-thumb HUD; existing movement, camera and throw models remain the owners. */
.phone-controls {
  display: none;
}
/* Playability v2: keep movement/thumb actions separate from configuration. */
@media (pointer: coarse) {
  .phone-move-zone {
    position: absolute;
    left: 0;
    top: 38%;
    bottom: 0;
    width: 45%;
    pointer-events: auto;
    touch-action: none;
    user-select: none;
  }
  .phone-stick {
    pointer-events: none !important;
  }
  .phone-stick.phone-floating-active {
    transform: translate(-50%, -50%);
  }
  .phone-actions {
    width: 144px !important;
    height: 176px !important;
    top: 50%;
    bottom: auto !important;
    transform: translateY(-50%);
  }
  .phone-actions button {
    width: 56px !important;
    height: 56px !important;
  }
  .phone-actions [aria-label='Charge throw'] {
    width: 84px !important;
    height: 84px !important;
    font-size: 15px !important;
    font-weight: 600;
  }
  .phone-jump {
    right: 0;
    top: 0;
  }
  .phone-aim {
    left: 0;
    right: auto !important;
    top: 50px !important;
  }
  .phone-settings-toggle {
    position: absolute;
    top: max(12px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
    pointer-events: auto;
    touch-action: manipulation;
    font-size: 20px;
  }
  .phone-settings-dialog {
    width: min(440px, calc(100vw - 32px));
    max-height: calc(100dvh - 32px);
    overflow: auto;
    padding: 20px;
    color: #eefaff;
    background: #142530;
    border: 1px solid #6e8996;
    border-radius: 12px;
  }
  .phone-settings-dialog::backdrop {
    background: #111921c0;
  }
  .phone-settings-dialog h2 {
    margin: 0 0 12px;
    font-size: 20px;
  }
  .phone-settings-dialog label {
    display: grid;
    gap: 8px;
    margin: 20px 0;
  }
  .phone-settings-dialog input {
    width: 100%;
    min-height: 44px;
  }
  .phone-settings-dialog button,
  .phone-settings-dialog select,
  .phone-settings-dialog a {
    min-height: 44px;
  }
  .phone-settings-dialog a {
    display: block;
    padding-top: 12px;
    color: #a9deff;
  }
  .phone-settings-close {
    float: right;
  }
  body:has(.phone-controls) .controller-toggle,
  body:has(.phone-controls) .controller-notice {
    display: none;
  }
  body:has(.phone-controls) header {
    right: 72px;
  }
  body:has(.phone-controls) .charge-feedback {
    left: 50%;
    right: auto;
    bottom: 20px;
    transform: translateX(-50%);
    max-width: min(220px, 40vw);
  }
  .phone-rotate-hint {
    display: none;
  }
}
@media (pointer: coarse) and (orientation: portrait) {
  .phone-actions {
    top: 64%;
  }
  .phone-rotate-hint {
    display: block;
    position: absolute;
    top: 106px;
    left: 12px;
    font-size: 12px;
    color: #a7c3ce;
    pointer-events: none;
  }
  body:has(.phone-controls) .charge-feedback {
    bottom: 20px;
    max-width: calc(100vw - 32px);
  }
}

@media (pointer: coarse) {
  canvas {
    height: 100dvh;
    touch-action: none;
  }
  .phone-controls {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 3;
    pointer-events: none;
  }
  .phone-stick {
    position: absolute;
    left: max(16px, env(safe-area-inset-left));
    bottom: max(28px, env(safe-area-inset-bottom));
    width: 128px;
    height: 128px;
    border: 1px solid #c9eaff70;
    border-radius: 50%;
    background: #14253055;
    box-shadow: inset 0 0 0 20px #c9eaff08;
    pointer-events: auto;
    touch-action: none;
    user-select: none;
  }
  .phone-stick-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid #c9eaffc0;
    background: #142530b0;
    transform: translate(-50%, -50%);
    pointer-events: none;
  }
  .phone-stick-label {
    position: absolute;
    width: 100%;
    bottom: -18px;
    text-align: center;
    font-size: 10px;
    letter-spacing: 0.08em;
    color: #c9eaff;
    pointer-events: none;
  }
  .phone-actions {
    position: absolute;
    right: max(16px, env(safe-area-inset-right));
    bottom: max(20px, env(safe-area-inset-bottom));
    width: 160px;
    height: 174px;
  }
  .phone-actions button {
    position: absolute;
    width: 52px;
    height: 52px;
    padding: 5px;
    border-radius: 50%;
    border: 1px solid #c9eaff90;
    color: #eefaff;
    background: #142530b0;
    pointer-events: auto;
    touch-action: none;
    user-select: none;
  }
  .phone-actions svg {
    display: block;
    width: 24px;
    height: 24px;
    margin: auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    pointer-events: none;
  }
  .phone-actions span {
    font-size: 10px;
    pointer-events: none;
  }
  .phone-actions button:active,
  .phone-actions button[aria-pressed='true'] {
    background: #385666;
    border-color: #eefaff;
  }
  .phone-jump {
    right: 0;
    top: 0;
  }
  .phone-aim {
    right: 66px;
    top: 38px;
  }
  .phone-view {
    left: 0;
    bottom: 0;
  }
  .phone-actions [aria-label='Charge throw'] {
    width: 76px;
    height: 76px;
    right: 0;
    bottom: 0;
    font-size: 13px;
    border-width: 2px;
    padding: 10px;
  }
  body .charge-feedback {
    bottom: calc(210px + env(safe-area-inset-bottom));
    left: auto;
    right: max(16px, env(safe-area-inset-right));
    transform: none;
    max-width: 220px;
  }
  body:has(.phone-controls):has(.charge-feedback:not([hidden])) #status {
    display: none;
  }
  #status {
    bottom: calc(210px + env(safe-area-inset-bottom));
    font-size: 12px;
    pointer-events: none;
  }
  .player-controls > div {
    display: none;
  }
}
