:root {
  color-scheme: light;
  --ink: #101827;
  --muted: #667085;
  --soft: #8a94a6;
  --line: #d9e2ef;
  --line-strong: #c6d3e3;
  --paper: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #fbfcff;
  --code: #111826;
  --code-line: #263043;
  --blue: #155eef;
  --blue-dark: #1247b8;
  --blue-weak: #eaf1ff;
  --green: #129262;
  --green-weak: #e8f7ef;
  --amber: #b86b00;
  --amber-weak: #fff4df;
  --red: #b42318;
  --red-weak: #fff0ed;
  --shadow: 0 16px 36px rgba(16, 24, 39, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  color: var(--ink);
  background: var(--paper);
}

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

button,
.result-link {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 13px;
  cursor: pointer;
}

button:hover:not(:disabled),
.result-link:hover {
  border-color: #a9b9cf;
  background: #f8fbff;
}

button:focus-visible,
.result-link:focus-visible {
  outline: 3px solid rgba(21, 94, 239, 0.42);
  outline-offset: 2px;
}

button.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
  font-weight: 720;
  box-shadow: 0 8px 18px rgba(21, 94, 239, 0.18);
}

button.primary:hover:not(:disabled) {
  border-color: var(--blue-dark);
  background: var(--blue-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #8db2ff;
  box-shadow: 0 0 0 3px rgba(21, 94, 239, 0.12);
}

input,
select {
  min-height: 38px;
  padding: 8px 10px;
}

input[type="color"] {
  padding: 3px;
}

textarea {
  resize: vertical;
  padding: 10px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: 0;
}

h2 {
  font-size: 15px;
  line-height: 1.3;
  letter-spacing: 0;
}

h3 {
  font-size: 13px;
  line-height: 1.35;
  letter-spacing: 0;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 680;
}

.app-header {
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.bar {
  min-height: 64px;
  width: min(1480px, calc(100vw - 28px));
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(240px, 0.7fr) minmax(460px, 1.35fr) auto;
  align-items: center;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  font-weight: 740;
}

.mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid #bcd1f4;
  border-radius: 6px;
  background: #eef5ff;
}

.mark span {
  width: 17px;
  height: 13px;
  border: 2px solid var(--blue);
  border-left: 6px solid var(--green);
  background: #fff;
}

.badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 6px;
  background: var(--blue);
  color: #fff;
  font-size: 12px;
  font-weight: 720;
}

.brand-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.sub {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.sub a {
  color: var(--blue);
  text-decoration: none;
}

.settings {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) minmax(150px, 0.75fr) auto auto;
  gap: 10px;
  align-items: end;
}

/* §5.6 a11y: plain-text storage notice under the API key field. */
.field-note {
  font-size: 10px;
  line-height: 1.4;
  color: var(--soft);
  font-weight: 400;
}

.status {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--amber);
}

.dot.ok {
  background: var(--green);
}

.dot.bad {
  background: var(--red);
}

.top-actions,
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

main {
  width: min(1480px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 16px 0 22px;
}

.studio {
  display: grid;
  grid-template-columns: minmax(290px, 0.78fr) minmax(520px, 1.55fr) minmax(320px, 0.82fr);
  gap: 14px;
  align-items: stretch;
}

.rail,
.stage,
.inspector {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.rail,
.inspector {
  display: grid;
  align-content: start;
}

.panel-head,
.section-head {
  min-height: 52px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-body,
.section-body {
  padding: 14px;
}

.upload {
  display: grid;
  gap: 10px;
  border-bottom: 1px solid var(--line);
}

.inline-error {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid #ffc7c0;
  border-radius: 6px;
  background: var(--red-weak);
  color: var(--red);
  font-size: 13px;
  line-height: 1.45;
}

.file-list {
  display: grid;
  gap: 4px;
}

.file-button {
  width: 100%;
  min-height: 32px;
  padding: 6px 8px;
  border-color: transparent;
  text-align: left;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.file-button.active {
  border-color: #b7d0ff;
  background: var(--blue-weak);
  color: var(--blue);
  font-weight: 720;
}

.file-button.asset {
  color: var(--muted);
}

/* B5 slide nav (§5.2): one real thumbnail per HTML file, manifest
         order. The iframe shows the same srcdoc document as the main preview
         and is scaled down; hit-testing stays on the button. */
.slide-nav {
  display: grid;
  gap: 6px;
}

.slide-thumb {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 6px;
  border-color: transparent;
  text-align: left;
  font-size: 12px;
}

.slide-thumb.active {
  border-color: #b7d0ff;
  background: var(--blue-weak);
  color: var(--blue);
  font-weight: 720;
}

.slide-thumb:focus-visible {
  outline: none;
  border-color: #8db2ff;
  box-shadow: 0 0 0 3px rgba(21, 94, 239, 0.12);
}

.slide-thumb-frame {
  display: block;
  width: 96px;
  height: 54px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  pointer-events: none;
}

/* Scaled live document: 1600x900 canvas x 0.06 = 96x54. */
.slide-thumb-frame iframe {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  transform: scale(0.06);
  pointer-events: none;
}

.slide-thumb-name {
  overflow-wrap: anywhere;
}

/* Assets & CSS demoted to an accordion below the slide nav (§5.2);
         non-HTML files stay directly editable through it. */
.assets {
  border-top: 1px solid var(--line);
}

.assets summary {
  min-height: 52px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  list-style: none;
}

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

.assets summary h3 {
  flex: 1;
}

.assets summary::after {
  content: "▸";
  color: var(--soft);
  font-size: 12px;
}

.assets[open] summary {
  border-bottom: 1px solid var(--line);
}

.assets[open] summary::after {
  content: "▾";
}

.source-panel {
  border-top: 1px solid var(--line);
}

.source-actions {
  display: flex;
  gap: 8px;
}

#sourceEditor {
  min-height: 344px;
  border-color: #202a3b;
  background: var(--code);
  color: #e8eefc;
  box-shadow: inset 0 1px 0 var(--code-line);
}

.source-panel.is-empty #sourceEditor {
  min-height: 96px;
  background: #f2f5fa;
  border-color: var(--line);
  box-shadow: none;
}

.stage {
  display: grid;
  /* toolbar / preview / §5.4 warning bar (collapses while hidden) */
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.stage-toolbar {
  min-height: 58px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.view-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.view-tools select {
  width: auto;
  min-width: 84px;
}

.preview-shell {
  margin: 14px;
  min-height: 500px;
  display: block;
  overflow: auto;
  border: 1px solid #d6e0ec;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(16, 24, 39, 0.035) 1px, transparent 1px),
    linear-gradient(180deg, rgba(16, 24, 39, 0.035) 1px, transparent 1px), #eef3f8;
  background-size: 24px 24px;
  padding: 18px;
}

/* B4 scale-to-fit: the iframe keeps the real 1600x900 canvas size and is
         scaled visually; the wrapper takes the scaled size so scrollbars and
         page layout stay correct. */
.preview-scale {
  position: relative;
  overflow: hidden;
  margin: 0 auto;
  width: 1600px;
  height: 900px;
}

iframe {
  display: block;
  width: 1600px;
  height: 900px;
  transform-origin: top left;
  border: 1px solid #b9c8dc;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 18px 42px rgba(16, 24, 39, 0.18);
}

/* §5.4 conversion feedback bar under the preview. */
.warning-bar {
  margin: 0 14px 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  display: grid;
  gap: 10px;
  max-height: 240px;
  overflow: auto;
}

.warning-bar[hidden] {
  display: none;
}

.warning-bar-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.warning-bar-head h3 {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.01em;
}

.warning-note {
  color: var(--red);
  font-size: 12px;
}

.warning-note[hidden] {
  display: none;
}

.rediagnose {
  margin-left: auto;
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.warning-section {
  display: grid;
  gap: 6px;
}

.warning-section[hidden] {
  display: none;
}

.warning-section h4 {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 720;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.warning-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-height: 32px;
  padding: 5px 9px;
  text-align: left;
  font-size: 12.5px;
  line-height: 1.45;
}

/* Locator-less warnings are informational rows, not grayed-out buttons. */
.warning-item:disabled {
  cursor: default;
  opacity: 1;
  background: var(--panel-soft);
}

.warning-code {
  flex: none;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.warning-item.sev-warning .warning-code {
  border: 1px solid #f3d494;
  background: var(--amber-weak);
  color: var(--amber);
}

.warning-item.sev-info .warning-code {
  border: 1px solid #bcd3ff;
  background: var(--blue-weak);
  color: var(--blue);
}

.warning-item.sev-error .warning-code {
  border: 1px solid #ffc7c0;
  background: var(--red-weak);
  color: var(--red);
}

.warning-msg {
  color: var(--ink);
}

.preflight-file {
  display: flex;
  align-items: center;
  gap: 8px;
}

.preflight-path {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12.5px;
  font-weight: 600;
}

.inspector .section-body {
  display: grid;
  gap: 14px;
}

.element-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

/* §5.4-3 static conversion hints inside the element card. */
.conversion-hints {
  grid-column: 1 / -1;
  display: grid;
  gap: 3px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
}

.conversion-hints[hidden] {
  display: none;
}

.hint-line {
  color: var(--amber);
  font-size: 12px;
  line-height: 1.45;
}

.hint-line::before {
  content: "▸ ";
  color: var(--soft);
}

.tool-section {
  display: grid;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.tool-section h4 {
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  letter-spacing: 0;
}

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

.text-control {
  min-height: 74px;
}

.checkline {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 0 10px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 520;
}

.checkline input {
  width: auto;
  min-height: 0;
}

.status-bar {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.metric {
  min-height: 78px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
  display: grid;
  align-content: start;
  gap: 8px;
}

.metric-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.empty,
.summary,
.error {
  padding: 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
}

.empty,
.summary {
  border: 1px solid var(--line);
  background: #fbfcfe;
  color: var(--muted);
}

.summary {
  display: none;
}

.summary.visible {
  display: block;
}

/* B8: cancel the export polling from the Job Status metric. */
.cancel-poll {
  justify-self: start;
  height: 30px;
  padding: 0 12px;
  font-size: 12px;
  border-color: var(--red);
  color: var(--red);
  background: var(--red-weak);
}

.error {
  display: none;
  border: 1px solid #ffc7c0;
  background: var(--red-weak);
  color: var(--red);
}

.error.visible {
  display: block;
}

.result-link {
  display: none;
  align-items: center;
  justify-content: center;
  border-color: var(--green);
  background: var(--green);
  color: #fff;
  text-decoration: none;
  font-weight: 720;
}

.result-link.visible {
  display: inline-flex;
}

.pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid #f3d494;
  border-radius: 999px;
  background: var(--amber-weak);
  color: var(--amber);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.pill.ok {
  border-color: #bde8d6;
  background: var(--green-weak);
  color: var(--green);
}

.pill.bad {
  border-color: #ffc7c0;
  background: var(--red-weak);
  color: var(--red);
}

.pill[hidden] {
  display: none;
}

/* Unsaved visual edits: highlighted Save button (N6). */
button.attention {
  border-color: #f3d494;
  background: var(--amber-weak);
  color: var(--amber);
  font-weight: 720;
}

/* Inline 3-way confirm shown when exporting with unsaved edits (N6). */
.export-confirm {
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid #f3d494;
  border-radius: 8px;
  background: var(--amber-weak);
  color: var(--amber);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  font-weight: 680;
}

.export-confirm[hidden] {
  display: none;
}

.confirm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

@media (max-width: 1260px) {
  .bar {
    grid-template-columns: 1fr;
    padding: 12px 0;
  }

  .settings {
    grid-template-columns: minmax(220px, 1fr) minmax(180px, 0.75fr) auto auto;
  }

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

  .inspector {
    grid-column: 1 / -1;
  }

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

@media (max-width: 840px) {
  .bar,
  main {
    width: min(100vw - 24px, 720px);
  }

  .settings,
  .studio,
  .status-bar,
  .tool-grid {
    grid-template-columns: 1fr;
  }

  .top-actions,
  .actions,
  .view-tools {
    width: 100%;
  }

  .top-actions > *,
  .actions > * {
    flex: 1 1 140px;
  }

  .preview-shell {
    min-height: 260px;
    margin: 10px;
    padding: 10px;
  }
}
