:root {
  --page-cream: #fdf8ec;
  --surface-cream: #fffaf1;
  --surface-warm: #fff7eb;
  --surface-white: #ffffff;
  --text-cocoa: #594026;
  --text-muted: #836d57;
  --orange: #f49a16;
  --orange-deep: #d96d0c;
  --green-muted: #4f7d5a;
  --border-warm: #ead8c6;
  --pastel-yellow: #fff2d9;
  --pastel-mint: #e7f5ed;
  --pastel-blue: #e7f3f8;
  --pastel-peach: #fde9e3;
  --canvas: var(--page-cream);
  --canvas-band: #f7ecd9;
  --surface: var(--surface-cream);
  --surface-strong: #ffffff;
  --surface-muted: var(--surface-warm);
  --ink: var(--text-cocoa);
  --ink-soft: #6b5035;
  --muted: var(--text-muted);
  --placeholder: #927b65;
  --inactive: #8f7a67;
  --line: var(--border-warm);
  --line-strong: #d9c1aa;
  --accent: var(--orange);
  --accent-dark: var(--orange-deep);
  --accent-soft: #fff0d7;
  --teal: var(--green-muted);
  --teal-dark: #386344;
  --teal-soft: var(--pastel-mint);
  --green: #347151;
  --amber: #9a632c;
  --red: #a63f3b;
  --focus: var(--orange-deep);
  --display: "Prompt", "Noto Sans Thai", "Leelawadee UI", Tahoma, sans-serif;
  --body: "Poppins", "Prompt", "Noto Sans Thai", "Leelawadee UI", Tahoma, sans-serif;
  --mono: "IBM Plex Mono", "Cascadia Code", Consolas, monospace;
  --shadow-small: 0 14px 34px -24px rgba(89, 64, 38, 0.3);
  --shadow-panel: 0 24px 54px -34px rgba(89, 64, 38, 0.4);
  --shadow-cta: 0 12px 24px -14px rgba(239, 126, 22, 0.75);
  --radius-small: 12px;
  --radius: 16px;
  --radius-large: 24px;
  --radius-pill: 9999px;
  --ease-out: cubic-bezier(0.2, 0, 0, 1);
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
  scroll-behavior: smooth;
  scroll-padding-top: 88px;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.65;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: 360px;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(135deg, #fffaf1 0%, #fff6e7 54%, #f8efe3 100%);
  border-bottom: 1px solid rgba(89, 64, 38, 0.06);
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
select,
input[type="radio"],
input[type="file"],
summary {
  cursor: pointer;
}

a,
button,
input,
select,
textarea,
summary {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: var(--teal);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

#studio-panel,
#library-panel,
#worksheet-form {
  scroll-margin-top: 88px;
}

[hidden],
.app-panel[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: -70px;
  left: 18px;
  z-index: 100;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 8px 16px;
  color: #fff;
  border-radius: var(--radius-small);
  background: var(--ink);
  text-decoration: none;
}

.skip-link:focus {
  top: 12px;
}

.utility-strip {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  padding: 8px max(18px, calc((100vw - 1296px) / 2));
  color: var(--text-cocoa);
  border-bottom: 1px solid #f1d7ad;
  background: var(--pastel-yellow);
  font-size: 12px;
}

.utility-strip strong {
  font-weight: 800;
}

.utility-strip div {
  display: flex;
  align-items: center;
  gap: 18px;
  white-space: nowrap;
}

.utility-strip span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
}

.utility-strip span::before {
  content: "";
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border: 2px solid var(--orange-deep);
  border-radius: 50%;
  background: #fff8e8;
}

/* Application header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 9px clamp(18px, 4vw, 56px);
  border-bottom: 1px solid var(--border-warm);
  background: rgba(255, 250, 242, 0.95);
  backdrop-filter: blur(18px);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--border-warm);
  border-radius: 16px;
  background: var(--surface-strong);
  box-shadow: var(--shadow-card, 0 14px 34px -24px rgba(89, 64, 38, 0.3));
}

.brand-mark img {
  width: 40px;
  height: 40px;
  display: block;
  object-fit: contain;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  color: var(--text-cocoa);
  font-size: 16px;
  line-height: 1.25;
  letter-spacing: -0.015em;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

/* Editorial introduction */
.page-shell {
  width: min(1328px, calc(100% - 32px));
  margin: 0 auto;
  padding: 38px 0 64px;
}

.intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(290px, 360px);
  align-items: end;
  gap: clamp(36px, 7vw, 96px);
  margin-bottom: 24px;
  padding: clamp(28px, 5vw, 62px);
  overflow: hidden;
  border: 1px solid var(--border-warm);
  border-radius: 24px;
  background: linear-gradient(135deg, rgba(255, 250, 241, 0.96), rgba(255, 243, 225, 0.9));
  box-shadow: var(--shadow-panel);
}

.hero-copy {
  max-width: 820px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
  letter-spacing: 0.045em;
}

.eyebrow > span {
  width: 20px;
  height: 1px;
  display: inline-block;
  margin: 0 7px 3px 0;
  background: currentColor;
}

.intro h1 {
  max-width: 850px;
  margin: 0;
  font-family: var(--display);
  font-size: clamp(42px, 4.6vw, 68px);
  font-weight: 800;
  line-height: 1.08;
  letter-spacing: -0.045em;
}

.lede {
  max-width: 760px;
  margin: 17px 0 0;
  color: var(--muted);
  font-size: clamp(16px, 1.1vw, 18px);
  line-height: 1.75;
}

.proof-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin: 26px 0 0;
  padding: 0;
}

.proof-strip div {
  min-width: 0;
  padding-left: 12px;
  border-left: 3px solid var(--orange);
}

.proof-strip dt {
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 850;
}

.proof-strip dd {
  margin: 3px 0 0;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.45;
}

.review-note {
  display: flex;
  align-items: flex-start;
  gap: 13px;
  padding: 18px;
  border: 1px solid #cfe6d7;
  border-left: 4px solid var(--teal);
  border-radius: 6px var(--radius-large) var(--radius-large) 6px;
  background: var(--pastel-mint);
  box-shadow: var(--shadow-small);
}

.review-note > span {
  width: 29px;
  height: 29px;
  flex: 0 0 29px;
  display: grid;
  place-items: center;
  color: #fff;
  border-radius: 50%;
  background: var(--teal);
  font-size: 13px;
  font-weight: 850;
}

.review-note small,
.review-note strong {
  display: block;
}

.review-note small {
  margin: 0 0 3px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
}

.review-note strong {
  font-size: 15px;
  line-height: 1.45;
}

.review-note p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

/* Workspace navigation */
.workspace-tabs {
  width: max-content;
  max-width: 100%;
  display: flex;
  gap: 4px;
  margin: 0 0 20px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: #f5eadc;
}

.workspace-tab,
.workspace-tab.primary,
.workspace-tab.secondary {
  min-height: 48px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  flex-direction: column;
  gap: 1px;
  padding: 7px 17px;
  color: var(--muted);
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  text-align: left;
  box-shadow: none;
}

.workspace-tab span,
.workspace-tab.primary span,
.workspace-tab.secondary span {
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 800;
}

.workspace-tab small,
.workspace-tab.secondary small {
  font-size: 12px;
}

.workspace-tab.active {
  color: var(--muted);
  background: var(--surface-strong);
  box-shadow: var(--shadow-small);
}

.workspace-tab.active span {
  color: var(--ink);
}

/* Workspace headers */
.studio-heading,
.library-heading,
.library-status-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

.studio-heading {
  margin: 0 0 14px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 250, 241, 0.84);
}

.studio-heading .eyebrow,
.library-heading .eyebrow {
  margin-bottom: 4px;
}

.studio-heading h2,
.library-heading h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 28px;
  font-weight: 800;
  line-height: 1.3;
  letter-spacing: -0.025em;
}

.studio-heading > p,
.library-heading p:not(.eyebrow) {
  max-width: 430px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 340px);
  align-items: start;
  gap: 16px;
}

.form-card,
.status-card {
  min-width: 0;
  border: 1px solid var(--line);
  background: rgba(255, 250, 241, 0.96);
}

.form-card {
  padding: clamp(24px, 3vw, 36px);
  border-radius: var(--radius-large);
  box-shadow: var(--shadow-panel);
}

.status-card {
  position: sticky;
  top: 84px;
  padding: 23px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-small);
}

.section-heading {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 23px;
}

.section-heading.compact {
  margin-bottom: 18px;
}

.section-heading h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 24px;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.section-heading p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.step-number {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  color: var(--accent-dark);
  border: 1px solid #f0c47f;
  border-radius: 50%;
  background: var(--accent-soft);
  font: 800 10px/1 var(--mono);
}

.field-grid {
  display: grid;
  gap: 15px;
  margin-bottom: 18px;
}

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

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

.three-cols {
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr) minmax(0, 0.8fr);
}

label {
  min-width: 0;
}

label > span,
.source-panel > label > span {
  display: block;
  margin-bottom: 6px;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 750;
}

label em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 500;
}

input:not([type="radio"]):not([type="file"]),
select,
textarea {
  width: 100%;
  color: var(--ink);
  border: 1px solid var(--border-warm);
  border-radius: 14px;
  background: #fffdf8;
  background: var(--surface-strong);
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

input:not([type="radio"]):not([type="file"]),
select {
  min-height: 48px;
  padding: 0 12px;
  font-size: 14px;
}

textarea {
  min-height: 126px;
  padding: 14px;
  font-size: 14px;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: var(--placeholder);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--orange-deep);
  background: var(--surface-strong);
  box-shadow: 0 0 0 3px rgba(244, 154, 22, 0.18);
}

select:disabled {
  cursor: not-allowed;
  color: var(--inactive);
  background: var(--surface-muted);
  opacity: 1;
}

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--red);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 16%, transparent);
}

button[aria-busy="true"] {
  cursor: progress;
}

button[aria-busy="true"]::after {
  content: "";
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  display: inline-block;
  margin-left: 7px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -2px;
  animation: busy-spin 700ms linear infinite;
}

@keyframes busy-spin {
  to {
    transform: rotate(1turn);
  }
}

.field-hint,
.provider-status {
  min-height: 16px;
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.provider-status.ready {
  color: var(--green);
}

.provider-status.pending {
  color: var(--amber);
}

.provider-status.error {
  color: var(--red);
}

.divider {
  height: 1px;
  margin: 32px 0;
  background: var(--line);
}

/* Template selection */
.template-picker {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  align-items: center;
  gap: 22px;
  margin: 8px 0 22px;
  padding: 20px;
  border: 1px solid #cfe6d7;
  border-left: 4px solid var(--teal);
  border-radius: 5px var(--radius) var(--radius) 5px;
  background: var(--pastel-mint);
}

.template-picker .eyebrow {
  color: var(--teal);
}

.template-picker-copy h3 {
  margin: 0 0 4px;
  font-family: var(--display);
  font-size: 22px;
  font-weight: 650;
}

.template-picker-copy > p:not(.eyebrow) {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.template-picker-copy label {
  display: block;
  max-width: 520px;
}

.template-picker-copy small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.image-prompt-button {
  min-height: 44px;
  margin-top: 11px;
  padding: 0 11px;
  color: var(--teal-dark);
  border: 1px solid #adc9c1;
  border-radius: 7px;
  background: #fff;
  font-size: 13px;
  font-weight: 750;
}

.image-prompt-button:hover {
  border-color: var(--teal);
  background: var(--teal-soft);
}

.image-prompt-button:disabled {
  cursor: wait;
  color: var(--inactive);
  background: var(--surface-muted);
  opacity: 1;
}

.template-preview {
  width: 142px;
  margin: 0;
  justify-self: end;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 20px rgba(23, 32, 51, 0.1);
}

.template-preview img {
  width: 100%;
  height: auto;
  display: block;
}

.template-preview figcaption {
  padding: 7px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  font-size: 12px;
  text-align: center;
}

.image-prompt-panel {
  grid-column: 1 / -1;
  padding-top: 15px;
  border-top: 1px solid #cbd9d4;
}

.image-prompt-panel > div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 12px;
}

.image-prompt-panel > div:first-child span {
  color: var(--muted);
}

.image-prompt-panel textarea {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
}

.image-prompt-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 8px;
}

.image-prompt-footer small {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.image-prompt-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.image-prompt-actions .image-prompt-button {
  margin-top: 0;
}

.image-prompt-footer button {
  min-height: 44px;
  padding: 0 12px;
  color: #fff;
  border: 0;
  border-radius: 6px;
  background: var(--teal);
  font-size: 13px;
  font-weight: 750;
}

/* Source input */
.source-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 3px;
  margin-bottom: 9px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-muted);
}

.source-authority-note {
  margin: 0 0 9px;
  padding: 10px 12px;
  color: var(--ink-soft);
  border-left: 3px solid var(--teal);
  border-radius: 0 7px 7px 0;
  background: color-mix(in srgb, var(--teal) 8%, var(--surface-strong));
  font-size: 12px;
  line-height: 1.55;
}

.source-tabs label {
  position: relative;
}

.source-tabs input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.source-tabs span {
  min-height: 44px;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 7px 10px;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 6px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
}

.source-tabs input:checked + span {
  color: var(--ink);
  border-color: var(--line);
  background: var(--surface-strong);
  box-shadow: 0 2px 7px rgba(23, 32, 51, 0.06);
}

.source-tabs input:focus-visible + span {
  outline: 3px solid rgba(198, 87, 49, 0.22);
}

.source-tabs input:disabled + span {
  cursor: not-allowed;
  opacity: 0.55;
}

.form-card.job-processing {
  cursor: wait;
}

.form-card.job-processing > :not(.job-lock-notice) {
  pointer-events: none;
}

.form-card.job-processing .source-tabs,
.form-card.job-processing .source-panel,
.form-card.job-processing .field-grid,
.form-card.job-processing .advanced,
.form-card.job-processing .consent-group {
  opacity: 0.58;
}

.job-lock-notice {
  margin: 14px 0 0;
  padding: 11px 13px;
  color: var(--teal-dark);
  border: 1px solid #b7d3ca;
  border-radius: 8px;
  background: var(--teal-soft);
  font-size: 13px;
  font-weight: 700;
}

.source-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-strong);
}

.source-panel textarea {
  display: block;
  min-height: 155px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.source-panel > label:not(.dropzone) > span:not(.visually-hidden) {
  padding: 14px 14px 0;
}

.source-panel > label:not(.dropzone) > input {
  width: calc(100% - 28px);
  margin: 0 14px 14px;
}

.source-panel > .field-hint {
  margin: -6px 14px 14px;
}

.youtube-source-preview {
  display: grid;
  grid-template-columns: minmax(220px, 44%) minmax(0, 1fr);
  gap: 14px;
  margin: 0 14px 14px;
  padding: 12px;
  border: 1px solid #cbd9d4;
  border-radius: 8px;
  background: var(--surface-muted);
}

.youtube-preview-frame {
  position: relative;
  overflow: hidden;
  border-radius: 6px;
  background: #111;
  aspect-ratio: 16 / 9;
}

.youtube-preview-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.youtube-preview-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 7px;
}

.youtube-preview-copy strong {
  color: var(--ink);
  font-size: 14px;
}

.youtube-preview-copy span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.youtube-preview-copy a {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  color: var(--teal);
  font-size: 13px;
  font-weight: 750;
}

.panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 13px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  background: #f7f7f3;
  font-size: 12px;
}

.source-actions {
  display: flex;
  align-items: center;
  gap: 15px;
}

.text-button {
  min-height: 44px;
  padding: 0 4px;
  color: var(--teal);
  border: 0;
  background: transparent;
  font-size: 13px;
  font-weight: 750;
}

.text-button:hover {
  color: var(--ink);
}

.text-button:disabled {
  cursor: not-allowed;
  color: var(--inactive);
}

.ai-button {
  color: var(--accent-dark);
}

.ai-button span {
  display: inline;
  margin: 0 3px 0 0;
  font-size: 12px;
}

.ai-draft-note {
  margin: 0;
  padding: 9px 13px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  background: #fffdfa;
  font-size: 12px;
  line-height: 1.55;
}

.source-assistant-status {
  margin: 0;
  padding: 10px 13px;
  color: var(--teal-dark);
  border-top: 1px solid #c7ddd6;
  background: var(--teal-soft);
  font-size: 13px;
}

.source-assistant-status.error {
  color: var(--red);
  border-color: #e5c6c3;
  background: #f7e7e5;
}

.dropzone {
  min-height: 176px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 6px;
  padding: 26px;
  border: 1px dashed #aeb8b2;
  border-radius: 9px;
  background: #fafaf7;
  text-align: center;
}

.dropzone:hover {
  border-color: var(--teal);
  background: #f4f8f6;
}

.dropzone input {
  width: min(310px, 100%);
  color: var(--muted);
  font-size: 13px;
}

.upload-icon {
  width: 50px;
  height: 36px;
  display: grid;
  place-items: center;
  margin: 0 0 2px !important;
  color: var(--teal);
  border: 1px solid #b7cec7;
  border-radius: 7px;
  background: var(--teal-soft);
  font-size: 10px;
  font-weight: 850;
}

.dropzone strong {
  font-size: 15px;
}

.dropzone small {
  max-width: 480px;
  color: var(--muted);
  font-size: 12px;
}

.dropzone output {
  color: var(--teal);
  font-size: 12px;
  font-weight: 750;
}

.advanced {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafaf7;
}

.advanced summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 750;
}

.advanced textarea {
  min-height: 92px;
  margin-top: 12px;
}

.consent-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 18px 0 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f8f7f3;
}

.consent-group legend {
  padding: 0 5px;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 800;
}

.consent-group > p {
  grid-column: 1 / -1;
  margin: -2px 0 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.consent-group label {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: start;
  gap: 8px;
  min-height: 48px;
  padding: 12px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.consent-group label:has(input:checked) {
  border-color: #abc9c0;
  background: #f5faf8;
}

.consent-group input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin: 1px 0 0;
  accent-color: var(--teal);
}

.consent-group strong {
  display: block;
  margin-bottom: 1px;
  color: var(--ink);
  font-size: 13px;
}

.consent-group a {
  margin-left: 2px;
  font-weight: 750;
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 18px;
}

.form-actions p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.primary-button {
  min-width: 238px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 17px;
  color: #fff;
  border: 1px solid var(--orange-deep);
  border-radius: var(--radius-pill);
  background: linear-gradient(135deg, var(--orange), var(--orange-deep));
  box-shadow: var(--shadow-cta);
  font-size: 14px;
  font-weight: 800;
}

.primary-button b {
  font-size: 16px;
  font-weight: 500;
  transition: transform 150ms ease;
}

.primary-button:hover {
  background: linear-gradient(135deg, #f7a728, #d96309);
  box-shadow: 0 16px 28px -15px rgba(239, 126, 22, 0.9);
}

.primary-button:hover b {
  transform: translateX(3px);
}

.primary-button:disabled {
  cursor: wait;
  color: var(--surface-strong);
  border-color: var(--inactive);
  background: var(--inactive);
  opacity: 1;
  box-shadow: none;
}

/* Job status and output */
.status-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.status-head .eyebrow {
  margin: 0;
}

.job-pill {
  padding: 4px 7px;
  color: var(--muted);
  border-radius: 5px;
  background: #ebece8;
  font-size: 12px;
  font-weight: 800;
}

.job-pill.running {
  color: #7d4b20;
  background: #f5e4d3;
}

.job-pill.success {
  color: #1f654b;
  background: #dcece3;
}

.job-pill.failed {
  color: #8f302b;
  background: #f3dedb;
}

.status-card > h2 {
  margin: 24px 0 7px;
  font-family: var(--display);
  font-size: 22px;
  font-weight: 650;
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.status-card > p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.progress-list {
  margin: 24px 0 0;
  padding: 0;
  list-style: none;
}

.progress-list li {
  position: relative;
  display: grid;
  grid-template-columns: 15px minmax(0, 1fr);
  gap: 10px;
  padding: 0 0 18px;
  color: var(--inactive);
}

.progress-list li:not(:last-child)::before {
  content: "";
  position: absolute;
  top: 14px;
  bottom: 0;
  left: 5px;
  width: 1px;
  background: var(--line);
}

.progress-list i {
  position: relative;
  z-index: 1;
  width: 11px;
  height: 11px;
  margin-top: 2px;
  border: 2px solid #c4c9c5;
  border-radius: 50%;
  background: var(--surface);
}

.progress-list strong,
.progress-list span {
  display: block;
}

.progress-list strong {
  color: inherit;
  font-size: 14px;
}

.progress-list span {
  margin-top: 2px;
  font-size: 12px;
  line-height: 1.45;
}

.progress-list li.active {
  color: var(--ink);
}

.progress-list li.active i {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.progress-list li.done {
  color: var(--green);
}

.progress-list li.done i {
  border-color: var(--green);
  background: var(--green);
}

.result-panel {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 11px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.result-panel > div:first-of-type:not(.result-mark) {
  min-width: 0;
}

.result-mark {
  width: 31px;
  height: 31px;
  display: grid;
  place-items: center;
  color: #fff;
  border-radius: 50%;
  background: var(--green);
  font-size: 13px;
  font-weight: 850;
}

.result-panel h3 {
  margin: 1px 0 0;
  font-size: 15px;
}

.result-panel p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.pdf-preview,
.download-title,
.download-grid,
.json-preview,
.source-preview,
.rewrite-panel {
  grid-column: 1 / -1;
}

.pdf-preview {
  margin-top: 7px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f4f4f1;
}

.pdf-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-strong);
}

.pdf-preview-head strong,
.pdf-preview-head span {
  display: block;
}

.pdf-preview-head strong {
  font-size: 13px;
}

.pdf-preview-head span {
  color: var(--muted);
  font-size: 12px;
}

.pdf-preview-head a {
  color: var(--teal);
  font-size: 12px;
  font-weight: 750;
  text-decoration: none;
}

.pdf-preview-pages {
  max-height: 420px;
  overflow: auto;
  padding: 10px;
}

.pdf-preview-pages figure {
  margin: 0 0 10px;
}

.pdf-preview-pages figure:last-child {
  margin-bottom: 0;
}

.pdf-preview-pages img {
  width: 100%;
  height: auto;
  display: block;
  border: 1px solid #d7d7d2;
  background: #fff;
}

.pdf-preview-pages figcaption {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.download-title {
  margin: 6px 0 0;
  font-size: 13px;
}

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

.download-button {
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-strong);
  text-decoration: none;
}

.download-button:hover {
  border-color: var(--teal);
  background: #f6faf8;
}

.download-button b,
.download-button span {
  display: block;
}

.download-button b {
  color: var(--teal);
  font-size: 13px;
}

.download-button span {
  color: var(--muted);
  font-size: 12px;
}

.rewrite-panel {
  display:grid;
  grid-template-columns:minmax(0,1fr) auto;
  align-items:center;
  gap:8px 12px;
  margin-top:4px;
  padding:12px;
  border:1px solid #b7d3ca;
  border-radius:8px;
  background:var(--teal-soft);
}

.rewrite-panel strong,
.rewrite-panel span {
  display:block;
}

.rewrite-panel strong {
  color:var(--teal-dark);
  font-size:13px;
}

.rewrite-panel span {
  margin-top:3px;
  color:var(--muted);
  font-size:12px;
  line-height:1.45;
}

.rewrite-panel .image-prompt-button {
  margin-top:0;
  white-space:nowrap;
}

.rewrite-panel p {
  grid-column:1 / -1;
  margin:0;
  padding-top:7px;
  border-top:1px solid #c7ddd6;
  color:var(--teal-dark);
  font-weight:700;
}

.rewrite-panel p.error {
  color:var(--red);
}

.json-preview,
.source-preview {
  margin-top: 2px;
  font-size: 12px;
}

.json-preview summary,
.source-preview summary {
  color: var(--teal);
  font-weight: 750;
}

.json-preview pre {
  max-height: 220px;
  overflow: auto;
  padding: 10px;
  color: #dfe8ef;
  border-radius: 6px;
  background: #172033;
  font: 12px/1.6 var(--mono);
  white-space: pre-wrap;
}

.source-preview {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8f8f4;
}

.source-preview strong {
  display: block;
  margin-top: 8px;
  color: var(--ink);
}

.source-preview p {
  margin: 4px 0 0;
  line-height: 1.55;
}

.error-panel {
  margin-top: 18px;
  padding: 11px;
  color: var(--red);
  border: 1px solid #e2bfbd;
  border-radius: 7px;
  background: #f8e9e7;
  font-size: 14px;
}

.error-panel p {
  margin: 3px 0 0;
  font-size: 13px;
}

/* Worksheet library */
.library-panel {
  overflow: hidden;
  padding: clamp(20px, 3vw, 30px);
  border: 1px solid var(--line);
  border-radius: var(--radius-large);
  background: rgba(255, 250, 241, 0.96);
  box-shadow: var(--shadow-panel);
}

.library-heading {
  align-items: flex-start;
}

.library-proof {
  min-width: 158px;
  padding: 11px 13px;
  border: 1px solid #bfd5ce;
  border-radius: 16px;
  background: var(--pastel-mint);
}

.library-proof strong {
  display: block;
  color: var(--teal-dark);
  font-family: var(--display);
  font-size: 19px;
}

.library-proof span {
  color: var(--muted);
  font-size: 12px;
}

.library-filters {
  display: grid;
  grid-template-columns: minmax(130px, 0.65fr) minmax(200px, 1fr) minmax(240px, 1.5fr) auto;
  gap: 10px;
  align-items: end;
  margin: 22px 0 15px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface-warm);
}

.library-filters label {
  display: grid;
  gap: 5px;
}

.library-filters label > span {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.library-filters input,
.library-filters select {
  min-height: 48px;
  background: #fff;
}

.library-filters button,
.library-more {
  min-height: 48px;
  padding: 0 17px;
  color: #fff;
  border: 0;
  border-radius: var(--radius-pill);
  background: linear-gradient(135deg, var(--orange), var(--orange-deep));
  box-shadow: var(--shadow-cta);
  font-size: 13px;
  font-weight: 800;
}

.library-filters button:hover,
.library-more:hover {
  background: linear-gradient(135deg, #f7a728, #d96309);
}

.library-status-row {
  align-items: center;
  margin: 0 0 13px;
  color: var(--muted);
  font-size: 12px;
}

.library-status-row p {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.library-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 7px;
}

.library-card {
  --subject-accent: #27786e;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) minmax(420px, auto);
  align-items: center;
  gap: 14px;
  min-height: 78px;
  padding: 11px 13px 11px 10px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--subject-accent);
  border-radius: 16px;
  background: #fffdf8;
  transition: transform 280ms var(--ease-out), box-shadow 280ms var(--ease-out), border-color 280ms var(--ease-out);
  content-visibility: auto;
  contain-intrinsic-size: auto 80px;
}

.library-card:hover {
  transform: translateY(-3px);
  border-color: #dfc4aa;
  box-shadow: var(--shadow-small);
}

.library-card.subject-math {
  --subject-accent: #b95d3e;
}

.library-card.subject-science {
  --subject-accent: #18766a;
}

.library-card.subject-thai {
  --subject-accent: #976022;
}

.library-card.subject-english {
  --subject-accent: #4268a3;
}

.library-card.subject-social {
  --subject-accent: #6d5191;
}

.library-grade-badge {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: color-mix(in srgb, var(--subject-accent) 12%, var(--surface-strong));
  color: var(--subject-accent);
  font-size: 12px;
  font-weight: 900;
}

.library-card-body {
  min-width: 0;
}

.library-card-meta {
  margin: 0 0 2px;
  color: var(--subject-accent);
  font-size: 12px;
  font-weight: 900;
}

.library-card h3 {
  margin: 0;
  overflow: hidden;
  font-family: var(--display);
  display: -webkit-box;
  font-size: 16px;
  font-weight: 650;
  line-height: 1.3;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.library-card-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
}

.library-preview-button {
  min-width: 125px;
  min-height: 44px;
  padding: 0 12px;
  color: #fff;
  border: 0;
  border-radius: 7px;
  background: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.library-preview-button::before {
  content: "▣";
  margin-right: 5px;
  color: #e8a78e;
}

.library-prompt-button {
  min-height: 44px;
  padding: 0 12px;
  color: var(--teal-dark);
  border: 1px solid color-mix(in srgb, var(--teal) 35%, var(--line));
  border-radius: 7px;
  background: color-mix(in srgb, var(--teal) 8%, #fff);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.library-prompt-button::before {
  content: none;
}

.library-prompt-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.library-downloads {
  display: flex;
  gap: 4px;
}

.library-downloads a {
  min-width: 48px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  color: var(--subject-accent);
  border-radius: 6px;
  background: color-mix(in srgb, var(--subject-accent) 9%, var(--surface-strong));
  font-size: 12px;
  font-weight: 900;
  text-align: center;
  text-decoration: none;
}

.library-empty {
  padding: 25px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f6f5f0;
  font-size: 14px;
  text-align: center;
}

.library-empty.error {
  color: var(--red);
}

.library-more {
  display: block;
  min-width: 190px;
  margin: 20px auto 0;
}

/* PDF dialog */
.library-pdf-dialog {
  width: min(1120px, calc(100vw - 30px));
  max-width: none;
  height: min(860px, calc(100vh - 24px));
  height: min(860px, calc(100dvh - 24px));
  max-height: none;
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 28px 90px rgba(10, 20, 36, 0.28);
}

.library-pdf-dialog::backdrop {
  background: rgba(10, 19, 34, 0.72);
  backdrop-filter: blur(5px);
}

.access-key-dialog {
  width: min(480px, calc(100vw - 30px));
  max-width: none;
  margin: auto;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-large);
  background: var(--surface);
  box-shadow: 0 28px 90px rgba(10, 20, 36, 0.32);
}

.access-key-dialog::backdrop {
  background: rgba(32, 24, 16, 0.68);
  backdrop-filter: blur(5px);
}

.access-key-shell {
  display: grid;
  gap: 18px;
  padding: clamp(24px, 5vw, 36px);
}

.access-key-shell h2,
.access-key-shell p {
  margin: 0;
}

.access-key-mark {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  color: #fff;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--orange-deep), var(--orange));
  font-family: var(--display);
  font-size: 20px;
  font-weight: 800;
}

.access-key-shell label {
  display: grid;
  gap: 7px;
  font-weight: 700;
}

.access-key-shell input {
  width: 100%;
  min-height: 50px;
  padding: 10px 13px;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-small);
  background: var(--surface-strong);
}

.access-key-error {
  color: var(--red);
  font-weight: 700;
}

.access-key-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.library-pdf-shell {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.library-pdf-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 19px 13px;
  border-bottom: 1px solid var(--line);
}

.library-pdf-head .eyebrow {
  margin-bottom: 3px;
}

.library-pdf-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 22px;
  font-weight: 650;
}

.library-pdf-head p:last-child {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.library-pdf-head button {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  font-size: 20px;
  line-height: 1;
}

.library-pdf-pages {
  overflow: auto;
  overscroll-behavior: contain;
  padding: 24px;
  background: #34383d;
}

.library-pdf-pages figure {
  width: min(740px, 100%);
  margin: 0 auto 24px;
}

.library-pdf-pages figure:last-child {
  margin-bottom: 0;
}

.library-pdf-pages img {
  width: 100%;
  height: auto;
  display: block;
  background: #fff;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.28);
}

.library-pdf-pages figcaption {
  margin-top: 7px;
  color: rgba(255, 255, 255, 0.8);
  font-size: 12px;
  text-align: center;
}

.library-pdf-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 19px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: #f4f3ee;
}

.library-pdf-actions span {
  color: var(--muted);
  font-size: 12px;
}

.library-pdf-actions a {
  min-width: 160px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  color: #fff;
  border-radius: 7px;
  background: var(--teal);
  font-size: 13px;
  font-weight: 850;
  text-align: center;
  text-decoration: none;
}

footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 20px clamp(18px, 4vw, 56px);
  color: var(--muted);
  border-top: 1px solid var(--line);
  background: var(--canvas-band);
  font-size: 12px;
}

@media (hover: hover) {
  .workspace-tab:hover:not(.active),
  .source-tabs label:hover span {
    color: var(--ink);
    background: color-mix(in srgb, var(--surface-strong) 72%, transparent);
  }

  .library-card:hover {
    border-color: var(--line-strong);
    box-shadow: var(--shadow-small);
  }

  .library-downloads a:hover {
    color: var(--surface-strong);
    background: var(--subject-accent);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .intro,
  .workspace-tabs,
  .app-panel:not([hidden]) {
    animation: enter 420ms cubic-bezier(0.2, 0.75, 0.25, 1) both;
  }

  .workspace-tabs {
    animation-delay: 55ms;
  }

  .app-panel:not([hidden]) {
    animation-delay: 90ms;
  }

  @keyframes enter {
    from {
      opacity: 0;
      transform: translateY(8px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}

@media (min-width: 1920px) {
  .page-shell {
    width: min(1480px, calc(100% - 96px));
  }

  .intro h1 {
    font-size: 68px;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 20px;
  }
}

@media (max-width: 1120px) {
  .intro {
    grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
    gap: 38px;
  }

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

  .status-card {
    position: relative;
    top: auto;
  }

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

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

  .library-card {
    grid-template-columns: 52px minmax(0, 1fr);
  }

  .library-card-actions {
    grid-column: 2;
    justify-content: flex-start;
  }
}

@media (max-width: 900px) {
  .page-shell {
    width: min(100% - 48px, 1440px);
  }

  .intro {
    grid-template-columns: minmax(0, 1fr);
    gap: 24px;
  }

  .intro h1 br {
    display: none;
  }

  .review-note {
    max-width: 560px;
  }

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

  .three-cols > label:first-child {
    grid-column: 1 / -1;
  }

  .studio-heading,
  .library-heading,
  .library-status-row {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .topbar {
    min-height: 62px;
    gap: 10px;
    padding: 8px 12px;
  }

  .brand {
    gap: 8px;
  }

  .brand-mark {
    width: 39px;
    height: 39px;
    flex-basis: 39px;
  }

  .brand-mark img {
    width: 36px;
    height: 36px;
  }

  .brand strong {
    max-width: 135px;
    overflow: hidden;
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .brand small {
    display: none;
  }

  .page-shell {
    width: min(100% - 32px, 1440px);
    padding: 24px 0 42px;
  }

  .intro {
    margin-bottom: 18px;
    padding: 12px 0 22px;
  }

  .intro h1 {
    font-size: clamp(36px, 10.2vw, 44px);
    line-height: 1.16;
  }

  .intro h1 br {
    display: none;
  }

  .lede {
    font-size: 14px;
  }

  .proof-strip {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .proof-strip div {
    display: grid;
    grid-template-columns: 70px minmax(0, 1fr);
    gap: 8px;
  }

  .proof-strip dd {
    margin: 0;
  }

  .workspace-tabs {
    width: 100%;
  }

  .workspace-tab,
  .workspace-tab.primary,
  .workspace-tab.secondary {
    min-width: 0;
    flex: 1;
    padding: 8px 10px;
  }

  .workspace-tab small {
    display: none;
  }

  .studio-heading {
    padding: 15px;
  }

  .studio-heading h2,
  .library-heading h2 {
    font-size: 24px;
  }

  .form-card,
  .status-card {
    padding: 21px 16px;
    box-shadow: 0 12px 30px rgba(23, 32, 51, 0.05);
  }

  .section-heading {
    align-items: flex-start;
  }

  .section-heading h2 {
    font-size: 22px;
  }

  .four-cols,
  .two-cols,
  .three-cols {
    grid-template-columns: minmax(0, 1fr);
  }

  .three-cols > label:first-child {
    grid-column: auto;
  }

  input:not([type="radio"]):not([type="file"]),
  select {
    min-height: 48px;
  }

  .template-picker {
    grid-template-columns: minmax(0, 1fr);
    padding: 16px;
  }

  .template-preview {
    width: 135px;
    justify-self: center;
  }

  .source-tabs span {
    min-height: 44px;
    padding: 7px 5px;
    font-size: 12px;
  }

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

  .panel-footer,
  .image-prompt-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .image-prompt-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .source-actions {
    width: 100%;
    justify-content: space-between;
  }

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

  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .primary-button {
    width: 100%;
    min-width: 0;
  }

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

  .rewrite-panel .image-prompt-button {
    width:100%;
    white-space:normal;
  }

  .library-panel {
    padding: 18px 13px;
  }

  .library-proof {
    width: 100%;
  }

  .library-filters {
    grid-template-columns: minmax(0, 1fr);
    padding: 12px;
  }

  .library-card {
    grid-template-columns: 43px minmax(0, 1fr);
    gap: 10px;
    padding: 10px;
  }

  .library-grade-badge {
    width: 39px;
    height: 39px;
  }

  .library-card-actions {
    grid-column: 1 / -1;
    justify-content: stretch;
  }

  .library-preview-button {
    flex: 1;
    min-width: 0;
  }

  .library-prompt-button {
    flex: 1;
  }

  .library-downloads {
    flex: 1;
    justify-content: flex-end;
  }

  .library-pdf-dialog {
    width: calc(100vw - 12px);
    height: calc(100vh - 12px);
    height: calc(100dvh - 12px);
    border-radius: 9px;
  }

  .library-pdf-head,
  .library-pdf-pages {
    padding: 13px;
  }

  .library-pdf-actions {
    align-items: stretch;
    flex-direction: column;
    gap: 7px;
    padding: 10px 13px;
  }

  .library-pdf-actions a {
    width: 100%;
  }

  footer {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
    padding-inline: 12px;
  }
}

.coloring-showcase {
  margin: 30px 0 34px;
  overflow: hidden;
  border: 1px solid var(--border-warm);
  border-radius: var(--radius-large);
  background:
    radial-gradient(circle at 92% 8%, rgba(244, 154, 22, 0.12), transparent 28%),
    linear-gradient(145deg, #fffdf7 0%, var(--surface-warm) 100%);
  box-shadow: var(--shadow-panel);
}

.coloring-showcase-summary {
  display: flex;
  min-height: 92px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 26px;
  list-style: none;
  cursor: pointer;
}

.coloring-showcase-summary::-webkit-details-marker {
  display: none;
}

.coloring-showcase-summary > span:first-child {
  display: grid;
  gap: 2px;
}

.coloring-showcase-summary small {
  color: var(--orange-deep);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.coloring-showcase-summary strong {
  color: var(--text-cocoa);
  font-family: var(--display);
  font-size: clamp(21px, 2.2vw, 30px);
  line-height: 1.3;
}

.coloring-showcase-summary > span:first-child > span {
  color: var(--text-muted);
  font-size: 14px;
}

.coloring-showcase-summary-badge {
  flex: 0 0 auto;
  padding: 9px 15px;
  color: var(--green-muted);
  border: 1px solid #bdd9c7;
  border-radius: var(--radius-pill);
  background: var(--pastel-mint);
  font-size: 13px;
  font-weight: 800;
}

.coloring-showcase-summary-badge::after {
  content: " +";
  color: var(--orange-deep);
}

.coloring-showcase[open] .coloring-showcase-summary-badge::after {
  content: " −";
}

.coloring-showcase-body {
  padding: 0 clamp(22px, 4vw, 44px) clamp(22px, 4vw, 44px);
  border-top: 1px solid var(--border-warm);
}

.coloring-showcase-description {
  margin: 18px 0 22px;
  color: var(--text-muted);
}

.coloring-showcase-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
}

.coloring-showcase-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border-warm);
  border-radius: 18px;
  background: var(--surface-white);
  box-shadow: var(--shadow-small);
  transition:
    transform 180ms var(--ease-out),
    box-shadow 180ms var(--ease-out),
    border-color 180ms var(--ease-out);
}

.coloring-showcase-card:hover {
  border-color: #e1b77e;
  box-shadow: 0 22px 44px -28px rgba(89, 64, 38, 0.5);
  transform: translateY(-4px);
}

.coloring-showcase-card > img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1055 / 1491;
  object-fit: cover;
  border-bottom: 1px solid var(--border-warm);
  background: #fff;
}

.coloring-showcase-card > div {
  position: relative;
  padding: 18px;
}

.coloring-showcase-card span {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 4px 11px;
  color: var(--orange-deep);
  border: 1px solid #f5c98b;
  border-radius: var(--radius-pill);
  background: var(--pastel-yellow);
  font-size: 12px;
  font-weight: 800;
}

.coloring-showcase-card h3 {
  margin: 11px 0 3px;
  color: var(--text-cocoa);
  font-family: var(--display);
  font-size: 19px;
  line-height: 1.35;
}

.coloring-showcase-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
}

.coloring-showcase-more {
  display: block;
  min-height: 46px;
  margin: 26px auto 0;
  padding: 10px 22px;
  color: #fff;
  border: 1px solid var(--orange-deep);
  border-radius: var(--radius-pill);
  background: linear-gradient(135deg, var(--orange), var(--orange-deep));
  box-shadow: var(--shadow-cta);
  font-weight: 800;
}

.coloring-showcase-more:hover {
  filter: brightness(0.98);
  transform: translateY(-1px);
}

.coloring-showcase-loading,
.coloring-showcase-error {
  grid-column: 1 / -1;
  margin: 0;
  padding: 18px;
  color: var(--text-muted);
  text-align: center;
  border: 1px dashed var(--border-warm);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
}

.coloring-showcase-error {
  color: var(--red);
}

@media (max-width: 900px) {
  .coloring-showcase-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .coloring-showcase {
    margin-inline: -2px;
  }

  .coloring-showcase-summary {
    align-items: flex-start;
    flex-direction: column;
    padding: 19px;
  }

  .coloring-showcase-body {
    padding: 0 19px 19px;
  }

  .coloring-showcase-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 360px) {
  .source-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace-tab span {
    font-size: 12px;
  }
}

@media (max-width: 767px) {
  .utility-strip {
    overflow-x: auto;
    justify-content: flex-start;
    padding-inline: 16px;
    scrollbar-width: none;
  }

  .utility-strip::-webkit-scrollbar {
    display: none;
  }

  .utility-strip strong {
    min-width: max-content;
  }

  .utility-strip div {
    gap: 14px;
  }
}

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

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

@media (prefers-color-scheme: dark) and (max-width: 0px) {
  :root {
    --canvas: #11161f;
    --canvas-band: #0d121a;
    --surface: #171e29;
    --surface-strong: #1d2633;
    --surface-muted: #202a37;
    --ink: #f1f5f3;
    --ink-soft: #d4ddd8;
    --muted: #aeb9c8;
    --placeholder: #9ba7b8;
    --inactive: #9aa6b6;
    --line: #3e4b58;
    --line-strong: #5c6978;
    --accent: #f08a65;
    --accent-dark: #f2a084;
    --accent-soft: #4a2b24;
    --teal: #62c8b6;
    --teal-dark: #9de0d3;
    --teal-soft: #203d39;
    --green: #72d2a8;
    --amber: #f0bb75;
    --red: #ff9690;
    --focus: #ffb08f;
    --shadow-small: 0 8px 24px rgba(0, 0, 0, 0.2);
    --shadow-panel: 0 18px 48px rgba(0, 0, 0, 0.24);
  }

  html {
    color-scheme: dark;
  }

  body::before {
    border-color: rgba(255, 255, 255, 0.05);
  }

  .topbar {
    border-color: rgba(255, 255, 255, 0.1);
    background: rgba(13, 18, 26, 0.94);
  }

  .brand-mark {
    border-color: rgba(255, 255, 255, 0.12);
  }

  .skip-link,
  .primary-button,
  .library-preview-button,
  .library-prompt-button {
    color: #fff;
    border-color: #34465e;
    background: #29384d;
  }

  .primary-button:hover,
  .library-preview-button:hover,
  .library-prompt-button:hover {
    background: #34465e;
  }

  .review-note {
    border-color: #36594f;
    border-left-color: var(--teal);
    background: #172a29;
  }

  .workspace-tabs {
    background: #0f151e;
  }

  .studio-heading {
    background: rgba(23, 30, 41, 0.82);
  }

  input:not([type="radio"]):not([type="file"]),
  select,
  textarea {
    border-color: var(--line);
  }

  .step-number {
    border-color: #7a4938;
  }

  .template-picker {
    border-color: #36594f;
    border-left-color: var(--teal);
    background: #172a29;
  }

  .image-prompt-button {
    border-color: #47796f;
    background: var(--surface-strong);
  }

  .template-preview,
  .template-preview img,
  .pdf-preview-pages img,
  .library-pdf-pages img {
    background: #fff;
  }

  .image-prompt-panel {
    border-color: #36594f;
  }

  .panel-footer,
  .ai-draft-note,
  .advanced,
  .consent-group,
  .source-preview,
  .library-empty,
  .library-pdf-actions {
    background: var(--surface-muted);
  }

  .source-assistant-status.error,
  .error-panel {
    border-color: #744743;
    background: #3f2628;
  }

  .dropzone {
    border-color: var(--line-strong);
    background: #1a222e;
  }

  .dropzone:hover {
    background: #1b2d2b;
  }

  .consent-group label:has(input:checked) {
    border-color: #47796f;
    background: #1b302d;
  }

  .job-pill {
    background: #293341;
  }

  .job-pill.running {
    color: #ffd3a1;
    background: #493524;
  }

  .job-pill.success {
    color: #a9e6c9;
    background: #203a31;
  }

  .job-pill.failed {
    color: #ffb2ac;
    background: #452a2b;
  }

  .progress-list i {
    border-color: var(--line-strong);
  }

  .pdf-preview {
    background: #121821;
  }

  .download-button:hover,
  .library-proof {
    border-color: #47796f;
    background: #1b302d;
  }

  .library-filters {
    background: #121821;
  }

  .library-filters input,
  .library-filters select,
  .library-card,
  .library-pdf-head button {
    background: var(--surface-strong);
  }

  .library-card {
    --subject-accent: #64c6b5;
  }

  .library-card.subject-math {
    --subject-accent: #ef9a79;
  }

  .library-card.subject-science {
    --subject-accent: #62c8b6;
  }

  .library-card.subject-thai {
    --subject-accent: #e4ae66;
  }

  .library-card.subject-english {
    --subject-accent: #8eace8;
  }

  .library-card.subject-social {
    --subject-accent: #ba9cdb;
  }

  .primary-button:disabled,
  .image-prompt-button:disabled {
    color: #1d2633;
    border-color: var(--inactive);
    background: var(--inactive);
    opacity: 1;
  }
}
