:root {
  --paper: #fffdfb;
  --cream: #fff8f4;
  --ink: #292323;
  --muted: #766b66;
  --line: #2e2928;

  --pink: #ffaead;
  --soft-pink: #fce0e3;
  --rose: #f4cbc2;
  --yellow: #f4d77b;
  --gold: #f4ad61;
  --mint: #8aceb5;
  --soft-mint: #cddfd4;
  --teal: #448f9c;
  --lavender: #bbb6da;
  --purple: #a95993;

  --shadow: 0 18px 45px rgba(57, 43, 36, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Nunito", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(252, 224, 227, 0.75), transparent 33rem),
    radial-gradient(circle at top right, rgba(138, 206, 181, 0.45), transparent 34rem),
    linear-gradient(180deg, #fffaf8, var(--cream));
}

button,
input,
select {
  font: inherit;
}

.page {
  max-width: 1420px;
  margin: 0 auto;
  padding: 18px 18px 34px;
}

.hero {
  text-align: center;
  margin-bottom: 18px;
}

.vault-pill {
  display: inline-block;
  padding: 7px 18px;
  margin-bottom: 8px;
  border: 2px dashed var(--mint);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.75);
  color: var(--teal);
  font-family: "Baloo 2", cursive;
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0;
  font-family: "Baloo 2", cursive;
  font-size: clamp(2.7rem, 4.9vw, 5.15rem);
  line-height: 0.9;
  letter-spacing: -0.04em;
}

.hero p {
  max-width: 860px;
  margin: 8px auto 0;
  color: var(--muted);
  font-size: 1.03rem;
  font-weight: 800;
}

.builder {
  display: grid;
  grid-template-columns: minmax(430px, 520px) 1fr;
  gap: 26px;
  align-items: start;
}

.card {
  background: rgba(255, 253, 251, 0.86);
  border: 3px solid var(--line);
  border-radius: 30px;
  box-shadow: var(--shadow);
}

.preview-card {
  padding: 18px;
}

.controls-card {
  padding: 20px;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  color: var(--purple);
}

.card-title.centered {
  justify-content: center;
}

.card-title h2,
.controls-header h2 {
  margin: 0;
  color: var(--ink);
  font-family: "Baloo 2", cursive;
  font-size: 2.05rem;
  line-height: 1;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border: 3px solid var(--line);
  border-radius: 26px;
  background: white;
  overflow: hidden;
}

.canvas-wrap::after {
  content: "";
  position: absolute;
  inset: 18px;
  border: 2px dashed rgba(138, 206, 181, 0.58);
  border-radius: 20px;
  pointer-events: none;
}

#builderCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background: white;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.main-btn {
  min-height: 50px;
  border: 3px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  font-family: "Baloo 2", cursive;
  font-size: 1.06rem;
  font-weight: 800;
  box-shadow: 0 6px 0 var(--line);
  cursor: pointer;
}

.main-btn.yellow {
  background: var(--yellow);
}

.main-btn.pink {
  background: #f4b6b7;
}

.main-btn.mint {
  background: #cde6e0;
}

.main-btn:active,
.tab:active,
.arrow-btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--line);
}

.controls-header h2 {
  margin-bottom: 2px;
}

.controls-header p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.98rem;
  font-weight: 800;
}

.tabs {
  display: inline-flex;
  gap: 8px;
  padding: 8px;
  margin-bottom: 18px;
  border: 2px solid rgba(46, 41, 40, 0.2);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.68);
}

.tab {
  padding: 8px 18px;
  border: 3px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-family: "Baloo 2", cursive;
  font-size: 1.03rem;
  font-weight: 800;
  cursor: pointer;
}

.tab.active {
  border-color: var(--line);
  background: var(--yellow);
  box-shadow: 0 5px 0 var(--line);
}

.tab-screen {
  display: grid;
  gap: 16px;
}

.control-group {
  padding: 14px;
  border: 3px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.68);
}

.control-group h3 {
  margin: 0 0 12px;
  color: var(--teal);
  font-family: "Baloo 2", cursive;
  font-size: 1.28rem;
  line-height: 1;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.option-card {
  display: grid;
  gap: 10px;
  min-height: 104px;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.86);
}

.option-card.disabled {
  opacity: 0.42;
  pointer-events: none;
}

.option-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.option-label {
  font-weight: 900;
  font-size: 1.02rem;
}

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.arrow-btn {
  width: 34px;
  height: 34px;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: white;
  color: var(--ink);
  font-family: "Baloo 2", cursive;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 2px 0 var(--line);
}

.value-pill {
  min-width: 70px;
  min-height: 36px;
  padding: 4px 12px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #eef8f5;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: "Baloo 2", cursive;
  font-size: 0.98rem;
  font-weight: 800;
}

.value-pill.none {
  background: #fff1f2;
}

.option-bottom {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 9px;
}

.color-chip {
  width: 34px;
  height: 34px;
  padding: 3px;
  border: 2px solid var(--line);
  border-radius: 11px;
  background: white;
  cursor: pointer;
  pointer-events: auto;
}

.color-chip-inner {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 7px;
  pointer-events: none;
}

.match-toggle,
.checkbox-label,
.pattern-target {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 5px 10px;
  border: 2px solid rgba(46, 41, 40, 0.18);
  border-radius: 999px;
  background: white;
  color: var(--muted);
  font-weight: 900;
  font-size: 0.9rem;
}

.match-toggle input,
.checkbox-label input {
  accent-color: var(--mint);
}

.pattern-target select {
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #fff8f4;
  padding: 3px 8px;
  font-weight: 900;
}

.option-note {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.name-card {
  padding: 14px;
  border: 3px dashed rgba(169, 89, 147, 0.45);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.72);
}

.name-card h3 {
  margin: 0 0 12px;
  font-family: "Baloo 2", cursive;
  font-size: 1.24rem;
}

.name-enable-toggle {
  margin-bottom: 12px;
}

.name-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.disabled-name-grid {
  opacity: 0.45;
  pointer-events: none;
}

.field {
  display: grid;
  gap: 6px;
}

.field.full {
  grid-column: 1 / -1;
}

.field label {
  font-weight: 900;
  font-size: 0.92rem;
}

.field input[type="text"],
.field select {
  min-height: 44px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: white;
  padding: 8px 12px;
  font-weight: 800;
}

.field input[type="range"] {
  width: 100%;
  accent-color: var(--mint);
}

.palette-popover {
  position: fixed;
  z-index: 9999;
  width: 280px;
  padding: 12px;
  border: 3px solid var(--line);
  border-radius: 20px;
  background: white;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.14);
  pointer-events: auto;
}

.palette-popover.hidden {
  display: none;
}

.palette-title {
  margin-bottom: 10px;
  font-family: "Baloo 2", cursive;
  font-size: 1.08rem;
  font-weight: 800;
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.palette-swatch {
  aspect-ratio: 1 / 1;
  border: 2px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  pointer-events: auto;
}

.custom-color-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  font-weight: 900;
}

#customColorInput {
  width: 58px;
  height: 38px;
  padding: 2px;
  border: 2px solid var(--line);
  border-radius: 11px;
  background: white;
}

.note {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

@media (max-width: 1150px) {
  .builder {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .control-grid,
  .name-grid {
    grid-template-columns: 1fr;
  }

  .field.full {
    grid-column: auto;
  }

  .tabs {
    flex-wrap: wrap;
  }

  .action-grid {
    grid-template-columns: 1fr;
  }
}