* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  background: linear-gradient(160deg, #1b1035 0%, #2a1a5e 45%, #3d2b8f 100%);
  color: #f4f2ff;
}

.game-wrap {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

#app {
  display: flex;
  flex-direction: column;
}

header.hud {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(0, 0, 0, 0.25);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.hud h1 {
  font-size: 16px;
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud .stats {
  display: flex;
  gap: 14px;
  font-size: 13px;
  flex-wrap: wrap;
}

.hud .stats span b {
  display: block;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}

.hud select, .hud button {
  background: #4c3fdb;
  color: white;
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}

.hud button.secondary {
  background: rgba(255,255,255,0.12);
}

.hud select:disabled, .hud button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 15% 20%, rgba(255,255,255,0.05), transparent 40%),
    radial-gradient(circle at 85% 70%, rgba(255,255,255,0.04), transparent 40%);
}

.floor-line {
  position: absolute;
  left: 0; right: 0;
  height: 2px;
  background: rgba(255, 90, 90, 0.6);
  box-shadow: 0 0 8px rgba(255, 90, 90, 0.6);
}

.word {
  position: absolute;
  padding: 4px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: 0.5px;
  transition: background 0.15s, transform 0.1s;
}

.word .matched { color: #7cf7a3; }
.word .pending { color: #f4f2ff; }

.word.active {
  background: rgba(124, 247, 163, 0.15);
  border-color: #7cf7a3;
}

.word.miss {
  animation: shake 0.25s;
  background: rgba(255, 90, 90, 0.25);
  border-color: #ff5a5a;
}

.word.sentence {
  white-space: normal;
  line-height: 1.4;
  font-size: 16px;
  padding: 8px 12px;
}

body.popup-mode .word.sentence { font-size: 12px; padding: 6px 8px; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  background: rgba(10, 5, 30, 0.85);
  text-align: center;
  padding: 20px;
}

.overlay h2 { margin: 0; font-size: 22px; }
.overlay p { margin: 0; opacity: 0.85; font-size: 14px; max-width: 320px; }

.overlay .big-score { font-size: 40px; font-weight: 800; color: #7cf7a3; }

.phase-countdown {
  font-size: 56px;
  font-weight: 800;
  color: #ffd43b;
  animation: countpulse 1s ease-in-out infinite;
}

@keyframes countpulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.7; }
}

.phase-badge {
  display: inline-block;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 700;
  margin-right: 8px;
}

body.popup-mode .phase-badge { font-size: 10px; padding: 4px 8px; }

.overlay button {
  background: #4c3fdb;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 22px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.overlay button:hover { background: #5b4df0; }

footer.tip {
  padding: 8px 16px;
  font-size: 12px;
  text-align: center;
  opacity: 0.6;
  background: rgba(0,0,0,0.2);
}

.keyboard-wrap {
  flex-shrink: 0;
  padding: 10px 14px 14px;
  background: rgba(0, 0, 0, 0.28);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.key-guide {
  text-align: center;
  font-size: 13px;
  margin-bottom: 8px;
  min-height: 18px;
  opacity: 0.95;
}

.key-guide b { font-weight: 700; }

.keyboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.key-row {
  display: flex;
  gap: 6px;
}

.key {
  position: relative;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid var(--finger-color, rgba(255,255,255,0.2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
  box-shadow: inset 0 0 0 2px rgba(0,0,0,0.15);
  transition: transform 0.12s, box-shadow 0.12s, background 0.12s;
}

.key.home-row {
  background: rgba(255, 255, 255, 0.16);
}

.key.bump::after {
  content: "";
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 10px;
  height: 3px;
  border-radius: 2px;
  background: var(--finger-color);
  opacity: 0.9;
}

.key.next {
  background: var(--finger-color);
  color: #1b1035;
  transform: translateY(-3px) scale(1.08);
  box-shadow: 0 4px 14px rgba(0,0,0,0.35), 0 0 0 3px rgba(255,255,255,0.25);
  animation: keypulse 0.9s ease-in-out infinite;
}

@keyframes keypulse {
  0%, 100% { box-shadow: 0 4px 14px rgba(0,0,0,0.35), 0 0 0 3px rgba(255,255,255,0.25); }
  50% { box-shadow: 0 4px 18px rgba(0,0,0,0.35), 0 0 0 6px rgba(255,255,255,0.12); }
}

.key.space-key {
  width: 180px;
  font-size: 10px;
  letter-spacing: 1px;
}

.key-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 14px;
  margin-top: 10px;
  font-size: 11px;
  opacity: 0.85;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.legend-item i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

/* popup: teclado compacto */
body.popup-mode .keyboard-wrap { padding: 6px 8px 10px; }
body.popup-mode .key { width: 21px; height: 21px; font-size: 10px; border-radius: 4px; }
body.popup-mode .key.space-key { width: 120px; font-size: 8px; }
body.popup-mode .key-row { gap: 3px; }
body.popup-mode .keyboard { gap: 3px; }
body.popup-mode .key-guide { font-size: 10px; }

/* seletor de modo (Chuva de Palavras / Modo Texto) */
.mode-switch {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.35);
  flex-shrink: 0;
}

.mode-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.08);
  color: #f4f2ff;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.mode-btn.active {
  background: #4c3fdb;
  border-color: #4c3fdb;
}

.mode-content { flex: 1; display: flex; min-height: 0; overflow-y: auto; overflow-x: hidden; }
.mode-content > .game-wrap { flex: 1; min-height: 0; }

.fullscreen-bar {
  flex-shrink: 0;
  text-align: center;
  padding: 6px;
  background: rgba(0, 0, 0, 0.3);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

body.popup-mode .mode-btn { font-size: 10px; padding: 6px 4px; }

/* Modo Texto: passagem de texto */
.text-stage {
  position: relative;
  flex: 1;
  overflow: hidden;
  display: flex;
}

.text-passage {
  flex: 1;
  overflow-y: auto;
  padding: 22px 26px;
  font-size: 19px;
  line-height: 1.9;
  letter-spacing: 0.3px;
}

body.popup-mode .text-passage { font-size: 14px; line-height: 1.7; padding: 14px 16px; }

.text-passage span.pending { color: rgba(244, 242, 255, 0.45); }
.text-passage span.correct { color: #7cf7a3; }
.text-passage span.wrong { color: #ff7676; text-decoration: underline wavy rgba(255,118,118,0.7); }
.text-passage span.cursor {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 3px;
  outline: 2px solid #4c3fdb;
  outline-offset: 1px;
}

/* popup sizing */
body.popup-mode {
  width: 400px;
  height: 600px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.popup-mode .hud h1 { font-size: 14px; }
body.popup-mode .word { font-size: 14px; }

/* ---- v1.2: página inteira, teclado ABNT2, guia em dois passos ---- */
html, body.page-mode { height: 100%; }
body.page-mode #app { height: 100vh; }

.fs-btn { flex: 0 0 auto; }

.key.next-2 {
  background: rgba(255, 255, 255, 0.14);
  box-shadow: 0 0 0 3px var(--finger-color);
  transform: translateY(-1px);
}

.key.shift-key { width: 78px; font-size: 11px; }
.key.space-key { width: 220px; }

body.popup-mode .key.shift-key { width: 52px; font-size: 8px; }
body.popup-mode .key.space-key { width: 130px; }

/* ---- v1.3: botão de soletrar ---- */
.speak-btn { flex: 0 0 auto; }
.speak-btn:disabled { opacity: 0.4; cursor: not-allowed; }
body.popup-mode .speak-btn { padding: 6px 10px; font-size: 13px; }
