/* Tools — /tools and /tools/token-speed. Loaded only on those pages. */

body.page-tools,
body.page-token-speed {
  background:
    radial-gradient(1200px 620px at 50% -12%, rgba(0, 229, 192, 0.1), transparent 62%),
    radial-gradient(900px 520px at 100% 4%, rgba(0, 229, 192, 0.045), transparent 55%),
    #0a0a0b;
  background-attachment: fixed;
  color-scheme: dark;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.tool-intro,
.tool-wide {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
}

.tool-intro {
  padding: calc(var(--nav) + 28px) 0 18px;
}

.tool-intro h1 {
  font-size: clamp(34px, 4.8vw, 56px);
  letter-spacing: -0.035em;
  max-width: 18ch;
}

.tool-intro .sub {
  margin-top: 14px;
  max-width: 42rem;
}

.tool-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 20px 0 0;
  padding: 0;
  list-style: none;
}

.tool-badges li {
  padding: 5px 11px;
  border: 1px solid rgba(0, 229, 192, 0.22);
  border-radius: 999px;
  background: rgba(0, 229, 192, 0.06);
  color: #b9fff1;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.crumbs ol {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  font-size: 13px;
  letter-spacing: 0.01em;
}

.crumbs li:not(:last-child)::after {
  content: "/";
  margin-left: 8px;
  color: rgba(245, 245, 247, 0.38);
}

.crumbs a { color: #c8c8d0; }
.crumbs a:hover { color: var(--accent); }
.crumbs [aria-current="page"] { color: #f5f5f7; }

.tool-grid {
  width: min(1180px, calc(100% - 40px));
  margin: 8px auto 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.tool-card {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 16px;
  padding: 28px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 18px;
  background: linear-gradient(180deg, #131316 0%, #0e0e10 100%);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
  transition: border-color 0.3s ease, transform 0.3s ease;
}

.tool-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(620px 300px at 100% 0%, rgba(0, 229, 192, 0.11), transparent 62%);
  pointer-events: none;
}

.tool-card > * {
  position: relative;
}

.tool-card:hover {
  border-color: rgba(0, 229, 192, 0.3);
  transform: translateY(-2px);
}

@media (min-width: 900px) {
  .tool-card.is-flagship { grid-column: span 2; }
}

.tool-aside {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  padding: 26px;
  border: 1px dashed rgba(255, 255, 255, 0.16);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.015);
}

.tool-aside h2 {
  margin: 0;
  font-size: clamp(22px, 2.4vw, 27px);
  letter-spacing: -0.025em;
}

.tool-aside p {
  margin: 0;
  color: #a9a9b3;
  font-size: 15px;
  line-height: 1.5;
}

.tool-aside .text-link {
  margin-top: auto;
  padding-top: 4px;
  font-size: 14px;
}

.tool-aside-list {
  display: grid;
  gap: 8px;
  margin: 2px 0 0;
  padding: 0;
  list-style: none;
}

.tool-aside-list li {
  position: relative;
  padding-left: 16px;
  color: #c4c4ce;
  font-size: 14px;
}

.tool-aside-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 6px;
  height: 1px;
  background: rgba(0, 229, 192, 0.7);
}

.tool-card .tool-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tool-card .tool-tags li {
  padding: 4px 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  color: #cfcfd8;
  font-size: 12px;
}

.tool-card .tool-tags li::before { content: none; }

.tool-card h2 {
  font-size: clamp(26px, 3vw, 34px);
  margin: 8px 0;
  letter-spacing: -0.03em;
}

.tool-card h2 a { color: var(--ink); }
.tool-card h2 a:hover { color: var(--accent); }

.tool-card p {
  margin: 0;
  max-width: 62ch;
  color: #c6c6ce;
  font-size: 17px;
}

.tool-card ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.tool-card li {
  color: #b7b7c0;
  font-size: 15px;
  padding-left: 14px;
  position: relative;
}

.tool-card li::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  position: absolute;
  left: 0;
  top: 0.55em;
}

.tool-note {
  width: min(1180px, calc(100% - 40px));
  margin: 18px auto 0;
  color: #9a9aa3;
  font-size: 14px;
}

.tool-doc.prose { padding-top: 56px; }
.tool-doc .inner { max-width: 740px; }
.tool-doc .inner > p { color: #c6c6ce; }

.tool-doc table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 20px;
  font-size: 15px;
}

.tool-doc caption {
  text-align: left;
  color: #b7b7c0;
  font-size: 14px;
  margin-bottom: 8px;
}

.tool-doc th,
.tool-doc td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  vertical-align: top;
}

.tool-doc th {
  color: #f5f5f7;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.04em;
}

.tool-doc td { color: #c6c6ce; }
.tool-doc td:first-child {
  font-variant-numeric: tabular-nums;
  color: #f5f5f7;
  white-space: nowrap;
}

/* —— Visualizer —— */
.ts-rate,
.tool-shell {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
}

.ts-rate {
  position: relative;
  overflow: hidden;
  margin-top: 8px;
  padding: 18px 20px 16px;
  border: 1px solid rgba(0, 229, 192, 0.2);
  border-radius: 16px;
  background: linear-gradient(180deg, #121416 0%, #0d0e0f 100%);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

.ts-rate::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(560px 180px at 15% 0%, rgba(0, 229, 192, 0.12), transparent 65%);
  pointer-events: none;
}

.ts-rate > * { position: relative; }

.ts-rate-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 8px;
}

.ts-rate-top label {
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}

.ts-rate-value {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.ts-rate-value input[type="number"] {
  width: 6.2rem;
  background: #0a0a0b;
  color: #f5f5f7;
  border: 1px solid rgba(0, 229, 192, 0.32);
  border-radius: 10px;
  padding: 7px 10px;
  font-variant-numeric: tabular-nums;
  font-size: 20px;
  font-weight: 600;
  text-align: right;
  font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
}

.ts-unit { color: #9a9aa3; font-size: 13px; }

.ts-hardware {
  margin: 8px 0 0;
  color: #b7b7c0;
  font-size: 14px;
  min-height: 1.3em;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  background: transparent;
  margin: 0;
  --fill: 0%;
}

input[type="range"]:focus { outline: none; }
input[type="range"]:focus-visible { outline: 2px solid #00e5c0; outline-offset: 2px; }

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: linear-gradient(to right, #00e5c0 0 var(--fill), rgba(255, 255, 255, 0.16) var(--fill) 100%);
  border-radius: 999px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -7px;
  border-radius: 50%;
  background: #00e5c0;
  border: 0;
  box-shadow: 0 0 0 4px rgba(0, 229, 192, 0.15);
}

input[type="range"]::-moz-range-track {
  height: 4px;
  background: rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  border: 0;
}

input[type="range"]::-moz-range-progress {
  height: 4px;
  background: #00e5c0;
  border-radius: 999px;
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #00e5c0;
  border: 0;
}

.ts-presets {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.ts-preset {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-height: 48px;
  padding: 7px 8px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #0a0a0b;
  color: #d4d4dc;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}

.ts-preset:hover { border-color: rgba(0, 229, 192, 0.45); transform: translateY(-1px); }
.ts-preset[aria-pressed="true"] {
  border-color: #00e5c0;
  background: rgba(0, 229, 192, 0.1);
  box-shadow: 0 0 0 1px rgba(0, 229, 192, 0.18), 0 8px 22px rgba(0, 229, 192, 0.08);
}

.ts-preset-n {
  font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
  font-size: 14px;
  color: #f5f5f7;
  font-variant-numeric: tabular-nums;
}

.ts-preset-l {
  font-size: 11px;
  letter-spacing: 0.01em;
  color: #9a9aa3;
  line-height: 1.25;
}
.ts-preset[aria-pressed="true"] .ts-preset-l { color: #d8fff6; }

.tool-shell {
  margin-top: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
}

.ts-stage,
.ts-controls {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  background: #111113;
}

.ts-stage {
  min-width: 0;
  overflow: hidden;
  background: linear-gradient(180deg, #121214 0%, #0e0e10 100%);
  box-shadow: 0 22px 64px rgba(0, 0, 0, 0.42);
}

.ts-stage-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.012);
}

.ts-mode-label {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}

.ts-stats {
  margin: 0;
  color: #c6c6ce;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
}

.ts-prefill { padding: 12px 16px 0; }
.ts-prefill[hidden] { display: none; }

.ts-prefill-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: #c6c6ce;
  margin-bottom: 8px;
}

.ts-bar {
  height: 4px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  overflow: hidden;
}

.ts-bar > span {
  display: block;
  height: 100%;
  width: 0;
  background: #00e5c0;
}

.ts-stream {
  margin: 0;
  min-height: 480px;
  max-height: min(70vh, 760px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 18px 18px 26px;
  font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 14.5px;
  line-height: 1.58;
  color: #f3f3f6;
  tab-size: 4;
  background:
    radial-gradient(700px 300px at 100% 0%, rgba(0, 229, 192, 0.035), transparent 60%),
    #0c0c0e;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
  scrollbar-width: thin;
}

.ts-stream::-webkit-scrollbar { width: 10px; height: 10px; }
.ts-stream::-webkit-scrollbar-track { background: transparent; }
.ts-stream::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border: 3px solid #0c0c0e;
  border-radius: 999px;
}
.ts-stream::-webkit-scrollbar-thumb:hover { background: rgba(0, 229, 192, 0.4); }

.ts-stream.code-live {
  overflow: hidden;
  overscroll-behavior: none;
  scrollbar-width: none;
}
.ts-stream.code-live::-webkit-scrollbar { display: none; }
.ts-stream.code-live .ts-code {
  white-space: pre-wrap;
  word-break: break-word;
}

.ts-wait {
  margin: 0;
  color: #9a9aa3;
  font-family: var(--font);
  font-size: 15px;
}

.ts-kicker {
  margin: 14px 0 6px;
  font-family: var(--font);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #9a9aa3;
}

.ts-prose {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0 0 8px;
}

.ts-think { color: #a7a7b2; font-style: italic; }
.ts-say { color: #f3f3f6; font-style: normal; }

.ts-codewrap { margin: 0 0 8px; }
.ts-code {
  margin: 0;
  white-space: pre;
  font: inherit;
  color: #f3f3f6;
}

.hl-c { color: #9aa3b5; font-style: italic; }
.hl-s { color: #b6f3d0; }
.hl-k { color: #00e5c0; }
.hl-n { color: #f0c987; }
.hl-f { color: #9fd4ff; }

.ts-caret {
  display: inline-block;
  width: 8px;
  height: 1.05em;
  background: #00e5c0;
  vertical-align: text-bottom;
  margin-left: 1px;
  animation: ts-blink 1.05s steps(1) infinite;
}

@keyframes ts-blink { 50% { opacity: 0; } }

.ts-tool {
  margin: 12px 0;
  border: 1px solid rgba(0, 229, 192, 0.28);
  border-radius: 12px;
  background: rgba(0, 229, 192, 0.045);
  overflow: hidden;
}

.ts-tool header {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  font-family: var(--font);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #d8fff6;
  border-bottom: 1px solid rgba(0, 229, 192, 0.16);
}

.ts-tool header span {
  color: #04231d;
  background: #00e5c0;
  border-radius: 999px;
  padding: 2px 7px;
  letter-spacing: 0.12em;
  font-weight: 700;
}

.ts-tool pre {
  margin: 0;
  padding: 10px 12px;
  white-space: pre-wrap;
  word-break: break-word;
  font: inherit;
}

.ts-tool-args { color: #d6d6de; }
.ts-tool-out {
  color: #c6c6ce;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.ts-run {
  margin: 0;
  padding: 8px 12px 10px;
  font-family: var(--font);
  font-size: 13px;
  color: #d8fff6;
}

.ts-run::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border-radius: 50%;
  background: #00e5c0;
  animation: ts-blink 1.05s steps(1) infinite;
}

.ts-controls {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: linear-gradient(180deg, #121214 0%, #101012 100%);
}

.ts-h {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}

.ts-field { display: flex; flex-direction: column; gap: 6px; }
.ts-field label,
.ts-field legend {
  font-size: 13px;
  color: #c6c6ce;
}

.ts-help { margin: 0; color: #8e8e98; font-size: 12px; line-height: 1.4; }

.ts-modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  border: 0;
  margin: 0;
  padding: 0;
}

.ts-modes legend { margin-bottom: 6px; }

.ts-mode {
  min-height: 40px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: #0a0a0b;
  color: #e4e4ea;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.ts-mode:hover { border-color: rgba(0, 229, 192, 0.5); }

.ts-mode[aria-checked="true"] {
  background: #00e5c0;
  color: #04231d;
  border-color: #00e5c0;
  font-weight: 600;
}

.ts-select,
.ts-textarea {
  width: 100%;
  background: #0a0a0b;
  color: #f5f5f7;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 10px 12px;
}

.ts-textarea {
  min-height: 110px;
  resize: vertical;
  font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
}

.ts-inline {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.ts-inline input[type="number"] {
  width: 6.5rem;
  background: #0a0a0b;
  color: #f5f5f7;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 6px 8px;
  font-variant-numeric: tabular-nums;
}

.ts-actions, .ts-custom-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ts-btn {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: transparent;
  color: #f5f5f7;
  cursor: pointer;
  font-size: 14px;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.ts-btn:hover { border-color: rgba(0, 229, 192, 0.6); color: #fff; }
.ts-btn:disabled { opacity: 0.4; cursor: not-allowed; }

#ts-pause {
  background: #00e5c0;
  border-color: #00e5c0;
  color: #04231d;
  font-weight: 600;
}

#ts-pause:hover { background: #33f0d0; color: #04231d; }
#ts-pause[aria-pressed="true"] {
  background: rgba(0, 229, 192, 0.14);
  color: #d8fff6;
}

.ts-file { position: relative; display: inline-flex; align-items: center; }
.ts-file input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}
.ts-file:focus-within { outline: 2px solid #00e5c0; outline-offset: 2px; }

.ts-note, .ts-error {
  margin: 0;
  min-height: 1.2em;
  font-size: 13px;
}
.ts-note { color: #b6f3d0; }
.ts-error { color: #ffb4b4; }

.ts-keys {
  margin: 0;
  color: #8e8e98;
  font-size: 12px;
  line-height: 1.5;
}

.ts-keys kbd {
  font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
  font-size: 11px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 4px;
  color: #e4e4ea;
}

.ts-credit {
  margin: 0;
  color: #9a9aa3;
  font-size: 13px;
}
.ts-credit a { color: #d8fff6; }

body.page-tools :focus-visible,
body.page-token-speed :focus-visible {
  outline: 2px solid #00e5c0;
  outline-offset: 2px;
}

@media (min-width: 961px) {
  .ts-controls {
    position: sticky;
    top: calc(var(--nav) + 12px);
    max-height: calc(100vh - var(--nav) - 24px);
    overflow: auto;
  }
}

@media (max-width: 960px) {
  .tool-shell { grid-template-columns: 1fr; }
  .ts-presets { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ts-stream { min-height: 360px; max-height: 68vh; }
  .tool-intro,
  .tool-wide,
  .tool-grid,
  .tool-note,
  .ts-rate,
  .tool-shell { width: min(1180px, calc(100% - 28px)); }
}

@media (max-width: 560px) {
  .tool-intro { padding-top: calc(var(--nav) + 18px); }
  .tool-card { padding: 22px; }
  .ts-rate { padding: 16px 14px 14px; }
  .ts-rate-value input[type="number"] { width: 5.2rem; font-size: 18px; }
  .ts-stream { font-size: 13.5px; min-height: 320px; }
  .ts-mode { min-height: 44px; }
  .ts-btn { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .ts-caret, .ts-run::before { animation: none; }
  .tool-card, .ts-preset, .ts-mode, .ts-btn { transition: none; }
  .tool-card:hover, .ts-preset:hover { transform: none; }
}
