:root {
  color-scheme: dark;
  --ink: #fff7ea;
  --muted: rgba(255, 247, 234, 0.72);
  --panel: rgba(9, 12, 15, 0.78);
  --line: rgba(255, 247, 234, 0.22);
  --red: #b83a34;
  --gold: #d1a64a;
  font-family:
    "Inter", "Yu Gothic", "YuGothic", "Hiragino Kaku Gothic ProN", Meiryo,
    system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  background: #000;
}

button,
a,
input,
select {
  font: inherit;
}

.projection-stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: #000;
}

.projection-background {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  opacity: 0;
  background: #000;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.projection-background::before,
.projection-background::after {
  position: absolute;
  inset: 0;
  content: "";
}

body:not(.camera-mode).bg-fuji .projection-background,
body:not(.camera-mode).bg-rooftop .projection-background,
body:not(.camera-mode).bg-flowers .projection-background {
  opacity: 1;
}

body.bg-fuji .projection-background {
  background:
    linear-gradient(180deg, #7fb7d9 0%, #f4d7b1 46%, #244e61 47%, #122735 100%);
}

body.bg-fuji .projection-background::before {
  inset: auto -8vw 24vh -8vw;
  height: 58vh;
  background:
    linear-gradient(135deg, transparent 0 41%, rgba(255, 255, 255, 0.9) 41% 51%, transparent 51%),
    linear-gradient(180deg, #dbe5ea 0 20%, #4f768a 21%, #17364b 100%);
  clip-path: polygon(50% 0%, 12% 100%, 88% 100%);
}

body.bg-fuji .projection-background::after {
  inset: auto 0 0;
  height: 33vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0) 34%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.14) 0 2px, transparent 2px 14px),
    linear-gradient(180deg, #2d6374, #0e2432);
}

body.bg-rooftop .projection-background {
  background:
    linear-gradient(180deg, #071126 0%, #18294d 48%, #111824 49%, #06080d 100%);
}

body.bg-rooftop .projection-background::before {
  inset: 18vh 0 33vh;
  background:
    linear-gradient(90deg, transparent 0 4%, #17263d 4% 13%, transparent 13% 17%, #101a2d 17% 24%, transparent 24% 30%, #1e3150 30% 41%, transparent 41% 45%, #101b31 45% 56%, transparent 56% 62%, #203454 62% 75%, transparent 75% 80%, #14233c 80% 96%, transparent 96%),
    repeating-linear-gradient(90deg, rgba(255, 224, 132, 0.85) 0 3px, transparent 3px 22px),
    repeating-linear-gradient(0deg, transparent 0 16px, rgba(255, 224, 132, 0.56) 16px 19px);
  opacity: 0.88;
}

body.bg-rooftop .projection-background::after {
  inset: auto 0 0;
  height: 38vh;
  background:
    linear-gradient(90deg, transparent 0 10%, rgba(225, 232, 244, 0.78) 10% 11%, transparent 11% 18%, rgba(225, 232, 244, 0.64) 18% 19%, transparent 19% 82%, rgba(225, 232, 244, 0.64) 82% 83%, transparent 83% 90%, rgba(225, 232, 244, 0.78) 90% 91%, transparent 91%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.2) 0 3px, transparent 3px 46px),
    linear-gradient(180deg, #273241 0 16%, #111923 17% 100%);
}

body.bg-flowers .projection-background {
  background:
    linear-gradient(180deg, #74bce8 0%, #dff2f6 42%, #6aa64f 43%, #2c6f3e 100%);
}

body.bg-flowers .projection-background::before {
  inset: 43vh 0 0;
  background:
    radial-gradient(circle at 8% 26%, #f7e05e 0 5px, #e4506b 5px 9px, transparent 10px),
    radial-gradient(circle at 22% 54%, #fff4a8 0 4px, #c93968 4px 8px, transparent 9px),
    radial-gradient(circle at 38% 34%, #fff7b8 0 5px, #7d4fb3 5px 9px, transparent 10px),
    radial-gradient(circle at 52% 62%, #f5e36a 0 4px, #e96f44 4px 8px, transparent 9px),
    radial-gradient(circle at 68% 30%, #fff0a4 0 5px, #d63f73 5px 10px, transparent 11px),
    radial-gradient(circle at 84% 58%, #f7e05e 0 4px, #6e74ca 4px 8px, transparent 9px),
    repeating-linear-gradient(90deg, rgba(18, 83, 42, 0.55) 0 2px, transparent 2px 22px),
    linear-gradient(180deg, rgba(149, 202, 96, 0.58), rgba(33, 107, 52, 0.9));
}

body.bg-flowers .projection-background::after {
  inset: auto 0 0;
  height: 21vh;
  background:
    repeating-linear-gradient(112deg, rgba(237, 245, 191, 0.28) 0 3px, transparent 3px 22px),
    linear-gradient(180deg, rgba(77, 151, 63, 0), rgba(24, 84, 39, 0.92));
}

body.bg-fuji .projection-background,
body.bg-rooftop .projection-background,
body.bg-flowers .projection-background {
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

body.bg-fuji .projection-background {
  background-image:
    linear-gradient(180deg, rgba(0, 0, 0, 0.08), rgba(0, 0, 0, 0.2)),
    url("./backgrounds/fuji-lake.png");
}

body.bg-rooftop .projection-background {
  background-image:
    linear-gradient(180deg, rgba(0, 0, 0, 0.06), rgba(0, 0, 0, 0.24)),
    url("./backgrounds/rooftop-night.png");
}

body.bg-flowers .projection-background {
  background-image:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(0, 0, 0, 0.14)),
    url("./backgrounds/flower-field.png");
}

body.bg-fuji .projection-background::before,
body.bg-fuji .projection-background::after,
body.bg-rooftop .projection-background::before,
body.bg-rooftop .projection-background::after,
body.bg-flowers .projection-background::before,
body.bg-flowers .projection-background::after {
  display: none;
}

#camera {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  pointer-events: none;
}

body.camera-mode #camera {
  opacity: 1;
}

body.camera-mode.mirror-camera #camera {
  transform: scaleX(-1);
}

body[data-app-mode="vtuber"] .projection-stage {
  background:
    radial-gradient(circle at 50% 42%, rgba(229, 83, 133, 0.2), transparent 32rem),
    linear-gradient(135deg, #10182d, #060a13 58%, #170d1f);
}

body[data-app-mode="vtuber"].camera-mode #camera {
  opacity: 0.42;
  filter: saturate(0.8) brightness(0.72);
}

body[data-app-mode="vtuber"] #projection3d {
  filter: drop-shadow(0 24px 46px rgba(0, 0, 0, 0.48));
}

#projection3d,
#bodyOcclusion,
#projectionGuide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#projection3d {
  z-index: 1;
  cursor: grab;
  touch-action: none;
}

#projection3d:active {
  cursor: grabbing;
}

#bodyOcclusion {
  z-index: 2;
  display: none;
  pointer-events: none;
}

body.camera-mode #bodyOcclusion {
  display: block;
}

#projectionGuide {
  pointer-events: none;
  z-index: 3;
}

.joint-ui {
  position: absolute;
  z-index: 4;
  display: none;
  min-width: 126px;
  padding: 7px 9px;
  border: 1px solid rgba(209, 166, 74, 0.72);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(9, 12, 15, 0.72);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(10px);
  pointer-events: auto;
}

.joint-ui strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.76rem;
}

.joint-ui input {
  width: 100%;
  accent-color: var(--gold);
}

.joint-ui.shoulder {
  transform: translate(-50%, -120%);
}

.joint-ui.hip {
  transform: translate(-50%, 18px);
}

.joint-ui.left {
  transform: translate(-112%, -50%);
}

.joint-ui.right {
  transform: translate(12%, -50%);
}

.projector-hud,
.status,
.projector-controls {
  position: absolute;
  z-index: 5;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(14px);
}

.projector-hud {
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
}

.projector-hud p,
.projector-hud h1 {
  margin: 0;
}

.projector-hud p {
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.projector-hud h1 {
  font-size: clamp(1.25rem, 2.2vw, 2.2rem);
}

.projector-hud nav {
  display: flex;
  gap: 10px;
}

.projector-hud a,
.projector-controls button {
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

.projector-controls button:first-child {
  border-color: transparent;
  background: var(--red);
}

#calibrateButton {
  border-color: rgba(209, 166, 74, 0.56);
  background: rgba(209, 166, 74, 0.18);
}

.status {
  left: 50%;
  bottom: 18px;
  display: grid;
  gap: 3px;
  width: min(620px, calc(100vw - 32px));
  padding: 12px 14px;
  transform: translateX(-50%);
  text-align: center;
}

.status span {
  color: var(--muted);
}

.projector-controls {
  top: 104px;
  right: 16px;
  display: grid;
  gap: 12px;
  width: 230px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  padding: 12px;
  overscroll-behavior: contain;
}

.projector-controls label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.projector-controls .control-field {
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: 7px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
  transition:
    border-color 0.16s ease,
    background 0.16s ease,
    box-shadow 0.16s ease;
}

.projector-controls .control-field:focus,
.projector-controls .control-field:focus-within,
.projector-controls .control-field.is-wheel-active {
  border-color: rgba(209, 166, 74, 0.82);
  background: rgba(209, 166, 74, 0.12);
  box-shadow: 0 0 0 2px rgba(209, 166, 74, 0.16);
  outline: none;
}

.projector-controls .control-field input,
.projector-controls .control-field select {
  grid-column: 1 / -1;
}

.projector-controls .control-value {
  grid-column: 2;
  grid-row: 1;
  max-width: 112px;
  overflow: hidden;
  color: var(--ink);
  font-size: 0.74rem;
  font-weight: 800;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.projector-controls input[type="range"] {
  width: 100%;
  height: 26px;
  margin: 0;
  appearance: none;
  accent-color: var(--gold);
  background: transparent;
  cursor: ew-resize;
}

.projector-controls input[type="range"]::-webkit-slider-runnable-track {
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    var(--gold) 0 var(--range-fill, 50%),
    rgba(255, 255, 255, 0.2) var(--range-fill, 50%) 100%
  );
}

.projector-controls input[type="range"]::-webkit-slider-thumb {
  width: 22px;
  height: 22px;
  margin-top: -6px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  appearance: none;
  background: var(--gold);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.38);
}

.projector-controls input[type="range"]::-moz-range-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
}

.projector-controls input[type="range"]::-moz-range-progress {
  height: 10px;
  border-radius: 999px;
  background: var(--gold);
}

.projector-controls input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--gold);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.38);
}

.projector-controls select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.1);
}

.check-row {
  grid-template-columns: 20px 1fr;
  align-items: center;
}

.check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--gold);
}

.model-structure-panel {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 6;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 10px;
  width: min(380px, calc(100vw - 32px));
  height: min(430px, calc(100vh - 132px));
  min-width: 260px;
  min-height: 220px;
  max-width: calc(100vw - 32px);
  max-height: min(520px, calc(100vh - 132px));
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(9, 12, 15, 0.82);
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(14px);
  overflow: hidden;
  resize: both;
}

.tracking-preview-panel {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 5;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  width: min(340px, calc(100vw - 32px));
  height: min(260px, calc(100vh - 148px));
  min-width: 230px;
  min-height: 170px;
  max-width: calc(100vw - 32px);
  max-height: min(520px, calc(100vh - 132px));
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(8, 10, 18, 0.76);
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(14px);
  overflow: hidden;
  resize: both;
}

.tracking-preview-panel[hidden] {
  display: none;
}

.tracking-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: move;
  user-select: none;
}

.tracking-preview-header p,
.tracking-preview-header strong {
  margin: 0;
}

.tracking-preview-header p {
  color: var(--gold);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.tracking-preview-header button {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-weight: 900;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

#trackingPreview {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 1px solid rgba(255, 247, 234, 0.12);
  border-radius: 8px;
  background:
    linear-gradient(rgba(255, 247, 234, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 247, 234, 0.04) 1px, transparent 1px),
    rgba(7, 10, 18, 0.74);
  background-size: 24px 24px;
}

.tracking-preview-summary {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.4;
}

.model-structure-panel[hidden] {
  display: none;
}

.model-structure-panel::after {
  content: "";
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 16px;
  height: 16px;
  opacity: 0.62;
  pointer-events: none;
  background:
    linear-gradient(135deg, transparent 0 45%, rgba(255, 247, 234, 0.55) 46% 52%, transparent 53%),
    linear-gradient(135deg, transparent 0 62%, rgba(255, 247, 234, 0.35) 63% 69%, transparent 70%);
}

.structure-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.structure-header p,
.structure-header strong {
  margin: 0;
}

.structure-header p {
  color: var(--gold);
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
}

.structure-header button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-weight: 900;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

.structure-summary {
  color: var(--muted);
  font-size: 0.82rem;
}

.structure-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.structure-tabs button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-weight: 800;
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
}

.structure-tabs button.is-active {
  border-color: rgba(209, 166, 74, 0.72);
  background: rgba(209, 166, 74, 0.22);
}

.structure-list {
  display: grid;
  gap: 7px;
  min-height: 0;
  max-height: none;
  overflow: auto;
  padding-right: 2px;
  overscroll-behavior: contain;
}

.structure-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: center;
  min-height: 34px;
  padding: 7px 8px;
  border: 1px solid rgba(255, 247, 234, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
}

.structure-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--gold);
}

.structure-name {
  overflow: hidden;
  font-size: 0.78rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.structure-meta {
  grid-column: 2;
  color: var(--muted);
  font-size: 0.7rem;
}

body.hide-hud .projector-hud,
body.hide-hud .status,
body.hide-hud .projector-controls,
body.hide-hud .tracking-preview-panel,
body.hide-hud .model-structure-panel {
  display: none;
}
