*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-app: #11141b;
  --bg-panel: #1a202b;
  --bg-panel-soft: #202836;
  --bg-panel-strong: #263246;
  --bg-canvas: #0d1118;
  --bg-input: #121a26;
  --border: #2c3648;
  --border-strong: #41506a;
  --text: #edf2ff;
  --text-dim: #9ca8bf;
  --text-muted: #66758f;
  --accent: #4f8cff;
  --accent-strong: #2f6de5;
  --accent-soft: rgba(79, 140, 255, 0.14);
  --green: #61d09b;
  --yellow: #f0c266;
  --red: #ef7272;
  --shadow-lg: 0 24px 56px rgba(0, 0, 0, 0.32);
  --topbar-h: 72px;
  --left-panel-w: 340px;
  --inspector-w: 340px;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(79, 140, 255, 0.18), transparent 30%),
    radial-gradient(circle at top right, rgba(97, 208, 155, 0.08), transparent 24%),
    var(--bg-app);
}

a {
  color: inherit;
}

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

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

#topbar {
  height: var(--topbar-h);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 20, 27, 0.94);
  backdrop-filter: blur(10px);
  position: relative;
  z-index: 3;
}

#builder-home-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 68px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(26, 32, 43, 0.88);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

#builder-home-link:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.topbar-project {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 220px;
  position: relative;
}

.topbar-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#project-name {
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  padding: 4px 8px;
  min-width: 220px;
  max-width: 360px;
}

#project-name:hover {
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.01);
}

#project-name:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(79, 140, 255, 0.08);
}

#project-name.has-error {
  border-color: var(--red);
  background: rgba(239, 114, 114, 0.08);
}

.inline-error {
  position: absolute;
  top: calc(100% + 2px);
  left: 8px;
  font-size: 11px;
  line-height: 1.2;
  color: var(--red);
  white-space: nowrap;
}

.topbar-status-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

#save-status,
.compile-badge,
.publish-chip,
.summary-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-dim);
}

#save-status.unsaved,
.unsaved {
  color: var(--yellow);
  border-color: rgba(240, 194, 102, 0.35);
  background: rgba(240, 194, 102, 0.12);
}

#save-status.saving,
.saving {
  color: var(--accent);
  border-color: rgba(79, 140, 255, 0.32);
  background: rgba(79, 140, 255, 0.12);
}

#save-status.saved,
.saved {
  color: var(--green);
  border-color: rgba(97, 208, 155, 0.32);
  background: rgba(97, 208, 155, 0.12);
}

#save-status.failed,
.failed {
  color: var(--red);
  border-color: rgba(239, 114, 114, 0.32);
  background: rgba(239, 114, 114, 0.12);
}

.compile-badge.done {
  color: var(--green);
  border-color: rgba(97, 208, 155, 0.32);
  background: rgba(97, 208, 155, 0.12);
}

.compile-badge.working {
  color: var(--yellow);
  border-color: rgba(240, 194, 102, 0.3);
  background: rgba(240, 194, 102, 0.12);
}

.compile-badge.error {
  color: var(--red);
  border-color: rgba(239, 114, 114, 0.3);
  background: rgba(239, 114, 114, 0.12);
}

.topbar-spacer {
  flex: 1;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(97, 208, 155, 0.32);
  background: rgba(97, 208, 155, 0.12);
  color: var(--green);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-decoration: none;
}

.live-badge:hover {
  filter: brightness(1.08);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn-ghost {
  background: var(--bg-panel);
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:not(:disabled):hover {
  background: var(--bg-panel-soft);
  border-color: var(--border-strong);
}

.btn-accent {
  background: linear-gradient(180deg, #5d98ff 0%, var(--accent-strong) 100%);
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.btn-accent:not(:disabled):hover {
  filter: brightness(1.06);
}

.btn-sm {
  min-height: 34px;
  padding: 0 12px;
  font-size: 11px;
}

#workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--left-panel-w) minmax(0, 1fr) var(--inspector-w);
}

#left-panel,
#inspector {
  min-height: 0;
  background: rgba(26, 32, 43, 0.92);
}

#left-panel {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
}

.workflow-rail {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.workflow-tab {
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.workflow-tab:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.workflow-tab.active {
  background: var(--accent-soft);
  border-color: rgba(79, 140, 255, 0.5);
  color: var(--accent);
}

#workflow-context {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(38, 50, 70, 0.55) 0%, rgba(26, 32, 43, 0.95) 100%);
  overflow: hidden;
  min-height: 144px;
}

.workflow-card {
  display: none;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
}

.workflow-card.active {
  display: flex;
}

.workflow-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.workflow-card-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.workflow-card-copy,
.workflow-card-meta {
  color: var(--text-dim);
  line-height: 1.5;
}

.target-workflow-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.workflow-card-detail {
  font-size: 12px;
  color: var(--text-muted);
}

.workflow-action {
  align-self: flex-start;
}

.panel-shell {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(17, 24, 35, 0.55);
  overflow: hidden;
}

.panel-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.panel-tab {
  min-height: 40px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.panel-tab.active {
  background: rgba(79, 140, 255, 0.14);
  color: var(--text);
}

.tab-content {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
}

.tab-content.active {
  display: flex;
}

.panel-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.panel-section-count {
  color: var(--text-muted);
}

#drop-zone {
  margin: 14px 14px 10px;
  padding: 20px 16px;
  border: 1.5px dashed var(--border-strong);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(79, 140, 255, 0.08) 0%, rgba(79, 140, 255, 0.03) 100%);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

#drop-zone:hover,
#drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(79, 140, 255, 0.12);
}

#drop-zone input[type="file"] {
  display: none;
}

.drop-zone-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.drop-zone-copy {
  color: var(--text-dim);
  line-height: 1.5;
}

#asset-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 14px 12px;
}

.filter-btn {
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
}

.filter-btn.active {
  background: var(--accent-soft);
  border-color: rgba(79, 140, 255, 0.5);
  color: var(--accent);
}

#asset-list,
#scene-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 10px 12px;
}

.asset-card,
.scene-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding: 12px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.02);
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.asset-card:hover,
.scene-item:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.06);
}

.scene-item.selected {
  background: rgba(79, 140, 255, 0.12);
  border-color: rgba(79, 140, 255, 0.42);
}

.scene-item.dragging {
  opacity: 0.58;
}

.scene-item.drop-before::before,
.scene-item.drop-after::after {
  content: '';
  position: absolute;
  left: 12px;
  right: 12px;
  height: 2px;
  border-radius: 999px;
  background: var(--accent);
  pointer-events: none;
}

.scene-item.drop-before::before {
  top: -5px;
}

.scene-item.drop-after::after {
  bottom: -5px;
}

.asset-icon,
.scene-icon {
  width: 28px;
  height: 28px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  flex-shrink: 0;
  font-size: 15px;
}

.asset-info,
.scene-main {
  flex: 1;
  min-width: 0;
}

.asset-name,
.scene-name {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.asset-meta,
.scene-meta {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 10px;
}

.scene-name-input {
  flex: 1;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--bg-input);
  color: var(--text);
  padding: 8px 10px;
  min-width: 0;
}

.asset-add-btn {
  opacity: 0;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(79, 140, 255, 0.42);
  background: rgba(79, 140, 255, 0.14);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.asset-card:hover .asset-add-btn {
  opacity: 1;
}

.scene-actions {
  display: flex;
  gap: 4px;
}

.scene-action-btn {
  width: 28px;
  height: 28px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.scene-action-btn:hover {
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

#viewport-area {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 18%),
    var(--bg-canvas);
}

#viewport-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}

.viewport-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}

.viewport-copy,
.viewport-toolbar-meta {
  color: var(--text-dim);
  line-height: 1.5;
}

.viewport-nudge-hint {
  display: block;
  font-size: 11px;
  margin-top: 4px;
  opacity: 0.6;
}

#viewport-canvas {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px) 0 0 / 32px 32px,
    radial-gradient(circle at center, rgba(79, 140, 255, 0.08), transparent 40%);
}
#viewport-canvas:focus-visible {
  outline: 2px solid rgba(91, 142, 240, 0.45);
  outline-offset: -2px;
}

#target-frame {
  position: relative;
  border: 1px solid rgba(79, 140, 255, 0.5);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.01)),
    #121824;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.03), var(--shadow-lg);
  overflow: hidden;
}

#target-frame::after {
  content: "";
  position: absolute;
  inset: 14px;
  border: 1px dashed rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  pointer-events: none;
}

#target-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#target-label {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 1;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(13, 17, 24, 0.72);
  border: 1px solid rgba(79, 140, 255, 0.35);
  color: var(--text);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.viewport-object {
  position: absolute;
  border: 1px dashed rgba(79, 140, 255, 0.45);
  border-radius: 14px;
  background: rgba(79, 140, 255, 0.12);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  padding: 8px;
  backdrop-filter: blur(4px);
}
.viewport-object:hover {
  border-color: rgba(79, 140, 255, 0.7);
}

.viewport-object.selected {
  border-style: solid;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(79, 140, 255, 0.2);
  background: rgba(79, 140, 255, 0.18);
}

.viewport-object-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.viewport-object .obj-icon {
  font-size: 20px;
  pointer-events: none;
}
.viewport-object .obj-label {
  max-width: 100%;
  margin-top: 6px;
  padding: 0 4px;
  color: var(--text);
  font-size: 10px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.viewport-handle {
  position: absolute;
  padding: 0;
  border: 1px solid rgba(255,255,255,.45);
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  appearance: none;
  cursor: pointer;
  border-radius: 999px;
  box-shadow: 0 4px 10px rgba(0,0,0,.35);
}
.viewport-handle:hover { background: var(--accent-dim); }
.move-handle {
  width: 24px;
  height: 24px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  cursor: grab;
  font-size: 12px;
  line-height: 1;
}
.move-handle:active { cursor: grabbing; }
.scale-handle {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  padding: 0;
}
.scale-handle.nw { left: -7px; top: -7px; cursor: nwse-resize; }
.scale-handle.ne { right: -7px; top: -7px; cursor: nesw-resize; }
.scale-handle.sw { left: -7px; bottom: -7px; cursor: nesw-resize; }
.scale-handle.se { right: -7px; bottom: -7px; cursor: nwse-resize; }

#viewport-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-dim);
  text-align: center;
  pointer-events: none;
  padding: 24px;
}

#viewport-empty .empty-icon {
  font-size: 36px;
  opacity: 0.55;
}

.empty-title {
  font-size: 18px;
  font-weight: 600;
}

.empty-copy {
  max-width: 360px;
  line-height: 1.6;
}

#inspector {
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.inspector-section {
  border-bottom: 1px solid var(--border);
  padding: 16px;
}

.inspector-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.field-label {
  width: 84px;
  flex-shrink: 0;
  color: var(--text-dim);
  font-size: 11px;
}

.field-inputs {
  flex: 1;
  display: flex;
  gap: 6px;
}

.text-input,
.select-input,
.num-input,
input[type="range"] {
  width: 100%;
}

.text-input,
.select-input,
.num-input {
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--bg-input);
  color: var(--text);
  padding: 9px 10px;
}

.text-input:focus,
.select-input:focus,
.num-input:focus,
.scene-name-input:focus {
  outline: none;
  border-color: var(--accent);
}

.num-input {
  min-width: 0;
  text-align: right;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.toggle-label {
  color: var(--text);
  font-size: 12px;
}

.toggle {
  position: relative;
  width: 38px;
  height: 22px;
}

.toggle input {
  display: none;
}

.toggle-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s ease;
}

.toggle input:checked + .toggle-track {
  background: rgba(79, 140, 255, 0.24);
  border-color: rgba(79, 140, 255, 0.5);
}

.toggle input:checked + .toggle-track::after {
  transform: translateX(16px);
}

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

#inspector-empty {
  padding: 28px 22px;
  color: var(--text-dim);
  line-height: 1.7;
}

.target-thumb {
  width: 100%;
  display: block;
  margin-bottom: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  object-fit: cover;
  max-height: 160px;
}

.target-upload-spinner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--text-dim);
}

.target-status {
  margin-bottom: 10px;
  font-size: 12px;
}

.target-meta {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.target-inline-error {
  font-size: 12px;
  line-height: 1.4;
  color: var(--red);
}

.target-status.idle {
  color: var(--text-muted);
}

.target-status.working {
  color: var(--yellow);
}

.target-status.done {
  color: var(--green);
}

.target-status.error {
  color: var(--red);
}

.compile-error-box {
  margin: 0 0 10px;
  padding: 10px;
  border: 1px solid rgba(239, 114, 114, 0.35);
  border-radius: 10px;
  background: rgba(239, 114, 114, 0.08);
}

.compile-error-box-title {
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--red);
}

.compile-error-box-message {
  margin-bottom: 10px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text);
}

.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Publish readiness indicators ────────────────────────────────────────── */
#readiness-indicators {
  display: flex;
  gap: 4px;
  align-items: center;
}
.ready-indicator {
  font-size: 13px;
  cursor: default;
  opacity: 0.5;
  transition: opacity .2s, color .2s;
}
.ready-indicator.ready {
  opacity: 1;
  color: var(--green);
}
.ready-indicator.not-ready {
  opacity: 0.45;
  color: var(--text-muted);
}

.publish-inline-error {
  position: absolute;
  top: var(--topbar-h);
  right: 12px;
  background: #3d1e1e;
  color: var(--red);
  border: 1px solid #6b2a2a;
  border-radius: 5px;
  padding: 7px 12px;
  font-size: 12px;
  z-index: 100;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
}

#toast-container {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 250;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  min-width: 240px;
  max-width: min(360px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(26, 32, 43, 0.96);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.35);
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
  pointer-events: auto;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast-error {
  border-color: rgba(239, 114, 114, 0.35);
  background: rgba(61, 30, 30, 0.94);
}

.toast-warning {
  border-color: rgba(240, 194, 102, 0.35);
  background: rgba(45, 45, 26, 0.96);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.66);
  backdrop-filter: blur(4px);
}

.modal-backdrop.hidden {
  display: none;
}

.modal {
  width: 460px;
  max-width: min(92vw, 560px);
  max-height: 90vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(38, 50, 70, 0.28), rgba(26, 32, 43, 0.98));
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 15px;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 12px 20px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.preview-modal {
  width: 560px;
}

.preview-state {
  text-align: center;
}

.preview-loading-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 4px auto 14px;
  animation: preview-spin 0.8s linear infinite;
}

.preview-loading-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
}

.preview-loading-copy {
  font-size: 12px;
  color: var(--text-dim);
  max-width: 280px;
  margin: 0 auto;
  line-height: 1.5;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
  text-align: left;
}

.preview-panel {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.preview-panel-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

#preview-qr-img,
.preview-target-thumb {
  display: block;
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
}

#preview-qr-img {
  max-width: 200px;
  margin: 0 auto;
  padding: 8px;
}

.preview-target-thumb {
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: #151519;
}

.preview-url-link {
  display: inline-block;
  max-width: 100%;
  font-size: 12px;
  color: var(--accent);
  word-break: break-all;
}

.preview-note {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 14px;
  line-height: 1.5;
}

.preview-error-title {
  color: var(--red);
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 10px;
}

.preview-error-msg {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
}

@keyframes preview-spin {
  to {
    transform: rotate(360deg);
  }
}

.publish-checklist {
  margin-bottom: 16px;
}

.check-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
}

.check-icon {
  width: 18px;
  text-align: center;
  padding-top: 1px;
}

.check-copy {
  flex: 1;
  min-width: 0;
}

.check-item.ok .check-icon::after {
  content: "✓";
  color: var(--green);
}

.check-item.fail .check-icon::after {
  content: "✗";
  color: var(--red);
}

.check-item.warn .check-icon::after {
  content: "⚠";
  color: var(--yellow);
}

.check-details {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-muted);
  white-space: pre-line;
}

.publish-progress,
.publish-success {
  text-align: center;
}

.preview-url,
.publish-url {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text-dim);
  font-size: 12px;
  word-break: break-all;
}

.qr-downloads {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.publish-history-section {
  margin-top: 20px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.publish-history-header {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.publish-history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
}

.history-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
}

.history-entry.latest {
  border-color: rgba(79, 140, 255, 0.42);
  background: rgba(79, 140, 255, 0.08);
}

.history-entry-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-entry-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.history-url {
  font-size: 11px;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: none;
}

.history-url:hover {
  text-decoration: underline;
}

.history-date {
  font-size: 10px;
  color: var(--text-muted);
}

.qr-lightbox-inner {
  position: relative;
  background: linear-gradient(180deg, rgba(38, 50, 70, 0.28), rgba(26, 32, 43, 0.98));
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
}

.qr-lightbox-inner img {
  max-width: 240px;
  display: block;
  border-radius: 10px;
  background: #fff;
  padding: 8px;
}

.qr-lightbox-close-btn {
  position: absolute;
  top: 8px;
  right: 8px;
}

#dashboard {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 48px 24px;
}

#dashboard h1 {
  font-size: 24px;
  font-weight: 700;
}

.dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.project-card {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(26, 32, 43, 0.86);
  cursor: pointer;
}

.project-card:hover {
  border-color: var(--border-strong);
}

.project-card-name {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-card-meta {
  color: var(--text-muted);
  font-size: 11px;
}

.project-status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin-top: 10px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.status-draft {
  background: rgba(240, 194, 102, 0.12);
  color: var(--yellow);
}

.status-published {
  background: rgba(97, 208, 155, 0.12);
  color: var(--green);
}

.status-compiled {
  background: rgba(79, 140, 255, 0.12);
  color: var(--accent);
}

.project-card-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.project-live-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid rgba(97, 208, 155, 0.32);
  background: rgba(97, 208, 155, 0.12);
  color: var(--green);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-decoration: none;
}

.project-live-badge:hover {
  filter: brightness(1.1);
}

.project-card-actions {
  display: none;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.project-card:hover .project-card-actions {
  display: flex;
}

#new-project-modal .modal {
  width: 380px;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.hidden {
  display: none !important;
}

.text-muted {
  color: var(--text-muted);
}

.text-dim {
  color: var(--text-dim);
}

@media (max-width: 1023px) {
  #builder-view,
  #dashboard-view {
    display: none !important;
  }

  body::after {
    content: 'AR Builder requires a desktop browser (1024 px or wider).';
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    color: var(--text-dim);
    text-align: center;
    line-height: 1.6;
  }
}
