:root {
  --ink: #1c1917;
  --muted: #6f675e;
  --line: rgba(28, 25, 23, 0.12);
  --paper: #f3efe6;
  --card: #fffdf8;
  --stage: #141210;
  --accent: #e24a1b;
  --accent-ink: #fff7f3;
  --shadow: 0 30px 70px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { overflow-x: hidden; }

body {
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: Outfit, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 480px);
  min-height: 100vh;
  min-height: 100dvh;
}

.stage {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 28px 36px 32px;
  color: #f6f1e8;
  background:
    radial-gradient(520px 320px at 12% 0%, rgba(226, 74, 27, 0.42), transparent 60%),
    radial-gradient(420px 320px at 100% 100%, rgba(20, 148, 138, 0.28), transparent 55%),
    var(--stage);
  overflow: hidden;
}

.spine {
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%) rotate(-90deg);
  transform-origin: center;
  letter-spacing: 0.28em;
  font-size: 11px;
  font-weight: 600;
  color: rgba(246, 241, 232, 0.45);
  white-space: nowrap;
}

.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-left: 28px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.mark {
  width: 36px;
  height: 36px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.mark i {
  display: block;
  border-radius: 4px;
  background: #f6f1e8;
}

.mark i:nth-child(1),
.mark i:nth-child(4) { background: var(--accent); }

.brand h1 {
  margin: 0;
  font-family: Fraunces, Georgia, serif;
  font-weight: 560;
  font-size: 28px;
  letter-spacing: -0.03em;
  font-style: italic;
}

.brand p {
  margin: 0;
  color: rgba(246, 241, 232, 0.62);
  font-size: 13px;
}

.pill {
  border: 1px solid rgba(246, 241, 232, 0.2);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: #f6f1e8;
  background: rgba(255, 255, 255, 0.04);
}

.pill b {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: #3ddc97;
  box-shadow: 0 0 0 4px rgba(61, 220, 151, 0.15);
}

.preview-wrap {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 18px 8px 10px 36px;
}

.ticket {
  width: min(100%, 420px, calc(100dvh - 230px));
  border-radius: 28px;
  padding: 22px 22px 16px;
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
  transition: background 0.25s ease, color 0.25s ease;
}

.ticket.is-clear {
  background-color: transparent;
  background-image:
    linear-gradient(45deg, #d9d3c7 25%, transparent 25%),
    linear-gradient(-45deg, #d9d3c7 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d9d3c7 75%),
    linear-gradient(-45deg, transparent 75%, #d9d3c7 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
  color: var(--ink);
}

.qr-frame {
  position: relative;
  aspect-ratio: 1;
  border-radius: 18px;
  overflow: hidden;
}

#qr, #empty { position: absolute; inset: 0; }

#qr svg, #qr canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

#empty {
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  border: 1.5px dashed rgba(28, 25, 23, 0.2);
  border-radius: 18px;
}

#empty strong { display: block; font-size: 18px; margin-bottom: 6px; }
#empty span { color: var(--muted); font-size: 13px; }

.mosaic {
  width: 92px;
  height: 92px;
  margin: 0 auto 14px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}

.mosaic i {
  border-radius: 3px;
  background: rgba(28, 25, 23, 0.16);
}

.mosaic i.on { background: var(--accent); border-radius: 6px; }

.card-label {
  margin: 12px 6px 2px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  padding-left: 28px;
}

.actions button {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  background: #f6f1e8;
  color: var(--ink);
  font-weight: 600;
}

.actions button.primary { background: var(--accent); color: var(--accent-ink); }

.actions button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.panel {
  min-width: 0;
  padding: 32px 32px 56px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.45), transparent 120px),
    var(--paper);
}

.panel h2 {
  margin: 28px 0 12px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel h2 span {
  margin-right: 8px;
  color: var(--accent);
  letter-spacing: 0.04em;
}

.lead {
  margin: 0 0 8px;
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(30px, 3vw, 36px);
  line-height: 1.12;
  font-weight: 560;
  letter-spacing: -0.03em;
}

.sub { margin: 0; color: var(--muted); max-width: 46ch; }

.chips, .swatches, .looks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip-demo {
  margin-top: 12px;
  border: 1px dashed rgba(28, 25, 23, 0.28);
  background: transparent;
  border-radius: 999px;
  padding: 7px 12px;
  font-weight: 600;
}

.chips button, .looks button, .seg button {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--ink);
}

.chips button[aria-pressed="true"],
.looks button[aria-pressed="true"],
.seg button[aria-pressed="true"] {
  background: var(--ink);
  color: #f6f1e8;
  border-color: var(--ink);
}

.fields { display: grid; gap: 10px; margin-top: 14px; }
.label-field, .export-row { margin-top: 12px; }
.field { display: grid; gap: 6px; }

.field em, .color-field em, .label {
  font-style: normal;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

#circleWrap { margin-top: 12px; }
#radialWrap { margin-top: 10px; }

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 14px;
  padding: 12px 14px;
}

textarea { min-height: 110px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.checks { display: grid; gap: 8px; margin-top: 12px; }

.swatches { margin-bottom: 12px; }

.swatches button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(28, 25, 23, 0.16);
  padding: 0;
}

.swatches button[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--ink); }

.seg {
  display: inline-flex;
  padding: 4px;
  border-radius: 999px;
  background: rgba(28, 25, 23, 0.05);
  margin-bottom: 12px;
}

.seg button { border: 0; background: transparent; }

.colors {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.color-field {
  display: grid;
  gap: 6px;
  padding: 8px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid var(--line);
}

.color-field input[type="color"] {
  width: 100%;
  height: 42px;
  border: 0;
  background: transparent;
  padding: 0;
}

.color-field input[type="text"] {
  border: 0;
  padding: 0 2px 2px;
  background: transparent;
  letter-spacing: 0.04em;
}

.slider {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: center;
  margin-top: 12px;
}

.slider input[type="range"] { grid-column: 1 / -1; accent-color: var(--ink); }
.slider b { font-weight: 600; }
.tune .slider { margin-top: 0; }

.drop {
  border: 1.5px dashed rgba(28, 25, 23, 0.25);
  border-radius: 16px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.55);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.drop.hot { border-color: var(--accent); background: #fff4ef; }
.logo-meta { display: flex; align-items: center; gap: 10px; min-width: 0; }

.logo-meta img {
  width: 42px;
  height: 42px;
  object-fit: cover;
  border-radius: 10px;
  background: #fff;
}

.logo-meta p {
  margin: 0;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logo-actions { display: flex; gap: 8px; flex-shrink: 0; }

.file-btn {
  position: relative;
  overflow: hidden;
  border-radius: 999px;
  border: 0;
  background: var(--ink);
  color: #f6f1e8;
  padding: 8px 12px;
  font-weight: 600;
  white-space: nowrap;
}

.file-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.text-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 600;
}

.tune {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr;
  gap: 12px;
  align-items: end;
  margin-top: 12px;
}

.warn {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fff4e8;
  color: #9a3412;
  font-size: 13px;
}

.history { display: grid; gap: 8px; }

.history-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-open {
  flex: 1;
  min-width: 0;
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 8px 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-delete {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: #9f1239;
}

.history-delete svg {
  width: 16px;
  height: 16px;
  display: block;
}

.muted { color: var(--muted); font-size: 13px; margin: 8px 0 0; }

#toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  width: max-content;
  max-width: calc(100% - 32px);
  text-align: center;
  transform: translateX(-50%) translateY(12px);
  background: var(--ink);
  color: #f6f1e8;
  padding: 10px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  z-index: 5;
}

#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 1080px) {
  .app { grid-template-columns: 1fr; }
  .panel { order: 1; }
  .stage { order: 2; }

  .stage {
    position: relative;
    height: auto;
    overflow: visible;
    padding: 20px 20px 12px;
  }

  .spine { display: none; }
  .top, .actions, .preview-wrap { padding-left: 0; margin-left: 0; }
  .preview-wrap { padding: 18px 0 8px; }
  .ticket { width: min(100%, 400px); }
  .panel {
    padding: 22px 20px calc(40px + env(safe-area-inset-bottom));
  }
  .colors { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row2, .tune { grid-template-columns: 1fr; }
  .drop { flex-wrap: wrap; }
}

@media (max-width: 720px) {
  .stage { padding: 16px 16px 8px; }
  .panel { padding: 18px 16px calc(36px + env(safe-area-inset-bottom)); }
  .brand h1 { font-size: 24px; }
  .pill { padding: 5px 10px; font-size: 11px; }
  .ticket {
    width: min(100%, 360px);
    border-radius: 22px;
    padding: 14px;
  }
  .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: min(100%, 360px);
    margin: 0 auto;
  }
  .actions .primary,
  #btnCopy { grid-column: 1 / -1; }
  .chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
  }
  .chips::-webkit-scrollbar { display: none; }
  .chips button { flex: 0 0 auto; }
  .drop { flex-direction: column; align-items: stretch; }
  .logo-actions { justify-content: flex-start; }
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="password"],
  textarea,
  select { font-size: 16px; }
}

@media (max-width: 380px) {
  .colors, .actions { grid-template-columns: 1fr; }
  .actions .primary,
  #btnCopy { grid-column: auto; }
  .swatches button { width: 36px; height: 36px; }
}

@media (pointer: coarse) {
  .chips button,
  .looks button,
  .seg button,
  .actions button,
  .file-btn,
  .text-btn,
  .chip-demo,
  .history-delete {
    min-height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
