:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #687385;
  --line: #d9dee7;
  --primary: #176b87;
  --primary-strong: #114d61;
  --accent: #d65a31;
  --green: #357a38;
  --stage: #cfd6df;
  --shadow: 0 18px 60px rgba(24, 35, 48, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0.62rem 0.8rem;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

button:hover {
  border-color: #9ea9b8;
}

button:active {
  transform: translateY(1px);
}

input[type="text"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0.64rem 0.72rem;
  color: var(--ink);
  background: #fff;
}

input[type="file"] {
  width: 100%;
  color: var(--muted);
}

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

.app-shell {
  display: grid;
  grid-template-columns: minmax(250px, 300px) minmax(420px, 1fr) minmax(280px, 340px);
  min-height: 100vh;
}

.left-panel,
.right-panel {
  background: var(--panel);
  border-color: var(--line);
  border-style: solid;
  overflow: auto;
}

.left-panel {
  border-width: 0 1px 0 0;
  padding: 1rem;
}

.right-panel {
  border-width: 0 0 0 1px;
  padding: 1rem;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-bottom: 1rem;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #fff;
  background: var(--primary);
  font-weight: 800;
}

.brand-block h1 {
  margin: 0;
  font-size: 1.05rem;
}

.brand-block p {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.panel-section {
  padding: 0.85rem 0;
  border-top: 1px solid var(--line);
}

.panel-section label,
.control-grid label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.file-stack {
  display: grid;
  gap: 0.65rem;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  padding: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f6f8fb;
}

.segment {
  border: 0;
  background: transparent;
}

.segment.active {
  color: #fff;
  background: var(--primary);
}

.url-row {
  display: grid;
  grid-template-columns: 1fr 42px;
  gap: 0.4rem;
}

.icon-button {
  padding: 0;
  font-size: 1.15rem;
}

.qr-section {
  display: grid;
  gap: 0.75rem;
}

#qrCanvas {
  width: 176px;
  height: 176px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.button-row,
.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.button-row button,
.top-actions button,
#launchArBtn {
  color: #fff;
  border-color: transparent;
  background: var(--primary);
}

.button-row button:first-child {
  background: var(--accent);
}

.workspace {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(12px);
}

.topbar strong {
  display: block;
}

.topbar span {
  color: var(--muted);
  font-size: 0.84rem;
}

.stage-wrap {
  display: grid;
  place-items: center;
  padding: 1.5rem;
  overflow: hidden;
}

.stage {
  position: relative;
  width: min(78vw, 920px);
  aspect-ratio: 16 / 10;
  border: 1px solid #b7c0cc;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.22) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.22) 1px, transparent 1px),
    var(--stage);
  background-size: 36px 36px;
  box-shadow: var(--shadow);
  perspective: 900px;
  overflow: hidden;
}

.marker-plane {
  position: absolute;
  inset: 7%;
  display: grid;
  place-items: center;
  border: 1px dashed #8190a2;
  border-radius: 7px;
  background: #f8fafc;
  background-position: center;
  background-size: contain;
  background-repeat: no-repeat;
  transform-origin: center;
  transition: transform 180ms ease;
}

.stage.perspective .marker-plane {
  transform: rotateX(58deg) translateY(5%);
}

.empty-marker {
  display: grid;
  gap: 0.25rem;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.empty-marker strong {
  color: var(--ink);
}

.marker-plane.has-image .empty-marker {
  display: none;
}

.object-layer {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 28%;
  aspect-ratio: 1 / 1;
  transform-style: preserve-3d;
  transform-origin: center;
  display: grid;
  place-items: center;
  transition: filter 180ms ease;
}

.object-layer model-viewer,
.fallback-object {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.object-layer model-viewer:not([src]) {
  display: none;
}

.fallback-object {
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(145deg, #176b87 0%, #2e7d32 100%);
  box-shadow: 0 20px 35px rgba(17, 77, 97, 0.22);
}

.fallback-object div {
  width: 45%;
  aspect-ratio: 1 / 1;
  border: 2px solid rgba(255, 255, 255, 0.9);
  transform: rotateX(58deg) rotateZ(45deg);
}

.fallback-object span {
  position: absolute;
  bottom: 12%;
  font-weight: 800;
}

.object-layer.has-model .fallback-object {
  display: none;
}

.object-shadow {
  position: absolute;
  bottom: 3%;
  width: 66%;
  height: 15%;
  border-radius: 50%;
  background: rgba(23, 32, 42, 0.18);
  filter: blur(10px);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.section-title span {
  border-radius: 999px;
  padding: 0.28rem 0.55rem;
  color: #fff;
  background: var(--green);
  font-size: 0.76rem;
  font-weight: 800;
}

.control-grid {
  display: grid;
  grid-template-columns: 60px 1fr 46px;
  align-items: center;
  gap: 0.62rem 0.5rem;
  padding: 0.85rem 0;
  border-top: 1px solid var(--line);
}

.control-grid output {
  color: var(--muted);
  font-size: 0.78rem;
  text-align: right;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--ink) !important;
}

.viewer-body {
  background: #111820;
}

.viewer-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 1fr auto;
}

.viewer-hero {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 72vh;
  overflow: hidden;
}

.viewer-marker {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(rgba(17, 24, 32, 0.22), rgba(17, 24, 32, 0.38)),
    linear-gradient(135deg, #cfd6df, #f3f5f7);
  background-position: center;
  background-size: cover;
}

.viewer-model-card {
  position: relative;
  width: min(82vw, 620px);
  aspect-ratio: 1 / 1;
  z-index: 1;
}

.viewer-model-card model-viewer {
  width: 100%;
  height: 100%;
}

.viewer-fallback {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  color: #fff;
  background: rgba(17, 24, 32, 0.72);
}

.viewer-model-card.has-model .viewer-fallback {
  display: none;
}

.viewer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  color: #fff;
  background: rgba(17, 24, 32, 0.92);
}

#launchArBtn {
  min-width: 120px;
  background: var(--accent);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .left-panel,
  .right-panel {
    border-width: 0 0 1px;
  }

  .workspace {
    min-height: 68vh;
  }

  .stage {
    width: min(94vw, 760px);
  }
}

@media (max-width: 640px) {
  .topbar,
  .viewer-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .stage-wrap {
    padding: 0.75rem;
  }

  .stage {
    aspect-ratio: 4 / 5;
  }
}
