:root {
  --bg-card: rgba(38, 49, 68, 0.86);
  --bg-card-dark: rgba(27, 36, 52, 0.92);
  --yellow-accent: #eab308;
  --blue-accent: #3b82f6;
  --purple-accent: #c026d3;
  --cyan-fill: #5cc9d6;
  --bt-blue: #1d6ce0;
  --bt-green: #10b981;
  --text-white: #f8fafc;
  --text-muted: #cbd5e1;
  --font-display: 'Barlow Condensed', sans-serif;
  --font-ui: 'Inter', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1a2436;
  font-family: var(--font-ui);
  color: var(--text-white);
}

#canvas-container {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1;
}

/* =========================================================
   HUD SUPERIOR (ESTILO EXR FIEL À IMAGEM DE REFERÊNCIA)
   ========================================================= */
.hud-top {
  position: fixed;
  top: 18px;
  left: 20px;
  right: 20px;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}

.hud-telemetry,
.hud-progress-wrapper,
.hud-right {
  pointer-events: auto;
}

.hud-telemetry {
  display: flex;
  flex-direction: column;
  gap: 7px;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.28));
}

.hud-row-primary {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.telemetry-card {
  position: relative;
  background: var(--bg-card);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: baseline;
  color: var(--text-white);
  font-family: var(--font-display);
  overflow: hidden;
}

/* Inclinação poligonal idêntica à referência */
.card-split {
  min-width: 195px;
  height: 62px;
  padding: 6px 24px 6px 18px;
  clip-path: polygon(0 0, 100% 0, 89% 100%, 0 100%);
}

.card-spm {
  min-width: 132px;
  height: 62px;
  padding: 6px 22px 6px 24px;
  margin-left: -14px;
  clip-path: polygon(15% 0, 100% 0, 85% 100%, 0 100%);
}

.card-distance {
  width: 174px;
  height: 46px;
  padding: 4px 24px 4px 18px;
  clip-path: polygon(0 0, 100% 0, 88% 100%, 0 100%);
}

.card-watts {
  width: 152px;
  height: 46px;
  padding: 4px 24px 4px 18px;
  clip-path: polygon(0 0, 100% 0, 87% 100%, 0 100%);
}

.card-content {
  display: flex;
  align-items: baseline;
  gap: 6px;
  z-index: 2;
}

.metric-big {
  font-size: 2.75rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.5px;
}

.metric-med {
  font-size: 2.35rem;
  font-weight: 700;
  line-height: 1;
}

.metric-sub {
  font-size: 1.95rem;
  font-weight: 700;
  line-height: 1;
}

.metric-unit {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.3px;
}

/* Barras de cor laterais dos cards */
.accent-bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
}

.accent-yellow-left {
  background: var(--yellow-accent);
}

.accent-blue {
  background: var(--blue-accent);
}

.accent-purple {
  background: var(--purple-accent);
}

.accent-bar-right {
  position: absolute;
  right: 9px;
  top: 0;
  bottom: 0;
  width: 5px;
  transform: skewX(-16deg);
}

.accent-yellow-right {
  background: var(--yellow-accent);
}

/* Pílulas extras discretas abaixo dos cards principais */
.telemetry-mini-row {
  display: flex;
  gap: 6px;
  margin-top: 2px;
}

.mini-pill {
  background: rgba(27, 36, 52, 0.78);
  backdrop-filter: blur(4px);
  padding: 4px 10px;
  border-radius: 4px;
  font-family: var(--font-display);
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 6px;
  border-left: 3px solid rgba(255, 255, 255, 0.35);
}

.mini-label {
  font-size: 0.75rem;
  color: #94a3b8;
  font-weight: 600;
}

/* =========================================================
   BARRA DE PROGRESSO POLIGONAL NO TOPO CENTRAL
   ========================================================= */
.hud-progress-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

.progress-bar-polygon {
  width: 240px;
  height: 20px;
  background: rgba(54, 67, 89, 0.85);
  border: 2px solid rgba(38, 49, 68, 0.95);
  clip-path: polygon(4% 0, 96% 0, 100% 50%, 96% 100%, 4% 100%, 0% 50%);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 3px;
  padding: 2px 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s ease;
}

.progress-bar-polygon:hover {
  transform: scale(1.04);
}

.progress-segment {
  background: rgba(30, 41, 59, 0.65);
  height: 100%;
  overflow: hidden;
  border-radius: 1px;
}

.segment-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #5cc9d6, #7be3ef);
  transition: width 0.25s ease;
}

.progress-goal-label {
  font-family: var(--font-display);
  font-size: 0.88rem;
  letter-spacing: 0.6px;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(27, 36, 52, 0.65);
  padding: 2px 10px;
  border-radius: 10px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

/* =========================================================
   PAINEL DE DESAFIOS DE 30 SEGUNDOS (30%, 60%, 90%)
   ========================================================= */
.hidden {
  display: none !important;
}

.challenge-intro-banner {
  margin-top: 4px;
  background: linear-gradient(90deg, #eab308, #f97316);
  color: #0f172a;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.7px;
  padding: 4px 14px;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(234, 179, 8, 0.55);
  animation: pulseChallenge 0.65s infinite alternate;
}

@keyframes pulseChallenge {
  from { transform: scale(1); }
  to { transform: scale(1.05); }
}

.challenge-hud-card {
  margin-top: 4px;
  width: 280px;
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(8px);
  border: 1.5px solid rgba(56, 189, 248, 0.45);
  border-radius: 8px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.challenge-hud-card.zone-ok {
  border-color: #10b981;
}

.challenge-hud-card.zone-warn {
  border-color: #f59e0b;
}

.challenge-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-display);
}

.challenge-title {
  font-size: 1.02rem;
  font-weight: 700;
  color: #f8fafc;
}

.challenge-timer {
  font-size: 1.1rem;
  font-weight: 800;
  color: #eab308;
}

.challenge-time-track {
  width: 100%;
  height: 5px;
  background: rgba(51, 65, 85, 0.7);
  border-radius: 99px;
  overflow: hidden;
}

.challenge-time-bar {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #f59e0b, #ef4444);
  transition: width 0.1s linear;
}

.challenge-metrics-box {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.challenge-metric-label {
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 700;
  color: #93c5fd;
  letter-spacing: 0.4px;
}

.challenge-metric-value {
  font-size: 0.76rem;
  font-weight: 600;
  color: #e2e8f0;
}

.challenge-status-track {
  width: 100%;
  height: 7px;
  background: rgba(30, 41, 59, 0.85);
  border-radius: 99px;
  overflow: hidden;
}

.challenge-status-bar {
  width: 50%;
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #10b981);
  transition: width 0.12s linear;
}

.challenge-result-toast {
  margin-top: 4px;
  background: rgba(16, 185, 129, 0.92);
  color: #ffffff;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

/* =========================================================
   BADGE BLUETOOTH GALLANT ELITE PRO (CANTO SUPERIOR DIREITO)
   ========================================================= */
.hud-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.bt-badge {
  display: flex;
  align-items: center;
  gap: 11px;
  background: var(--bg-card);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  padding: 7px 16px 7px 10px;
  border-radius: 4px;
  color: var(--text-white);
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.28);
  transition: all 0.2s ease;
  text-align: left;
}

.bt-badge:hover {
  background: rgba(48, 62, 86, 0.95);
  transform: translateY(-1px);
}

.bt-icon-box {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bt-blue);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 0 10px rgba(29, 108, 224, 0.6);
  transition: background 0.3s ease;
}

.bt-badge.connected .bt-icon-box {
  background: #1d6ce0;
  box-shadow: 0 0 14px rgba(59, 130, 246, 0.9);
}

.bt-text-box {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.bt-status-line {
  font-size: 0.78rem;
  color: #dbeafe;
  font-weight: 500;
}

.bt-device-line {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #ffffff;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.action-pill {
  background: rgba(27, 36, 52, 0.8);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #e2e8f0;
  font-family: var(--font-ui);
  font-size: 0.76rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.action-pill:hover {
  background: rgba(51, 65, 85, 0.92);
  color: #fff;
}

.action-pill.active {
  border-color: #38bdf8;
  color: #bae6fd;
}

.btn-fullscreen-mobile {
  background: rgba(14, 116, 144, 0.85);
  border-color: rgba(56, 189, 248, 0.55);
  color: #f0f9ff;
}

.btn-fullscreen-mobile.active {
  background: rgba(16, 185, 129, 0.85);
  border-color: #34d399;
  color: #ffffff;
}

/* =========================================================
   RODAPÉ DE SIMULAÇÃO E FEEDBACK DE REMADA
   ========================================================= */
.hud-bottom {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  width: min(640px, 94vw);
  pointer-events: auto;
}

.stroke-bar-panel {
  background: rgba(24, 33, 48, 0.82);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
}

.stroke-phase-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  gap: 8px;
  flex-wrap: wrap;
}

#stroke-phase-text {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: #38bdf8;
}

.sim-hint {
  color: #cbd5e1;
  font-size: 0.74rem;
}

kbd {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  padding: 1px 5px;
  font-weight: 700;
  font-size: 0.72rem;
}

.power-curve-track {
  width: 100%;
  height: 7px;
  background: rgba(15, 23, 42, 0.75);
  border-radius: 99px;
  overflow: hidden;
}

.power-curve-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #eab308, #ec4899);
  transition: width 0.08s linear;
}

.sim-controls-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-stroke-trigger {
  flex: 1.4;
  background: linear-gradient(135deg, #0284c7, #2563eb);
  border: none;
  color: white;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease;
}

.btn-stroke-trigger:hover {
  filter: brightness(1.1);
}

.btn-stroke-trigger:active {
  transform: scale(0.97);
}

.btn-secondary-ctrl {
  flex: 1;
  background: rgba(51, 65, 85, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #f1f5f9;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-secondary-ctrl:hover {
  background: rgba(71, 85, 105, 0.95);
}

.btn-secondary-ctrl.active-auto {
  background: rgba(16, 185, 129, 0.28);
  border-color: #10b981;
  color: #a7f3d0;
}

/* =========================================================
   MODAL DE DIAGNÓSTICO BLE
   ========================================================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-card {
  width: min(620px, 95vw);
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: #0f172a;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header h2 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  letter-spacing: 0.4px;
}

.btn-close {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 1.6rem;
  cursor: pointer;
}

.modal-body {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-desc {
  font-size: 0.85rem;
  color: #cbd5e1;
  line-height: 1.45;
}

.ble-info-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  background: rgba(15, 23, 42, 0.6);
  padding: 12px;
  border-radius: 8px;
}

.ble-stat {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.8rem;
  color: #94a3b8;
}

.ble-stat strong {
  color: #f8fafc;
  font-size: 0.92rem;
}

.ble-log-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
}

.ble-raw-log {
  background: #090d16;
  color: #38bdf8;
  font-family: monospace;
  font-size: 0.76rem;
  padding: 10px;
  border-radius: 6px;
  height: 150px;
  overflow-y: auto;
  white-space: pre-wrap;
  border: 1px solid rgba(56, 189, 248, 0.2);
}

.modal-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-primary {
  flex: 1;
  background: #2563eb;
  border: none;
  color: white;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 6px;
  cursor: pointer;
}

.btn-primary:hover {
  background: #1d4ed8;
}

/* =========================================================
   RESPONSIVIDADE MOBILE (RETRATO E PAISAGEM) — HUD COMPACTA
   ========================================================= */
@media (max-width: 820px), (max-height: 540px) {
  .hud-top {
    top: 8px;
    left: 8px;
    right: 8px;
    gap: 6px;
    align-items: flex-start;
  }

  .hud-telemetry {
    gap: 4px;
  }

  .hud-row-primary {
    gap: 4px;
  }

  .card-split {
    min-width: 112px;
    height: 36px;
    padding: 3px 14px 3px 10px;
  }

  .card-spm {
    min-width: 78px;
    height: 36px;
    padding: 3px 12px 3px 14px;
    margin-left: -9px;
  }

  .card-distance {
    width: 102px;
    height: 28px;
    padding: 2px 12px 2px 10px;
  }

  .card-watts {
    width: 90px;
    height: 28px;
    padding: 2px 12px 2px 10px;
  }

  .metric-big {
    font-size: 1.45rem;
  }

  .metric-med {
    font-size: 1.3rem;
  }

  .metric-sub {
    font-size: 1.15rem;
  }

  .metric-unit {
    font-size: 0.72rem;
  }

  .accent-bar {
    width: 4px;
  }

  .accent-bar-right {
    width: 3px;
    right: 5px;
  }

  .telemetry-mini-row {
    gap: 3px;
  }

  .mini-pill {
    padding: 2px 6px;
    font-size: 0.72rem;
    gap: 3px;
    border-left-width: 2px;
  }

  .mini-label {
    font-size: 0.58rem;
  }

  /* Barra de progresso central mais compacta */
  .hud-progress-wrapper {
    gap: 2px;
  }

  .progress-bar-polygon {
    width: 130px;
    height: 12px;
    padding: 1px 4px;
    gap: 2px;
  }

  .progress-goal-label {
    font-size: 0.65rem;
    padding: 1px 6px;
  }

  .challenge-hud-card {
    width: 195px;
    padding: 5px 8px;
    gap: 3px;
  }

  .challenge-title,
  .challenge-timer {
    font-size: 0.82rem;
  }

  .challenge-metric-label {
    font-size: 0.66rem;
  }

  .challenge-metric-value {
    font-size: 0.62rem;
  }

  .challenge-intro-banner {
    font-size: 0.78rem;
    padding: 2px 8px;
  }

  /* Bloco Bluetooth e pílulas de ação compactos no canto direito */
  .hud-right {
    gap: 4px;
    max-width: 46vw;
  }

  .bt-badge {
    padding: 4px 9px 4px 6px;
    gap: 6px;
  }

  .bt-icon-box {
    width: 22px;
    height: 22px;
  }

  .bt-icon-box svg {
    width: 13px;
    height: 13px;
  }

  .bt-status-line {
    font-size: 0.6rem;
  }

  .bt-device-line {
    font-size: 0.76rem;
  }

  .quick-actions {
    gap: 3px;
  }

  .action-pill {
    font-size: 0.62rem;
    padding: 3px 6px;
    border-radius: 4px;
  }

  /* Barra inferior super enxuta para não cobrir o remador */
  .hud-bottom {
    bottom: 6px;
    width: min(460px, 96vw);
  }

  .stroke-bar-panel {
    padding: 6px 10px;
    gap: 4px;
    border-radius: 8px;
    background: rgba(24, 33, 48, 0.68);
  }

  .sim-hint {
    display: none;
  }

  #stroke-phase-text {
    font-size: 0.76rem;
  }

  .power-curve-track {
    height: 4px;
  }

  .sim-controls-row {
    gap: 5px;
  }

  .btn-stroke-trigger {
    font-size: 0.82rem;
    padding: 5px 8px;
  }

  .btn-secondary-ctrl {
    font-size: 0.66rem;
    padding: 5px 6px;
  }
}

/* Ajustes extras para celulares em modo Retrato (tela muito estreita <= 480px) */
@media (max-width: 480px) {
  .hud-progress-wrapper {
    position: fixed;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
  }

  .progress-bar-polygon {
    width: 96px;
    height: 10px;
  }

  .progress-goal-label {
    font-size: 0.58rem;
    padding: 1px 5px;
  }

  .card-split {
    min-width: 96px;
    height: 32px;
    padding: 2px 10px 2px 8px;
  }

  .card-spm {
    min-width: 66px;
    height: 32px;
    padding: 2px 8px 2px 10px;
  }

  .metric-big {
    font-size: 1.25rem;
  }

  .metric-med {
    font-size: 1.1rem;
  }

  .metric-sub {
    font-size: 1rem;
  }

  .telemetry-mini-row {
    display: none;
  }
}


