:root {
  color-scheme: light;
  --bg: #f7f4ed;
  --surface: #fffdfa;
  --surface-strong: #fff7e8;
  --ink: #1f2933;
  --muted: #66788a;
  --line: #d9e2ec;
  --accent: #0e7490;
  --accent-strong: #155e75;
  --good: #166534;
  --warn: #92400e;
  --shadow: 0 18px 40px rgba(31, 41, 51, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

body.vmd-auto-page {
  background: var(--bg);
}

body.vmd-preserve-page {
  background: initial;
}

button,
textarea {
  font: inherit;
}

.auto-banner {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px clamp(18px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
  background: rgba(247, 244, 237, 0.94);
  backdrop-filter: blur(10px);
}

.auto-banner h1 {
  font-size: 24px;
  line-height: 1.1;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 24px clamp(18px, 4vw, 48px) 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

.app-header h1 {
  font-size: 36px;
  line-height: 1.05;
}

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

.file-button,
.actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid #b6c6d6;
  border-radius: 8px;
  padding: 9px 12px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.file-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.file-button input {
  display: none;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 0.75fr) minmax(420px, 1.25fr);
  gap: 18px;
  padding: 18px clamp(18px, 4vw, 48px) 34px;
}

.source-panel,
.preview-panel {
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
}

.panel-head h2 {
  font-size: 14px;
  text-transform: uppercase;
  color: var(--muted);
}

#file-name {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#source-input {
  width: 100%;
  height: calc(100vh - 160px);
  min-height: 460px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #0f172a;
  color: #dbeafe;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.6;
  outline: none;
}

#source-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14, 116, 144, 0.15);
}

.mode-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
}

.mode-tab {
  border: 0;
  border-radius: 6px;
  padding: 6px 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.mode-tab.active {
  background: var(--ink);
  color: #fff;
}

.diagnostics {
  display: none;
  gap: 8px;
  max-height: 120px;
  overflow: auto;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
}

.diagnostics.active {
  display: grid;
}

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

.layer-summary.active {
  display: grid;
}

.layer-card {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.layer-card strong {
  font-size: 13px;
}

.layer-card span {
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 700;
}

.layer-card small {
  color: var(--muted);
  line-height: 1.35;
}

.diagnostic {
  border-left: 3px solid var(--warn);
  padding-left: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.diagnostic.error {
  border-color: #dc2626;
  color: #991b1b;
}

.drop-zone {
  min-height: 460px;
  height: calc(100vh - 160px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.drop-zone.dragging {
  outline: 3px solid rgba(14, 116, 144, 0.22);
  outline-offset: 3px;
}

.preview {
  min-height: 100%;
}

.empty-state {
  display: grid;
  place-items: center;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.doc-view {
  padding: clamp(24px, 4vw, 54px);
}

.doc-title {
  max-width: 880px;
  margin: 0 auto 32px;
}

.doc-title h1 {
  margin-top: 6px;
  font-size: 56px;
  line-height: 0.98;
}

.doc-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.meta-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--muted);
  font-size: 12px;
}

.frame {
  max-width: 880px;
  margin: 18px auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: clamp(18px, 3vw, 30px);
  background: #fff;
}

.frame-role {
  margin: 0 0 12px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.frame h2 {
  margin-bottom: 16px;
  font-size: 30px;
  line-height: 1.15;
}

.block {
  margin-top: 14px;
  border-radius: 8px;
  padding: 16px;
  line-height: 1.62;
}

.block-label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.block p {
  margin: 0;
}

.block-claim {
  background: #ecfeff;
  border: 1px solid #a5f3fc;
  font-size: 26px;
  line-height: 1.28;
}

.block-evidence {
  background: #f8fafc;
  border: 1px solid var(--line);
}

.block-insight {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
}

.block-decision {
  background: #fff7ed;
  border: 1px solid #fed7aa;
}

.block-action {
  background: #eef2ff;
  border: 1px solid #c7d2fe;
}

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

.compare-column {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.compare-column h3 {
  padding: 12px 14px;
  background: var(--surface-strong);
  font-size: 14px;
}

.compare-column ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 14px 18px 16px 30px;
}

.loop-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.loop-node {
  border: 1px solid #99f6e4;
  border-radius: 999px;
  padding: 8px 11px;
  background: #f0fdfa;
  color: #134e4a;
  font-weight: 700;
}

.loop-arrow {
  color: var(--accent);
}

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

.timeline-list li {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  align-items: start;
}

.timeline-index {
  display: inline-grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.matrix-block {
  display: grid;
  gap: 10px;
}

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

.matrix-cell {
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface);
}

.matrix-cell span,
.matrix-axis,
.layout-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.matrix-cell strong {
  display: block;
  margin-top: 6px;
  font-size: 17px;
  line-height: 1.25;
}

.layout {
  margin-top: 14px;
}

.layout-stack {
  display: grid;
  gap: var(--vmd-gap, 14px);
  max-width: var(--vmd-width, none);
  align-items: var(--vmd-align, stretch);
}

.layout-grid {
  display: grid;
  grid-template-columns: var(--vmd-columns, repeat(auto-fit, minmax(220px, 1fr)));
  gap: var(--vmd-gap, 16px);
}

.layout-split {
  display: grid;
  grid-template-columns: var(--vmd-columns, minmax(0, 1fr) minmax(0, 1fr));
  gap: var(--vmd-gap, 18px);
  align-items: var(--vmd-align, stretch);
}

.layout-cluster {
  display: flex;
  flex-wrap: wrap;
  gap: var(--vmd-gap, 10px);
  align-items: var(--vmd-align, center);
}

.layout-panel,
.component {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--surface);
}

.layout-device {
  display: grid;
  place-items: center;
}

.device-shell {
  width: min(100%, var(--vmd-width, 390px));
  border: 1px solid #b8c2cc;
  border-radius: 30px;
  padding: 12px;
  background: #101820;
  box-shadow: var(--shadow);
}

.device-bar {
  width: 74px;
  height: 6px;
  margin: 0 auto 10px;
  border-radius: 999px;
  background: #3c4856;
}

.device-screen {
  min-height: 520px;
  overflow: hidden;
  border-radius: 22px;
  padding: 18px;
  background: #fbfcfd;
  color: #18212f;
}

.layout-tabs {
  display: grid;
  gap: 12px;
}

.tab-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tab-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.tab-panels {
  display: grid;
  gap: 10px;
}

.tab-panel > .frame {
  margin: 0;
}

.component {
  display: grid;
  gap: 8px;
}

.component-card h3,
.component-persona h3 {
  font-size: 18px;
}

.component-metric {
  align-content: start;
}

.component-metric p,
.component-metric span,
.persona-role {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.component-metric strong {
  font-size: 32px;
  line-height: 1;
}

.component-persona {
  grid-template-columns: 46px 1fr;
  align-items: start;
}

.persona-avatar {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 999px;
  background: #dcfce7;
  color: #14532d;
  font-weight: 800;
}

.component-browser {
  padding: 0;
  overflow: hidden;
}

.browser-bar {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  background: #eef2f6;
}

.browser-bar span {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #94a3b8;
}

.browser-canvas {
  padding: 16px;
}

.component-token-table {
  overflow-x: auto;
}

.component-token-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.component-token-table th,
.component-token-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
}

.style-token-block .token-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.token-item {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
}

.token-item code {
  color: var(--accent-strong);
  white-space: normal;
}

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

.token-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.token-badge {
  width: auto;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.token-badge-editable {
  border-color: #bbf7d0;
  background: #ecfdf5;
  color: #166534;
}

.token-badge-locked {
  border-color: #fed7aa;
  background: #fff7ed;
  color: #9a3412;
}

.token-swatch {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.directive-block {
  border-style: dashed;
  background: #f8fafc;
}

.directive-block pre {
  max-height: 240px;
  overflow: auto;
  border-radius: 8px;
  padding: 12px;
  background: #111827;
  color: #e5e7eb;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.directive-fields {
  display: grid;
  gap: 8px;
  margin: 0;
}

.directive-fields div {
  display: grid;
  grid-template-columns: minmax(110px, 0.4fr) minmax(0, 1fr);
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.directive-fields div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.directive-fields dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.directive-fields dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.replay-layer {
  background: #f6f8fb;
}

.directive-residual {
  border-color: #cbd5e1;
  color: #334155;
}

.raw-embed {
  display: contents;
}

.raw-disabled pre {
  max-height: 260px;
  overflow: auto;
  border-radius: 8px;
  padding: 12px;
  background: #111827;
  color: #e5e7eb;
}

.preserve-view {
  min-height: 100vh;
}

.deck-view {
  display: grid;
  gap: 18px;
  padding: 24px;
}

.slide {
  display: grid;
  min-height: calc(100vh - 220px);
  align-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: clamp(24px, 5vw, 72px);
  background: #fff;
}

.slide .frame {
  max-width: none;
  margin: 0;
  border: 0;
  padding: 0;
  box-shadow: none;
}

.map-view {
  padding: clamp(24px, 4vw, 54px);
}

.map-list {
  display: grid;
  gap: 14px;
  max-width: 760px;
  margin: 0 auto;
  padding: 0;
  list-style: none;
}

.map-node {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fff;
}

.map-node + .map-node::before {
  content: "";
  position: absolute;
  top: -15px;
  left: 30px;
  width: 2px;
  height: 14px;
  background: var(--accent);
}

.map-node strong {
  display: block;
  margin-bottom: 6px;
  color: var(--accent-strong);
  font-size: 12px;
  text-transform: uppercase;
}

.error {
  margin: 24px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 16px;
  background: #fef2f2;
  color: #991b1b;
}

@media (max-width: 900px) {
  .auto-banner {
    align-items: flex-start;
    flex-direction: column;
  }

  .auto-banner h1 {
    font-size: 20px;
  }

  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .actions {
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .layer-summary {
    grid-template-columns: 1fr;
  }

  .app-header h1 {
    font-size: 30px;
  }

  .doc-title h1 {
    font-size: 42px;
  }

  .frame h2 {
    font-size: 24px;
  }

  .block-claim {
    font-size: 22px;
  }

  #source-input,
  .drop-zone {
    height: auto;
  }

  .compare-grid {
    grid-template-columns: 1fr;
  }
}
