/* H5 AR Studio — zh-Hant-HK */
:root {
  --bg: #0b1220;
  --panel: #121a2b;
  --panel2: #182235;
  --border: #243049;
  --text: #e8eefc;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent2: #60a5fa;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
  --shadow: 0 12px 40px rgba(0,0,0,.35);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang HK", "Helvetica Neue", sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  width: 100%;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
  overflow-x: hidden;
}
button, input, select { font: inherit; }
a { color: var(--accent2); }
.app {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 12px 16px 16px;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  overflow: hidden;
  min-height: 0;
}
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px; flex-shrink: 0;
}
.brand h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: .02em; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  background: rgba(59,130,246,.15); color: var(--accent2);
  font-size: 12px; font-weight: 600;
}
#statusLine { flex-shrink: 0; margin-bottom: 12px; }
.layout {
  display: grid;
  grid-template-columns: minmax(320px, 400px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 16px;
  flex: 1 1 0%;
  min-height: 0;
  overflow: hidden;
  width: 100%;
}
@media (min-width: 1600px) {
  .layout {
    grid-template-columns: 420px minmax(0, 1fr);
  }
}
.left-shell {
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}
.editor-scroll {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow-y: scroll !important;
  overflow-x: hidden !important;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding-right: 8px;
  padding-bottom: 48px;
  scrollbar-gutter: stable;
}
.editor-scroll .card {
  overflow: visible;
  flex-shrink: 0;
}
.preview-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
}
.preview-pane > .body { flex-shrink: 0; }
@media (max-width: 960px) {
  html, body {
    height: auto; max-height: none; overflow: auto;
  }
  .app {
    height: auto; max-height: none; overflow: visible;
  }
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    height: auto;
    max-height: none;
    overflow: visible;
  }
  .left-shell {
    height: auto;
    max-height: none;
    overflow: visible;
  }
  .layout > .editor-scroll,
  #editor.editor-scroll {
    height: auto;
    max-height: none;
    overflow: visible;
  }
  .preview-pane { height: auto; max-height: none; overflow: visible; }
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card h2 {
  margin: 0; padding: 14px 16px;
  font-size: 14px; font-weight: 700;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,.03), transparent);
  flex-shrink: 0;
}
.card .body { padding: 14px 16px 16px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
label.field {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 12px; color: var(--muted); font-weight: 600;
}
label.field > input, label.field > select, label.field > textarea {
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; outline: none;
}
label.field > input:focus, label.field > select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,.25);
}
input[type="color"] {
  height: 42px; padding: 4px; cursor: pointer;
}
input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.btn {
  appearance: none; border: none; cursor: pointer;
  border-radius: 999px; padding: 10px 16px;
  font-weight: 700; font-size: 13px;
  background: var(--accent); color: #fff;
  box-shadow: 0 8px 20px rgba(59,130,246,.35);
  transition: transform .12s ease, opacity .12s;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.secondary {
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); box-shadow: none;
}
.btn.danger { background: var(--danger); box-shadow: 0 8px 20px rgba(239,68,68,.3); }
.btn.ghost {
  background: transparent; color: var(--muted);
  border: 1px dashed var(--border); box-shadow: none;
}
.project-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 280px; overflow: auto; }
.project-list li button {
  width: 100%; text-align: left;
  background: var(--panel2); border: 1px solid var(--border);
  color: var(--text); border-radius: 12px; padding: 10px 12px; cursor: pointer;
}
.project-list li button.active {
  border-color: var(--accent); background: rgba(59,130,246,.12);
}
.project-list .meta { display: block; margin-top: 4px; font-size: 11px; color: var(--muted); }
.templates {
  display: grid; grid-template-columns: 1fr; gap: 8px;
}
.tpl {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--panel2);
  cursor: pointer;
}
.tpl input { margin-top: 3px; }
.tpl.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.tpl strong { display: block; font-size: 13px; }
.tpl span { font-size: 11px; color: var(--muted); line-height: 1.35; }
.preview-wrap {
  position: relative;
  flex: 1;
  min-height: 320px;
  background: radial-gradient(1200px 500px at 50% -10%, #1e293b, #0b1220 60%);
}
#previewCanvas, .preview-wrap canvas {
  width: 100% !important;
  height: 100% !important;
  min-height: 280px;
  display: block;
}
@media (max-width: 960px) {
  .preview-wrap { min-height: 420px; flex: none; }
  #previewCanvas, .preview-wrap canvas { height: 420px !important; }
}
.preview-hud {
  position: absolute; left: 12px; top: 12px; right: 12px;
  display: flex; justify-content: space-between; gap: 8px; pointer-events: none;
}
.chip {
  pointer-events: none;
  background: rgba(0,0,0,.45); backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 999px; padding: 6px 10px; font-size: 11px; color: #dbeafe;
}
.marker-preview {
  width: 100%; max-height: 140px; object-fit: contain;
  background: #fff; border-radius: 10px; border: 1px solid var(--border);
}
.hint { font-size: 12px; color: var(--muted); line-height: 1.45; }
.status-line {
  font-size: 12px; padding: 8px 10px; border-radius: 10px;
  background: rgba(34,197,94,.12); color: #86efac; border: 1px solid rgba(34,197,94,.25);
}
.status-line.warn { background: rgba(245,158,11,.12); color: #fcd34d; border-color: rgba(245,158,11,.25); }
.status-line.err { background: rgba(239,68,68,.12); color: #fca5a5; border-color: rgba(239,68,68,.25); }
.drop {
  border: 1.5px dashed var(--border); border-radius: 12px;
  padding: 16px; text-align: center; color: var(--muted); font-size: 12px;
  background: rgba(255,255,255,.02); cursor: pointer;
}
.drop.drag { border-color: var(--accent); color: var(--accent2); }
.params-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
@media (max-width: 520px) { .params-grid { grid-template-columns: 1fr; } }
.slider-val { font-variant-numeric: tabular-nums; color: var(--text); }
.orient-block {
  display: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: rgba(255,255,255,.02);
}
.orient-block.visible { display: block; }
.orient-block .orient-title {
  font-size: 12px; font-weight: 700; color: var(--muted);
  margin-bottom: 10px;
}
hr.sep { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* ---- 2D layers studio ---- */
.layer-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 6px;
  max-height: 220px; overflow: auto;
}
.layer-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 10px;
  background: var(--panel2); border: 1px solid var(--border);
  cursor: grab; user-select: none;
}
.layer-list li.active { border-color: var(--accent); background: rgba(59,130,246,.12); }
.layer-list li .layer-name { flex: 1; font-size: 13px; font-weight: 600; }
.layer-list li .layer-meta { font-size: 10px; color: var(--muted); }
.layer-list .icon-btn {
  appearance: none; border: 1px solid var(--border);
  background: transparent; color: var(--muted);
  border-radius: 8px; padding: 2px 6px; cursor: pointer; font-size: 11px;
}
.layer-list .icon-btn.on { color: var(--accent2); border-color: var(--accent); }
.layer-inspector {
  border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; background: rgba(255,255,255,.02);
}
.timeline-bar {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--panel2);
}
.timeline-tracks {
  padding: 0 12px 10px;
  max-height: 120px; overflow: auto;
  display: flex; flex-direction: column; gap: 4px;
}
.tl-track {
  display: grid; grid-template-columns: 88px 1fr; gap: 8px; align-items: center;
  font-size: 11px; color: var(--muted);
}
.tl-track-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-track-bar {
  position: relative; height: 18px; border-radius: 6px;
  background: #0b1220; border: 1px solid var(--border);
}
.tl-kf {
  position: absolute; top: 2px; width: 8px; height: 12px;
  margin-left: -4px; background: var(--accent2); border-radius: 2px;
  cursor: pointer;
}
.tl-kf.tl-kf-flash {
  background: #fde68a;
  box-shadow: 0 0 0 3px rgba(250, 204, 21, .45);
  animation: kfFlash 1.1s ease-out;
}
@keyframes kfFlash {
  0% { transform: scaleY(1.6); background: #fff; }
  100% { transform: scaleY(1); }
}
.layers2d-canvas {
  position: absolute; inset: 0; width: 100% !important; height: 100% !important;
  /* Mild default tilt (~5°) so Z-distance is visible without hunting for a toggle */
  transform: perspective(1100px) rotateX(5deg) rotateY(-3deg);
  transform-origin: 50% 58%;
  transition: transform .25s ease;
}
.preview-pane.mode-2d .preview-wrap { position: relative; }
.preview-pane.mode-2d .preview-hud .chip::after { content: none; }

/* Stronger 「立體預覽」 tilt (~25°) when toggle is on */
.layers2d-canvas.stereo-tilt {
  transform: perspective(920px) rotateX(22deg) rotateY(-12deg);
}
.preview-pane.mode-2d .preview-wrap {
  perspective: 1000px;
  overflow: hidden;
}
#btnStereoPreview.on {
  border-color: var(--accent);
  color: var(--accent2);
  background: rgba(59,130,246,.15);
}

.tl-kf.tl-kf-selected {
  background: #f472b6;
  box-shadow: 0 0 0 2px rgba(244, 114, 182, .55);
  width: 10px;
  margin-left: -5px;
}
.kf-ctx-menu {
  position: fixed;
  z-index: 10000;
  min-width: 128px;
  display: none;
  background: var(--panel2, #111827);
  border: 1px solid var(--border, #334155);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(0,0,0,.45);
  padding: 4px;
}
.kf-ctx-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text, #e5e7eb);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.kf-ctx-menu button:hover {
  background: rgba(239, 68, 68, .22);
  color: #fca5a5;
}

.layer-inspector .check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
}
.layer-inspector .check input { width: auto; margin: 0; }
