:root {
  --purple: #9b3d89;
  --teal: #197b69;
  --ink: #2a2230;
  --muted: #6b6270;
  --line: #e4dde6;
  --bg: #f6f3f7;
  --card: #fff;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Balto", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
}
[hidden] { display: none !important; }

.top {
  display: flex; align-items: center; gap: 20px;
  padding: 18px 24px;
  background: linear-gradient(90deg, var(--purple), var(--teal));
  color: #fff;
}
.top-logo { height: 56px; width: auto; }
.top h1 { margin: 0; font-size: 1.6rem; font-weight: 700; }
.top p { margin: 2px 0 0; opacity: .9; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 20px 16px 48px; }

.tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tab {
  font: inherit; font-weight: 700; font-size: 1.05rem;
  padding: 10px 20px; border-radius: 999px; cursor: pointer;
  border: 2px solid var(--purple); background: #fff; color: var(--purple);
}
.tab.active { background: var(--purple); color: #fff; }

.layout { display: grid; grid-template-columns: 360px 1fr; gap: 24px; align-items: start; }
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .preview { order: -1; }
  .top { padding: 14px 16px; }
  .top-logo { height: 42px; }
  .top p { display: none; }
}

.controls { display: flex; flex-direction: column; gap: 14px; }
.group { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.group h2 { margin: 0 0 12px; font-size: 1.05rem; font-weight: 700; color: var(--purple); }

.formats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fmt {
  font: inherit; text-align: left; cursor: pointer;
  border: 2px solid var(--line); background: #fff; border-radius: 10px;
  padding: 8px 10px; display: flex; align-items: center; gap: 10px;
}
.fmt .shape { flex: none; width: 26px; height: 26px; display: grid; place-items: center; }
.fmt .shape i { display: block; background: var(--line); border-radius: 2px; }
.fmt b { display: block; font-size: .92rem; line-height: 1.2; }
.fmt small { display: block; color: var(--muted); font-size: .76rem; line-height: 1.3; margin-top: 2px; }
.fmt.on { border-color: var(--purple); background: #faf3f8; }
.fmt.on .shape i { background: linear-gradient(90deg, var(--purple), var(--teal)); }

.btn {
  font: inherit; font-weight: 700; cursor: pointer; display: inline-block; text-align: center;
  width: 100%; padding: 11px 14px; border-radius: 10px; border: 2px solid transparent;
}
.btn + .btn { margin-top: 8px; }
.btn-primary, .btn-upload { background: linear-gradient(90deg, var(--purple), var(--teal)); color: #fff; }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn:hover { filter: brightness(1.05); }
.btn:focus-visible, .tab:focus-visible, .fmt:focus-visible { outline: 3px solid #f2b84b; outline-offset: 2px; }

.hint { margin: 10px 0 0; color: var(--muted); font-size: .88rem; }
.field { display: block; margin: 12px 0; }
.field > span { display: flex; justify-content: space-between; font-weight: 700; font-size: .92rem; margin-bottom: 4px; }
.field output { font-weight: 400; color: var(--muted); }
input[type=range] { width: 100%; accent-color: var(--purple); }
textarea {
  width: 100%; font: inherit; font-size: 1rem; padding: 10px; resize: vertical;
  border: 2px solid var(--line); border-radius: 10px;
}
textarea:focus, .input:focus { border-color: var(--purple); outline: none; }
.input { width: 100%; font: inherit; font-size: 1rem; padding: 9px 10px; border: 2px solid var(--line); border-radius: 10px; }
.seg { display: flex; border: 2px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; font: inherit; padding: 7px; border: 0; background: #fff; cursor: pointer; }
.seg button.on { background: var(--purple); color: #fff; font-weight: 700; }

.preview { position: sticky; top: 12px; }
@media (max-width: 820px) { .preview { position: static; } }
.stage {
  position: relative; display: flex; justify-content: center; align-items: center;
  background: repeating-conic-gradient(#ebe6ee 0 25%, #f7f4f8 0 50%) 0 0 / 22px 22px;
  border-radius: var(--radius); border: 1px solid var(--line);
  padding: 16px; min-height: 300px;
}
canvas {
  display: block; max-width: 100%; max-height: 72vh; width: auto; height: auto;
  box-shadow: 0 6px 24px rgba(42, 34, 48, .18); touch-action: none; background: #fff;
}
canvas.draggable { cursor: grab; }
canvas.dragging { cursor: grabbing; }
.drop {
  position: absolute; inset: 16px; display: grid; place-items: center; text-align: center;
  padding: 24px; color: #fff; font-weight: 700; font-size: 1.1rem; pointer-events: none;
  text-shadow: 0 1px 3px rgba(0,0,0,.35);
}
.stage.over { outline: 3px dashed var(--purple); outline-offset: -8px; }
.size-label { text-align: center; color: var(--muted); font-size: .85rem; margin: 8px 0 0; }
