:root {
  --bg: #f4f0e8;
  --bg-strong: #ebe5da;
  --surface: rgba(255, 255, 255, 0.74);
  --surface-strong: rgba(255, 255, 255, 0.9);
  --surface-selected: #171412;
  --text-main: #171412;
  --text-soft: #5c534c;
  --text-muted: #7d7268;
  --text-inverse: #f8f5ef;
  --line: rgba(23, 20, 18, 0.14);
  --line-strong: rgba(23, 20, 18, 0.22);
  --accent: #bc5b28;
  --shadow-soft: 0 16px 40px rgba(48, 38, 29, 0.08);
  --shadow-strong: 0 24px 70px rgba(48, 38, 29, 0.12);
  --radius-lg: 1.5rem;
  --radius-md: 1rem;
  --gutter: clamp(1rem, 2vw, 1.5rem);
  --font-display: "Space Grotesk", "Avenir Next", sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", monospace;
}

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

html {
  font-size: 16px;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  color: var(--text-main);
  font-family: var(--font-display);
  background:
    radial-gradient(circle at top left, rgba(188, 91, 40, 0.08), transparent 24%),
    radial-gradient(circle at top right, rgba(41, 69, 145, 0.06), transparent 22%),
    linear-gradient(180deg, #f7f3eb 0%, var(--bg) 55%, #efe9df 100%);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(23, 20, 18, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 20, 18, 0.035) 1px, transparent 1px);
  background-size: 32px 32px;
  opacity: 0.42;
}

::selection {
  background: rgba(188, 91, 40, 0.18);
  color: var(--text-main);
}

a,
button {
  color: inherit;
}

button {
  font: inherit;
}

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

code {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: minmax(16.5rem, 21rem) minmax(0, 1fr);
  gap: var(--gutter);
  min-height: 100vh;
  padding: var(--gutter);
}

.viewer-sidebar,
.viewer-stage {
  position: relative;
  z-index: 1;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius-lg) + 0.2rem);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(16px);
}

.viewer-sidebar {
  display: grid;
  grid-template-rows: auto auto auto auto auto;
  gap: 0.85rem;
  padding: 1rem;
  align-self: start;
}

.sidebar-copy {
  display: grid;
  gap: 0.75rem;
}

.eyebrow,
.meta-label,
.draft-tag,
.stage-tag,
.stage-meta dt,
.frame-status {
  margin: 0;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sidebar-copy h1,
.stage-heading h2 {
  margin: 0;
  letter-spacing: -0.05em;
  line-height: 0.96;
}

.sidebar-copy h1 {
  max-width: 8ch;
  font-size: clamp(2rem, 4vw, 3.9rem);
}

.intro,
.sidebar-note p,
.stage-description,
.draft-description,
.stage-meta dd {
  margin: 0;
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: 0.86rem;
  line-height: 1.6;
}

.sidebar-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

.meta-chip {
  display: grid;
  gap: 0.25rem;
  padding: 0.9rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-strong);
}

.meta-chip strong {
  font-size: 0.98rem;
  letter-spacing: -0.03em;
}

.sidebar-note {
  padding: 0.95rem;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.45);
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.filter-chip,
.support-chip,
.support-runtime {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2rem;
  padding: 0.48rem 0.75rem;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.filter-chip {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.filter-chip:hover {
  transform: translateY(-1px);
  border-color: rgba(23, 20, 18, 0.28);
}

.filter-chip[aria-pressed="true"] {
  border-color: var(--surface-selected);
  background: var(--surface-selected);
  color: var(--text-inverse);
}

.version-list {
  display: grid;
  gap: 0.7rem;
}

.draft-button {
  display: grid;
  gap: 0.55rem;
  width: 100%;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.55);
  text-align: left;
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease;
}

.draft-button:hover {
  transform: translateY(-1px);
  border-color: rgba(23, 20, 18, 0.28);
  box-shadow: 0 10px 24px rgba(48, 38, 29, 0.08);
}

.draft-button[aria-selected="true"] {
  border-color: var(--surface-selected);
  background: var(--surface-selected);
  box-shadow: var(--shadow-strong);
}

.draft-poster {
  overflow: hidden;
  border: 1px solid rgba(23, 20, 18, 0.08);
  border-radius: calc(var(--radius-md) - 0.2rem);
  aspect-ratio: 16 / 10;
  background: rgba(255, 255, 255, 0.78);
}

.draft-poster img,
.stage-poster img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.draft-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.draft-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.8rem;
}

.draft-title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.04em;
}

.draft-focus {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.74rem;
}

.draft-runtime {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.support-chip {
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.7);
  color: var(--text-main);
}

.support-chip[data-tier="stable"] {
  border-color: rgba(69, 119, 82, 0.2);
  background: rgba(111, 164, 124, 0.12);
  color: #2d6b45;
}

.support-chip[data-tier="progressive"] {
  border-color: rgba(49, 88, 165, 0.18);
  background: rgba(77, 121, 214, 0.12);
  color: #244ea7;
}

.support-chip[data-tier="experimental"] {
  border-color: rgba(164, 88, 33, 0.18);
  background: rgba(196, 117, 55, 0.12);
  color: #9c4e14;
}

.draft-button[aria-selected="true"] .draft-title,
.draft-button[aria-selected="true"] .draft-tag,
.draft-button[aria-selected="true"] .draft-focus,
.draft-button[aria-selected="true"] .draft-description {
  color: var(--text-inverse);
}

.draft-button[aria-selected="true"] .support-chip {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-inverse);
  border-color: rgba(255, 255, 255, 0.18);
}

.stage-overview {
  display: grid;
  grid-template-columns: minmax(10rem, 12.5rem) minmax(0, 1fr);
  gap: 0.8rem;
  align-items: start;
}

.stage-poster {
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius-lg) - 0.1rem);
  background: rgba(255, 255, 255, 0.8);
  box-shadow: var(--shadow-soft);
  aspect-ratio: 16 / 11;
}

.stage-details {
  display: grid;
  gap: 0.65rem;
  min-width: 0;
}

.viewer-stage {
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 0.85rem;
  min-width: 0;
  padding: 1rem;
  align-self: start;
}

.stage-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.stage-heading {
  display: grid;
  gap: 0.45rem;
  min-width: 0;
}

.stage-heading h2 {
  font-size: clamp(1.7rem, 3vw, 2.6rem);
}

.action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.45rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  text-decoration: none;
  white-space: nowrap;
}

.action-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.stage-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
  margin: 0;
}

.stage-meta div {
  display: grid;
  gap: 0.28rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.45);
}

.support-panel {
  display: grid;
  gap: 0.7rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.52);
}

.support-panel-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.6rem;
}

.support-runtime {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.66);
  color: var(--text-soft);
}

.support-note {
  margin: 0;
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.6;
}

.frame-wrap {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: min(66vh, 46rem);
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: calc(var(--radius-lg) - 0.1rem);
  background: #fff;
  box-shadow: var(--shadow-strong);
}

.frame-wrap[data-loading="true"] .frame-status::before {
  content: "";
  display: inline-block;
  width: 0.65rem;
  height: 0.65rem;
  margin-right: 0.45rem;
  border: 1px solid rgba(23, 20, 18, 0.4);
  border-top-color: var(--accent);
  border-radius: 999px;
  vertical-align: middle;
  animation: spin 720ms linear infinite;
}

.frame-toolbar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(247, 243, 235, 0.98), rgba(238, 231, 221, 0.98));
  font-family: var(--font-mono);
}

.frame-dots {
  display: inline-flex;
  gap: 0.35rem;
}

.frame-dots span {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 999px;
  background: rgba(23, 20, 18, 0.18);
}

.frame-dots span:first-child {
  background: #d36d43;
}

.frame-dots span:nth-child(2) {
  background: #d9a13b;
}

.frame-dots span:last-child {
  background: #5f8b53;
}

.frame-path {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--text-soft);
  font-size: 0.8rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 1080px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .stage-overview {
    grid-template-columns: 1fr;
  }

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

  .frame-wrap {
    min-height: 58vh;
  }
}

@media (max-width: 760px) {
  .app-shell {
    height: auto;
    padding: 0.75rem;
  }

  .viewer-sidebar,
  .viewer-stage {
    padding: 1rem;
  }

  .sidebar-copy h1,
  .stage-heading h2 {
    max-width: none;
  }

  .sidebar-meta,
  .stage-meta,
  .version-list {
    grid-template-columns: 1fr;
  }

  .draft-meta,
  .draft-header,
  .support-panel-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .stage-header {
    flex-direction: column;
  }

  .action-link {
    width: 100%;
  }

  .frame-wrap {
    min-height: 62vh;
  }
}
