:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #f8fbff;
  --muted: rgba(248, 251, 255, 0.68);
  --panel: rgba(5, 8, 12, 0.62);
  --line: rgba(255, 255, 255, 0.16);
  --pull: #45e8ff;
  --traj: #ffb240;
  --court: #2872cf;
  --court-deep: #143e86;
}

* {
  box-sizing: border-box;
}

html,
body,
.app {
  width: 100%;
  max-width: 100vw;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  background: #05070a;
  color: var(--ink);
  touch-action: none;
  user-select: none;
}

.app.camera-live .camera-fallback {
  opacity: 0;
}

.camera,
.camera-fallback,
.three-stage,
.trajectory {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.camera {
  z-index: 0;
  object-fit: cover;
  transform: scale(var(--camera-zoom, 1));
  opacity: 1;
}

.camera-fallback {
  z-index: 0;
  transition: opacity 220ms ease;
  background:
    linear-gradient(rgba(6, 10, 14, 0.04), rgba(6, 10, 14, 0.2)),
    radial-gradient(circle at 72% 10%, rgba(220, 242, 255, 0.25), transparent 16%),
    radial-gradient(circle at 16% 40%, rgba(255, 178, 64, 0.18), transparent 22%),
    linear-gradient(140deg, #354147 0%, #1a1e21 44%, #101418 100%);
}

.camera-fallback::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(90deg, rgba(255, 255, 255, 0.07) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px);
  background-size: 72px 72px;
  transform: perspective(700px) rotateX(64deg) translateY(18%);
  transform-origin: 50% 100%;
  opacity: 0.18;
}

.trajectory {
  z-index: 4;
  pointer-events: none;
}

.three-stage {
  z-index: 2;
  mix-blend-mode: screen;
}

.three-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hud {
  position: absolute;
  z-index: 5;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: auto;
  width: calc(100vw - max(12px, env(safe-area-inset-left)) - max(12px, env(safe-area-inset-right)));
  display: grid;
  grid-template-columns: auto auto auto;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.brand,
.score,
.icon-btn,
.zoom-control,
.stat-panel,
.surface-lock,
.status {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(18px);
}

.ar-panels {
  position: absolute;
  z-index: 5;
  top: calc(max(12px, env(safe-area-inset-top)) + 126px);
  left: 50%;
  display: flex;
  gap: 10px;
  transform: translateX(-50%);
  pointer-events: none;
}

.stat-panel {
  min-width: 128px;
  padding: 8px 10px;
  border-color: rgba(255, 153, 43, 0.84);
  border-radius: 5px;
  background: rgba(5, 8, 12, 0.42);
  box-shadow: 0 0 20px rgba(255, 153, 43, 0.16), inset 0 0 16px rgba(255, 153, 43, 0.09);
  color: #f8fbff;
  font-variant-numeric: tabular-nums;
}

.stat-panel h2 {
  margin: 0 0 5px;
  color: #ff9f2b;
  font-size: 11px;
  line-height: 1;
  letter-spacing: 0.08em;
}

.stat-panel p {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin: 0;
  font-size: 11px;
  line-height: 1.35;
  font-weight: 750;
}

.stat-panel b {
  color: #ffb240;
}

.brand {
  display: inline-flex;
  min-width: 0;
  width: fit-content;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
  font-weight: 780;
  letter-spacing: 0;
  pointer-events: auto;
}

.brand img {
  width: 26px;
  height: 24px;
  object-fit: contain;
}

.score {
  display: grid;
  min-width: 64px;
  min-height: 48px;
  justify-items: center;
  align-content: center;
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
}

.score strong {
  font-size: 22px;
  line-height: 0.9;
}

.score span {
  color: var(--traj);
  font-size: 10px;
  font-weight: 820;
  letter-spacing: 0.16em;
}

.icon-btn {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  color: var(--ink);
  pointer-events: auto;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.zoom-control {
  position: absolute;
  z-index: 5;
  top: calc(max(12px, env(safe-area-inset-top)) + 62px);
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: 36px minmax(72px, 96px) 36px;
  align-items: center;
  gap: 7px;
  padding: 7px;
  border-radius: 8px;
}

.zoom-control .icon-btn {
  width: 36px;
  height: 36px;
  border-color: rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.07);
  box-shadow: none;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--pull);
}

.stage {
  position: absolute;
  z-index: 2;
  display: none;
  inset: 0;
  perspective: 900px;
  pointer-events: none;
}

.court-rig {
  position: absolute;
  left: 50%;
  top: 55%;
  width: 300px;
  height: 400px;
  transform: translate(-50%, -50%) translate(var(--court-x, 0px), var(--court-y, 0px)) scale(var(--court-scale, 1)) rotateZ(var(--court-rot, 0deg));
  transform-origin: 50% 50%;
  transform-style: preserve-3d;
}

.court-cube {
  position: absolute;
  inset: 0;
  transform: rotateX(64deg) rotateZ(-8deg);
  transform-style: preserve-3d;
  filter: drop-shadow(0 30px 26px rgba(0, 0, 0, 0.42));
}

.court-face {
  position: absolute;
  border-radius: 8px;
}

.court-top {
  inset: 0;
  overflow: visible;
  border: 2px solid rgba(255, 255, 255, 0.72);
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.12), transparent 20%),
    linear-gradient(90deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    linear-gradient(var(--court), #1e5db5);
  background-size: auto, 55px 55px, auto;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  transform: translateZ(22px);
}

.court-front {
  left: 0;
  right: 0;
  bottom: -44px;
  height: 44px;
  background: linear-gradient(180deg, var(--court-deep), #0a2151);
  transform: rotateX(-90deg);
  transform-origin: 50% 0;
}

.court-right {
  top: 0;
  right: -44px;
  width: 44px;
  height: 100%;
  background: linear-gradient(90deg, #0d2e67, #07193d);
  transform: rotateY(90deg);
  transform-origin: 0 50%;
}

.court-lines,
.court-lines span {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.court-lines span {
  border-color: rgba(255, 255, 255, 0.74);
}

.midline {
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  background: rgba(255, 255, 255, 0.7);
}

.circle.center {
  left: 50%;
  top: 50%;
  width: 96px;
  height: 96px;
  margin: -48px 0 0 -48px;
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-radius: 50%;
}

.key {
  left: 50%;
  width: 118px;
  height: 82px;
  margin-left: -59px;
  border: 2px solid rgba(255, 255, 255, 0.72);
}

.key.near {
  bottom: 0;
}

.key.far {
  top: 0;
}

.arc {
  left: 50%;
  width: 190px;
  height: 120px;
  margin-left: -95px;
  border: 2px solid rgba(255, 255, 255, 0.66);
  border-radius: 50%;
}

.arc.near {
  bottom: -54px;
}

.arc.far {
  top: -54px;
}

.hoop {
  position: absolute;
  left: var(--hoop-x, 50%);
  top: var(--hoop-y, 12%);
  width: 92px;
  height: 86px;
  margin: -43px 0 0 -46px;
  border: 0;
  background: transparent;
  color: inherit;
  pointer-events: auto;
  transform: translateZ(70px) rotateX(-64deg) rotateZ(8deg);
  transform-style: preserve-3d;
}

.backboard {
  position: absolute;
  left: 5px;
  top: 0;
  display: grid;
  width: 82px;
  height: 48px;
  place-items: center;
  border: 2px solid rgba(248, 251, 255, 0.88);
  border-radius: 5px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.94), rgba(184, 220, 255, 0.78));
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

.yesjo-mark {
  color: #121820;
  font-size: 13px;
  font-weight: 860;
  letter-spacing: 0;
}

.rim {
  position: absolute;
  left: 22px;
  top: 39px;
  width: 48px;
  height: 18px;
  border: 4px solid #ff6c22;
  border-radius: 50%;
  box-shadow: 0 0 18px rgba(255, 108, 34, 0.52);
}

.net {
  position: absolute;
  left: 31px;
  top: 54px;
  width: 30px;
  height: 26px;
  border-left: 2px solid rgba(255, 255, 255, 0.76);
  border-right: 2px solid rgba(255, 255, 255, 0.76);
  background: repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.7) 0 1px, transparent 1px 9px);
  clip-path: polygon(0 0, 100% 0, 72% 100%, 28% 100%);
  opacity: 0.86;
}

.ball {
  position: absolute;
  left: var(--ball-x, 50%);
  top: var(--ball-y, 84%);
  width: 42px;
  height: 42px;
  margin: -21px 0 0 -21px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 24%, rgba(255, 236, 178, 0.78), transparent 18%),
    radial-gradient(circle at 58% 60%, #df6e18, #8f340c);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.42);
  transform: translateZ(85px) rotateX(-64deg) rotateZ(8deg) scale(var(--ball-scale, 1));
  pointer-events: none;
}

.ball::before,
.ball::after {
  content: "";
  position: absolute;
  inset: 6px;
  border: 2px solid rgba(77, 27, 10, 0.76);
  border-left-color: transparent;
  border-right-color: transparent;
  border-radius: 50%;
}

.ball::after {
  transform: rotate(90deg);
}

.status {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  width: min(430px, calc(100vw - 24px));
  transform: translateX(-50%);
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 620;
  line-height: 1.35;
  text-align: center;
  white-space: normal;
  overflow-wrap: break-word;
  pointer-events: none;
}

.surface-lock {
  position: absolute;
  z-index: 5;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 68px);
  padding: 8px 10px;
  border-radius: 5px;
  color: #45e8ff;
  font-size: 10px;
  font-weight: 820;
  line-height: 1.1;
  letter-spacing: 0.11em;
  text-align: left;
  background: rgba(5, 8, 12, 0.26);
  border-color: rgba(69, 232, 255, 0.38);
  box-shadow: 0 0 22px rgba(69, 232, 255, 0.16);
}

.place-btn {
  position: absolute;
  z-index: 5;
  left: max(18px, env(safe-area-inset-left));
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 68px);
  padding: 10px 14px;
  border: 1px solid rgba(125, 255, 122, 0.42);
  border-radius: 8px;
  color: #7dff7a;
  font-size: 12px;
  font-weight: 820;
  letter-spacing: 0.05em;
  background: rgba(5, 8, 12, 0.5);
  box-shadow: 0 0 22px rgba(125, 255, 122, 0.16);
  backdrop-filter: blur(18px);
  pointer-events: auto;
}

.place-btn.is-placing {
  color: #ffb240;
  border-color: rgba(255, 178, 64, 0.62);
  box-shadow: 0 0 24px rgba(255, 178, 64, 0.26);
}

@media (min-width: 720px) {
  .court-rig {
    width: 420px;
    height: 560px;
  }

}

@media (max-width: 390px) {
  .brand span {
    display: none;
  }

  .zoom-control {
    grid-template-columns: 34px 76px 34px;
    top: calc(max(12px, env(safe-area-inset-top)) + 58px);
  }

  .court-rig {
    width: 260px;
    height: 346px;
    top: 54%;
  }

  .hud {
    right: 10px;
    left: 10px;
  }

  .score {
    min-width: 58px;
  }

  .status {
    font-size: 11px;
  }

  .ar-panels {
    top: calc(max(12px, env(safe-area-inset-top)) + 116px);
  }

  .stat-panel {
    min-width: 112px;
    padding: 7px 8px;
  }

  .stat-panel h2,
  .stat-panel p {
    font-size: 10px;
  }
}

@media (max-width: 600px) {
  .hud {
    left: 12px;
    width: min(366px, calc(100vw - 24px));
    transform: none;
  }

  .status {
    width: min(366px, calc(100vw - 24px));
  }
}
