@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;700&family=JetBrains+Mono:wght@400;500;700&display=swap');

:root {
  --bg: #121212;
  --bg-glow: rgba(255, 255, 255, 0.015);
  --bg-2: #1a1a1a;
  --card: #222222;
  --line: #2b2b2b;
  --line-soft: #1e1e1e;
  --grey-1: #8e8e8e;
  --grey-2: #5a5a5a;
  --grey-3: #363636;
  --ink: #ededed;
  --ink-dim: #a3a3a3;
  --white: #ffffff;
  --ok: #10b981;

  --gauge-grad-start: #6366f1;
  /* Indigo-500 */
  --gauge-grad-end: #d946ef;
  /* Fuchsia-500 */
  --gauge-glow: rgba(99, 102, 241, 0.15);
  --noise-opacity: 0.035;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);

  --font-display: 'Space Grotesk', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

.light-theme {
  --bg: #f5f5f5;
  --bg-glow: rgba(0, 0, 0, 0.005);
  --bg-2: #ffffff;
  --card: #ffffff;
  --line: #e5e5e5;
  --line-soft: #f0f0f0;
  --grey-1: #525252;
  --grey-2: #909090;
  --grey-3: #d4d4d4;
  --ink: #171717;
  --ink-dim: #404040;
  --white: #171717;
  --ok: #059669;

  --gauge-grad-start: #4f46e5;
  /* Indigo-600 */
  --gauge-grad-end: #c084fc;
  /* Purple-400 */
  --gauge-glow: rgba(79, 70, 229, 0.1);
  --noise-opacity: 0.015;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.03);
}

/* Theme Toggle Button */
.theme-toggle {
  background: transparent;
  border: 1px solid var(--line-soft);
  color: var(--ink-dim);
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.1s ease;
}

.theme-toggle:hover {
  background: var(--line-soft);
  border-color: var(--line);
  color: var(--ink);
}

.theme-toggle:active {
  transform: scale(0.95);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

.theme-toggle .sun-icon {
  display: block;
}

.theme-toggle .moon-icon {
  display: none;
}

.light-theme .theme-toggle .sun-icon {
  display: none;
}

.light-theme .theme-toggle .moon-icon {
  display: block;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-display);
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s ease, color 0.3s ease;
}

body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  background-image: radial-gradient(circle at 50% 0%, var(--bg-glow) 0%, var(--bg) 75%);
  transition: background-color 0.3s ease;
}

.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: var(--noise-opacity);
  z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  transition: opacity 0.3s ease;
}

.stage {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
}

.logo-wrap {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.mark {
  color: var(--grey-1);
  font-size: 14px;
  transition: color 0.3s ease;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.14em;
  font-size: 13px;
  color: var(--ink);
  transition: color 0.3s ease;
}

.tagline {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--grey-2);
  margin-left: auto;
  letter-spacing: 0.01em;
}

.gauge-wrap {
  position: relative;
  width: 240px;
  height: 240px;
}

.gauge {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.gauge-track {
  fill: none;
  stroke: var(--line-soft);
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke 0.3s ease;
}

.gauge-fill {
  fill: none;
  stroke: url(#gaugeGrad);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 653.45;
  stroke-dashoffset: 653.45;
  transition: stroke-dashoffset .25s linear;
  filter: drop-shadow(0 0 8px var(--gauge-glow));
}

.ticks line {
  stroke: var(--grey-3);
  stroke-width: 1;
  transition: stroke 0.3s ease;
}

.gauge-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.reading {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 44px;
  color: var(--ink);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  transition: color 0.3s ease;
}

.unit {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--grey-1);
  letter-spacing: 0.08em;
  transition: color 0.3s ease;
}

.phase {
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--grey-2);
  transition: color 0.3s ease;
}

.go {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.04em;
  padding: 13px 36px;
  border-radius: 100px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  transition: background .2s ease, border-color .2s ease, transform .1s ease, box-shadow .2s ease, color .2s ease;
}

.go:hover {
  border-color: var(--grey-1);
  background: var(--line-soft);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.go:active {
  transform: scale(0.97);
}

.go:disabled {
  opacity: .5;
  cursor: default;
}

.go:focus-visible {
  outline: 2px solid var(--grey-1);
  outline-offset: 3px;
}

.stats {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: box-shadow 0.3s ease, border-color 0.3s ease, background 0.3s ease;
}

.stat {
  background: var(--bg-2);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: background 0.3s ease;
}

.stat-label {
  font-size: 11px;
  color: var(--grey-1);
  letter-spacing: 0.04em;
  transition: color 0.3s ease;
}

.stat-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 22px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  transition: color 0.3s ease;
}

.stat-suffix {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--grey-2);
  margin-top: -4px;
  transition: color 0.3s ease;
}

.meta {
  width: 100%;
  border-top: 1px solid var(--line-soft);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 11px;
}

.meta-key {
  color: var(--grey-2);
  transition: color 0.3s ease;
}

.meta-val {
  color: var(--ink-dim);
  transition: color 0.3s ease;
}

.foot {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--grey-2);
  letter-spacing: 0.03em;
  transition: color 0.3s ease;
}

.foot a {
  color: var(--ink-dim);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: var(--grey-3);
  transition: color 0.3s ease, text-decoration-color 0.3s ease;
}

.foot a:hover {
  color: var(--ink);
}

@media (max-width: 460px) {
  .gauge-wrap {
    width: 200px;
    height: 200px;
  }

  .reading {
    font-size: 36px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .gauge-fill {
    transition: none;
  }
}

/* Collapsible Advanced Panel */
.advanced-panel {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: border-color 0.3s ease, background-color 0.3s ease, box-shadow 0.3s ease;
}

.advanced-header {
  width: 100%;
  padding: 16px 20px;
  background: transparent;
  border: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  color: var(--ink-dim);
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-align: left;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.advanced-header:hover {
  background: var(--line-soft);
  color: var(--ink);
}

.advanced-header .chevron {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--grey-1);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.advanced-header[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

.advanced-content {
  border-top: 1px solid var(--line-soft);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Tabs */
.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line-soft);
  padding-bottom: 12px;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--grey-1);
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 10px;
  letter-spacing: 0.02em;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.2s ease, background-color 0.2s ease;
}

.tab-btn:hover {
  color: var(--ink);
  background: var(--line-soft);
}

.tab-btn.active {
  color: var(--ink);
  background: var(--line);
  font-weight: 600;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Diagnostics Tab Grid */
.diagnostics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.diag-card {
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.diag-label {
  font-size: 10px;
  color: var(--grey-1);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.diag-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 20px;
  color: var(--ink);
}

.diag-sub {
  font-size: 10px;
  color: var(--grey-2);
}

.plan-efficiency-card {
  border-color: var(--line);
  background: radial-gradient(circle at 100% 0%, var(--bg-glow) 0%, var(--bg-2) 100%);
}

/* History Controls & Table */
.history-controls {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 12px;
}

.btn-sm {
  background: var(--line);
  border: 1px solid var(--line-soft);
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 11px;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-sm:hover {
  background: var(--line-soft);
  border-color: var(--grey-2);
}

.btn-sm.btn-danger {
  color: #ef4444;
}

.btn-sm.btn-danger:hover {
  background: rgba(239, 68, 68, 0.05);
  border-color: #fca5a5;
}

.history-table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 11px;
  text-align: left;
}

.history-table th,
.history-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-soft);
}

.history-table th {
  background: var(--bg-2);
  color: var(--grey-1);
  font-family: var(--font-display);
  font-weight: 600;
}

.history-table tr:last-child td {
  border-bottom: none;
}

.empty-history {
  text-align: center;
  color: var(--grey-2);
  padding: 20px 0 !important;
}

/* Settings List */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.setting-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 70%;
}

.setting-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
}

.setting-desc {
  font-size: 10px;
  color: var(--grey-1);
}

/* Toggle Switch Widget */
.toggle-switch {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toggle-text {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--grey-1);
  min-width: 80px;
}

.switch-lbl {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 20px;
}

.switch-lbl input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: var(--line);
  border: 1px solid var(--line-soft);
  border-radius: 20px;
  transition: .2s ease;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background-color: var(--grey-1);
  border-radius: 50%;
  transition: .2s ease;
}

input:checked+.slider {
  background-color: var(--bg-glow);
  border-color: var(--grey-2);
}

input:checked+.slider:before {
  transform: translateX(18px);
  background-color: var(--ink);
}

/* Numeric Plan Input styling */
.setting-input-wrap {
  display: flex;
  align-items: center;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 10px;
  width: 110px;
  transition: border-color 0.2s ease;
}

.setting-input-wrap:focus-within {
  border-color: var(--grey-2);
}

.setting-input-wrap input {
  background: transparent;
  border: none;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 12px;
  width: 100%;
  outline: none;
}

.setting-input-wrap input::-webkit-outer-spin-button,
.setting-input-wrap input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.input-suffix {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--grey-2);
}

@media (max-width: 460px) {
  .diagnostics-grid {
    grid-template-columns: 1fr;
  }

  .plan-efficiency-card {
    grid-column: span 1 !important;
  }
}