/* stylelint-disable no-descending-specificity -- scoped rules deliberately follow the base element rules. */

/* Tokens use light-dark(), so forcing a scheme is one color-scheme switch. */
:root {
  --bg: light-dark(#f7f7f8, #0f1115);
  --panel: light-dark(#fff, #161920);
  --panel-2: light-dark(#f1f2f4, #1d2129);
  --fg: light-dark(#17191c, #e9ebee);
  --muted: light-dark(#5d6672, #9aa3af);
  --border: light-dark(#e1e4e8, #2a2f38);
  --accent: #e04e39;
  --accent-soft: light-dark(#fdecea, #3a1d19);
  --accent-fg: #fff;
  --down: light-dark(#1f6feb, #6ea8ff);
  --up: light-dark(#b35900, #f0a35c);
  --danger: light-dark(#c62828, #ff8a80);
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", menlo, monospace;
  --j-key: light-dark(#8250df, #c4a3ff);
  --j-str: light-dark(#0a7c4a, #7ee0a8);
  --j-num: light-dark(#b35900, #f0a35c);
  --j-lit: light-dark(#cf222e, #ff8a80);

  color-scheme: light dark;
}

:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font:
    14px/1.5 system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
}

/* Base element styles stay out of .preview, where the A2UI catalog renders
   light-DOM elements that must look exactly as they would in any app. */

:where(a:not(.preview *)) {
  color: inherit;
  text-decoration-color: color-mix(in srgb, currentcolor 40%, transparent);
  text-underline-offset: 2px;
}

:where(a:not(.preview *):hover) {
  color: var(--accent);
}

:where(h1:not(.preview *)),
:where(h2:not(.preview *)),
:where(h3:not(.preview *)) {
  margin: 0;
  line-height: 1.25;
}

:where(h3:not(.preview *)) {
  margin: 1rem 0 0.4rem;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

:where(h3:not(.preview *):first-of-type) {
  margin-top: 0;
}

:where(p:not(.preview *)) {
  margin: 0;
}

:where(code:not(.preview *)),
:where(kbd:not(.preview *)) {
  font-family: var(--mono);
  font-size: 0.92em;
}

:where(kbd:not(.preview *)) {
  padding: 0 0.3em;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--panel);
}

:where(button:not(.preview *)),
:where(select:not(.preview *)) {
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: inherit;
  font: inherit;
  cursor: pointer;
}

:where(button:not(.preview *):hover:not(:disabled)),
:where(select:not(.preview *):hover) {
  border-color: var(--accent);
}

:where(button:not(.preview *):disabled) {
  opacity: 0.4;
  cursor: default;
}

:where(button:not(.preview *):focus-visible),
:where(select:not(.preview *):focus-visible),
:where(a:not(.preview *):focus-visible),
:where(textarea:not(.preview *):focus-visible),
:where(input:not(.preview *):focus-visible),
:where(summary:not(.preview *):focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-fg);
}

.btn-small {
  padding: 0.15rem 0.5rem;
  font-size: 12px;
}

.muted {
  color: var(--muted);
}

.error {
  margin-top: 0.5rem;
  color: var(--danger);
  font-size: 13px;
}

.visually-hidden {
  position: absolute;
  overflow: hidden;
  width: 1px;
  height: 1px;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---- Header ------------------------------------------------------------ */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  align-items: center;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.brand {
  display: flex;
  gap: 0.65rem;
  align-items: center;
}

.logo {
  width: 34px;
  height: 34px;
  flex: none;
}

.logo rect {
  fill: var(--accent);
}

.logo path {
  fill: none;
  stroke: #fff;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.5;
}

.brand h1 {
  font-size: 1.1rem;
  letter-spacing: -0.01em;
}

.tagline {
  color: var(--muted);
  font-size: 12.5px;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.badges li {
  padding: 0.1rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
}

.header-links {
  display: flex;
  gap: 1rem;
  margin-left: auto;
  font-weight: 500;
}

.theme-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.segmented {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--panel-2);
}

.segmented button {
  padding: 0.2rem 0.6rem;
  border: 0;
  border-radius: 7px;
  background: transparent;
  font-size: 13px;
}

.segmented button[aria-pressed="true"] {
  background: var(--panel);
  box-shadow: 0 1px 2px rgb(0 0 0 / 15%);
}

.brand-picker {
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
}

.brand-picker select {
  font-size: 13px;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 15%);
}

/* ---- Explorer layout ---------------------------------------------------- */

.explorer {
  display: grid;
  flex: 1;
  grid-template-columns: 14.5rem minmax(0, 1fr) minmax(20rem, 28rem);
  min-height: 0;
}

.explorer-sidebar,
.stage,
.inspector-body {
  overflow: auto;
}

.explorer-sidebar {
  padding: 1rem 0.75rem;
  border-right: 1px solid var(--border);
  background: var(--panel);
}

.explorer-sidebar h2 {
  margin: 1rem 0.5rem 0.35rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.explorer-sidebar h2:first-child {
  margin-top: 0;
}

.explorer-sidebar ul {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.sample-btn {
  display: flex;
  width: 100%;
  gap: 0.5rem;
  align-items: baseline;
  justify-content: space-between;
  border-color: transparent;
  background: transparent;
  text-align: left;
}

.sample-btn:hover:not(:disabled) {
  border-color: transparent;
  background: var(--panel-2);
}

.sample-btn[aria-current="true"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.sample-btn small {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.sidebar-hint {
  margin: 1.25rem 0.5rem 0;
  font-size: 12px;
}

/* ---- Stage ------------------------------------------------------------- */

.stage {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.25rem 1.5rem 2rem;
}

.stage-header h2 {
  margin-bottom: 0.2rem;
  font-size: 1.35rem;
  letter-spacing: -0.01em;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6rem;
  margin: 0;
}

.stats > div {
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-end;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}

.stats dd {
  margin: 0;
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}

.stats dt {
  color: var(--muted);
  font-size: 12px;
}

.stats dt span {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  opacity: 0.8;
}

.transport {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  padding: 0.45rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}

.icon-btn {
  display: inline-grid;
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  place-items: center;
  font-size: 15px;
}

.icon-btn.play {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 13px;
}

.scrubber {
  flex: 1;
  min-width: 4rem;
  accent-color: var(--accent);
}

.progress {
  min-width: 3.5rem;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  text-align: center;
}

.speed select {
  padding: 0.3rem 0.4rem;
  font-size: 13px;
}

/* ---- Conversation -------------------------------------------------------- */

.chat {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  max-width: 46rem;
}

.turn {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
}

.turn-user {
  justify-content: flex-end;
}

.avatar {
  display: grid;
  width: 2rem;
  height: 2rem;
  flex: none;
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  place-items: center;
}

.turn-agent .avatar {
  background: var(--accent);
  color: var(--accent-fg);
}

.bubble {
  max-width: 80%;
  padding: 0.55rem 0.9rem;
  border-radius: 16px 16px 4px;
  background: var(--accent);
  color: var(--accent-fg);
}

.preview {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 4px 16px 16px;
  background: var(--panel);
}

.preview:empty {
  display: none;
}

.skeleton {
  display: grid;
  gap: 0.6rem;
}

.skeleton span {
  height: 0.9rem;
  border-radius: 6px;
  background: linear-gradient(
    90deg,
    var(--panel-2) 0%,
    var(--border) 50%,
    var(--panel-2) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}

.skeleton span:nth-child(1) {
  width: 55%;
  height: 1.4rem;
}

.skeleton span:nth-child(3) {
  width: 75%;
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

.typing {
  display: flex;
  gap: 0.3rem;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: bounce 1s infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing span:nth-child(3) {
  margin-right: 0.3rem;
  animation-delay: 0.3s;
}

@keyframes bounce {
  50% {
    opacity: 0.3;
    transform: translateY(-3px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton span,
  .typing span {
    animation: none;
  }
}

/* ---- Inspector ----------------------------------------------------------- */

.inspector {
  display: flex;
  min-height: 0;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--panel);
}

.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

.tabs button {
  margin-bottom: -1px;
  padding: 0.45rem 0.8rem;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
}

.tabs button:hover:not(:disabled) {
  color: var(--fg);
}

.tabs button[aria-selected="true"] {
  border-bottom-color: var(--accent);
  color: var(--fg);
}

.count {
  margin-left: 0.3rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: var(--panel-2);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.inspector-body {
  flex: 1;
  padding: 0.9rem;
}

.panel-intro {
  margin-bottom: 0.75rem;
  font-size: 12.5px;
}

.json {
  margin: 0;
  padding: 0.6rem 0.75rem;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font: 12px/1.45 var(--mono);
  tab-size: 2;
}

.j-key {
  color: var(--j-key);
}

.j-str {
  color: var(--j-str);
}

.j-num {
  color: var(--j-num);
}

.j-lit {
  color: var(--j-lit);
}

.wire {
  display: grid;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.wire-entry {
  border: 1px solid var(--border);
  border-left: 3px solid var(--down);
  border-radius: 8px;
  background: var(--panel);
  transition: opacity 0.2s;
}

.wire-up {
  border-left-color: var(--up);
}

.wire-entry.is-pending {
  border-left-color: var(--border);
  border-style: dashed;
  opacity: 0.5;
}

.wire-toggle {
  display: flex;
  width: 100%;
  gap: 0.45rem;
  align-items: baseline;
  padding: 0.4rem 0.6rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}

.wire-toggle:hover:not(:disabled) {
  background: var(--panel-2);
}

.wire-dir {
  color: var(--down);
  font-weight: 700;
}

.wire-up .wire-dir {
  color: var(--up);
}

.wire-kind {
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 600;
}

.wire-detail {
  overflow: hidden;
  flex: 1;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wire-meta {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.wire-body {
  padding: 0 0.6rem 0.6rem;
}

.wire-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.4rem;
  font-size: 12px;
}

.wire-body .json {
  max-height: 22rem;
}

.editor {
  width: 100%;
  min-height: 24rem;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: inherit;
  font: 12px/1.45 var(--mono);
  resize: vertical;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.5rem;
}

.capabilities {
  margin-top: 1rem;
}

.capabilities summary {
  margin-bottom: 0.4rem;
  color: var(--muted);
  cursor: pointer;
  font-size: 12.5px;
}

.capabilities .json {
  max-height: 20rem;
}

/* ---- Small screens ------------------------------------------------------- */

@media (width <= 1100px) {
  .explorer {
    grid-template-columns: 13rem minmax(0, 1fr);
  }

  .inspector {
    grid-column: 1 / -1;
    border-top: 1px solid var(--border);
    border-left: 0;
  }

  .app {
    height: auto;
    min-height: 100vh;
  }

  .inspector-body {
    max-height: 70vh;
  }
}

@media (width <= 700px) {
  .explorer {
    grid-template-columns: minmax(0, 1fr);
  }

  .explorer-sidebar {
    display: flex;
    overflow-x: auto;
    gap: 0.25rem;
    padding: 0.5rem 1rem;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .explorer-sidebar h2,
  .sidebar-hint {
    display: none;
  }

  .explorer-sidebar ul {
    display: flex;
    gap: 0.25rem;
  }

  .sample-btn {
    white-space: nowrap;
  }

  .stage {
    padding: 1rem;
  }

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

  .header-links {
    margin-left: 0;
  }

  .avatar {
    display: none;
  }

  .bubble {
    max-width: 100%;
  }
}
