:root {
  --bg: #fff3e6;
  --bg-soft: #ffe8d4;
  --surface: #ffffff;
  --surface-soft: #ffe0c8;
  --line: #f0c9a8;
  --text: #3a2418;
  --muted: #8a6a55;
  --ink: #3a2418;
  --coral: #ff6b57;
  --coral-dark: #e85542;
  --sun: #ffd44a;
  --sun-dark: #f0c030;
  --mint: #5fd08a;
  --sky: #5ba3ff;
  --danger: #ff6b57;
  --ok: #5fd08a;
  --bed: #fff8ef;
  --bed-edge: #f0c9a8;
  --shadow-toy: 4px 6px 0 rgba(58, 36, 24, 0.12);
  --shadow-soft: 0 8px 24px rgba(58, 36, 24, 0.08);
  --radius-sm: 16px;
  --radius-md: 24px;
  --radius-lg: 32px;
  --radius-pill: 999px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 "Fredoka", "Segoe UI", system-ui, sans-serif;
}

button,
input {
  font: inherit;
}

body.screen-landing {
  overflow: auto;
}

body.screen-editor {
  overflow: hidden;
  overscroll-behavior: none;
}

.is-hidden {
  display: none !important;
}

/* -------------------------------- buttons --------------------------------- */

.btn {
  border: 0;
  border-radius: var(--radius-pill);
  padding: 10px 18px;
  cursor: pointer;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow-toy);
  font-weight: 600;
  touch-action: manipulation;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.btn:active:not(:disabled) {
  transform: translate(2px, 2px);
  box-shadow: 2px 3px 0 rgba(58, 36, 24, 0.12);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.primary {
  background: linear-gradient(180deg, var(--coral), var(--coral-dark));
  color: #fff;
  font-weight: 700;
}

.btn.ghost {
  background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--line);
}

/* -------------------------------- brand ----------------------------------- */

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.brand-mark {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: block;
  transition: transform 0.12s ease;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.brand-btn {
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  text-align: left;
  color: inherit;
  min-width: 0;
}

.brand-btn:hover .brand-mark {
  transform: scale(1.05);
}

/* ================================ LANDING ================================= */

.landing {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.landing-header {
  padding: 20px 24px;
}

.landing-main {
  flex: 1;
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
  padding: 0 24px 48px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.landing-hero {
  text-align: center;
}

.landing-hero h2 {
  margin: 0 0 10px;
  font-size: clamp(28px, 5vw, 42px);
  font-weight: 700;
  line-height: 1.15;
  color: var(--text);
}

.landing-hero p {
  margin: 0 auto;
  max-width: 520px;
  color: var(--muted);
  font-size: 16px;
  font-weight: 500;
}

.landing-drop {
  position: relative;
  background: var(--surface);
  border: 3px dashed var(--line);
  border-radius: var(--radius-lg);
  padding: 40px 28px;
  text-align: center;
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.landing-drop:hover,
.landing-drop:focus-visible {
  border-color: var(--coral);
  background: #fffaf5;
  outline: none;
}

.landing-drop.is-drop {
  border-color: var(--coral);
  background: var(--surface-soft);
  transform: scale(1.01);
}

.landing-drop-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 12px;
  border: 3px dashed var(--muted);
  border-radius: var(--radius-md);
  position: relative;
  opacity: 0.7;
}

.landing-drop-icon::before,
.landing-drop-icon::after {
  content: "";
  position: absolute;
  background: var(--muted);
  border-radius: 2px;
}

.landing-drop-icon::before {
  width: 28px;
  height: 3px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.landing-drop-icon::after {
  width: 3px;
  height: 28px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.landing-drop h3 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
}

.landing-drop p {
  margin: 0 0 18px;
  color: var(--muted);
  font-weight: 500;
}

.landing-drop-actions {
  position: relative;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  align-items: center;
}

.landing-drop-actions .btn {
  position: relative;
  z-index: 2;
}

.landing-status {
  margin: 12px 0 0;
  color: var(--coral-dark);
  font-weight: 600;
  font-size: 14px;
}

.landing-status[hidden] {
  display: none;
}

.landing-examples h3,
.landing-steps {
  text-align: center;
}

.landing-examples h3 {
  margin: 0 0 14px;
  font-size: 16px;
  font-weight: 600;
  color: var(--muted);
}

.example-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.example-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px 12px;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-toy);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  min-height: 44px;
}

.example-card:hover {
  transform: translateY(-2px);
  box-shadow: 6px 8px 0 rgba(58, 36, 24, 0.12);
}

.example-card:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 3px 0 rgba(58, 36, 24, 0.12);
}

.example-preview {
  width: 100%;
  aspect-ratio: 1;
  background: var(--bed);
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  padding: 12px;
}

.example-preview svg {
  width: 100%;
  height: 100%;
}

.example-label {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.landing-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.step-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 18px 12px;
  background: var(--surface-soft);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-toy);
}

.step-icon {
  font-size: 28px;
  line-height: 1;
}

.step-card strong {
  font-size: 15px;
  font-weight: 700;
}

.step-card span:last-child {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  text-align: center;
}

/* ================================ EDITOR ================================== */

.editor {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: nowrap;
  gap: 16px;
  padding: 14px 20px;
  min-width: 0;
  background: var(--surface);
  border-bottom: 2px solid var(--line);
  box-shadow: var(--shadow-soft);
}

.top-actions,
.stage-toolbar,
.stage-tools,
.tabs {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-actions {
  flex: 0 0 auto;
  flex-wrap: nowrap;
}

.stage-tools {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.stage {
  padding: 16px 18px 18px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.stage-toolbar {
  justify-content: space-between;
  flex-wrap: wrap;
}

.tabs {
  background: var(--surface-soft);
  border: 2px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 4px;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
}

.tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-toy);
}

.tab:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.bed {
  position: relative;
  min-height: 0;
  height: 100%;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, #fffaf5, var(--bed));
  box-shadow: var(--shadow-toy), inset 0 0 0 2px var(--bed-edge);
  overflow: hidden;
}

.frame {
  position: absolute;
  inset: 18px;
}

.frame img,
.svg-layer,
.svg-layer svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.svg-layer svg {
  display: block;
}

.frame.is-original #binaryImg,
.frame.is-original #svgLayer,
.frame.is-binary #originalImg,
.frame.is-binary #svgLayer,
.frame.is-svg #originalImg,
.frame.is-svg #binaryImg {
  opacity: 0;
  pointer-events: none;
}

.frame.is-overlay #binaryImg {
  opacity: 0;
  pointer-events: none;
}

.frame.is-overlay #svgLayer {
  mix-blend-mode: multiply;
}

.frame.is-rejected #originalImg,
.frame.is-rejected #binaryImg,
.frame.is-rejected #svgLayer {
  filter: grayscale(0.45) brightness(0.62);
}

.reject-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(58, 36, 24, 0.35);
  pointer-events: none;
}

.reject-overlay[hidden] {
  display: none;
}

.frame.is-rejected .reject-overlay {
  animation: reject-fade 0.28s ease-out;
}

.reject-stamp {
  transform: rotate(-8deg);
  text-align: center;
  color: var(--coral-dark);
  background: rgba(255, 255, 255, 0.96);
  border: 4px solid var(--coral);
  box-shadow: var(--shadow-toy);
  border-radius: var(--radius-md);
  padding: 16px 24px 18px;
  max-width: min(320px, 86%);
}

.reject-stamp strong {
  display: block;
  font-size: clamp(26px, 6vw, 40px);
  letter-spacing: 0.12em;
  line-height: 1;
  text-transform: uppercase;
  font-weight: 700;
}

.reject-stamp span {
  display: block;
  margin-top: 8px;
  font-size: 14px;
  font-weight: 650;
}

.reject-stamp em {
  display: block;
  margin-top: 6px;
  font-style: normal;
  font-size: 12px;
  line-height: 1.35;
  color: var(--muted);
}

@keyframes reject-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* crop */

.crop-ui {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  z-index: 4;
  background: linear-gradient(180deg, #fffaf5, var(--bed));
}

.crop-stage {
  position: relative;
  min-height: 0;
  margin: 14px;
  overflow: hidden;
  border-radius: var(--radius-md);
  background:
    linear-gradient(45deg, #f0e4d4 25%, transparent 25%) 0 0 / 18px 18px,
    linear-gradient(-45deg, #f0e4d4 25%, transparent 25%) 0 0 / 18px 18px,
    #faf3ea;
  cursor: grab;
  touch-action: none;
}

.crop-stage.is-dragging {
  cursor: grabbing;
}

.crop-world {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.crop-world img {
  display: block;
  max-width: none;
  user-select: none;
  pointer-events: none;
  box-shadow: var(--shadow-soft);
  border-radius: 8px;
}

.crop-frame {
  position: absolute;
  inset: 10px;
  border: 3px solid var(--coral);
  border-radius: var(--radius-sm);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5);
  pointer-events: none;
}

.crop-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 14px 14px;
  color: var(--ink);
}

.crop-hint {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.crop-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.crop-ui .btn {
  color: var(--ink);
}

/* busy */

.busy {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  background: rgba(58, 36, 24, 0.4);
  color: #fff;
  text-align: center;
  padding: 24px;
  font-weight: 600;
  font-size: 16px;
}

.bed.is-busy .frame img,
.bed.is-busy .svg-layer {
  filter: brightness(0.85);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: var(--sun);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.status {
  margin: 0;
  color: var(--muted);
  min-height: 1.45em;
  font-weight: 500;
}

.status.is-error {
  color: var(--danger);
  font-weight: 600;
}

/* panel / settings */

.panel {
  border-left: 2px solid var(--line);
  background: var(--surface);
  overflow: hidden;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.panel-handle {
  display: none;
}

.panel-body {
  padding: 18px 18px 28px;
  overflow: auto;
  flex: 1;
  min-height: 0;
}

.panel h2 {
  margin: 18px 0 12px;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}

.panel h2:first-child {
  margin-top: 0;
}

.field,
.check {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}

.field span {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.field strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.check {
  grid-template-columns: auto 1fr;
  align-items: start;
  color: var(--text);
  font-size: 14px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--coral);
}

.panel-hint {
  margin: -6px 0 16px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
  font-weight: 500;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 18px 0 0;
}

.stats div {
  background: var(--surface-soft);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
}

.stats dt {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.stats dd {
  margin: 4px 0 0;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

/* disc + demo */

.stage-panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  min-height: 0;
}

.sheet-toolbar,
.sheet-actions,
.demo-buttons,
.demo-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.sheet-toolbar {
  justify-content: space-between;
}

.tabs-sm {
  padding: 3px;
}

.tabs-sm .tab {
  padding: 6px 10px;
  font-size: 13px;
}

.stage-panel .tabs {
  background: rgba(255, 255, 255, 0.85);
  border-color: var(--bed-edge);
}

.stage-panel .tab {
  color: var(--muted);
}

.stage-panel .tab.is-active {
  background: var(--surface);
  color: var(--ink);
}

.stage-panel .btn {
  color: var(--ink);
  font-size: 13px;
  padding: 7px 11px;
}

.stage-panel .btn.ghost {
  background: var(--surface);
}

.sheet-preview {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.sheet-viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  border-radius: var(--radius-sm);
}

.sheet-viewport.is-dragging {
  cursor: grabbing;
}

.sheet-world {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.sheet-world svg {
  display: block;
  background: #ffffff;
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
  user-select: none;
  pointer-events: none;
}

.sheet-hint {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.sheet-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  color: var(--muted);
  text-align: center;
  max-width: 320px;
  justify-self: center;
  align-self: center;
  font-weight: 500;
}

.preview-3d {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preview-3d-viewport {
  position: relative;
  flex: 1;
  min-height: 0;
}

.preview-3d-viewport canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  border-radius: var(--radius-md);
  background: #5a5048;
  touch-action: none;
}

.preview-3d-busy {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  background: rgba(58, 36, 24, 0.8);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  pointer-events: none;
}

.preview-3d-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.preview-3d-hint {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.demo-viewport {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
}

.demo-layers {
  position: relative;
  aspect-ratio: 1 / 1;
  height: 100%;
  max-height: 100%;
  max-width: 100%;
}

@supports (width: 1cqmin) {
  .demo-viewport {
    container-type: size;
  }

  .demo-layers {
    width: min(100cqw, 100cqh);
    height: min(100cqw, 100cqh);
    max-width: none;
    max-height: none;
  }
}

.demo-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.demo-paper circle {
  filter: drop-shadow(0 6px 16px rgba(58, 36, 24, 0.15));
}

.demo-ink {
  pointer-events: none;
}

.demo-disc {
  transform-origin: 50% 50%;
  transition:
    transform var(--rot-dur, 0ms) cubic-bezier(0.4, 0, 0.2, 1),
    opacity 420ms ease;
}

.demo-disc-body {
  fill: #fff8ef;
  fill-opacity: 0.87;
  stroke: #c9b89a;
  stroke-width: 0.5;
}

.demo-hub {
  fill: #3a352c;
}

.demo-slot {
  stroke: #857c6c;
}

.demo-slot.is-hole {
  fill: #857c6c;
  stroke: none;
}

.demo-slot.is-active {
  stroke: var(--coral);
}

.demo-slot.is-hole.is-active {
  fill: var(--coral);
  stroke: none;
}

.demo-mark line {
  stroke: #453f34;
}

.demo-mark text {
  fill: #453f34;
}

.demo-mark.is-active line {
  stroke: var(--coral);
  stroke-width: 0.9;
}

.demo-mark.is-active text {
  fill: var(--coral);
  font-weight: bold;
}

.demo-frag-leader {
  stroke: #8d7f66;
  stroke-width: 0.35;
  opacity: 0.75;
}

.demo-frag.is-active .demo-frag-leader {
  stroke: var(--coral);
  opacity: 1;
}

.demo-frag.is-active .demo-frag-label {
  fill: var(--coral);
}

.demo-layers.is-done .demo-disc,
.demo-layers.is-disc-hidden .demo-disc {
  opacity: 0.08;
}

.demo-controls {
  display: grid;
  gap: 8px;
  color: var(--ink);
}

.demo-progress {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color: var(--ink);
  background: var(--surface);
  border-radius: var(--radius-pill);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: inset 0 0 0 2px var(--line);
}

.demo-speed {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.demo-speed input[type="range"] {
  width: 130px;
}

.demo-speed strong {
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  font-weight: 700;
}

.check.inline {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.demo-hint {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  min-height: 1.4em;
  font-weight: 500;
}

.stats-two {
  grid-template-columns: 1fr 1fr;
}

.bed.is-drop {
  outline: 3px dashed var(--coral);
  outline-offset: -10px;
}

.label-short {
  display: none;
}

@keyframes preview-hint-fade {
  0%, 55% { opacity: 1; }
  100% { opacity: 0; }
}

/* ============================== RESPONSIVE ================================ */

@media (max-width: 960px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
  }

  .panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    height: auto;
    max-height: 70vh;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    border-left: 0;
    border-top: 2px solid var(--line);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: 0 -8px 32px rgba(58, 36, 24, 0.12);
    transform: translateY(calc(100% - 48px - env(safe-area-inset-bottom, 0px)));
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .panel.is-open {
    transform: translateY(0);
  }

  .panel-handle {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 16px;
    border: 0;
    background: var(--surface-soft);
    cursor: pointer;
    color: var(--text);
    min-height: 48px;
  }

  .panel-handle-title {
    font-weight: 700;
    font-size: 15px;
  }

  .panel-handle-mini {
    margin-left: auto;
    font-size: 13px;
    color: var(--muted);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
  }

  .panel-handle-chevron {
    width: 10px;
    height: 10px;
    border-right: 2.5px solid var(--muted);
    border-bottom: 2.5px solid var(--muted);
    transform: rotate(225deg);
    transition: transform 0.2s ease;
    flex-shrink: 0;
  }

  .panel.is-open .panel-handle-chevron {
    transform: rotate(45deg);
  }

  .panel-body {
    max-height: calc(70vh - 48px);
  }

  .stage {
    padding: 10px 12px calc(56px + env(safe-area-inset-bottom, 0px));
    gap: 8px;
  }

  .editor[data-view="disc"] .stage,
  .editor[data-view="demo"] .stage {
    padding-bottom: 8px;
  }

  .editor[data-view="disc"] .status,
  .editor[data-view="demo"] .status {
    display: none;
  }

  .topbar {
    flex-wrap: nowrap;
    padding: 8px 10px;
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
    gap: 8px;
  }

  .brand {
    gap: 8px;
    flex: 1 1 auto;
  }

  .brand p {
    display: none;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
  }

  .brand h1 {
    font-size: 16px;
  }

  .top-actions {
    flex-wrap: nowrap;
    flex: 0 0 auto;
    gap: 6px;
  }

  .top-actions .btn {
    white-space: nowrap;
    padding: 7px 10px;
    font-size: 13px;
  }

  @media (max-width: 480px) {
    .topbar .brand h1 {
      display: none;
    }
  }

  .editor[data-view="disc"] #downloadBtn,
  .editor[data-view="demo"] #downloadBtn {
    display: none;
  }

  /* Full-bleed 2D / 3D / demo inside the bed */
  .editor[data-view="disc"] .stage-panel,
  .editor[data-view="demo"] .stage-panel {
    padding: 0;
    gap: 0;
  }

  .editor[data-view="disc"] .sheet-toolbar {
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    z-index: 5;
    flex-wrap: nowrap;
    pointer-events: none;
  }

  .editor[data-view="disc"] .sheet-toolbar > * {
    pointer-events: auto;
  }

  .editor[data-view="disc"] .sheet-actions {
    flex-wrap: nowrap;
    margin-left: auto;
  }

  .editor[data-view="disc"] .sheet-toolbar .tabs,
  .editor[data-view="disc"] .sheet-toolbar .btn {
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--shadow-toy);
    backdrop-filter: blur(10px);
  }

  .editor[data-view="disc"] .sheet-preview,
  .editor[data-view="disc"] .preview-3d {
    position: absolute;
    inset: 0;
    z-index: 1;
  }

  .editor[data-view="disc"] .preview-3d-viewport {
    position: absolute;
    inset: 0;
  }

  .editor[data-view="disc"] .preview-3d-viewport canvas {
    border-radius: 0;
  }

  .editor[data-view="disc"] .sheet-hint,
  .editor[data-view="disc"] .preview-3d-tools {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 56px;
    z-index: 4;
    margin: 0;
    pointer-events: none;
    text-align: center;
    animation: preview-hint-fade 5.5s ease forwards;
  }

  .editor[data-view="disc"] .sheet-hint,
  .editor[data-view="disc"] .preview-3d-hint {
    font-size: 12px;
    line-height: 1.3;
    color: rgba(255, 255, 255, 0.92);
    text-shadow: 0 1px 3px rgba(58, 36, 24, 0.55);
  }

  .editor[data-view="disc"][data-sheet="disc"] .sheet-hint {
    color: var(--muted);
    text-shadow: none;
    background: rgba(255, 248, 239, 0.82);
    border-radius: var(--radius-pill);
    padding: 6px 12px;
    width: max-content;
    max-width: calc(100% - 24px);
    margin: 0 auto;
  }

  .editor[data-view="demo"] .demo-viewport {
    position: absolute;
    inset: 0;
    z-index: 1;
  }

  .editor[data-view="demo"] .demo-controls {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 56px;
    z-index: 5;
    padding: 8px 10px;
    gap: 6px;
    background: rgba(255, 248, 239, 0.92);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-toy);
  }

  .editor[data-view="demo"] .demo-buttons,
  .editor[data-view="demo"] .demo-meta {
    flex-wrap: nowrap;
    justify-content: center;
  }

  .editor[data-view="demo"] .demo-buttons {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .editor[data-view="demo"] .demo-buttons .btn {
    flex-shrink: 0;
  }

  .editor[data-view="demo"] .demo-meta {
    justify-content: space-between;
  }

  .editor[data-view="demo"] .demo-speed {
    flex: 1;
    min-width: 0;
  }

  .editor[data-view="demo"] .demo-speed input[type="range"] {
    width: auto;
    flex: 1;
    min-width: 72px;
  }

  .editor[data-view="demo"] .demo-progress {
    padding: 5px 8px;
    font-size: 12px;
  }

  .editor[data-view="demo"] .demo-hint {
    display: block;
    min-height: 0;
    font-size: 12px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .label-full {
    display: none;
  }

  .label-short {
    display: inline;
  }

  .editor[data-view="disc"] .sheet-toolbar .tabs {
    flex-shrink: 0;
  }
}

@media (max-width: 640px) {
  .landing-main {
    padding: 0 16px 36px;
    gap: 22px;
  }

  .landing-drop {
    padding: 28px 20px;
  }

  .example-grid {
    grid-template-columns: repeat(3, minmax(90px, 1fr));
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }

  .landing-steps {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .step-card {
    flex-direction: row;
    text-align: left;
    padding: 14px 16px;
  }

  .step-card span:last-child {
    text-align: left;
  }

  .stage-toolbar {
    gap: 6px;
    flex-wrap: nowrap;
  }

  .tabs {
    padding: 3px;
  }

  .tabs .tab {
    padding: 7px 10px;
    font-size: 13px;
  }

  .btn {
    padding: 8px 12px;
    font-size: 13px;
  }

  .stage-panel .btn {
    padding: 6px 9px;
    font-size: 12px;
  }

  .top-actions .btn {
    padding: 7px 10px;
    font-size: 13px;
  }

  .tabs-sm .tab {
    padding: 6px 9px;
    font-size: 12px;
  }

  .panel-handle-title {
    display: none;
  }
}

@media (max-width: 960px) and (max-height: 520px) {
  .topbar {
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .brand h1 {
    display: none;
  }

  .stage {
    padding: 6px 8px 6px;
    gap: 6px;
  }

  .stage-toolbar .tab {
    padding: 6px 9px;
  }

  .editor[data-view="disc"] .sheet-toolbar {
    top: 6px;
    left: 6px;
    right: 6px;
  }

  .editor[data-view="disc"] .sheet-hint,
  .editor[data-view="disc"] .preview-3d-tools {
    bottom: 12px;
  }

  .editor[data-view="demo"] .demo-controls {
    bottom: 10px;
    left: 8px;
    right: 132px;
    padding: 6px 8px;
    gap: 8px;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
  }

  .editor[data-view="demo"] .demo-hint {
    display: none;
  }

  .editor[data-view="demo"] .demo-meta {
    flex: 1;
    min-width: 0;
  }

  .panel-handle-title {
    display: none;
  }

  .panel:not(.is-open) {
    left: auto;
    right: max(12px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    width: auto;
    border: 0;
    background: transparent;
    box-shadow: none;
    transform: none;
    padding: 0;
    border-radius: 0;
  }

  .panel:not(.is-open) .panel-handle {
    width: auto;
    min-height: 40px;
    padding: 8px 12px;
    border-radius: var(--radius-pill);
    box-shadow: var(--shadow-toy);
  }

  .panel:not(.is-open) .panel-body {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .editor[data-view="disc"] .sheet-hint,
  .editor[data-view="disc"] .preview-3d-tools {
    animation: none;
  }
}

/* ------------------------------ camera scanner ----------------------------- */

body.camera-open {
  overflow: hidden;
}

body.camera-open .landing,
body.camera-open .editor {
  pointer-events: none;
}

.camera-scanner {
  position: fixed;
  inset: 0;
  z-index: 10000;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  background: #0a0a0a;
  color: #fff;
  pointer-events: auto;
}

.camera-scanner.is-hidden {
  display: none !important;
}

.camera-viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #111;
}

.camera-video,
.camera-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-overlay {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  mix-blend-mode: multiply;
}

.camera-overlay.is-visible {
  opacity: 0.72;
}

.camera-frame {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(78vw, 320px);
  height: min(78vw, 320px);
  transform: translate(-50%, -58%);
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.camera-frame-corner {
  position: absolute;
  width: 22px;
  height: 22px;
  border: 3px solid var(--coral);
}

.camera-frame-corner-tl {
  left: -2px;
  top: -2px;
  border-right: 0;
  border-bottom: 0;
  border-radius: 12px 0 0 0;
}

.camera-frame-corner-tr {
  right: -2px;
  top: -2px;
  border-left: 0;
  border-bottom: 0;
  border-radius: 0 12px 0 0;
}

.camera-frame-corner-bl {
  left: -2px;
  bottom: -2px;
  border-right: 0;
  border-top: 0;
  border-radius: 0 0 0 12px;
}

.camera-frame-corner-br {
  right: -2px;
  bottom: -2px;
  border-left: 0;
  border-top: 0;
  border-radius: 0 0 12px 0;
}

.camera-hint {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 88px);
  transform: translateX(-50%);
  margin: 0;
  padding: 8px 14px;
  max-width: calc(100% - 32px);
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

.camera-loading,
.camera-error {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  padding: 12px 18px;
  border-radius: var(--radius-pill);
  font-weight: 600;
  text-align: center;
  max-width: calc(100% - 32px);
}

.camera-loading {
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
}

.camera-error {
  background: rgba(255, 107, 87, 0.92);
  color: #fff;
}

.camera-loading[hidden],
.camera-error[hidden] {
  display: none;
}

.camera-toolbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: center;
  gap: 8px;
  padding: 12px 16px calc(env(safe-area-inset-bottom, 0px) + 12px);
  background: rgba(10, 10, 10, 0.92);
}

.camera-scanner .btn.camera-btn {
  color: #fff;
  background: rgba(255, 255, 255, 0.16);
  box-shadow: none;
  min-width: 0;
  padding: 10px 10px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.camera-scanner .btn.camera-btn[aria-pressed="true"] {
  background: var(--coral);
  color: #fff;
}

.camera-shutter {
  justify-self: center;
  width: 72px;
  height: 72px;
  border: 0;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.18);
  display: grid;
  place-items: center;
  transition: transform 0.12s ease;
}

.camera-shutter:active {
  transform: scale(0.94);
}

.camera-shutter-ring {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: var(--coral);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35);
}

@media (max-width: 640px) {
  .landing-drop-actions {
    flex-direction: column;
    width: 100%;
  }

  .landing-drop-actions .btn {
    width: 100%;
    max-width: 280px;
  }

  .camera-frame {
    width: min(82vw, 300px);
    height: min(82vw, 300px);
  }
}

/* -------------------------------- draw pad -------------------------------- */

body.draw-open {
  overflow: hidden;
  overscroll-behavior: none;
}

body.draw-open .landing,
body.draw-open .editor {
  pointer-events: none;
}

.draw-pad {
  position: fixed;
  inset: 0;
  z-index: 10000;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  background: #1a120e;
  color: #fff;
  pointer-events: auto;
}

.draw-pad.is-hidden {
  display: none !important;
}

.draw-viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 16px 16px 8px;
  overflow: hidden;
  background: #1a120e;
}

.draw-paper {
  position: relative;
  width: min(86vw, 86vh, 520px);
  height: min(86vw, 86vh, 520px);
  max-height: calc(100% - 8px);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45), 0 0 0 3px rgba(255, 107, 87, 0.35);
  overflow: hidden;
  touch-action: none;
}

.draw-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
  overscroll-behavior: none;
}

.draw-canvas.is-erase {
  cursor: cell;
}

.draw-hint {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  background: rgba(58, 36, 24, 0.08);
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  pointer-events: none;
  white-space: nowrap;
}

.draw-hint[hidden] {
  display: none;
}

.draw-toolbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: center;
  gap: 8px;
  padding: 12px 16px calc(env(safe-area-inset-bottom, 0px) + 12px);
  background: rgba(26, 18, 14, 0.96);
}

.draw-pad .btn.draw-btn {
  color: #fff;
  background: rgba(255, 255, 255, 0.16);
  box-shadow: none;
  min-width: 0;
  min-height: 44px;
  padding: 10px 8px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.draw-pad .btn.draw-btn[aria-pressed="true"] {
  background: var(--coral);
  color: #fff;
}

.draw-pad .btn.draw-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.draw-pad .btn.draw-vectorize {
  grid-column: 1 / -1;
  background: var(--coral);
  color: #fff;
  box-shadow: var(--shadow-toy);
}

.draw-pad .btn.draw-vectorize:disabled {
  background: rgba(255, 255, 255, 0.16);
  box-shadow: none;
}

@media (min-width: 641px) {
  .draw-toolbar {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .draw-pad .btn.draw-vectorize {
    grid-column: auto;
  }
}

@media (max-width: 640px) {
  .draw-paper {
    width: min(92vw, calc(100vh - 200px));
    height: min(92vw, calc(100vh - 200px));
  }
}
