:root {
  --bg: #eef2f4;
  --ink: #111827;
  --muted: #64748b;
  --line: #cbd5df;
  --panel: #ffffff;
  --panel-strong: #f8fafc;
  --accent: #1d8f78;
  --accent-dark: #0f6f60;
  --gold: #d09b2c;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

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

button,
input,
textarea {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 0;
}

.app-shell.narrow {
  width: min(920px, calc(100vw - 32px));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.topbar h1,
.topbar h2,
.panel-head h2,
.compile-panel h2,
.ar-card h1 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 52px;
  line-height: 0.95;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.nav-actions,
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.button,
.file-button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 800;
}

.button.primary {
  background: var(--accent);
  color: white;
}

.button.primary:hover {
  background: var(--accent-dark);
}

.button.secondary,
.file-button {
  background: var(--panel);
  border-color: var(--line);
}

.button.ghost {
  background: transparent;
  border-color: var(--line);
}

.button.wide {
  width: 100%;
}

.button.disabled,
.button:disabled {
  opacity: 0.48;
  pointer-events: none;
}

.file-button input,
.file-drop input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 18px;
  align-items: start;
}

.preview-pane,
.control-pane,
.target-builder,
.ar-card {
  background: var(--panel);
  border: 1px solid rgba(148, 163, 184, 0.4);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.preview-pane {
  overflow: hidden;
}

.image-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-strong);
}

.target-presets {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #f1f5f7;
}

.target-preset {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  background: white;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.target-preset img {
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 6px;
  object-fit: cover;
}

.target-preset.active {
  border-color: var(--accent);
  color: var(--accent-dark);
  outline: 3px solid rgba(29, 143, 120, 0.18);
}

.target-canvas {
  position: relative;
  display: grid;
  min-height: 680px;
  overflow: hidden;
  place-items: center;
  background:
    linear-gradient(90deg, rgba(15, 23, 42, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(15, 23, 42, 0.05) 1px, transparent 1px), #e7edf1;
  background-size: 32px 32px;
}

#targetImage {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#targetImage.visible {
  display: block;
}

.empty-target {
  width: min(420px, calc(100% - 32px));
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.empty-target.hidden,
.hidden {
  display: none !important;
}

.tower-sketch {
  position: relative;
  width: 220px;
  height: 280px;
  margin: 0 auto 20px;
}

.tower-sketch::before {
  position: absolute;
  left: 50%;
  bottom: 18px;
  width: 88px;
  height: 210px;
  border-radius: 44px 44px 18px 18px;
  background: linear-gradient(90deg, #84909a, #edf2f6 42%, #7d8992);
  content: "";
  transform: translateX(-50%);
}

.tower-sketch::after {
  position: absolute;
  left: 36px;
  right: 36px;
  bottom: 0;
  height: 24px;
  border-radius: 8px;
  background: #1f2933;
  content: "";
}

.tower-sketch span {
  position: absolute;
  top: 42px;
  width: 18px;
  height: 95px;
  border-radius: 12px;
  background: #17202a;
  transform-origin: bottom;
}

.tower-sketch span:nth-child(1) {
  left: 48px;
  transform: rotate(-11deg);
}

.tower-sketch span:nth-child(2) {
  left: 88px;
  top: 18px;
  transform: rotate(-4deg);
}

.tower-sketch span:nth-child(3) {
  right: 88px;
  top: 18px;
  transform: rotate(4deg);
}

.tower-sketch span:nth-child(4) {
  right: 48px;
  transform: rotate(11deg);
}

.label-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.tap-marker {
  position: absolute;
  display: grid;
  min-width: 132px;
  max-width: 190px;
  min-height: 54px;
  padding: 8px 11px;
  border: 1px solid rgba(15, 23, 42, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.16);
  color: var(--ink);
  pointer-events: auto;
  text-align: left;
  transform: translate(-50%, -50%);
}

.tap-marker::after {
  position: absolute;
  left: 50%;
  bottom: -14px;
  width: 2px;
  height: 14px;
  background: var(--gold);
  content: "";
}

.tap-marker strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tap-marker span {
  color: var(--muted);
  font-size: 13px;
}

.tap-label-thumb {
  width: 156px;
  aspect-ratio: 16 / 9;
  border-radius: 6px;
  object-fit: cover;
}

.tap-marker.active {
  border-color: var(--accent);
  outline: 3px solid rgba(29, 143, 120, 0.22);
}

.control-pane {
  display: grid;
  gap: 14px;
  padding: 16px;
}

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

.tap-editor {
  display: grid;
  max-height: 580px;
  gap: 12px;
  overflow: auto;
  padding-right: 4px;
}

.tap-form {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel-strong);
}

.tap-form-head,
.detail-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.tap-form-head strong {
  color: var(--ink);
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: white;
  color: var(--ink);
  resize: vertical;
}

.split {
  display: grid;
  grid-template-columns: 1fr 96px;
  gap: 10px;
}

.tap-detail {
  border: 1px solid rgba(29, 143, 120, 0.26);
  border-radius: 8px;
  padding: 14px;
  background: #eefbf7;
}

.tap-detail h3,
.ar-detail h2 {
  margin: 0 0 8px;
}

.tap-detail p:last-child,
.ar-detail p:last-child {
  margin-bottom: 0;
}

.detail-label-image {
  display: block;
  width: 100%;
  max-height: 220px;
  margin-bottom: 12px;
  border-radius: 8px;
  object-fit: contain;
  background: #0b1424;
}

.target-builder {
  display: grid;
  grid-template-columns: 1fr 0.85fr;
  gap: 18px;
  padding: 18px;
}

.drop-panel {
  display: grid;
  gap: 14px;
  align-content: start;
}

.file-drop {
  display: grid;
  min-height: 220px;
  place-items: center;
  border: 2px dashed #8aa6b6;
  border-radius: 8px;
  background: #f3f8fa;
  color: var(--accent-dark);
  cursor: pointer;
  font-size: 18px;
  font-weight: 850;
}

#targetPreview {
  display: none;
  width: 100%;
  max-height: 520px;
  border-radius: 8px;
  object-fit: contain;
  background: #0f172a;
}

#targetPreview.visible {
  display: block;
}

.target-preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.target-preview-card {
  display: grid;
  gap: 6px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: var(--panel-strong);
}

.target-preview-card img {
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 6px;
  object-fit: cover;
}

.target-preview-card figcaption {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.compile-panel {
  display: grid;
  gap: 16px;
  align-content: start;
  border-left: 1px solid var(--line);
  padding-left: 18px;
}

progress {
  width: 100%;
  height: 14px;
  accent-color: var(--accent);
}

.status-line {
  margin: 0;
  color: var(--muted);
}

.ar-body {
  min-height: 100vh;
  overflow: hidden;
  background: #05070a;
}

.ar-setup {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 18px;
}

.ar-card {
  display: grid;
  width: min(430px, 100%);
  gap: 16px;
  padding: 20px;
}

.ar-card h1 {
  font-size: 36px;
  line-height: 1;
}

#arRoot,
#arRoot a-scene {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
}

.ar-hud {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.hud-button,
.tracking-state {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  border-radius: 999px;
  padding: 0 14px;
  background: rgba(7, 10, 14, 0.72);
  color: white;
  font-weight: 800;
  pointer-events: auto;
}

.tracking-state {
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.ar-detail {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 30;
  width: min(430px, calc(100vw - 28px));
  border-radius: 8px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
  transform: translateX(-50%);
}

.close-detail {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

@media (max-width: 860px) {
  .topbar,
  .workspace,
  .target-builder {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
  }

  .target-canvas {
    min-height: 540px;
  }

  .compile-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding-top: 18px;
    padding-left: 0;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100vw - 20px, 1180px);
    padding-top: 12px;
  }

  .topbar {
    display: grid;
  }

  .nav-actions,
  .row-actions,
  .image-toolbar {
    width: 100%;
  }

  .button,
  .file-button {
    flex: 1 1 auto;
  }

  .target-canvas {
    min-height: 430px;
  }

  .target-presets,
  .target-preview-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar h1 {
    font-size: 36px;
  }

  .tap-marker {
    min-width: 104px;
    max-width: 136px;
    min-height: 48px;
    padding: 7px 8px;
    font-size: 13px;
  }

  .tap-label-thumb {
    width: 112px;
  }

  .split {
    grid-template-columns: 1fr;
  }
}
