:root {
  color-scheme: light dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #0b0d12;
  --panel: #171a21;
  --panel-2: #20242d;
  --text: #f7f8fa;
  --muted: #a6adbb;
  --border: #343a46;
  --accent: #0a84ff;
  --danger: #ff453a;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}
body { overscroll-behavior: none; }
button, input, select { font: inherit; }
button, .import-button, .tool { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }

.app-shell {
  width: 100%;
  height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 13, 18, 0.94);
}
.brand { font-weight: 700; letter-spacing: -0.02em; }
.top-actions { display: flex; align-items: center; gap: 8px; }

button, .import-button {
  min-height: 42px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  padding: 0 14px;
}
button:disabled { opacity: 0.38; }
button.primary, .import-button {
  border-color: transparent;
  background: var(--accent);
  color: white;
  font-weight: 700;
}

main { min-height: 0; overflow: hidden; }
.empty-state {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  text-align: center;
  padding: 28px;
}
.empty-state h1 { margin: 0 0 8px; font-size: clamp(26px, 7vw, 38px); }
.empty-state p { margin: 0 0 24px; max-width: 34rem; color: var(--muted); line-height: 1.5; }
.import-button { display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }

.editor {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}
.canvas-stage {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background:
    linear-gradient(45deg, #181b22 25%, transparent 25%),
    linear-gradient(-45deg, #181b22 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #181b22 75%),
    linear-gradient(-45deg, transparent 75%, #181b22 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}
.canvas-viewport {
  min-width: 100%;
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 10px;
}
canvas {
  display: block;
  max-width: none;
  max-height: none;
  width: auto;
  height: auto;
  background: black;
  box-shadow: 0 8px 30px rgba(0,0,0,.28);
  touch-action: none;
}

.properties {
  min-height: 0;
  max-height: 44dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-top: 1px solid var(--border);
  background: var(--panel);
  padding: 10px 12px 12px;
  display: grid;
  gap: 10px;
}
.quick-controls { display: grid; gap: 10px; }
.size-control { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.size-control span { font-weight: 650; color: var(--text); }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.colour-swatches {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 9px;
  align-items: center;
}
.colour-swatch {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35);
  background: var(--swatch, transparent);
  box-shadow: 0 0 0 2px rgba(0,0,0,.35) inset;
  cursor: pointer;
}
.colour-swatch.active {
  border-color: #fff;
  box-shadow: 0 0 0 3px var(--accent), 0 0 0 2px rgba(0,0,0,.4) inset;
}
.custom-swatch {
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--text);
  border-style: dashed;
  overflow: hidden;
}
.custom-swatch span { font-size: 22px; line-height: 1; pointer-events: none; }
.custom-swatch input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.quick-actions button { min-height: 40px; }
#deleteBtn:not(:disabled) { color: #ffd0cd; border-color: rgba(255,69,58,.45); }

.advanced-controls {
  padding-top: 2px;
  display: grid;
  gap: 9px;
}
.advanced-controls[hidden] { display: none; }
.advanced-group { display: grid; gap: 9px; }
.advanced-controls label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}
.advanced-controls input[type="text"] {
  width: 100%;
  min-height: 40px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 10px;
  outline: none;
}
.advanced-controls input[type="text"]:focus { border-color: var(--accent); }

.toolbar {
  min-height: 66px;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 2px;
  padding: 7px 5px calc(7px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: rgba(11, 13, 18, 0.96);
}
.tool {
  min-width: 0;
  min-height: 52px;
  padding-inline: 2px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
}
.tool span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 9px;
  font-weight: 650;
}
.tool.active { background: rgba(10,132,255,.16); color: #8cc8ff; }
.import-tool { position: relative; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(82px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(16px);
  max-width: calc(100vw - 32px);
  background: rgba(32,36,45,.96);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 9px 14px;
  color: var(--text);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: .18s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 760px) {
  .app-shell { max-width: 1180px; margin: 0 auto; border-inline: 1px solid var(--border); }
  .editor { grid-template-columns: minmax(0, 1fr) 330px; grid-template-rows: 1fr; }
  .properties {
    max-height: none;
    border-top: 0;
    border-left: 1px solid var(--border);
    align-content: start;
  }
  .colour-swatches { grid-template-columns: repeat(4, 1fr); }
}
