/* API explorer: terminal + live code, embedded in the docs site. */

.explorer {
  color-scheme: dark;
  --bg: #0a0d13;
  --bg-glow: radial-gradient(1200px 500px at 70% -10%, rgba(94, 234, 212, 0.07), transparent 60%),
             radial-gradient(900px 500px at 10% 110%, rgba(167, 139, 250, 0.06), transparent 60%);
  --panel: #10141d;
  --panel-edge: #1d2432;
  --panel-title: #0c1017;
  --text: #d7dee8;
  --dim: #6b7687;
  --dimmer: #454f5f;
  --accent: #5eead4;
  --accent-dim: rgba(94, 234, 212, 0.14);
  --active-edge: rgba(94, 234, 212, 0.3);
  --purple: #a78bfa;
  --yellow: #fbd38d;
  --red: #f87171;
  --green: #6ee7a0;
  --blue: #7cc7ff;
  --magenta: #d8a8ff;
  --panel-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  --kbd-bg: #1a2130;
  --kbd-edge: #2a3345;
  --copy-bg: rgba(16, 20, 29, 0.85);
  --badge-bg: rgba(251, 211, 141, 0.1);
  --badge-edge: rgba(251, 211, 141, 0.25);
  --tip-bg: rgba(167, 139, 250, 0.07);
  --tip-edge: rgba(167, 139, 250, 0.22);
  --tip-text: #c9bdf5;
  --mark-bg: rgba(94, 234, 212, 0.13);
  --mark-edge: rgba(94, 234, 212, 0.25);
  --scroll-thumb: #232c3d;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

:root[data-theme="light"] .explorer {
    color-scheme: light;
    --bg: #f5f7fb;
    --bg-glow: radial-gradient(1100px 480px at 75% -10%, rgba(13, 148, 136, 0.08), transparent 62%),
               radial-gradient(800px 420px at 5% 105%, rgba(109, 40, 217, 0.05), transparent 62%);
    --panel: #ffffff;
    --panel-edge: #d9e0ea;
    --panel-title: #f7f9fc;
    --text: #273142;
    --dim: #697586;
    --dimmer: #98a2b3;
    --accent: #0f766e;
    --accent-dim: rgba(15, 118, 110, 0.1);
    --active-edge: rgba(15, 118, 110, 0.24);
    --purple: #6d28d9;
    --yellow: #8a5200;
    --red: #c53030;
    --green: #18794e;
    --blue: #0969a2;
    --magenta: #8b3fc7;
    --panel-shadow: 0 16px 40px rgba(33, 45, 65, 0.1);
    --kbd-bg: #eef2f7;
    --kbd-edge: #d2d9e4;
    --copy-bg: rgba(247, 249, 252, 0.92);
    --badge-bg: rgba(138, 82, 0, 0.08);
    --badge-edge: rgba(138, 82, 0, 0.2);
    --tip-bg: rgba(109, 40, 217, 0.05);
    --tip-edge: rgba(109, 40, 217, 0.18);
    --tip-text: #5b3a8e;
    --mark-bg: rgba(15, 118, 110, 0.1);
    --mark-edge: rgba(15, 118, 110, 0.22);
    --scroll-thumb: #c7cfdb;
}


/* The explorer is embedded in the docs page (#explorer-view). The docs
   frame owns the page chrome; everything here is scoped to .explorer. */

.explorer {
  --bg: #18181b;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: var(--mono);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  color: var(--text);
  font-family: var(--mono);
}
:root[data-theme="light"] .explorer { --bg: #ffffff; }
.explorer[hidden] { display: none; }
.explorer *, .explorer *::before, .explorer *::after { box-sizing: border-box; }

.explorer-intro {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 16px;
  flex: 0 0 auto;
}
.explorer-title {
  margin: 0;
  font-size: 24px;
  font-weight: 400;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--text-color, var(--text));
}
.explorer-lede {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-color-secondary, var(--dim));
}

/* The guided tour lives in the docs sidebar; this chip rail is the
   same list for small screens, where the sidebar is hidden. */
.explorer-steps { display: none; }

.explorer-panels {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: 14px;
  min-height: 0;
}
.explorer-panels > * { min-width: 0; }
.explorer .mobile-view-tabs { display: none; }

.explorer .panel { min-height: 0; }

/* Keep the shortcut row to what fits beside the reset button. */
@media (max-width: 1400px) {
  .explorer .term-help-shortcuts > span:nth-child(4) { display: none; }
}
.explorer #terminal-panel #terminal { flex: 1; min-height: 0; }
.explorer #code-panel { min-height: 0; }

/* ---------- panels ---------- */

.explorer .panel {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 480px;
  box-shadow: var(--panel-shadow);
}

.explorer .panel-title {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--panel-title);
  border-bottom: 1px solid var(--panel-edge);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--dim);
}

.explorer .dots { display: inline-flex; gap: 6px; }
.explorer .dots i { width: 10px; height: 10px; border-radius: 50%; background: #2c3547; }
.explorer .dots i:nth-child(1) { background: #f8717155; }
.explorer .dots i:nth-child(2) { background: #fbd38d55; }
.explorer .dots i:nth-child(3) { background: #6ee7a055; }

.explorer .latency { margin-left: auto; color: var(--dimmer); font-size: 11px; }

/* ---------- terminal ---------- */

.explorer #terminal {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 6px 16px 4px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  overflow-y: auto;
  cursor: text;
  white-space: pre-wrap;
  word-break: break-word;
}

.explorer #terminal-panel #terminal {
  flex: 1;
  min-height: 0;
  max-height: none;
}

.explorer #terminal:focus { outline: none; }

/* Keep short sessions against the prompt edge; this collapses once output scrolls. */
.explorer #term-lines { flex: 0 0 auto; margin-top: auto; }

.explorer #term-lines .out { color: var(--text); animation: rise 0.18s ease-out; }
.explorer #term-lines .err { color: var(--red); animation: rise 0.18s ease-out; }
.explorer #term-lines .echo { color: var(--dim); }
.explorer #term-lines .echo .prompt { margin-right: 8px; }

.explorer #flag-tooltip {
  position: fixed;
  z-index: 100;
  width: max-content;
  max-width: min(360px, calc(100vw - 20px));
  padding: 10px 12px;
  border: 1px solid var(--active-edge);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--panel-shadow);
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1.4;
  pointer-events: none;
}
.explorer #flag-tooltip[hidden] { display: none; }
.explorer .flag-tooltip-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 4px; }
.explorer .flag-tooltip-head code { color: var(--accent); font-family: var(--mono); font-size: 12px; font-weight: 700; }
.explorer .flag-tooltip-head span { margin-left: auto; color: var(--dimmer); font-family: var(--mono); font-size: 10px; }
.explorer .flag-tooltip-usage { color: var(--dim); }

@media (min-width: 901px) and (hover: hover) and (pointer: fine) {
  .explorer #term-lines .echo .tok-flag[data-flag-name] {
    border-bottom: 1px dotted transparent;
    cursor: help;
  }
  #term-lines .echo .tok-flag[data-flag-name]:hover,
  .explorer #term-lines .echo .tok-flag.flag-help-active {
    border-bottom-color: currentColor;
  }
}

@media (max-width: 900px) {
  .explorer #flag-tooltip { display: none !important; }
}

.explorer #term-lines .sys { color: var(--dimmer); font-style: italic; }
.explorer #term-lines .welcome { color: var(--dim); }
.explorer #term-lines .welcome b { color: var(--accent); font-weight: 600; }
.explorer #term-lines .ansi-bold { font-weight: 700; }
.explorer #term-lines .ansi-dim { opacity: 0.65; }
.explorer #term-lines .ansi-red { color: var(--red); }
.explorer #term-lines .ansi-green { color: var(--green); }
.explorer #term-lines .ansi-yellow { color: var(--yellow); }
.explorer #term-lines .ansi-magenta { color: var(--magenta); }
.explorer #term-lines .ansi-cyan { color: var(--accent); }
.explorer #term-lines .ansi-gray { color: var(--dimmer); }

@keyframes rise {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}

.explorer .prompt { color: var(--accent); font-weight: 600; user-select: none; }
.explorer #input-line { position: relative; display: block; }
.explorer #input-line .prompt { margin-right: 8px; }
.explorer #line-render { pointer-events: none; }

.explorer #line-render .cursor {
  display: inline-block;
  width: 8px;
  margin-left: 0;
  background: var(--accent);
  color: var(--bg);
  animation: blink 1.1s steps(1) infinite;
  border-radius: 1px;
  min-height: 1em;
}

.explorer #terminal.unfocused #line-render .cursor { animation: none; background: var(--dimmer); }

@keyframes blink { 50% { background: transparent; color: inherit; } }

.explorer #term-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  border: 0;
  background: transparent;
  color: transparent;
  caret-color: transparent;
  font: 16px/1 var(--mono);
}

.explorer .term-help {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 14px;
  border-top: 1px solid var(--panel-edge);
  font-size: 11px;
  color: var(--dimmer);
}
.explorer .term-help-shortcuts {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
}
.explorer .term-help-shortcuts::-webkit-scrollbar { display: none; }

.explorer #reset-btn {
  flex: 0 0 auto;
  margin-left: auto;
  padding: 3px 8px;
  border: 1px solid var(--panel-edge);
  border-radius: 5px;
  background: transparent;
  color: var(--dimmer);
  font: inherit;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.explorer #reset-btn:hover {
  border-color: var(--red);
  color: var(--red);
}
.explorer #reset-btn:focus-visible {
  outline: 2px solid var(--active-edge);
  outline-offset: 2px;
  color: var(--text);
}

.explorer kbd {
  font-family: var(--mono);
  font-size: 10px;
  background: var(--kbd-bg);
  border: 1px solid var(--kbd-edge);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--dim);
}

/* ---------- code panel ---------- */

.explorer .tabs { gap: 2px; padding: 6px 10px 0; }

.explorer .tabs button {
  font-family: var(--mono);
  font-size: 12px;
  background: transparent;
  color: var(--dim);
  border: none;
  border-bottom: 2px solid transparent;
  padding: 7px 12px 9px;
  cursor: pointer;
  transition: color 0.12s;
}

.explorer .tabs button:hover { color: var(--text); }
.explorer .tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

.explorer .code-wrap { position: relative; display: flex; min-height: 0; }

.explorer .code-wrap { max-height: 52%; }

.explorer #code-view {
  margin: 0;
  padding: 16px 18px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  overflow: auto;
  min-height: 150px;
  flex: 1;
  white-space: pre;
}

.explorer #response-view {
  margin: 0;
  padding: 14px 18px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  overflow: auto;
  flex: 1;
  min-height: 120px;
  white-space: pre-wrap;
  word-break: break-word;
}

.explorer .copy-btn {
  position: absolute;
  top: 10px;
  right: 12px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dim);
  background: var(--copy-bg);
  border: 1px solid var(--panel-edge);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  transition: all 0.12s;
}
.explorer .copy-btn:hover { color: var(--accent); border-color: var(--accent); }
.explorer .copy-btn.copied { color: var(--green); border-color: var(--green); }
.explorer .copy-btn.static-pos { position: static; margin-left: auto; }

.explorer .json-note {
  padding: 9px 18px;
  font-size: 12px;
  color: var(--dim);
  border-top: 1px solid var(--panel-edge);
  border-bottom: 1px solid var(--panel-edge);
  background: var(--panel-title);
}

.explorer .badge {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--yellow);
  background: var(--badge-bg);
  border: 1px solid var(--badge-edge);
  border-radius: 5px;
  padding: 1px 6px;
}

.explorer .response-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 18px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--dim);
  border-bottom: 1px solid var(--panel-edge);
}

.explorer .resp-status { font-weight: 600; color: var(--dimmer); }
.explorer .resp-status.ok { color: var(--green); }
.explorer .resp-status.fail { color: var(--red); }
.explorer .resp-hint code { color: var(--blue); font-size: 11px; }

.explorer .tip {
  margin: 0 14px 12px;
  padding: 10px 14px;
  background: var(--tip-bg);
  border: 1px solid var(--tip-edge);
  border-radius: 10px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--tip-text);
  animation: rise 0.25s ease-out;
}
.explorer .tip a { color: var(--purple); }
.explorer .tip code { color: var(--yellow); font-size: 11.5px; }

/* ---------- syntax colors ---------- */

.explorer .tok-kw { color: var(--purple); }
.explorer .tok-str { color: var(--green); }
.explorer .tok-cmt { color: var(--dimmer); font-style: italic; }
.explorer .tok-num { color: var(--yellow); }
.explorer .tok-fn { color: var(--blue); }
.explorer .tok-flag { color: var(--yellow); }
.explorer .tok-url { color: var(--blue); }
.explorer mark.cmd-mark {
  background: var(--mark-bg);
  color: inherit;
  border-radius: 3px;
  padding: 1px 2px;
  outline: 1px solid var(--mark-edge);
}

.explorer .dim { color: var(--dimmer); }

/* json highlight in response */
.explorer .j-key { color: var(--blue); }
.explorer .j-str { color: var(--green); }
.explorer .j-num { color: var(--yellow); }
.explorer .j-bool { color: var(--purple); }

/* scrollbars */
.explorer ::-webkit-scrollbar { width: 10px; height: 10px; }
.explorer ::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 6px; }
.explorer ::-webkit-scrollbar-track { background: transparent; }

.explorer .json-note code { color: var(--blue); font-size: 11px; }

.explorer #code-view { tab-size: 4; }


/* ---------- narrow: one panel at a time ---------- */

@media (max-width: 1180px) {
  .explorer-panels { grid-template-columns: minmax(0, 1fr); }

  .explorer .mobile-view-tabs {
    position: relative;
    z-index: 20;
    display: grid;
    flex: 0 0 auto;
    grid-template-columns: 1fr 1fr;
    gap: 3px;
    padding: 3px;
    background: var(--panel-title);
    border: 1px solid var(--panel-edge);
    border-radius: 10px;
  }
  .explorer .mobile-view-tabs button {
    min-height: 36px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--dim);
    font: 12px var(--mono);
    cursor: pointer;
  }
  .explorer .mobile-view-tabs button[aria-selected="true"] {
    color: var(--accent);
    background: var(--panel);
    box-shadow: inset 0 0 0 1px var(--panel-edge);
  }

  body[data-mobile-view="terminal"] .explorer #code-panel,
  body[data-mobile-view="code"] .explorer #terminal-panel { display: none; }

  .explorer #code-panel {
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .explorer .code-wrap { flex: none; max-height: none; overflow: visible; }
  .explorer #code-view { flex: none; overflow: visible; white-space: pre-wrap; overflow-wrap: anywhere; }
  .explorer #response-view { flex: none; min-height: 200px; overflow: visible; }
}

@media (max-width: 900px) {
  .explorer #flag-tooltip { display: none !important; }
}

/* ---------- phones: the sidebar is gone, so show the tour here ---------- */

@media (max-width: 768px) {
  .explorer { gap: 10px; }
  .explorer-title { font-size: 20px; }
  .explorer-lede { display: none; }

  .explorer-steps {
    display: flex;
    flex: 0 0 auto;
    gap: 6px;
    margin: 0 -2px;
    padding: 0 2px 4px;
    list-style: none;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    counter-reset: ex;
  }
  .explorer-steps::-webkit-scrollbar { display: none; }
  .explorer-steps li { flex: 0 0 min(190px, 72vw); scroll-snap-align: start; counter-increment: ex; }
  .explorer-step {
    display: flex;
    flex-direction: column;
    gap: 2px;
    height: 100%;
    padding: 6px 9px;
    border: 1px solid var(--panel-edge);
    border-radius: 8px;
    color: var(--text);
    font-size: 12px;
    text-decoration: none;
  }
  .explorer-step::before {
    content: counter(ex, decimal-leading-zero);
    font-size: 10px;
    color: var(--dimmer);
  }
  .explorer-step.active { background: var(--accent-dim); border-color: var(--active-edge); }
  .explorer-step .ex-desc { font-size: 10.5px; color: var(--dim); }

  .explorer .panel { border-radius: 12px; }
  .explorer .panel-title { gap: 8px; padding: 9px 10px; }
  .explorer #terminal { padding: 6px 10px 4px; font-size: 12px; line-height: 1.45; }
  .explorer .term-help { gap: 8px; padding: 7px 10px; overflow: hidden; font-size: 10px; white-space: nowrap; }
  .explorer .term-help-shortcuts { gap: 8px; }
  .explorer .term-help kbd { padding: 1px 3px; }
  .explorer #reset-btn { min-height: 28px; padding: 3px 7px; }
  .explorer .tabs { padding-inline: 6px; }
  .explorer .tabs button { flex: 1 0 auto; min-height: 40px; padding-inline: 9px; }
  .explorer #code-view { width: 100%; min-height: 120px; padding: 12px; font-size: 11.5px; }
  .explorer .json-note { padding: 8px 12px; font-size: 11px; }
  .explorer .response-head {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
    padding: 8px 10px 8px 12px;
    font-size: 10.5px;
  }
  .explorer .resp-status { white-space: nowrap; }
  .explorer .resp-hint { font-size: 0; }
  .explorer .resp-hint code { font-size: 10.5px; }
  .explorer .resp-hint::after { content: " response"; font-size: 10.5px; }
  .explorer #response-view { min-height: 240px; padding: 12px; font-size: 11.5px; }
  .explorer .copy-btn { right: 8px; min-height: 32px; }
  .explorer .tip { margin: 0 10px 10px; padding: 9px 11px; font-size: 11.5px; }

  /* With the on-screen keyboard up, give the terminal everything. */
  body.mobile-keyboard .docs-topbar,
  body.mobile-keyboard .explorer .mobile-top-row,
  body.mobile-keyboard .explorer-intro,
  body.mobile-keyboard .explorer-steps { display: none; }

  .explorer a, .explorer button { touch-action: manipulation; }
}
