#gypsy-tattoo-builder {
  --gtb-bg: #f4f1ed;
  --gtb-panel: #ffffff;
  --gtb-ink: #171717;
  --gtb-muted: #77716a;
  --gtb-line: #ddd7d0;
  --gtb-soft: #ece7e1;
  --gtb-danger: #a92f2f;
  width: 100%;
  box-sizing: border-box;
  color: var(--gtb-ink);
  font-family: Arial, Helvetica, sans-serif;
}

#gypsy-tattoo-builder *,
#gypsy-tattoo-builder *::before,
#gypsy-tattoo-builder *::after {
  box-sizing: border-box;
}

.gtb-app {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 24px;
  background: var(--gtb-bg);
}

.gtb-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  margin-bottom: 18px;
}

.gtb-kicker,
.gtb-panel-label {
  font-size: 11px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--gtb-muted);
}

.gtb-title {
  margin: 5px 0 0;
  font-size: clamp(24px, 3vw, 42px);
  line-height: 1;
  font-weight: 700;
}

.gtb-top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.gtb-grid {
  display: grid;
  grid-template-columns: minmax(210px, 270px) minmax(0, 1fr) minmax(220px, 280px);
  gap: 14px;
  align-items: start;
}

.gtb-panel,
.gtb-stage-panel {
  border: 1px solid var(--gtb-line);
  background: var(--gtb-panel);
}

.gtb-panel {
  padding: 16px;
}

.gtb-stage-panel {
  min-width: 0;
}

.gtb-panel-head,
.gtb-stage-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.gtb-panel-head h3 {
  margin: 4px 0 0;
  font-size: 20px;
}

.gtb-count {
  display: inline-grid;
  place-items: center;
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--gtb-soft);
  font-size: 12px;
  font-weight: 700;
}

.gtb-help,
.gtb-stage-tip,
.gtb-empty-selection,
.gtb-layers-empty {
  color: var(--gtb-muted);
  font-size: 13px;
  line-height: 1.45;
}

.gtb-help {
  margin: 10px 0 14px;
}

.gtb-divider {
  height: 1px;
  background: var(--gtb-line);
  margin: 18px 0;
}

.gtb-elements {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.gtb-element {
  appearance: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--gtb-line);
  background: #fff;
  color: var(--gtb-ink);
  cursor: grab;
  transition: border-color .15s ease, transform .15s ease, background .15s ease;
}

.gtb-element:hover {
  border-color: #99918a;
  background: #faf8f6;
  transform: translateY(-1px);
}

.gtb-element:active {
  cursor: grabbing;
}

.gtb-element-preview {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  overflow: hidden;
  background: #f4f2ef;
}

.gtb-element-preview img {
  display: block;
  width: 82%;
  height: 82%;
  object-fit: contain;
}

.gtb-element-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 700;
}

.gtb-stage-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--gtb-line);
}

.gtb-stage-status {
  font-size: 12px;
  color: var(--gtb-muted);
}

.gtb-stage-status[data-kind="ok"] { color: #3f6f4e; }
.gtb-stage-status[data-kind="error"] { color: var(--gtb-danger); }

.gtb-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 520px;
  padding: 12px;
  overflow: auto;
  background:
    linear-gradient(45deg, #ebe7e2 25%, transparent 25%),
    linear-gradient(-45deg, #ebe7e2 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ebe7e2 75%),
    linear-gradient(-45deg, transparent 75%, #ebe7e2 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}

.gtb-stage.is-dragover {
  outline: 3px solid #222;
  outline-offset: -6px;
}

.gtb-canvas-shell {
  position: relative;
  max-width: 100%;
  box-shadow: 0 8px 34px rgba(0,0,0,.14);
  background: #fff;
}

.gtb-canvas-shell .canvas-container {
  max-width: 100%;
}

.gtb-loading {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(255,255,255,.9);
  color: var(--gtb-muted);
  font-size: 14px;
}

.gtb-loading[hidden] { display: none; }
.gtb-loading.is-error { color: var(--gtb-danger); }

.gtb-stage-tip {
  margin: 0;
  padding: 10px 14px 13px;
  border-top: 1px solid var(--gtb-line);
}

.gtb-field {
  display: grid;
  gap: 7px;
  margin-top: 14px;
  font-size: 12px;
  font-weight: 700;
}

.gtb-field--row {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.gtb-field-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.gtb-field input[type="text"],
.gtb-field select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--gtb-line);
  background: #fff;
  color: var(--gtb-ink);
  padding: 0 10px;
  font: inherit;
  font-weight: 400;
}

.gtb-field input[type="color"] {
  width: 46px;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--gtb-line);
  background: #fff;
  cursor: pointer;
}

.gtb-field input[type="range"] {
  width: 100%;
}

.gtb-btn {
  appearance: none;
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--gtb-line);
  background: #fff;
  color: var(--gtb-ink);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}

.gtb-btn:hover:not(:disabled) {
  border-color: #9a928a;
  background: #f3efea;
}

.gtb-btn:disabled {
  opacity: .4;
  cursor: default;
}

.gtb-btn--primary {
  border-color: #171717;
  background: #171717;
  color: #fff;
}

.gtb-btn--primary:hover:not(:disabled) {
  background: #333;
  color: #fff;
}

.gtb-btn--wide {
  width: 100%;
  margin-top: 10px;
}

.gtb-btn--small {
  width: 100%;
  min-height: 40px;
}

.gtb-btn--danger {
  color: var(--gtb-danger);
}

.gtb-button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-top: 16px;
}

.gtb-layers {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  max-height: 240px;
  overflow: auto;
}

.gtb-layer {
  appearance: none;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 7px;
  border: 1px solid var(--gtb-line);
  background: #fff;
  color: var(--gtb-ink);
  text-align: left;
  cursor: pointer;
}

.gtb-layer.is-active {
  border-color: #1d1d1d;
  background: #f2efeb;
}

.gtb-layer-index {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--gtb-soft);
  font-size: 11px;
  font-weight: 700;
}

.gtb-layer-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 700;
}

.gtb-error {
  padding: 20px;
  border: 1px solid #c97979;
  background: #fff3f3;
  color: #8a2424;
}

@media (max-width: 1080px) {
  .gtb-grid {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .gtb-settings {
    grid-column: 1 / -1;
  }

  .gtb-settings .gtb-object-controls {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    align-items: end;
  }

  .gtb-settings .gtb-button-grid {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .gtb-app {
    padding: 10px;
  }

  .gtb-topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .gtb-top-actions {
    justify-content: flex-start;
    width: 100%;
  }

  .gtb-top-actions .gtb-btn {
    flex: 1 1 calc(50% - 8px);
  }

  .gtb-grid {
    display: flex;
    flex-direction: column;
  }

  .gtb-stage-panel {
    order: 1;
    width: 100%;
  }

  .gtb-library {
    order: 2;
    width: 100%;
  }

  .gtb-settings {
    order: 3;
    width: 100%;
  }

  .gtb-elements {
    grid-template-columns: repeat(5, minmax(92px, 1fr));
    overflow-x: auto;
    padding-bottom: 5px;
  }

  .gtb-stage {
    min-height: 360px;
    padding: 6px;
  }

  .gtb-settings .gtb-object-controls {
    display: block;
  }

  .gtb-button-grid {
    grid-template-columns: 1fr 1fr;
  }
}
