:root {
  color-scheme: light;
  --brand: #236fa1;
  --brand-hover: #1a5a85;
  --brand-soft: rgba(35, 111, 161, 0.12);
  --brand-glow: rgba(35, 111, 161, 0.22);
  --surface: #ffffff;
  --surface-muted: #f6f9fc;
  --surface-inset: #eef3f8;
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.14);
  --text: #0f172a;
  --text-secondary: #64748b;
  --text-tertiary: #94a3b8;
  --success: #0d9488;
  --success-soft: rgba(13, 148, 136, 0.12);
  --warn: #b45309;
  --warn-soft: rgba(180, 83, 9, 0.12);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 10px 30px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 24px 60px rgba(15, 23, 42, 0.1);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --font: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --accent: var(--brand);
  --accent-soft: var(--brand-soft);
  --ink: var(--text);
  --muted: var(--text-secondary);
  --panel: rgba(255, 255, 255, 0.82);
  --panel-border: var(--border);
  --shadow: var(--shadow-lg);
}

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

html {
  scroll-behavior: smooth;
  overflow-x: clip;
}

img {
  max-width: 100%;
  height: auto;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

body {
  margin: 0;
  min-height: 100vh;
  width: 100%;
  overflow-x: clip;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(ellipse 80% 50% at 0% 0%, var(--brand-soft), transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(148, 163, 184, 0.12), transparent 50%),
    linear-gradient(165deg, #f8fafc 0%, #f1f5f9 48%, #eef2f7 100%);
}

button,
input,
textarea {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 400px) minmax(0, 1fr);
  gap: 20px;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
  align-items: start;
  box-sizing: border-box;
}

.panel {
  background: var(--panel);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  min-width: 0;
  width: 100%;
  max-width: 100%;
}

.controls {
  padding: 0;
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 40px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.controls-scroll {
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex: 1;
  min-height: 0;
  margin: 0 6px 0 0;
  padding: 24px 6px 28px 24px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--brand) transparent;
}

.controls-scroll::-webkit-scrollbar {
  width: 4px;
}

.controls-scroll::-webkit-scrollbar-track {
  background: transparent;
  margin: 22px 0 24px;
}

.controls-scroll::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--brand) 0%, #2a85be 100%);
  border-radius: 999px;
  min-height: 56px;
}

.controls-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--brand-hover);
}

.workspace {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.app-brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 14px;
}

.app-logo {
  display: block;
  width: min(200px, 100%);
  height: auto;
  max-height: 56px;
  object-fit: contain;
  object-position: left center;
}

.app-logo,
.btn-icon {
  flex-shrink: 0;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  max-width: 100%;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.eyebrow::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.85;
}

h1,
h2,
h3 {
  margin: 6px 0 0;
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--text);
}

h1 {
  font-size: clamp(1.5rem, 2.2vw, 1.85rem);
}

h2 {
  font-size: 1.25rem;
}

.lede {
  margin: 8px 0 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.55;
  max-width: 36ch;
}

.section-card {
  padding: 16px;
  border-radius: var(--radius-lg);
  background: var(--surface-muted);
  border: 1px solid var(--border);
}

.group {
  margin: 0;
}

.group-title {
  margin: 0 0 12px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
}

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

.field-grid-single {
  grid-template-columns: 1fr;
}

.field-grid label,
.toggle-chips label {
  display: grid;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.field-grid label.full,
.field-grid label.full-span {
  grid-column: 1 / -1;
}

.field-grid label:has(input[readonly]),
.field-grid label:has(textarea[readonly]) {
  display: none;
}

input,
textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 180ms var(--ease), box-shadow 180ms var(--ease);
}

input:hover,
textarea:hover {
  border-color: rgba(35, 111, 161, 0.35);
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

input[readonly],
textarea[readonly] {
  background: var(--surface-inset);
  color: var(--text-tertiary);
  border-color: var(--border);
  cursor: default;
}

input[readonly]:hover,
textarea[readonly]:hover {
  border-color: var(--border);
  box-shadow: none;
}

textarea {
  resize: vertical;
  min-height: 72px;
}

.toggle-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  margin: 0;
}

.toggle-chip input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.toggle-chip span {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  transition: background 180ms var(--ease), border-color 180ms var(--ease), color 180ms var(--ease), box-shadow 180ms var(--ease);
}

.toggle-chip input:checked + span {
  background: var(--brand-soft);
  border-color: rgba(35, 111, 161, 0.35);
  color: var(--brand);
  box-shadow: inset 0 0 0 1px rgba(35, 111, 161, 0.15);
}

.toggle-chip input:focus-visible + span {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.actions {
  display: grid;
  gap: 10px;
  margin: 0;
}

.copy-toast {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 900;
  width: min(520px, calc(100vw - 24px));
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(22, 101, 52, 0.18);
  background: rgba(220, 252, 231, 0.95);
  color: #166534;
  font-size: 0.84rem;
  line-height: 1.45;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

a.btn {
  text-decoration: none;
}

a.btn-primary,
a.btn-primary:visited {
  color: #fff;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  max-width: 100%;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  cursor: pointer;
  transition: transform 160ms var(--ease), box-shadow 160ms var(--ease), background 160ms var(--ease), border-color 160ms var(--ease);
}

.btn:active {
  transform: scale(0.98);
}

.btn:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.btn-primary {
  background: linear-gradient(160deg, var(--brand) 0%, #2a85be 100%);
  color: #fff;
  box-shadow: 0 10px 28px var(--brand-glow);
}

.btn-primary:hover {
  background: linear-gradient(160deg, var(--brand-hover) 0%, var(--brand) 100%);
  box-shadow: 0 14px 32px var(--brand-glow);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
  border-color: rgba(35, 111, 161, 0.3);
  background: var(--surface-muted);
  transform: translateY(-1px);
}

.btn-icon {
  width: 1.1em;
  height: 1.1em;
  flex-shrink: 0;
}

.hint-box {
  padding: 16px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
}

.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 0.86rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

.step-num {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 0.75rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.step-path {
  display: block;
  margin-top: 4px;
  font-weight: 600;
  color: var(--brand);
}

.workspace-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.workspace-header--preview {
  align-items: center;
  justify-content: space-between;
}

.workspace-header--preview .eyebrow {
  flex: 0 0 auto;
  width: fit-content;
}

.workspace-copy-btn {
  flex: 0 0 auto;
  padding: 7px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 6px 16px var(--brand-glow);
}

.workspace-copy-btn .btn-icon {
  width: 0.95em;
  height: 0.95em;
}

.workspace-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.preview-shell {
  overflow: visible;
  min-width: 0;
  width: 100%;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.preview-chrome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface-muted) 0%, var(--surface) 100%);
}

.preview-dots {
  display: flex;
  gap: 6px;
}

.preview-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border-strong);
}

.preview-dots span:first-child {
  background: #f87171;
}

.preview-dots span:nth-child(2) {
  background: #fbbf24;
}

.preview-dots span:nth-child(3) {
  background: #4ade80;
}

.preview-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
}

.preview-stage {
  padding: 16px;
  overflow: visible;
  min-width: 0;
  width: 100%;
  background:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 20px 20px;
  background-color: var(--surface-inset);
}

.signature-preview {
  min-height: 120px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  background: #fff;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  padding: 16px;
  box-shadow: var(--shadow-md);
  box-sizing: border-box;
}

.signature-preview table {
  transform-origin: top left;
}

.signature-preview img {
  max-width: 100%;
  height: auto;
}

.signature-preview:focus {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.code-section {
  display: none;
  animation: fadeIn 280ms var(--ease);
}

.code-section.is-open {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.code-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.code-section-header span {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
}

#htmlOutput {
  width: 100%;
  min-height: 200px;
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: #0f172a;
  color: #e2e8f0;
  font-family: "Cascadia Code", Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.55;
}

.clipboard-buffer {
  position: fixed;
  left: -99999px;
  top: 0;
  opacity: 0;
  pointer-events: none;
  user-select: text;
}

/* Embed: 3-column + instructions */
.shell-embed {
  grid-template-columns: minmax(0, 340px) minmax(0, 1fr) minmax(0, 320px);
  max-width: 100%;
  align-items: start;
}

.shell-embed .workspace,
.shell-embed .instructions-panel,
.shell-embed .controls {
  min-height: calc(100vh - 40px);
  max-height: calc(100vh - 40px);
  position: sticky;
  top: 20px;
  overflow: hidden;
}

.shell-embed .workspace {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.shell-embed .preview-shell {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.shell-embed .preview-stage {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.shell-embed .signature-preview {
  min-height: 100%;
}

.instructions-panel {
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.instructions-scroll {
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  min-height: 0;
  margin: 0 6px 0 0;
  padding: 24px 6px 28px 24px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--brand) transparent;
}

.instructions-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.instructions-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--text);
}

.instructions-scroll::-webkit-scrollbar {
  width: 4px;
}

.instructions-scroll::-webkit-scrollbar-track {
  background: transparent;
  margin: 22px 0 24px;
}

.instructions-scroll::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--brand) 0%, #2a85be 100%);
  border-radius: 999px;
  min-height: 56px;
}

.hint-box p {
  margin: 0 0 12px;
  color: var(--text-secondary);
  font-size: 0.86rem;
  line-height: 1.5;
}

.video-card {
  padding: 16px;
  border-radius: var(--radius-lg);
  background: var(--surface-muted);
  border: 1px solid var(--border);
  display: grid;
  gap: 12px;
}

.video-card p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.86rem;
  line-height: 1.5;
}

.video-frame {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-inset);
  cursor: pointer;
  aspect-ratio: 16 / 9;
  min-height: 140px;
}

.video-frame-media {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(15, 23, 42, 0.15), rgba(15, 23, 42, 0.55)),
    linear-gradient(135deg, #d8e8f3 0%, #b9d5e8 100%);
}

.video-frame-poster {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 1;
}

.video-frame-poster::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.15), rgba(15, 23, 42, 0.55));
}

.video-play-button {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.25);
  display: grid;
  place-items: center;
}

.video-play-button::before {
  content: "";
  margin-left: 4px;
  border-top: 11px solid transparent;
  border-bottom: 11px solid transparent;
  border-left: 17px solid var(--brand);
}

.video-frame-title {
  position: absolute;
  left: 16px;
  right: 16px;
  top: 14px;
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.35;
  z-index: 2;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.4);
}

.video-frame-label {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.75);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 600;
  white-space: nowrap;
  z-index: 3;
  pointer-events: none;
}

.video-frame-trigger {
  position: absolute;
  inset: 0;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  z-index: 4;
}

.video-frame-trigger:focus-visible {
  outline: 2px solid #fff;
  outline-offset: -4px;
}

.video-link {
  color: var(--brand);
  font-size: 0.84rem;
  font-weight: 600;
  text-decoration: none;
}

.video-link:hover {
  text-decoration: underline;
}


.mobile-copy-bar {
  display: none;
}

@media (max-width: 1200px) {
  .shell-embed {
    grid-template-columns: 1fr;
  }

  .shell-embed .workspace,
  .shell-embed .instructions-panel,
  .shell-embed .controls {
    position: static;
    min-height: auto;
    max-height: none;
  }

  .shell-embed .preview-shell,
  .shell-embed .preview-stage {
    flex: none;
    min-height: auto;
  }

  .shell-embed .signature-preview {
    min-height: 120px;
  }

  .instructions-panel,
  .controls {
    position: static;
    max-height: none;
  }
}

@media (max-width: 900px) {
  .shell,
  .shell-embed {
    grid-template-columns: minmax(0, 1fr);
    padding: max(10px, env(safe-area-inset-left, 0px)) max(10px, env(safe-area-inset-right, 0px));
    gap: 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
  }

  .controls,
  .instructions-panel {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .controls-scroll,
  .instructions-scroll {
    max-height: none;
    overflow: visible;
    padding-right: 16px;
  }

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

  .workspace-header--preview {
    flex-direction: row;
    align-items: center;
    gap: 10px;
  }

  .workspace-header--preview .eyebrow {
    width: auto;
  }

  .workspace-copy-btn {
    display: none !important;
  }

  .controls .actions {
    display: grid;
  }

  .preview-chrome {
    flex-wrap: wrap;
    gap: 8px;
  }

  .preview-label {
    font-size: 0.65rem;
  }

  .preview-stage {
    padding: 12px;
  }

  .signature-preview {
    padding: 12px;
  }
}

@media (max-width: 480px) {
  html {
    font-size: 14px;
  }

  .shell,
  .shell-embed {
    padding: 8px;
    padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
  }

  .controls,
  .workspace,
  .instructions-panel {
    padding: 12px;
    border-radius: 16px;
  }

  .app-logo {
    max-width: min(168px, 72vw);
    max-height: 44px;
  }

  .lede {
    font-size: 0.84rem;
    max-width: none;
  }

  .section-card {
    padding: 10px;
  }

  .btn {
    padding: 11px 12px;
    font-size: 0.86rem;
  }

  .toggle-chips {
    gap: 6px;
  }

  .toggle-chip span {
    padding: 7px 10px;
    font-size: 0.74rem;
  }

  .step {
    font-size: 0.8rem;
  }

  .preview-chrome {
    padding: 8px 10px;
  }

  .signature-preview {
    padding: 10px;
  }

  .video-modal {
    padding: 8px;
  }

  .video-modal-body iframe {
    height: min(52vh, 320px);
  }
}
