:root {
  --bg: #0f1b2b;
  --panel: #16263a;
  --text: #eaf2ff;
  --muted: #a7b3c9;
  --accent: #2dd4bf;
  --danger: #fb7185;
  --bar-h: 26px;
  --radius: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Alegreya Sans", "Trebuchet MS", sans-serif;
  color: var(--text);
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1200px 700px at 20% 10%, #223a5a 0%, rgba(34,58,90,0) 60%),
    radial-gradient(900px 600px at 80% 80%, #203c3b 0%, rgba(32,60,59,0) 55%),
    linear-gradient(160deg, #0b1220 0%, #0f1b2b 50%, #0b1a1a 100%);
}

.app {
  width: min(92vw, 620px);
  background: rgba(22, 38, 58, 0.88);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  padding: 22px 20px 26px;
  box-shadow: 0 12px 50px rgba(3, 8, 16, 0.55);
  backdrop-filter: blur(10px);
  position: relative;
}

h1 {
  margin: 0 0 8px;
  font-size: 1.6rem;
  letter-spacing: 0.4px;
}

p {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.4;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.mode-row {
  margin-top: 10px;
}

.fullscreen-only {
  display: none;
}

button {
  background: linear-gradient(135deg, #22d3ee, #10b981);
  color: #062018;
  border: none;
  padding: 12px 16px;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.3px;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease;
}

button:active {
  transform: scale(0.98);
}

button.secondary {
  background: #1e2e44;
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.08);
}

.btn-danger {
  background: linear-gradient(135deg, #fb7185, #ef4444);
  color: #2b0a0a;
  border: 1px solid rgba(255,255,255,0.12);
}

.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 700;
  letter-spacing: 0.3px;
}

button.is-active {
  background: linear-gradient(135deg, #fde047, #f97316);
  color: #1a1407;
}

.meter {
  margin-top: 18px;
  padding: 14px;
  background: rgba(8, 16, 26, 0.7);
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.06);
}

.bar {
  height: var(--bar-h);
  width: 100%;
  background: #0b1624;
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #22d3ee, #34d399, #facc15, #fb7185);
  transition: width 80ms linear;
}

.range-wrap {
  position: relative;
  margin-top: 10px;
  height: 28px;
}

.range-track {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 6px;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.08);
  border-radius: 999px;
}

.range-selected {
  position: absolute;
  top: 50%;
  height: 6px;
  transform: translateY(-50%);
  background: linear-gradient(90deg, #22d3ee, #34d399, #facc15, #fb7185);
  border-radius: 999px;
}

.range {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  width: 100%;
  height: 28px;
  background: none;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
}

.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #f8fafc;
  border: 2px solid #0b1624;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  pointer-events: auto;
  cursor: pointer;
}

.range::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #f8fafc;
  border: 2px solid #0b1624;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  pointer-events: auto;
  cursor: pointer;
}

.stats {
  margin-top: 10px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.95rem;
}

.pill {
  padding: 6px 10px;
  background: rgba(255,255,255,0.06);
  border-radius: 999px;
}

.pill input[type="number"] {
  width: 72px;
  margin-left: 6px;
  background: rgba(255,255,255,0.08);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 2px 6px;
}

.config-card {
  margin-bottom: 14px;
  padding: 14px;
  background: rgba(7, 14, 24, 0.6);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
}

.config-title {
  font-weight: 700;
  letter-spacing: 0.3px;
  margin-bottom: 10px;
  color: #e9f1ff;
}

.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  align-items: end;
}

.config-field label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.config-field input {
  width: 100%;
  background: rgba(255,255,255,0.08);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 8px 10px;
}

.config-field select {
  width: 100%;
  background: rgba(255,255,255,0.08);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 8px 10px;
}

.config-field select option {
  color: #0b1220;
}

.config-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.status {
  margin-top: 12px;
  font-size: 0.95rem;
  color: var(--muted);
}

.status strong { color: var(--text); }

.ble-status {
  color: var(--muted);
  font-size: 0.9rem;
}

.hint {
  margin-top: 12px;
  font-size: 0.9rem;
  color: #9fb1c8;
}

.info {
  margin-top: 12px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  font-size: 0.9rem;
  color: #b7c6dc;
  line-height: 1.35;
}

.logo {
  position: absolute;
  right: 14px;
  top: 12px;
  width: 92px;
  opacity: 0.55;
  filter: grayscale(1) contrast(1.1);
}

.logo img {
  display: block;
  width: 100%;
  height: auto;
}

.version {
  margin-top: -6px;
  margin-bottom: 10px;
  font-size: 0.85rem;
  color: #9fb1c8;
}

.view {
  display: none;
}

.meter[data-tab="config"] .view-config {
  display: block;
}

.meter[data-tab="needle"] .view-needle {
  display: block;
}

.meter[data-tab="score"] .view-score {
  display: flex;
}

.view-score {
  min-height: 260px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
}

.score-label {
  font-size: 1rem;
  color: var(--muted);
  letter-spacing: 1.2px;
  text-transform: uppercase;
}

.score-value {
  font-size: clamp(56px, 16vw, 180px);
  font-weight: 800;
  letter-spacing: 1px;
  color: #f8fafc;
  text-shadow: 0 10px 30px rgba(0,0,0,0.35);
}

.score-sub {
  font-size: 0.95rem;
  color: #9fb1c8;
}

body.fullscreen .app {
  width: 100vw;
  height: 100vh;
  border-radius: 0;
  padding: 8px 12px;
}

body.fullscreen .score-value {
  font-size: clamp(160px, 40vw, 520px);
}

body.fullscreen .meter {
  height: calc(100vh - 56px);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

body.fullscreen .bar {
  height: min(12vh, 120px);
}

body.fullscreen .mode-row {
  display: none;
}

body.fullscreen .fullscreen-only {
  display: flex;
}

body.fullscreen .score-sub,
body.fullscreen .score-label,
body.fullscreen .stats,
body.fullscreen .hint,
body.fullscreen .info,
body.fullscreen .status {
  display: none;
}

body.fullscreen h1,
body.fullscreen p,
body.fullscreen .logo,
body.fullscreen .row:not(.fullscreen-only) {
  display: none;
}

body.fullscreen .meter {
  background: transparent;
  border: none;
  padding: 0;
}

.needle-wrap {
  display: grid;
  place-items: center;
  gap: 10px;
  width: 100%;
  justify-items: center;
}

.needle-svg {
  width: min(70vw, 520px);
  height: auto;
}

.needle-arc-bg {
  fill: none;
  stroke: rgba(255,255,255,0.12);
  stroke-width: 16;
  stroke-linecap: round;
}

.needle-arc {
  fill: none;
  stroke: url(#arcGrad);
  stroke-width: 16;
  stroke-linecap: round;
  stroke-dasharray: 376;
  stroke-dashoffset: 376;
}

.needle-group line {
  stroke: #f8fafc;
  stroke-width: 4;
  stroke-linecap: round;
}

.needle-group circle {
  fill: #f8fafc;
}

.needle-group {
  transform-origin: 150px 150px;
  transform: rotate(-90deg);
}

.needle-value {
  font-size: clamp(48px, 10vw, 120px);
  font-weight: 800;
  color: #f8fafc;
}

body.fullscreen .needle-svg {
  width: 96vw;
  height: 70vh;
}

body.fullscreen .needle-value {
  font-size: clamp(140px, 32vw, 360px);
}
.display-value {
  font-size: clamp(56px, 12vw, 140px);
  font-weight: 800;
  letter-spacing: 1px;
  color: #f8fafc;
  text-align: center;
}
