:root {
  color-scheme: dark;
  --ink: #f4f7fb;
  --muted: #b0b8c3;
  --line: rgba(255, 255, 255, 0.13);
  --paper: #0b0d11;
  --panel: #151922;
  --surface: #202633;
  --accent: #3b82f6;
  --accent-2: #d7193f;
  --gold: #c5943d;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.46);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

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

body::before {
  content: "";
  position: fixed;
  inset: -20vh -10vw auto auto;
  z-index: -1;
  width: 54vw;
  height: 54vw;
  min-width: 420px;
  min-height: 420px;
  background: radial-gradient(circle, rgba(59, 130, 246, 0.18), transparent 70%);
  filter: blur(90px);
  pointer-events: none;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 60px;
  padding: 9px clamp(14px, 3vw, 32px);
  border-bottom: 1px solid var(--line);
  background: rgba(11, 13, 17, 0.88);
  backdrop-filter: blur(14px);
}

.brand-logo {
  display: block;
  width: min(260px, 48vw);
  height: 38px;
  object-fit: contain;
  object-position: left center;
}

.topbar nav {
  display: flex;
  gap: 8px;
}

.topbar a {
  border-radius: 999px;
  color: var(--ink);
  padding: 8px 11px;
  text-decoration: none;
}

.topbar a:hover {
  background: rgba(255, 255, 255, 0.1);
}

.designer-shell {
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(320px, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 14px;
  height: calc(100dvh - 60px);
  padding: 14px;
  overflow: hidden;
}

.panel {
  align-self: stretch;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.28);
}

.controls,
.job-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px;
}

.controls {
  overflow: auto;
}

.tools-toggle {
  display: none;
}

.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  background: #0d1118;
}

.mode-tabs button,
.button-row button,
#resetDesign {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.mode-tabs button.active {
  background: var(--accent);
  color: #fff;
}

.tool-section {
  display: grid;
  gap: 9px;
}

.property-group {
  display: grid;
  gap: 9px;
}

.tool-section.hidden,
.property-group.hidden,
.hidden {
  display: none;
}

label {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #0b0c10;
  color: var(--ink);
}

input,
select {
  min-height: 42px;
  padding: 8px 10px;
}

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

.selected-object-card {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #0d1118;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 750;
}

.selected-object-card span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.button-row button {
  border-color: var(--line);
  background: var(--surface);
}

.grid-controls {
  display: grid;
  gap: 10px;
}

.grid-controls label {
  display: grid;
  gap: 5px;
}

.preview-stage {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 28%, rgba(59, 130, 246, 0.12), transparent 36%),
    linear-gradient(180deg, #171d27, #101319);
}

#ornamentCanvas {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
  cursor: grab;
  touch-action: none;
}

#ornamentCanvas.dragging {
  cursor: grabbing;
}

.stage-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 9px 12px;
  border-top: 1px solid var(--line);
  background: rgba(13, 16, 22, 0.92);
}

.rotation-control {
  display: grid;
  grid-template-columns: auto minmax(160px, 260px);
  align-items: center;
  gap: 10px;
  flex: 1;
  max-width: 440px;
}

#selectionLabel {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

#resetDesign {
  border-color: var(--line);
  padding: 0 14px;
}

.job-panel {
  grid-column: 2;
  display: block;
  padding: 0;
  overflow: hidden;
}

.job-panel summary {
  cursor: pointer;
  padding: 12px 14px;
  color: var(--muted);
  font-weight: 800;
}

.qr-card {
  display: grid;
  place-items: center;
  min-height: 240px;
  margin: 0 18px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b0c10;
}

#qrCode {
  width: 220px;
  height: 220px;
}

#qrCode img,
#qrCode canvas {
  width: 220px;
  height: 220px;
}

.qr-fallback {
  color: var(--muted);
  font-weight: 700;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 18px 18px;
}

.metrics div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #0b0c10;
}

.metrics dt {
  color: var(--muted);
  font-size: 0.78rem;
}

.metrics dd {
  margin: 3px 0 0;
  font-size: 1.05rem;
  font-weight: 800;
}

#payloadPreview {
  min-height: 160px;
  margin: 0 18px 18px;
  width: calc(100% - 36px);
  resize: vertical;
  padding: 10px;
  background: #0b0c10;
  color: #d7e7ee;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
}

@media (max-width: 1040px) {
  .designer-shell {
    grid-template-columns: 270px minmax(280px, 1fr);
  }
}

@media (max-width: 760px) {
  body {
    overflow: hidden;
  }

  .topbar {
    position: fixed;
    inset: 0 0 auto;
    min-height: 54px;
    padding: 8px 12px;
    align-items: center;
  }

  .brand-logo {
    width: 190px;
    height: 34px;
  }

  .topbar nav {
    display: none;
  }

  .designer-shell,
  .job-panel {
    grid-template-columns: 1fr;
  }

  .designer-shell {
    display: block;
    height: 100dvh;
    min-height: 0;
    padding: 62px 8px 8px;
    overflow: hidden;
  }

  .preview-stage {
    height: calc(100dvh - 124px);
    min-height: 0;
  }

  .stage-footer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    min-height: 96px;
    align-items: center;
  }

  .rotation-control {
    order: -1;
    grid-template-columns: 1fr;
    grid-column: 1 / -1;
    flex-basis: auto;
    max-width: none;
    gap: 5px;
  }

  #ornamentCanvas {
    min-height: 0;
  }

  .controls {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: 8px;
    z-index: 20;
    max-height: min(68dvh, 560px);
    padding: 0 12px 12px;
    overflow: auto;
    transform: translateY(calc(100% - 54px));
    transition: transform 0.22s ease;
  }

  .controls.open {
    transform: translateY(0);
  }

  .tools-toggle {
    position: sticky;
    top: 0;
    z-index: 2;
    display: block;
    width: calc(100% + 24px);
    min-height: 54px;
    margin: 0 -12px 12px;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 8px 8px 0 0;
    background: #202633;
    color: var(--ink);
    font-weight: 850;
    cursor: pointer;
  }

  .job-panel {
    display: none;
  }
}
