:root {
  --tg-bg: #0f1012;
  --tg-card: #1a1c20;
  --tg-card-2: #22252b;
  --tg-line: #2c3038;
  --tg-text: #f2f3f5;
  --tg-muted: #9aa1ad;
  --tg-accent: #ff7a1a;
  --tg-accent-2: #ffb061;
  --tg-blue: #3a9ff5;
  --tg-good: #3ddc84;
  --tg-bad: #ff5c5c;
  --tg-radius: 14px;
}

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }
body {
  background: var(--tg-bg);
  color: var(--tg-text);
  font-family: 'Segoe UI', Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
}
body::before {
  content: "";
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(255,122,26,.18), transparent 60%),
    radial-gradient(800px 500px at 90% 0%, rgba(58,159,245,.14), transparent 60%),
    var(--tg-bg);
}

/* ---------- Header ---------- */
.tg-header {
  position: sticky; top: 0; z-index: 100;
  height: 56px; width: auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 clamp(12px, 3vw, 32px);
  background: rgba(15,16,18,.85);
  backdrop-filter: blur(10px);
  box-shadow: none;
  border-bottom: 1px solid var(--tg-line);
  box-sizing: border-box;
}
.tg-logo img { height: 30px; width: auto; display: block; }
.tg-header-right { display: flex; align-items: center; gap: 14px; }
.tg-units { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--tg-muted); letter-spacing: .3px; }
.tg-units .toggle-switch { margin: 0; }
#tgShareBtn { font-size: 12px; font-weight: 600; letter-spacing: .04em; }

.tg-btn {
  border: 1px solid var(--tg-line);
  background: var(--tg-card-2);
  color: var(--tg-text);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.tg-btn:hover { background: #2a2e36; border-color: #3a3f49; }
.tg-btn:active { transform: translateY(1px); }
.tg-btn-ghost { background: transparent; }
.tg-btn-primary { background: var(--tg-accent); border-color: var(--tg-accent); color: #111; font-weight: 600; }
.tg-btn-primary:hover { background: var(--tg-accent-2); border-color: var(--tg-accent-2); }

/* ---------- Layout ---------- */
.tg-main { width: 100%; max-width: 1240px; margin: 0 auto; padding: 0 clamp(12px, 3vw, 32px) 40px; box-sizing: border-box; flex: 1; }

/* ---------- Hero ---------- */
.tg-hero { text-align: center; padding: clamp(48px, 10vh, 110px) 0 40px; }
.tg-hero h1 { font-size: clamp(32px, 6vw, 56px); margin: 0 0 12px; letter-spacing: -.02em; line-height: 1.05; }
.tg-sub { color: var(--tg-muted); font-size: clamp(15px, 2vw, 18px); margin: 0 auto 28px; max-width: 560px; }
.tg-search { position: relative; max-width: 640px; margin: 0 auto; }
.tg-search > input {
  width: 100%; box-sizing: border-box;
  font-size: 18px; padding: 16px 20px;
  border-radius: 14px; border: 1px solid var(--tg-line);
  background: var(--tg-card); color: var(--tg-text);
  outline: none; box-shadow: 0 10px 40px rgba(0,0,0,.35);
}
.tg-search > input:focus { border-color: var(--tg-accent); }
.tg-search #carSearchResults {
  position: absolute; left: 0; right: 0; top: calc(100% + 8px);
  max-height: min(60vh, 460px); overflow-y: auto;
  background: var(--tg-card); border: 1px solid var(--tg-line); border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0,0,0,.5);
  z-index: 60; text-align: left; padding: 6px;
}
.tg-chips { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; margin: 18px auto 0; max-width: 720px; }
.tg-chips-label { color: var(--tg-muted); font-size: 13px; margin-right: 4px; }
.tg-chips button {
  border: 1px solid var(--tg-line); background: rgba(255,255,255,.03); color: var(--tg-text);
  border-radius: 999px; padding: 7px 14px; font-size: 13px; cursor: pointer;
}
.tg-chips button:hover { border-color: var(--tg-accent); color: var(--tg-accent-2); }
.tg-hero-alt { color: var(--tg-muted); font-size: 14px; margin: 22px 0 0; }
.tg-hero-alt a { color: var(--tg-blue); }
.tg-hero-stat { color: #6d7480; font-size: 12px; margin: 10px 0 0; }

/* ---------- Stage ---------- */
.tg-stage { padding-top: 20px; }
.tg-grid { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; align-items: start; }
.tg-side, .tg-content { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.tg-card {
  background: var(--tg-card); border: 1px solid var(--tg-line);
  border-radius: var(--tg-radius); padding: 16px; box-sizing: border-box;
}
.tg-card-title { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--tg-muted); margin-bottom: 10px; font-weight: 600; }

/* Car card */
.tg-carname { font-size: 17px; font-weight: 600; line-height: 1.25; margin-bottom: 10px; }
.tg-carcard #selectedCarDetails { margin: 0; padding: 0; text-align: left; }
.tg-carcard .car-image-container { position: relative; isolation: isolate; aspect-ratio: 4 / 5; min-height: 340px; border-radius: 10px; overflow: hidden; background: #0c0d0f; margin: 0; text-align: left; }
.tg-carcard .car-image-container img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; object-fit: cover; border-radius: 0; box-shadow: none; }
.tg-carcard #oModel { position: absolute; top: 0; left: 0; right: 0; z-index: 1; margin: 0; padding: 16px 14px 50px; background: linear-gradient(to bottom, rgba(0,0,0,.92), rgba(0,0,0,.65) 55%, transparent); text-shadow: 0 1px 4px rgba(0,0,0,.8); }
.tg-carcard .tg-tags { position: absolute; bottom: 0; left: 0; right: 0; z-index: 1; padding: 60px 14px 16px; background: linear-gradient(to top, rgba(0,0,0,.94), rgba(0,0,0,.65) 60%, transparent); }
.tg-carcard #noImageMessage { position: absolute; inset: 45% 14px auto; margin: 0; text-align: center; }
.tg-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tg-tags .spec-bubble { margin: 0; font-size: 12px; background-color: rgba(12,14,18,.8); backdrop-filter: blur(4px); }
.tg-tags .spec-bubble:empty, .tg-tags .spec-bubble .spec-value:empty { display: none; }
.tg-carcard-actions { display: flex; justify-content: flex-end; margin-bottom: 10px; }
.tg-carcard-actions #clearCarBtn { margin: 0; background: transparent; color: var(--tg-muted); font-size: 12px; font-weight: 600; padding: 2px 0; border: 0; border-radius: 0; }
.tg-carcard-actions #clearCarBtn:hover { background: transparent; color: var(--tg-text); }
.tg-customcar p { color: var(--tg-muted); font-size: 13px; margin: 0; }
#tgCarSelector > label { display: block; }
#tgCarSelector .tg-search > input { font-size: 14px; padding: 12px; box-shadow: none; }
#tgCarSelector #carSearchResults { position: static; margin-top: 8px; box-sizing: border-box; max-height: 460px; box-shadow: none; }

/* Big numbers */
.tg-bignums { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; padding: 18px; }
.tg-big { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tg-big-lbl { font-size: 12px; color: var(--tg-muted); letter-spacing: .04em; text-transform: uppercase; }
.tg-big-val { font-size: clamp(22px, 3.2vw, 34px); font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.tg-big-sub { font-size: 12px; color: var(--tg-muted); }
.tg-big-delta { font-size: 13px; font-weight: 600; min-height: 16px; }
.tg-big-delta.good { color: var(--tg-good); }
.tg-big-delta.bad { color: var(--tg-bad); }
.tg-claim { font-size: 13px; color: var(--tg-muted); padding: 0 6px; }
.tg-claim b { color: var(--tg-text); }

/* Chart */
.tg-chartwrap { position: relative; height: 300px; }
.tg-chartwrap canvas { width: 100% !important; height: 100% !important; }

/* Modlist */
.tg-modlist-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tg-tag {
  font-size: 12px; padding: 5px 10px; border-radius: 999px;
  background: rgba(255,122,26,.12); color: var(--tg-accent-2); border: 1px solid rgba(255,122,26,.3);
}
.tg-tag.neutral { background: rgba(58,159,245,.12); color: #9cd0ff; border-color: rgba(58,159,245,.3); }

/* Tune panel */
.tg-tune-title { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.tg-tune-sub { font-size: 13px; color: var(--tg-muted); margin-bottom: 14px; }
.tg-tune-group { margin-bottom: 14px; }
.tg-tune-lbl { font-size: 12px; color: var(--tg-muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 6px; }
.tg-seg { display: grid; grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); gap: 6px; }
.tg-seg button {
  border: 1px solid var(--tg-line); background: var(--tg-card-2); color: var(--tg-text);
  border-radius: 10px; padding: 8px 6px; cursor: pointer; font-size: 13px; line-height: 1.2;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 48px; box-sizing: border-box;
}
.tg-seg button small { color: var(--tg-muted); font-size: 11px; }
.tg-seg button:hover { border-color: #3a3f49; }
.tg-seg button.active { background: rgba(255,122,26,.16); border-color: var(--tg-accent); color: #fff; }
.tg-seg button.active small { color: var(--tg-accent-2); }
.tg-tune-hint { font-size: 12px; color: var(--tg-muted); margin-top: 6px; }
.tg-tune-foot { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.tg-tune-foot a { color: var(--tg-blue); font-size: 13px; }

/* Details / all results */
.tg-more > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 8px; }
.tg-more > summary::-webkit-details-marker { display: none; }
.tg-more > summary::before { content: "▸"; color: var(--tg-muted); transition: transform .15s; }
.tg-more[open] > summary::before { transform: rotate(90deg); }
.tg-results-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; margin-top: 14px; }
.tg-results-grid .result-item { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--tg-line); font-size: 13px; }
.tg-results-grid .result-name { color: var(--tg-muted); }
.tg-results-grid .result-value { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.tg-custom-range { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.tg-custom-range input { width: 64px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--tg-line); background: var(--tg-card-2); color: var(--tg-text); }

/* ---------- Advanced ---------- */
.tg-advanced { margin-top: 24px; border-top: 1px solid var(--tg-line); padding-top: 20px; }
.tg-advanced-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.tg-advanced-head h2 { margin: 0; font-size: 20px; }
.tg-advanced-head p { margin: 0; color: var(--tg-muted); font-size: 13px; flex-basis: 100%; }
.tg-advanced-tools { display: flex; gap: 8px; }
.tg-adv-grid { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 16px; align-items: start; }
.tg-adv-col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.tg-adv-col .card, .tg-adv-col .card1 { background: var(--tg-card); border: 1px solid var(--tg-line); border-radius: var(--tg-radius); }
.tg-adv-charts .chart-container { min-height: 380px; }
.tg-adv-charts .card1 .card-title { display: flex; justify-content: space-between; align-items: center; }

/* ---------- Footer ---------- */
.footer { border-top: 1px solid var(--tg-line); background: transparent; }

/* ---------- Mobile ---------- */
@media (max-width: 960px) {
  .tg-grid { grid-template-columns: 1fr; }
  .tg-side, .tg-content { display: contents; }
  .tg-carcard { order: 1; }
  .tg-bignums { order: 2; }
  .tg-claim { order: 3; }
  .tg-tune { order: 4; }
  .tg-chartcard { order: 5; }
  .tg-modlist { order: 6; }
  .tg-more { order: 7; }
  .tg-adv-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .tg-bignums { grid-template-columns: repeat(2, 1fr); gap: 14px 10px; }
  .tg-search > input { font-size: 16px; padding: 14px 16px; }
  .tg-hero { padding-top: 40px; }
  .tg-header { height: 52px; }
  .tg-logo img { height: 22px; }
  .tg-header-right { gap: 8px; }
  .tg-header .tg-btn { font-size: 12px; padding: 7px 8px; }
  .tg-header #tgShareBtn { font-size: 10px; max-width: 108px; white-space: normal; line-height: 1.2; }
  .tg-units span:not(.toggle-switch):not(.toggle-slider) { display: none; }
}

@media (max-width: 380px) {
  .tg-logo img { height: 18px; }
  .tg-header #tgShareBtn { max-width: 86px; }
  .tg-header #tgAdvancedBtn { font-size: 11px; padding: 7px 6px; }
}

/* How it works */
.tg-steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; max-width: 860px; margin: 56px auto 0; text-align: left; }
.tg-step { background: rgba(255,255,255,.03); border: 1px solid var(--tg-line); border-radius: var(--tg-radius); padding: 16px; }
.tg-step b { display: block; font-size: 15px; margin-bottom: 4px; }
.tg-step span { color: var(--tg-muted); font-size: 13px; }
.tg-step em { color: var(--tg-accent-2); font-style: normal; font-size: 12px; letter-spacing: .1em; display: block; margin-bottom: 8px; }
@media (max-width: 700px) { .tg-steps { grid-template-columns: 1fr; margin-top: 36px; } }
