/* API tab — spell chain → generated endpoints */

#panel-api.panel[hidden],
#panel-chains.panel[hidden] { display: none !important; }

#panel-api.panel.active,
#panel-chains.panel.active {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 8rem);
  max-height: calc(100dvh - 8rem);
  overflow: hidden;
  padding: 0;
  margin: 0;
}

body.api-tab-active #panel-api.panel.active,
body.sc-tab-active #panel-chains.panel.active {
  min-height: calc(100dvh - 5.5rem);
  max-height: calc(100dvh - 5.5rem);
}

body.api-tab-active .site-footer,
body.api-tab-active .site-header .subtitle,
body.sc-tab-active .site-footer,
body.sc-tab-active .site-header .subtitle { display: none; }

.api-shell {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  background: var(--bg);
}

.api-subtabs {
  display: flex;
  gap: 0.25rem;
  flex: 0 0 auto;
  padding: 0.4rem 0.65rem 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.api-subtab {
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.82rem;
  padding: 0.4rem 0.85rem;
  cursor: pointer;
}

.api-subtab.active {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border);
}

.api-pane[hidden] {
  display: none !important;
}

.api-pane[data-api-pane="chains"]:not([hidden]) {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.api-logic-pane {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 0.75rem 1rem 1.5rem;
}

.api-logic {
  max-width: 42rem;
}

.api-logic h2 {
  margin: 0 0 0.4rem;
  font-family: var(--font-display);
  font-size: 1.45rem;
}

.api-logic-lede {
  margin: 0 0 1.1rem;
  font-size: 1rem;
  line-height: 1.45;
  color: #e8c547;
}

.api-logic h3 {
  margin: 1.15rem 0 0.4rem;
  font-size: 1.02rem;
}

.api-logic p,
.api-logic li {
  margin: 0 0 0.65rem;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text);
}

.api-logic ul,
.api-logic ol {
  margin: 0 0 0.75rem;
  padding-left: 1.25rem;
}

.api-logic code {
  font-size: 0.8em;
}

.api-logic-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 1rem;
  font-size: 0.8rem;
}

.api-logic-table th,
.api-logic-table td {
  text-align: left;
  vertical-align: top;
  padding: 0.4rem 0.5rem 0.4rem 0;
  border-bottom: 1px solid var(--border);
}

.api-logic-table th {
  color: var(--text-muted);
  font-weight: 600;
}

.logan7in-unlimited {
  position: fixed;
  top: 0.4rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10050;
  padding: 0.22rem 0.7rem;
  border-radius: 999px;
  border: 1px solid rgba(232, 197, 71, 0.55);
  background: rgba(18, 16, 10, 0.92);
  color: #e8c547;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  white-space: nowrap;
}

.logan7in-unlimited:hover {
  color: #fff3c4;
}

.api-logic-hint {
  margin: -0.35rem 0 1rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.api-logic mark.api-define-mark {
  background: rgba(232, 197, 71, 0.35);
  color: inherit;
  padding: 0 0.12em;
  border-radius: 2px;
}

.api-define-card {
  position: fixed;
  z-index: 10080;
  background: #14120c;
  border: 1px solid rgba(232, 197, 71, 0.45);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
  color: #e8eee6;
}

.api-define-menu {
  position: fixed;
  z-index: 10140;
  min-width: 12rem;
  padding: 0.25rem;
  background: #1a1810;
  border: 1px solid rgba(232, 197, 71, 0.55);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.65);
  color: #e8eee6;
}

.api-define-menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.82rem;
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
  cursor: pointer;
}

.api-define-menu button:hover {
  background: rgba(232, 197, 71, 0.16);
}

.api-define-card {
  width: min(24rem, calc(100vw - 1.5rem));
  padding: 0.7rem 0.8rem 0.8rem;
  user-select: text;
  -webkit-user-select: text;
}

.api-define-toolbar {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0 0 0.4rem;
}

.api-define-toolbar button {
  flex: 0 0 auto;
  border: 1px solid rgba(232, 197, 71, 0.4);
  border-radius: 6px;
  background: transparent;
  color: #e8c547;
  font: inherit;
  font-size: 0.72rem;
  padding: 0.18rem 0.45rem;
  cursor: pointer;
}

.api-define-crumb {
  font-size: 0.68rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.api-define-card h4 {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
  color: #e8c547;
}

.api-define-visual {
  display: block;
  width: 100%;
  max-height: 10.5rem;
  object-fit: cover;
  border-radius: 6px;
  margin: 0 0 0.5rem;
}

.api-visuals {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
  gap: 0.55rem;
  margin: 0 0 1.1rem;
}

.api-visual-tile {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0c0d10;
  color: #e8c547;
  font: inherit;
  font-size: 0.72rem;
  cursor: pointer;
  overflow: hidden;
}

.api-visual-tile img {
  width: 100%;
  height: 5.6rem;
  object-fit: cover;
  display: block;
}

.api-visual-tile span {
  padding: 0 0.4rem 0.4rem;
}

.api-define-body {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.45;
}

.api-define-hint {
  margin: 0.55rem 0 0;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.api-suggest-box {
  margin: 1.25rem 0 0;
  padding: 0.7rem 0 0;
  border-top: 1px solid var(--border);
}

.api-suggest-box h3 {
  margin: 0 0 0.35rem;
}

.api-suggest-box ul {
  margin: 0.35rem 0 0.6rem;
  padding-left: 1.15rem;
}

.api-suggest-box li {
  font-size: 0.82rem;
}

.api-suggest-empty {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.api-suggest-export {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.78rem;
  padding: 0.28rem 0.55rem;
  cursor: pointer;
}

.api-suggest-term {
  position: fixed;
  z-index: 10150;
  width: min(28rem, calc(100vw - 1.25rem));
  padding: 0.55rem 0.65rem 0.65rem;
  background: #0c0d10;
  border: 1px solid rgba(232, 197, 71, 0.5);
  border-radius: 8px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.7);
  color: #d4e8c8;
  font-family: ui-monospace, Consolas, "Cascadia Mono", monospace;
}

.api-term-bar {
  font-size: 0.72rem;
  color: #e8c547;
  margin: 0 0 0.4rem;
  word-break: break-word;
}

.api-term-row {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
}

.api-term-gt {
  color: #8ec9a0;
  line-height: 1.4;
  padding-top: 0.35rem;
}

.api-term-input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 4.5rem;
  resize: vertical;
  border: 0;
  background: transparent;
  color: #e8eee6;
  font: inherit;
  font-size: 0.82rem;
  line-height: 1.4;
  outline: none;
}

.api-term-hint {
  margin: 0.4rem 0 0;
  font-size: 0.68rem;
  color: #8a9388;
}

.api-reflection {
  color: #c9a227;
  font-size: 0.92em;
}

.api-top {
  flex: 0 0 auto;
  padding: 0.5rem 0.65rem 0.4rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.api-top h2 {
  margin: 0 0 0.25rem;
  font-family: var(--font-display);
  font-size: 1.2rem;
}

.api-hint {
  margin: 0 0 0.4rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.api-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}

.api-name-input,
.api-desc-input {
  flex: 1 1 160px;
  min-width: 0;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}

.api-save-chain-btn {
  min-height: 40px;
  padding: 0.35rem 1rem;
  font: inherit;
  font-size: 0.82rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: #1a1816;
  cursor: pointer;
  font-weight: 700;
}

.api-save-chain-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.api-status {
  margin: 0.25rem 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.api-status.ok { color: #8ec9a0; }
.api-status.error { color: #e8a090; }
.api-status.pending { color: var(--accent); }

.api-body {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr min(18rem, 34vw);
  gap: 0;
}

.api-chain-wrap {
  min-height: 0;
  overflow: auto;
  padding: 0.65rem;
  background: #080a10;
}

.api-chain-canvas {
  min-height: 12rem;
  border: 2px dashed var(--border);
  border-radius: calc(var(--radius) + 2px);
  padding: 0.75rem;
  transition: box-shadow 0.15s, border-color 0.15s;
}

.api-chain-canvas.api-drop-active {
  border-color: var(--accent);
  box-shadow: inset 0 0 60px rgba(201, 162, 39, 0.12);
}

.api-chain-empty {
  margin: 0 0 0.75rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.api-chain-empty[hidden] { display: none !important; }

.api-chain-steps {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 0.5rem;
}

.api-chain-step {
  position: relative;
  flex: 0 0 auto;
  width: 9.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.api-chain-step::after {
  content: "→";
  position: absolute;
  right: -0.65rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent);
  font-size: 1rem;
  z-index: 1;
  pointer-events: none;
}

.api-chain-step:last-child::after { content: none; }

.api-step-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem;
  padding: 0.3rem 0.4rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--accent);
}

.api-step-rm {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  padding: 0;
}

.api-step-rm:hover { color: #e8a090; }

.api-step-thumb {
  aspect-ratio: 1;
  background: #000;
}

.api-step-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.api-step-meta {
  padding: 0.35rem 0.4rem 0.45rem;
}

.api-step-label {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.api-step-op {
  margin: 0.15rem 0 0;
  font-size: 0.65rem;
  color: var(--text-muted);
}

.api-spec-panel {
  border-left: 1px solid var(--border);
  background: rgba(8, 10, 18, 0.92);
  overflow-y: auto;
  padding: 0.55rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.api-spec-panel h3 {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.api-run-block {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-bottom: 0.65rem;
  margin-bottom: 0.65rem;
  border-bottom: 1px solid var(--border);
}

.api-run-input {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
}

.api-run-btn {
  padding: 0.4rem 0.7rem;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: #1a1816;
  cursor: pointer;
}

.api-run-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.api-fused-output {
  margin: 0;
  min-height: 5rem;
  max-height: 10rem;
  padding: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: ui-monospace, monospace;
  font-size: 0.62rem;
  line-height: 1.45;
  color: var(--text);
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.api-fused-output.api-fused-empty {
  color: var(--text-muted);
}

.api-endpoint {
  margin: 0;
  padding: 0.45rem 0.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: ui-monospace, monospace;
  font-size: 0.68rem;
  color: var(--accent);
  word-break: break-all;
}

.api-spec-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.api-copy-btn {
  padding: 0.35rem 0.55rem;
  font: inherit;
  font-size: 0.72rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.api-copy-btn:hover { border-color: var(--accent); color: var(--accent); }

.api-spec-pre {
  flex: 1 1 auto;
  min-height: 8rem;
  margin: 0;
  padding: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: ui-monospace, monospace;
  font-size: 0.62rem;
  line-height: 1.45;
  color: var(--text-muted);
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.api-saved-panel {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  padding: 0.45rem 0.65rem;
  background: var(--bg-elevated);
  max-height: 7rem;
  overflow-y: auto;
}

.api-saved-panel h3 {
  margin: 0 0 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.api-saved-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.api-saved-card {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.45rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.72rem;
}

.api-saved-card button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.68rem;
}

.api-saved-card button:hover { color: var(--accent); }

#panel-api .st-tray { flex: 0 0 auto; }

#panel-api .api-spell { cursor: grab; touch-action: none; }

#panel-api .api-spell:active { cursor: grabbing; }

@media (max-width: 860px) {
  .api-body { grid-template-columns: 1fr; }
  .api-spec-panel { border-left: none; border-top: 1px solid var(--border); max-height: 14rem; }
}
/* Phones: the pill moves to the right end of the top line, clear of the
   "N online" count and the Hide button beside it. */
@media (max-width: 540px) {
  .logan7in-unlimited {
    top: max(0.4rem, env(safe-area-inset-top, 0px));
    left: auto;
    right: max(0.45rem, env(safe-area-inset-right, 0px));
    transform: none;
    padding: 0.2rem 0.5rem;
    font-size: 0.6rem;
    letter-spacing: 0.05em;
  }
}
