/* ==========================================================================
   SAFARI DO S: DESAFIO DO ARO - ESTILOS VISUAIS (TABLET & TOUCH OPTIMIZED)
   ========================================================================== */

:root {
  --primary-green: #2e7d32;
  --light-green: #4caf50;
  --accent-yellow: #fbc02d;
  --accent-orange: #ff9800;
  --sky-blue: #81d4fa;
  --cloud-white: #ffffff;
  --text-dark: #2c3e50;
  --shadow-color: rgba(0, 0, 0, 0.15);
  --border-radius-lg: 20px;
  --border-radius-md: 12px;
  --border-radius-sm: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #1b5e20;
  font-family: 'Fredoka', 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text-dark);
}

#app-container {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  background: linear-gradient(180deg, #7ad5fa 0%, #b3e5fc 55%, #c8e6c9 80%, #81c784 100%);
}

/* ==========================================================================
   1. TOP HUD (Header do Safari e Pontuação)
   ========================================================================== */

#hud-header {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 3px solid #81c784;
  box-shadow: 0 4px 12px var(--shadow-color);
  z-index: 10;
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar-badge {
  display: flex;
  align-items: center;
  background: #e8f5e9;
  border: 2px solid #a5d6a7;
  padding: 4px 12px;
  border-radius: 50px;
  gap: 8px;
}

.avatar-emoji {
  font-size: 1.8rem;
}

.avatar-info {
  display: flex;
  flex-direction: column;
}

.player-name {
  font-weight: 700;
  font-size: 1.1rem;
  color: #1b5e20;
  line-height: 1.1;
}

.player-level {
  font-size: 0.75rem;
  color: #558b2f;
  font-weight: 600;
}

/* Seletor de Fases (Fase do S / Fase do Z) */
.phase-selector {
  display: flex;
  background: #e8f5e9;
  padding: 3px;
  border-radius: 30px;
  border: 2px solid #a5d6a7;
  gap: 4px;
}

.phase-btn {
  background: transparent;
  border: none;
  padding: 5px 12px;
  border-radius: 20px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  color: #33691e;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  white-space: nowrap;
}

.phase-btn.active {
  background: #2e7d32;
  color: white;
  box-shadow: 0 2px 6px rgba(46, 125, 50, 0.35);
  transform: scale(1.04);
}

.phase-btn:active {
  transform: scale(0.96);
}

/* Trilha de 10 Casas do Safari */
.safari-track-container {
  flex: 1;
  max-width: 650px;
  margin: 0 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.track-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: #33691e;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

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

.step-node {
  flex: 1;
  height: 38px;
  background: #f1f8e9;
  border: 2px solid #c5e1a5;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #558b2f;
  position: relative;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.step-node.active {
  background: #ffeb3b;
  border-color: #f57f17;
  color: #e65100;
  transform: scale(1.15);
  box-shadow: 0 4px 8px rgba(245, 127, 23, 0.3);
  z-index: 2;
}

.step-node.completed {
  background: #a5d6a7;
  border-color: #388e3c;
  color: #1b5e20;
}

.step-node .step-icon {
  font-size: 0.85rem;
}

.step-node .step-text {
  line-height: 1;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.star-counter {
  display: flex;
  align-items: center;
  background: #fff8e1;
  border: 2px solid #ffe082;
  border-radius: 50px;
  padding: 4px 14px;
  font-weight: 800;
  font-size: 1.2rem;
  color: #ff8f00;
  box-shadow: 0 2px 4px var(--shadow-color);
}

.star-icon {
  font-size: 1.4rem;
  margin-right: 4px;
  animation: starPulse 2s infinite ease-in-out;
}

@keyframes starPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15) rotate(8deg); }
}

.icon-button {
  background: #ffffff;
  border: 2px solid #cfd8dc;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px var(--shadow-color);
  transition: transform 0.15s;
}

.icon-button:active {
  transform: scale(0.9);
}

/* ==========================================================================
   2. MAIN GAME STAGE (Canvas & Overlays)
   ========================================================================== */

#game-stage {
  flex: 1;
  position: relative;
  width: 100%;
  height: calc(100% - 76px);
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* Banner da Sílaba Atual */
.syllable-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.94);
  border: 3px solid #ffb300;
  border-radius: 24px;
  padding: 8px 24px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  animation: floatBanner 3s ease-in-out infinite;
  z-index: 5;
}

@keyframes floatBanner {
  0%, 100% { transform: translate(-50%, 0px); }
  50% { transform: translate(-50%, -4px); }
}

.banner-badge {
  font-size: 0.75rem;
  font-weight: 800;
  color: #e65100;
  letter-spacing: 1px;
}

.banner-syllable {
  font-size: 3.2rem;
  font-weight: 900;
  color: #d84315;
  line-height: 1;
  text-shadow: 2px 2px 0px #ffe0b2;
}

.banner-tip {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.95rem;
  color: #37474f;
  margin-top: 4px;
}

.tip-icon {
  font-size: 1.2rem;
}

/* Barra do Medidor Acústico (Força do S / Fricção) */
.mic-feedback-bar {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 550px;
  background: rgba(255, 255, 255, 0.92);
  border: 3px solid #81c784;
  border-radius: 20px;
  padding: 10px 18px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  z-index: 6;
}

.gauge-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  font-weight: 700;
  color: #1b5e20;
  margin-bottom: 6px;
}

.status-badge {
  font-size: 0.8rem;
  padding: 2px 10px;
  border-radius: 12px;
  background: #eceff1;
  color: #455a64;
  font-weight: 700;
  transition: all 0.2s;
}

.status-badge.listening {
  background: #fff9c4;
  color: #f57f17;
}

.status-badge.detected {
  background: #c8e6c9;
  color: #2e7d32;
  box-shadow: 0 0 8px #81c784;
}

.status-badge.launched {
  background: #bbdefb;
  color: #1565c0;
}

.status-badge.warning {
  background: #ffe0b2;
  color: #d84315;
  border: 1px solid #ffb74d;
  font-weight: 800;
}

.gauge-track {
  width: 100%;
  height: 22px;
  background: #e0e0e0;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.15);
}

.gauge-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #ffca28 0%, #66bb6a 60%, #2e7d32 100%);
  border-radius: 12px;
  transition: width 0.08s linear;
}

.gauge-target-line {
  position: absolute;
  top: 0;
  left: 65%; /* Limiar terapêutico */
  width: 4px;
  height: 100%;
  background: #d32f2f;
  box-shadow: 0 0 6px rgba(211, 47, 47, 0.8);
}

/* Botão de Suporte: Toque Mágico para Pais/Fono */
#parent-assist-container {
  position: absolute;
  bottom: 20px;
  right: 20px;
  z-index: 7;
}

.magic-assist-btn {
  background: linear-gradient(135deg, #ab47bc, #7b1fa2);
  color: white;
  border: 2px solid #ea80fc;
  border-radius: 30px;
  padding: 10px 18px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(123, 31, 162, 0.4);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: transform 0.15s, box-shadow 0.15s;
}

.magic-assist-btn:active {
  transform: scale(0.92);
  box-shadow: 0 2px 6px rgba(123, 31, 162, 0.6);
}

/* ==========================================================================
   3. OVERLAYS (Início de Jogo e Vitória)
   ========================================================================== */

.game-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.game-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.overlay-card {
  background: white;
  border-radius: var(--border-radius-lg);
  padding: 30px 36px;
  width: 90%;
  max-width: 580px;
  text-align: center;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.3);
  border: 5px solid #ffca28;
  animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
  0% { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.overlay-mascot {
  font-size: 3.2rem;
  margin-bottom: 6px;
}

.overlay-title {
  font-size: 2.4rem;
  color: #1b5e20;
  font-weight: 900;
  line-height: 1.1;
}

.overlay-subtitle {
  font-size: 1.2rem;
  color: #ff8f00;
  font-weight: 700;
  margin-bottom: 20px;
}

.instructions-box {
  background: #f1f8e9;
  border: 2px dashed #aed581;
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 22px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.instr-item {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1rem;
  color: #2e7d32;
}

.instr-num {
  background: #ffb300;
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.btn-primary-play {
  background: linear-gradient(180deg, #66bb6a 0%, #388e3c 100%);
  color: white;
  border: none;
  border-radius: 50px;
  padding: 14px 40px;
  font-family: inherit;
  font-size: 1.4rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(46, 125, 50, 0.4);
  transition: transform 0.15s, box-shadow 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.btn-primary-play:active {
  transform: scale(0.96);
  box-shadow: 0 4px 8px rgba(46, 125, 50, 0.4);
}

.mic-permission-note {
  margin-top: 14px;
  font-size: 0.85rem;
  color: #78909c;
}

/* Card de Vitória */
.victory-card {
  border-color: #4caf50;
}

.trophy-anim {
  font-size: 4rem;
  animation: bounceTrophy 1.5s infinite ease-in-out;
}

@keyframes bounceTrophy {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

.victory-title {
  font-size: 2.2rem;
  color: #2e7d32;
  font-weight: 900;
}

.victory-msg {
  font-size: 1.2rem;
  color: #558b2f;
  margin: 12px 0 16px;
  font-weight: 600;
}

.victory-stars {
  font-size: 2.2rem;
  margin-bottom: 24px;
  letter-spacing: 6px;
}

/* ==========================================================================
   4. MODAL DE AJUSTES E CALIBRAÇÃO (Fonoaudiologia)
   ========================================================================== */

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: #ffffff;
  border-radius: 20px;
  width: 90%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 12px 30px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 16px 22px;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 1.2rem;
  color: #1b5e20;
  font-weight: 800;
}

.btn-close {
  background: none;
  border: none;
  font-size: 1.8rem;
  color: #757575;
  cursor: pointer;
  line-height: 1;
}

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

.modal-desc {
  font-size: 0.9rem;
  color: #546e7a;
  line-height: 1.4;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.setting-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.95rem;
  font-weight: 700;
  color: #263238;
}

.setting-val {
  color: #2e7d32;
  font-weight: 800;
}

input[type="range"] {
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: #cfd8dc;
  outline: none;
  accent-color: #388e3c;
}

.setting-hint {
  font-size: 0.8rem;
  color: #78909c;
  line-height: 1.3;
}

.radio-toggle-group {
  display: flex;
  gap: 8px;
}

.toggle-btn {
  flex: 1;
  padding: 8px 12px;
  border-radius: 10px;
  border: 2px solid #cfd8dc;
  background: #f5f5f5;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  color: #455a64;
  cursor: pointer;
}

.toggle-btn.active {
  border-color: #4caf50;
  background: #e8f5e9;
  color: #1b5e20;
}

#spectrum-canvas {
  width: 100%;
  background: #212121;
  border-radius: 8px;
  display: block;
}

.spectrum-legend {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  font-weight: 600;
  margin-top: 2px;
}

.legend-low {
  color: #42a5f5;
}

.legend-high {
  color: #66bb6a;
}

.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid #e0e0e0;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.btn-secondary {
  background: #eceff1;
  border: none;
  padding: 10px 18px;
  border-radius: 10px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  color: #37474f;
  cursor: pointer;
}

.btn-primary {
  background: #388e3c;
  border: none;
  padding: 10px 22px;
  border-radius: 10px;
  font-family: inherit;
  font-weight: 800;
  font-size: 0.95rem;
  color: white;
  cursor: pointer;
}

/* ==========================================================================
   5. RESPONSIVIDADE ADAPTATIVA (Tablets & Orientação)
   ========================================================================== */

@media (max-width: 900px) {
  .safari-track-container {
    max-width: 420px;
  }
  .banner-syllable {
    font-size: 2.6rem;
  }
}

@media (max-height: 600px) {
  #hud-header {
    height: 62px;
  }
  .banner-syllable {
    font-size: 2.2rem;
  }
  .banner-tip {
    font-size: 0.8rem;
  }
  .mic-feedback-bar {
    bottom: 8px;
    padding: 6px 14px;
  }
  .step-node {
    height: 32px;
    font-size: 0.65rem;
  }
}
