/* Bottleneck calculator widget.
   Tokens are defined on :root for light, then redefined for dark twice: once
   for the system preference and once for an explicit data-theme, so the widget
   is correct whether or not the host page stamps a theme. */

:root {
  --bt-bg: #ffffff;
  --bt-surface: #f6f7f9;
  --bt-surface-2: #eceef2;
  --bt-line: #dde0e6;
  --bt-ink: #14171f;
  --bt-muted: #626878;
  --bt-accent: #2f6df6;
  --bt-accent-ink: #ffffff;
  --bt-cpu: #f0883e;
  --bt-gpu: #3ba55d;
  --bt-good: #1f9d55;
  --bt-warn: #d98324;
  --bt-bad: #d2413a;
  --bt-radius: 12px;
  --bt-shadow: 0 1px 2px rgba(16, 20, 30, .06), 0 6px 20px rgba(16, 20, 30, .05);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bt-bg: #0f1218;
    --bt-surface: #171b23;
    --bt-surface-2: #1f242e;
    --bt-line: #2b313d;
    --bt-ink: #e8ebf1;
    --bt-muted: #98a0b3;
    --bt-accent: #5b8cff;
    --bt-accent-ink: #0b0e14;
    --bt-good: #3ecf7d;
    --bt-warn: #e8a54a;
    --bt-bad: #f2635b;
    --bt-shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  }
}

:root[data-theme="dark"] {
  --bt-bg: #0f1218;
  --bt-surface: #171b23;
  --bt-surface-2: #1f242e;
  --bt-line: #2b313d;
  --bt-ink: #e8ebf1;
  --bt-muted: #98a0b3;
  --bt-accent: #5b8cff;
  --bt-accent-ink: #0b0e14;
  --bt-good: #3ecf7d;
  --bt-warn: #e8a54a;
  --bt-bad: #f2635b;
  --bt-shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
}

.bt {
  --bt-font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-family: var(--bt-font);
  color: var(--bt-ink);
  display: grid;
  gap: 18px;
  container-type: inline-size;
}

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

.bt-card {
  background: var(--bt-surface);
  border: 1px solid var(--bt-line);
  border-radius: var(--bt-radius);
  box-shadow: var(--bt-shadow);
  padding: 18px;
}

/* ---------- form ---------- */

.bt-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr;
}

@container (min-width: 560px) {
  .bt-grid { grid-template-columns: 1fr 1fr; }
  .bt-field--wide { grid-column: 1 / -1; }
}

@container (min-width: 900px) {
  .bt-grid { grid-template-columns: repeat(3, 1fr); }
}

.bt-field { display: grid; gap: 6px; min-width: 0; }

.bt-field > label,
.bt-toggles-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--bt-muted);
}

.bt-input {
  width: 100%;
  font: inherit;
  font-size: 15px;
  color: var(--bt-ink);
  background: var(--bt-bg);
  border: 1px solid var(--bt-line);
  border-radius: 9px;
  padding: 10px 12px;
  appearance: none;
}

select.bt-input {
  background-image: linear-gradient(45deg, transparent 50%, var(--bt-muted) 50%),
                    linear-gradient(135deg, var(--bt-muted) 50%, transparent 50%);
  background-position: right 15px center, right 10px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}

.bt-input:focus-visible {
  outline: 2px solid var(--bt-accent);
  outline-offset: 1px;
  border-color: var(--bt-accent);
}

/* ---------- combobox ---------- */

.bt-combobox { position: relative; }

.bt-results {
  position: absolute;
  z-index: 30;
  inset-inline: 0;
  top: calc(100% + 4px);
  margin: 0;
  padding: 4px;
  list-style: none;
  max-height: 264px;
  overflow-y: auto;
  background: var(--bt-bg);
  border: 1px solid var(--bt-line);
  border-radius: 10px;
  box-shadow: var(--bt-shadow);
}

.bt-results[hidden] { display: none; }

.bt-option {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 14px;
}

.bt-option[aria-selected="true"],
.bt-option:hover { background: var(--bt-surface-2); }

.bt-option-meta {
  flex: none;
  font-size: 12px;
  color: var(--bt-muted);
  font-variant-numeric: tabular-nums;
}

.bt-empty { padding: 10px; font-size: 14px; color: var(--bt-muted); }

/* ---------- toggles ---------- */

.bt-toggle-row { display: flex; flex-wrap: wrap; gap: 8px; }

.bt-switch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 14px;
  padding: 7px 11px;
  border: 1px solid var(--bt-line);
  border-radius: 999px;
  background: var(--bt-bg);
  cursor: pointer;
  user-select: none;
}

.bt-switch input {
  appearance: none;
  margin: 0;
  width: 30px;
  height: 17px;
  border-radius: 999px;
  background: var(--bt-surface-2);
  border: 1px solid var(--bt-line);
  position: relative;
  flex: none;
  transition: background .15s ease;
}

.bt-switch input::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 1px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--bt-muted);
  transition: transform .15s ease, background .15s ease;
}

.bt-switch input:checked { background: var(--bt-accent); border-color: var(--bt-accent); }
.bt-switch input:checked::after { transform: translateX(13px); background: #fff; }
.bt-switch input:focus-visible { outline: 2px solid var(--bt-accent); outline-offset: 2px; }

/* ---------- button ---------- */

.bt-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }

.bt-btn {
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 12px 22px;
  border-radius: 9px;
  border: 1px solid transparent;
  cursor: pointer;
  background: var(--bt-accent);
  color: var(--bt-accent-ink);
}

.bt-btn--ghost {
  background: transparent;
  color: var(--bt-muted);
  border-color: var(--bt-line);
}

.bt-btn:focus-visible { outline: 2px solid var(--bt-accent); outline-offset: 2px; }
.bt-btn[disabled] { opacity: .55; cursor: not-allowed; }

.bt-error {
  margin: 12px 0 0;
  font-size: 14px;
  color: var(--bt-bad);
}

.bt-error[hidden] { display: none; }

/* ---------- results ---------- */

.bt-results-card[hidden] { display: none; }

.bt-top {
  display: grid;
  gap: 20px;
  grid-template-columns: 1fr;
  align-items: center;
}

@container (min-width: 620px) {
  .bt-top { grid-template-columns: 200px 1fr; }
}

.bt-gauge-wrap { position: relative; justify-self: center; width: 200px; }
.bt-gauge { display: block; width: 100%; height: auto; }
.bt-gauge-track { fill: none; stroke: var(--bt-surface-2); stroke-width: 14; stroke-linecap: round; }

.bt-gauge-fill {
  fill: none;
  stroke: var(--bt-good);
  stroke-width: 14;
  stroke-linecap: round;
  transition: stroke-dashoffset .5s ease, stroke .3s ease;
}

.bt-gauge-value {
  position: absolute;
  inset: auto 0 6px;
  text-align: center;
}

.bt-gauge-number {
  display: block;
  font-size: 34px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.bt-gauge-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--bt-muted);
}

.bt-headline h3 { margin: 0 0 6px; font-size: 21px; }
.bt-summary { margin: 0 0 12px; font-size: 15px; line-height: 1.55; color: var(--bt-muted); }

.bt-badges { display: flex; flex-wrap: wrap; gap: 7px; }

.bt-badge {
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--bt-surface-2);
  border: 1px solid var(--bt-line);
  color: var(--bt-muted);
}

.bt-badge b { color: var(--bt-ink); font-weight: 600; }

/* load bars */

.bt-bars { display: grid; gap: 10px; margin-top: 22px; }

.bt-bar-row {
  display: grid;
  grid-template-columns: 74px 1fr 46px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.bt-bar-track {
  height: 9px;
  border-radius: 999px;
  background: var(--bt-surface-2);
  overflow: hidden;
}

.bt-bar-fill { height: 100%; border-radius: 999px; transition: width .5s ease; }
.bt-bar-fill--cpu { background: var(--bt-cpu); }
.bt-bar-fill--gpu { background: var(--bt-gpu); }
.bt-bar-pct { text-align: right; font-variant-numeric: tabular-nums; color: var(--bt-muted); }

/* fps tiles */

.bt-tiles {
  display: grid;
  gap: 10px;
  margin-top: 22px;
  grid-template-columns: repeat(2, 1fr);
}

@container (min-width: 620px) {
  .bt-tiles { grid-template-columns: repeat(4, 1fr); }
}

.bt-tile {
  background: var(--bt-bg);
  border: 1px solid var(--bt-line);
  border-radius: 10px;
  padding: 12px;
  display: grid;
  gap: 3px;
}

.bt-tile--accent { border-color: var(--bt-accent); }

.bt-tile-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--bt-muted);
}

.bt-tile-value { font-size: 25px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* upgrades */

.bt-upgrades { margin-top: 24px; }
.bt-upgrades h4 { margin: 0 0 10px; font-size: 15px; }

.bt-upgrade-cards {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
}

@container (min-width: 620px) {
  .bt-upgrade-cards { grid-template-columns: 1fr 1fr; }
}

.bt-upgrade {
  background: var(--bt-bg);
  border: 1px solid var(--bt-line);
  border-radius: 10px;
  padding: 12px 14px;
}

.bt-upgrade-kind {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--bt-muted);
}

.bt-upgrade-name { font-size: 15px; font-weight: 600; margin: 3px 0; }
.bt-upgrade-gain { font-size: 13px; color: var(--bt-muted); font-variant-numeric: tabular-nums; }

.bt-share-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}

.bt-share-status {
  font-size: 13px;
  color: var(--bt-good);
  font-weight: 600;
}

.bt-note {
  margin: 18px 0 0;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--bt-muted);
}

@media (prefers-reduced-motion: reduce) {
  .bt * { transition: none !important; }
}
