/* ============================================================
   QR al momento — print shop / ticket look
   ============================================================ */

:root[data-theme="light"] {
  --bg: #F2EEE5;
  --surface: #FBF9F4;
  --ink: #1B1A17;
  --muted: #6B665C;
  --line: #1B1A17;
  --accent: #E8492B;
  --accent-ink: #FFFFFF;
  --hl: #FFD84D;
  --shadow: #1B1A17;
}

:root[data-theme="dark"] {
  --bg: #141311;
  --surface: #1E1C19;
  --ink: #F2EEE5;
  --muted: #A39D90;
  --line: #3A362F;
  --accent: #FF6A4A;
  --accent-ink: #141311;
  --hl: #FFD84D;
  --shadow: #000000;
}

/* ---------- base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-weight: 500;
  font-size: 1rem;
  line-height: 1.5;
  transition: background-color 200ms ease, color 200ms ease;
  overflow-x: hidden;
}

img,
canvas,
svg {
  max-width: 100%;
}

h1 {
  margin: 0 0 16px;
  font-family: "Bricolage Grotesque", system-ui, sans-serif;
  font-weight: 800;
  font-size: clamp(2.4rem, 6vw, 4.2rem);
  letter-spacing: -0.03em;
  line-height: 0.95;
}

.hl {
  background: linear-gradient(transparent 55%, var(--hl) 55%);
  padding: 0 0.05em;
}

:root[data-theme="dark"] .hl {
  background: var(--hl);
  color: #141311;
  padding: 0 0.15em;
}

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  text-decoration: none;
  color: var(--ink);
}

.brand-mark {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
}

.brand-dot {
  fill: var(--accent);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background-color 200ms ease, color 200ms ease, border-color 200ms ease;
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.theme-label {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

:root[data-theme="light"] .icon-sun {
  display: none;
}

:root[data-theme="dark"] .icon-moon {
  display: none;
}

.theme-toggle:focus-visible,
.segmented button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- layout ---------- */

.layout {
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px 48px;
}

.intro {
  order: 1;
  margin: 8px 0 8px;
}

.preview {
  order: 2;
}

.controls {
  order: 3;
}

.lede {
  margin: 0;
  max-width: 46ch;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.55;
}

.panel {
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 22px;
}

/* ---------- controls ---------- */

.controls {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.label output {
  color: var(--ink);
  letter-spacing: 0.04em;
}

textarea {
  width: 100%;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.95rem;
  line-height: 1.5;
  background: var(--bg);
  color: var(--ink);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  resize: vertical;
  transition: background-color 200ms ease, color 200ms ease, border-color 200ms ease;
}

textarea::placeholder {
  color: var(--muted);
  opacity: 0.8;
}

textarea:focus {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.hint {
  display: block;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--muted);
}

.field:has(textarea) .hint,
.hint:has(#charCount) {
  text-align: right;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.swatch {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 6px 10px 6px 6px;
  background: var(--bg);
}

.swatch input[type="color"] {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border: none;
  padding: 0;
  background: none;
  border-radius: 8px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.swatch input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.swatch input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 8px;
}

.swatch input[type="color"]::-moz-color-swatch {
  border: none;
  border-radius: 8px;
}

.swatch code {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.85rem;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.segmented button {
  min-height: 44px;
  padding: 0 4px;
  background: transparent;
  color: var(--ink);
  border: none;
  border-right: 1.5px solid var(--line);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}

.segmented button:last-child {
  border-right: none;
}

.segmented button[aria-checked="true"] {
  background: var(--ink);
  color: var(--bg);
}

input[type="range"] {
  width: 100%;
  height: 44px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ---------- preview / ticket ---------- */

.preview {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.ticket {
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 4px 4px 0 var(--shadow);
}

.qr-frame {
  position: relative;
  width: 100%;
  max-width: 340px;
  aspect-ratio: 1;
  margin: 0 auto;
  display: grid;
  place-items: center;
  padding: 14px;
  background-image:
    linear-gradient(var(--accent), var(--accent)),
    linear-gradient(var(--accent), var(--accent)),
    linear-gradient(var(--accent), var(--accent)),
    linear-gradient(var(--accent), var(--accent)),
    linear-gradient(var(--accent), var(--accent)),
    linear-gradient(var(--accent), var(--accent)),
    linear-gradient(var(--accent), var(--accent)),
    linear-gradient(var(--accent), var(--accent));
  background-repeat: no-repeat;
  background-size:
    18px 3px, 3px 18px,
    18px 3px, 3px 18px,
    18px 3px, 3px 18px,
    18px 3px, 3px 18px;
  background-position:
    left top, left top,
    right top, right top,
    left bottom, left bottom,
    right bottom, right bottom;
  background-origin: border-box;
  background-clip: border-box;
}

canvas#qrCanvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
  image-rendering: pixelated;
}

.empty-msg {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  margin: 0;
  color: var(--muted);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.85rem;
  line-height: 1.5;
}

.empty-msg[hidden] {
  display: none;
}

.caption {
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1.5px dashed var(--line);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--muted);
  text-align: center;
  word-break: break-all;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

/* ---------- actions ---------- */

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

#btnDownload {
  grid-column: 1 / -1;
}

.btn {
  min-height: 48px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 120ms ease, background-color 200ms ease, color 200ms ease,
    border-color 200ms ease, box-shadow 120ms ease;
}

.btn svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.btn:hover {
  transform: translate(-1px, -1px);
}

.btn:active {
  transform: translate(1px, 1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--line);
  box-shadow: 3px 3px 0 var(--shadow);
}

.btn-primary:active {
  box-shadow: none;
  transform: translate(3px, 3px);
}

.btn-primary:disabled {
  box-shadow: 3px 3px 0 var(--shadow);
}

.btn-link {
  grid-column: 1 / -1;
  min-height: 44px;
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.8rem;
  cursor: pointer;
  transition: color 200ms ease;
}

.btn-link:hover {
  color: var(--ink);
}

.btn-link:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- footer ---------- */

.foot {
  text-align: center;
  color: var(--muted);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  padding: 24px 16px 40px;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  background: var(--ink);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: 10px;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.85rem;
  max-width: calc(100vw - 32px);
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 50;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- desktop ---------- */

@media (min-width: 860px) {
  .layout {
    display: grid;
    grid-template-columns: 1fr 420px;
    gap: 24px;
    align-items: start;
  }

  .intro {
    grid-column: 1 / -1;
    grid-row: 1;
    order: 0;
    margin: 24px 0 8px;
  }

  .controls {
    grid-column: 1;
    grid-row: 2;
    order: 0;
  }

  .preview {
    grid-column: 2;
    grid-row: 2;
    order: 0;
    position: sticky;
    top: 20px;
    align-self: start;
  }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }

  .btn:hover,
  .btn:active,
  .btn-primary:active {
    transform: none;
  }
}
