*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Segoe UI", sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  display: flex;
  height: 100vh;
  overflow: hidden;
}

body.app-loading #sidebar,
body.app-loading #canvas-wrap {
  visibility: hidden;
}

#page-loading {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: #0f172a;
  color: #3b82f6;
}

/* ── Sidebar ── */
#sidebar {
  width: 290px;
  min-width: 290px;
  background: #1e293b;
  border-right: 1px solid #334155;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#sidebar-header {
  padding: 14px 16px 12px;
  border-bottom: 1px solid #334155;
  flex-shrink: 0;
}

#sidebar-header h1 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #f8fafc;
  letter-spacing: 0.5px;
}

#sidebar-header p {
  font-size: 0.7rem;
  color: #64748b;
  margin-top: 2px;
}

.view-toggle {
  display: flex;
  margin-top: 10px;
}

.view-btn {
  flex: 1;
  padding: 6px 0;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 1px;
  border: 1px solid #475569;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  transition: all 0.15s;
}

.view-btn:first-child {
  border-radius: 6px 0 0 6px;
}

.view-btn:last-child {
  border-radius: 0 6px 6px 0;
  border-left: none;
}

.view-btn.active {
  background: #3b82f6;
  border-color: #3b82f6;
  color: #fff;
}

#sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

#sidebar-body::-webkit-scrollbar {
  width: 4px;
}

#sidebar-body::-webkit-scrollbar-track {
  background: #1e293b;
}

#sidebar-body::-webkit-scrollbar-thumb {
  background: #475569;
  border-radius: 2px;
}

.section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-title {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #3b82f6;
}

.control-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

label {
  font-size: 0.74rem;
  color: #94a3b8;
}

input[type="text"],
select {
  background: #0f172a;
  border: 1px solid #334155;
  color: #e2e8f0;
  padding: 6px 9px;
  border-radius: 5px;
  font-size: 0.83rem;
  width: 100%;
  outline: none;
}

input[type="text"]:focus,
select:focus {
  border-color: #3b82f6;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.slider-row input[type="range"] {
  flex: 1;
  accent-color: #3b82f6;
  cursor: pointer;
}

.slider-val {
  font-size: 0.75rem;
  color: #3b82f6;
  min-width: 38px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toggle-label {
  font-size: 0.74rem;
  color: #94a3b8;
  flex: 1;
}

.toggle {
  position: relative;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: #334155;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle input:checked + .toggle-track {
  background: #3b82f6;
}

.toggle-track::after {
  content: "";
  position: absolute;
  left: 2px;
  top: 2px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-track::after {
  transform: translateX(16px);
}

.color-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

input[type="color"] {
  width: 34px;
  height: 28px;
  padding: 2px;
  border: 1px solid #334155;
  border-radius: 5px;
  background: #0f172a;
  cursor: pointer;
  flex-shrink: 0;
}

.color-hex {
  font-size: 0.74rem;
  color: #64748b;
  font-variant-numeric: tabular-nums;
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.preset-swatch {
  width: 28px;
  height: 28px;
  border-radius: 5px;
  cursor: pointer;
  border: 2px solid transparent;
  transition:
    transform 0.12s,
    border-color 0.12s;
  position: relative;
}

.preset-swatch:hover {
  transform: scale(1.15);
}

.preset-swatch.active {
  border-color: #f8fafc;
}

.preset-swatch .inner {
  position: absolute;
  inset: 3px;
  border-radius: 3px;
}

.shape-btns {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.shape-btn {
  flex: 1;
  min-width: 56px;
  padding: 6px 4px;
  background: #0f172a;
  border: 1px solid #334155;
  color: #94a3b8;
  border-radius: 5px;
  font-size: 0.73rem;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}

.shape-btn:hover,
.shape-btn.active {
  background: #3b82f6;
  border-color: #3b82f6;
  color: #fff;
}

.side-btns {
  display: flex;
  gap: 5px;
}

.side-btn {
  flex: 1;
  padding: 6px 4px;
  background: #0f172a;
  border: 1px solid #334155;
  color: #94a3b8;
  border-radius: 5px;
  font-size: 0.73rem;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}

.side-btn:hover,
.side-btn.active {
  background: #0ea5e9;
  border-color: #0ea5e9;
  color: #fff;
}

#dims-display {
  display: flex;
  gap: 10px;
  padding: 8px 10px;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 6px;
  font-size: 0.78rem;
}

#dims-display span {
  color: #64748b;
}

#dims-display b {
  color: #e2e8f0;
  font-variant-numeric: tabular-nums;
}

#sidebar-footer {
  padding: 16px;
  border-top: 1px solid #334155;
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex-shrink: 0;
  background: #0f172a;
}

.btn-row {
  display: flex;
  gap: 7px;
}

.btn {
  flex: 1;
  padding: 9px 6px;
  border: none;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    opacity 0.15s,
    transform 0.1s;
}

.btn:hover {
  opacity: 0.88;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: #3b82f6;
  color: #fff;
}

.btn-secondary {
  background: #0f172a;
  color: #94a3b8;
  border: 1px solid #334155;
}

.btn-accent {
  background: #0ea5e9;
  color: #fff;
}

.divider {
  height: 1px;
  background: #334155;
}

/* ── Canvas ── */

/* -- Collapsible sections -- */
.sec-group {
  border-bottom: 1px solid #334155;
  padding: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
}

.sec-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  cursor: pointer;
  user-select: none;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #94a3b8;
  background: #1e293b;
  width: 100%;
  flex-shrink: 0;
}

.sec-header:hover {
  color: #cbd5e1;
  background: #293548;
}

.sec-chevron {
  font-size: 0.6rem;
  transition: transform 0.2s;
  color: #475569;
}

.sec-header.collapsed .sec-chevron {
  transform: rotate(-90deg);
}

.sec-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: #0f172a;
  width: 100%;
  flex-shrink: 0;
}

.sec-content.hidden {
  display: none;
}

input[type="number"] {
  background: #0f172a;
  border: 1px solid #334155;
  color: #e2e8f0;
  padding: 6px 8px;
  border-radius: 5px;
  font-size: 0.83rem;
  width: 100%;
  outline: none;
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  opacity: 0.5;
}

input[type="number"]:focus {
  border-color: #3b82f6;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.num-label {
  font-size: 0.72rem;
  color: #64748b;
  margin-bottom: 3px;
}

.slider-unit-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.slider-unit-row input[type="range"] {
  flex: 1;
  accent-color: #3b82f6;
  cursor: pointer;
}

.slider-unit {
  font-size: 0.72rem;
  color: #3b82f6;
  min-width: 48px;
  text-align: right;
  white-space: nowrap;
}

.cb-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.cb-row input[type="checkbox"] {
  accent-color: #3b82f6;
  width: 14px;
  height: 14px;
  cursor: pointer;
  flex-shrink: 0;
}

.cb-label {
  font-size: 0.78rem;
  color: #94a3b8;
  cursor: pointer;
}

.dims-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 8px 10px;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 6px;
  font-size: 0.78rem;
}

.dims-row span {
  color: #64748b;
}

.dims-row b {
  color: #e2e8f0;
  font-variant-numeric: tabular-nums;
}

.btn-sm {
  font-size: 0.75rem !important;
  padding: 6px !important;
}

.num-input-sm {
  width: 80px;
}

.dims-display-footer {
  margin: 0;
  padding: 16px;
  background: #0f172a;
  border-top: 1px solid #334155;
}

.btn-row-mt {
  margin-top: 6px;
}

.btn-label-center {
  cursor: pointer;
  text-align: center;
}

.file-input-hidden {
  display: none;
}

.btn-full-width {
  width: 100%;
}

#canvas-wrap {
  flex: 1;
  position: relative;
  background: #0f172a;
}

#canvas-wrap canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

#hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.5);
  color: #64748b;
  font-size: 0.68rem;
  padding: 4px 14px;
  border-radius: 20px;
  pointer-events: none;
  letter-spacing: 0.4px;
  white-space: nowrap;
}

#loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0f172a;
  color: #3b82f6;
  font-size: 0.9rem;
  gap: 14px;
  z-index: 10;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #1e293b;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

div#download-section {
  display: none;
}
