*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  overflow-x: clip;
}

/* Embedded in case-study iframe: fill width so layout matches parent; avoid phantom height from centered max-width column */
html.cta-lab-embed,
html.cta-lab-embed body {
  width: 100%;
  max-width: 100%;
}

html.cta-lab-embed .lab {
  max-width: none;
}

body {
  margin: 0;
  min-height: 0;
  font-family: 'Red Hat Text', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #1a1814;
  background: #f7f5f2;
  -webkit-font-smoothing: antialiased;
}

#root {
  min-height: 0;
}

.lab {
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 20px 28px;
}

.lab-header {
  margin-bottom: 20px;
}

.lab-title {
  margin: 0 0 6px;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.lab-sub {
  margin: 0;
  color: #4f4a43;
  font-size: 0.88rem;
  max-width: 52ch;
}

.lab-sub code {
  font-size: 0.86em;
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 6px;
  border-radius: 4px;
}

/* Desktop: full-width preview row (hero CTA), compact controls + wide readout, full-width code */
.lab-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(200px, 270px) minmax(0, 1fr);
  grid-template-areas:
    'preview preview'
    'controls readout'
    'code code';
}

@media (max-width: 720px) {
  .lab-grid {
    grid-template-columns: 1fr;
    gap: 12px;
    grid-template-areas:
      'preview'
      'controls'
      'readout'
      'code';
  }
}

@media (min-width: 721px) {
  .preview-canvas {
    min-height: 180px;
    padding: 36px 32px;
  }
}

/* Narrow phones: readable readout, no squeezed two-column dl, safe areas */
@media (max-width: 640px) {
  .lab {
    padding: 12px max(10px, env(safe-area-inset-left)) 14px max(10px, env(safe-area-inset-right));
    max-width: none;
  }

  .lab-header {
    margin-bottom: 12px;
  }

  .lab-title {
    font-size: 1.02rem;
  }

  .lab-sub {
    font-size: 0.8rem;
    max-width: none;
  }

  .lab-grid {
    gap: 10px;
  }

  .panel {
    padding: 10px 12px 12px;
    border-radius: 10px;
    min-width: 0;
  }

  .panel-label {
    margin-bottom: 8px;
    font-size: 0.68rem;
  }

  .preview-canvas {
    min-height: 104px;
    padding: 18px 14px;
  }

  .field {
    margin-bottom: 10px;
  }

  .field input[type='text'],
  .field select {
    min-height: 44px;
    padding: 8px 10px;
    font-size: 16px; /* limits iOS zoom-on-focus */
  }

  .field select {
    padding-right: 38px;
    background-position: right 10px center;
    background-size: 20px 20px;
  }

  .field-check input[type='checkbox'] {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
  }

  .readout {
    gap: 0;
  }

  .readout-row {
    display: block;
    padding: 8px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    font-size: 0.75rem;
  }

  .readout-row:last-child {
    border-bottom: none;
  }

  .readout-row dt {
    font-size: 0.68rem;
    margin-bottom: 4px;
  }

  .readout-row dd {
    font-size: 0.72rem;
    margin: 0;
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .code-block {
    margin-bottom: 8px;
    padding: 10px 11px;
    font-size: 0.7rem;
    line-height: 1.45;
    max-height: 10rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
    max-width: 100%;
  }

  .lab-foot {
    font-size: 0.68rem;
  }

  .lab-loading,
  .lab-error {
    padding: 28px 14px;
  }

  .cta-button .cta-btn-icon {
    font-size: 20px;
  }
}

.panel {
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  padding: 14px 16px 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  min-width: 0;
}

.panel-preview {
  grid-area: preview;
}

.panel-controls {
  grid-area: controls;
}

.panel-readout {
  grid-area: readout;
}

.panel-code {
  grid-area: code;
}

.panel-label {
  margin: 0 0 12px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #78726a;
}

.preview-canvas {
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #f0ebe4 0%, #e8e2da 100%);
  border-radius: 10px;
  padding: 24px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.field:last-child {
  margin-bottom: 0;
}

.field-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: #4f4a43;
}

.field-check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.field-check .field-label {
  margin: 0;
}

.field input[type='text'],
.field select {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 8px;
  background: #fff;
}

.field select {
  /* Keep the chevron centered and consistent across browsers */
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  line-height: 1.25;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M7 10l5 5 5-5' stroke='%23615d56' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 18px 18px;
}

.readout {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.readout-row {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 8px;
  font-size: 0.8rem;
  align-items: baseline;
}

.readout-row dt {
  margin: 0;
  color: #78726a;
  font-weight: 500;
}

.readout-row dd {
  margin: 0;
  word-break: break-word;
  font-family: ui-monospace, monospace;
  font-size: 0.78rem;
}

.code-block {
  margin: 0 0 12px;
  padding: 12px 14px;
  background: #1a1814;
  color: #e8e2da;
  border-radius: 10px;
  font-size: 0.78rem;
  line-height: 1.55;
  overflow-x: auto;
}

.lab-foot {
  margin: 0;
  font-size: 0.75rem;
  color: #78726a;
  line-height: 1.5;
}

.lab-foot code {
  font-size: 0.92em;
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 4px;
}

.cta-button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  max-width: 100%;
  font: inherit;
}

/* Label gets token typography only (primary/secondary: Red Hat Text bold uppercase 1rem; conversion: bold 1rem, sentence case). */
.cta-button__label {
  color: inherit;
}

/* Material Symbols: do not inherit CTA uppercase / body font */
.cta-button .cta-btn-icon {
  font-family: 'Material Symbols Outlined';
  font-weight: normal;
  font-style: normal;
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1em;
  height: 1em;
  text-transform: none;
  letter-spacing: normal;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

.cta-button:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.lab-loading {
  padding: 48px 24px;
  text-align: center;
  color: #4f4a43;
}

.lab-error {
  padding: 24px;
  color: #933030;
  font-size: 0.9rem;
}
