:root {
  --ink: #172126;
  --muted: #596a72;
  --paper: #f8fbfa;
  --panel: #ffffff;
  --line: #dce7e4;
  --green: #063b1d;
  --accent: #18a058;
  --cream: #fffdf5;
  --shadow: 0 18px 50px rgba(23, 33, 38, 0.12);
  --tag-w: 1.3in;
  --tag-h: 1.3in;
  --preview-scale: 2.2;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #ffffff 0%, var(--paper) 72%);
}

button,
input,
select {
  font: inherit;
}

.tag-studio-shell {
  width: min(100%, 1180px);
  margin: 0 auto;
  padding: 16px 14px 88px;
}

.studio-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.studio-header h1 {
  margin: 0;
  font-size: 1.55rem;
  line-height: 1;
}

.studio-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.studio-logo {
  width: 54px;
  height: auto;
}

.back-link,
.primary-button,
.secondary-button,
.order-button {
  width: 100%;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 16px;
  color: #007c73;
  background: #ffffff;
  font-weight: 850;
  text-decoration: none;
  cursor: pointer;
}

.primary-button {
  color: #ffffff;
  background: var(--accent);
  border-color: var(--accent);
}

.order-button {
  color: #ffffff;
  background: #0b4c2a;
  border-color: #0b4c2a;
}

.step-tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  padding: 8px 0;
  background: rgba(248, 251, 250, 0.94);
  backdrop-filter: blur(14px);
}

.step-tab {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #ffffff;
  font-weight: 850;
}

.step-tab span {
  display: inline-grid;
  width: 22px;
  height: 22px;
  margin-right: 4px;
  place-items: center;
  border-radius: 50%;
  color: #ffffff;
  background: #8aa29e;
  font-size: 0.78rem;
}

.step-tab.is-active {
  color: #ffffff;
  background: var(--accent);
  border-color: var(--accent);
}

.step-tab.is-active span {
  color: var(--accent);
  background: #ffffff;
}

.studio-preview-bar {
  display: grid;
  place-items: center;
  min-height: clamp(250px, 72vw, 340px);
  margin: 8px 0 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.preview-stage {
  width: calc(var(--tag-w) * var(--preview-scale));
  height: calc(var(--tag-h) * var(--preview-scale));
  display: grid;
  place-items: center;
  max-width: 100%;
  max-height: 100%;
  transition: width 160ms ease, height 160ms ease;
}

.pet-tag {
  width: var(--tag-w);
  height: var(--tag-h);
  flex: 0 0 auto;
  overflow: hidden;
  border: 0.018in solid var(--tag-color, var(--green));
  border-radius: var(--tag-radius, 0.14in);
  color: var(--tag-color, var(--green));
  background: var(--tag-bg, var(--cream));
  box-shadow: inset 0 0 0 0.009in rgba(6, 59, 29, 0.22);
  transform: scale(var(--preview-scale));
  transform-origin: center;
}

.pet-tag.is-exporting {
  box-shadow: none;
  transform: none;
}

.tag-inner {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: clamp(0.018in, 3%, 0.035in);
  padding: 0.075in;
}

.tag-media {
  width: 0.28in;
  height: 0.28in;
  justify-self: center;
  overflow: hidden;
  border: 0.006in solid currentColor;
  border-radius: 999px;
  background: #ffffff;
}

.tag-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tag-bar {
  min-width: 0;
  min-height: 0.15in;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.03in;
  border-radius: 0.045in;
  color: #ffffff;
  background: var(--tag-color, var(--green));
  font-weight: 1000;
  line-height: 1;
  letter-spacing: 0;
  text-transform: uppercase;
}

.tag-bar-top {
  font-size: 0.075in;
}

.tag-bar-bottom {
  font-size: 0.078in;
}

.paw-icon {
  width: 0.115in;
  height: 0.115in;
  fill: currentColor;
}

.pet-name {
  max-width: 100%;
  align-self: center;
  color: var(--tag-color, var(--green));
  font-size: var(--name-size, 0.3in);
  font-weight: 1000;
  line-height: 0.9;
  text-align: center;
  white-space: nowrap;
  letter-spacing: 0;
}

.badge-row {
  display: grid;
  grid-template-columns: 1fr auto auto 1fr;
  align-items: center;
  gap: 0.028in;
}

.rule {
  height: 0.007in;
  border-radius: 999px;
  background: currentColor;
}

.nfc-badge,
.qr-badge {
  width: 0.14in;
  height: 0.14in;
}

.nfc-badge {
  display: inline-grid;
  place-items: center;
  border: 0.005in solid currentColor;
  border-radius: 999px;
  font-size: 0.035in;
  font-weight: 1000;
}

.qr-badge {
  object-fit: contain;
  border: 0.004in solid currentColor;
  background: #ffffff;
}

.phone-number {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--phone-color, #211004);
  font-size: var(--phone-size, 0.118in);
  font-weight: 1000;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  letter-spacing: 0;
}

.font-rounded {
  font-family: Arial Rounded MT Bold, Nunito, Inter, sans-serif;
}

.font-bold {
  font-family: Arial Black, Inter, sans-serif;
}

.font-modern {
  font-family: Inter, Helvetica, Arial, sans-serif;
}

.font-cute {
  font-family: Comic Sans MS, Trebuchet MS, sans-serif;
}

.template-minimal {
  --tag-radius: 0.14in;
}

.template-cute {
  --tag-bg: #fff7fb;
  --tag-color: #0b6b48;
  --tag-radius: 0.18in;
}

.template-premium {
  --tag-bg: #fffaf0;
  --tag-color: #08391f;
  --tag-radius: 0.12in;
}

.template-modern {
  --tag-bg: #ffffff;
  --tag-color: #0d5c5a;
  --tag-radius: 0.06in;
}

.template-paw {
  --tag-bg: #f8fff7;
  --tag-color: #136c36;
}

.template-bone {
  --tag-bg: #fffdf5;
  --tag-color: #0c4a28;
  --tag-radius: 0.28in;
}

.template-circle {
  --tag-radius: 999px;
}

.studio-form,
.studio-step,
.source-profile {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.studio-form {
  padding: 14px;
}

.studio-step {
  display: none;
  padding: 16px;
  box-shadow: none;
}

.studio-step.is-active {
  display: block;
}

.step-heading h2 {
  margin: 0;
  font-size: 1.35rem;
}

.step-heading p {
  margin: 4px 0 16px;
  color: var(--muted);
}

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

.template-card {
  min-height: 118px;
  display: grid;
  gap: 8px;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 900;
}

.template-card.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(24, 160, 88, 0.14);
}

.mini-tag {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  border: 3px solid var(--tag-color, var(--green));
  border-radius: var(--tag-radius, 16px);
  color: var(--tag-color, var(--green));
  background: var(--tag-bg, var(--cream));
  font-size: 1rem;
}

.control-grid,
.toggle-grid,
.finish-actions,
.step-actions {
  display: grid;
  gap: 10px;
}

.control-grid label {
  display: grid;
  gap: 7px;
  color: #42545c;
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.control-grid input,
.control-grid select {
  width: 100%;
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: #ffffff;
  font-weight: 750;
}

.toggle-grid {
  margin: 12px 0;
}

.toggle-grid label {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  font-weight: 850;
}

.toggle-grid input {
  width: 20px;
  height: 20px;
}

.source-profile {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  margin: 12px 0;
  padding: 10px;
  box-shadow: none;
}

.source-profile img {
  width: 54px;
  height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: contain;
  background: #f7fbfa;
}

.source-profile strong,
.source-profile span {
  display: block;
}

.source-profile span,
.status-message {
  color: var(--muted);
}

.step-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 14px;
}

.step-next,
.finish-actions {
  margin-top: 14px;
}

.finish-actions {
  grid-template-columns: minmax(0, 1fr);
}

.status-message {
  min-height: 24px;
  margin: 12px 0 0;
  text-align: center;
  font-size: 0.92rem;
}

@media print {
  @page {
    size: var(--tag-w) var(--tag-h);
    margin: 0;
  }

  body {
    background: #ffffff;
  }

  body * {
    visibility: hidden;
  }

  .pet-tag,
  .pet-tag * {
    visibility: visible;
  }

  .pet-tag {
    position: fixed;
    inset: 0;
    margin: 0;
    box-shadow: none;
    transform: none;
  }
}

@media (min-width: 860px) {
  .tag-studio-shell {
    display: grid;
    grid-template-columns: minmax(420px, 1fr) minmax(380px, 460px);
    gap: 22px;
    align-items: start;
    padding-top: 28px;
  }

  .studio-header,
  .step-tabs {
    grid-column: 1 / -1;
  }

  .studio-preview-bar {
    grid-column: 1;
    position: sticky;
    top: 72px;
    min-height: min(66vh, 620px);
  }

  .studio-form {
    grid-column: 2;
    position: sticky;
    top: 72px;
    max-height: calc(100vh - 92px);
    overflow: auto;
  }

  .template-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .control-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .finish-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 390px) {
  .studio-header {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .studio-logo {
    display: none;
  }

  .step-tab {
    font-size: 0.82rem;
  }

  .template-grid {
    gap: 8px;
  }

  .template-card {
    min-height: 104px;
  }

  .mini-tag {
    width: 62px;
    height: 62px;
  }
}
