/* ================================================================
   TECH FORMULA RACE — Folha de estilo principal
   Tema: cyberpunk / Fórmula 1 futurista, neon, glassmorphism.
   ================================================================ */

/* ---------- Reset & base ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --neon-cyan: #00f0ff;
  --neon-magenta: #ff00d4;
  --neon-green: #19ff8a;
  --neon-yellow: #ffe600;
  --bg-deep: #05010f;
  --bg-panel: rgba(10, 6, 30, 0.72);
  --glass-border: rgba(0, 240, 255, 0.35);
  --font: "Segoe UI", "Trebuchet MS", Tahoma, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg-deep);
  color: #e7f7ff;
  font-family: var(--font);
  overflow: hidden;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Container ---------- */
#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#bg-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

/* ---------- Telas ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  z-index: 2;
}
.screen.active { display: block; }

/* Tela inicial e final usam flex de rolagem */
#start-screen.active,
#end-screen.active {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 24px 16px;
}

/* ================================================================
   TELA INICIAL
   ================================================================ */
.start-inner {
  position: relative;
  z-index: 3;
  width: min(720px, 100%);
  background: var(--bg-panel);
  border: 1px solid var(--glass-border);
  border-radius: 18px;
  padding: 30px 28px;
  backdrop-filter: blur(8px);
  box-shadow: 0 0 40px rgba(0, 240, 255, 0.18), inset 0 0 30px rgba(255, 0, 212, 0.06);
  text-align: center;

  /* Layout em grade: 1 coluna (mobile/vertical), 2 colunas em telas largas */
  display: grid;
  grid-template-columns: 1fr;
  gap: 0 32px;
}
.start-footer { grid-column: 1 / -1; }

/* Monitores e TVs (paisagem larga): coluna do logo/form à esquerda,
   instruções à direita — aproveita melhor a tela horizontal. */
@media (min-width: 980px) and (orientation: landscape) {
  #start-screen.active { padding: 24px 32px; }
  .start-inner {
    width: min(1240px, 96%);
    grid-template-columns: minmax(360px, 460px) 1fr;
    align-items: start; /* alinha a coluna lateral na linha da logo */
    padding: 30px 38px;
  }
  .start-info { text-align: left; }
  .start-info .instructions { margin-top: 0; }
  .start-info .top5 { margin-top: 16px; }
  /* Blocos de controles empilhados na coluna lateral */
  .instructions-grid { grid-template-columns: 1fr 1fr; }
  .instructions-grid .ctrl-block:last-child { grid-column: 1 / -1; }
  .logo-line { font-size: clamp(38px, 5vw, 64px); }
}

/* TVs muito largas: instruções voltam a ficar lado a lado em 3 colunas */
@media (min-width: 1500px) and (orientation: landscape) {
  .start-inner { width: min(1480px, 94%); }
  .instructions-grid { grid-template-columns: repeat(3, 1fr); }
  .instructions-grid .ctrl-block:last-child { grid-column: auto; }
}

.logo {
  line-height: 0.92;
  margin-bottom: 22px;
  letter-spacing: 4px;
  font-weight: 800;
}
.logo-line {
  display: block;
  font-size: clamp(38px, 9vw, 78px);
  color: #fff;
  text-shadow: 0 0 8px var(--neon-cyan), 0 0 24px var(--neon-cyan);
  animation: flicker 4s infinite;
}
.logo-line.accent {
  color: var(--neon-magenta);
  text-shadow: 0 0 10px var(--neon-magenta), 0 0 30px var(--neon-magenta);
}
.logo-sub {
  display: block;
  margin-top: 12px;
  font-size: clamp(11px, 2.4vw, 15px);
  letter-spacing: 6px;
  color: var(--neon-green);
  text-shadow: 0 0 8px var(--neon-green);
  animation: scan 3s linear infinite;
}

@keyframes flicker {
  0%, 18%, 22%, 25%, 53%, 57%, 100% { opacity: 1; }
  20%, 24%, 55% { opacity: 0.55; }
}
@keyframes scan { 0% { opacity: 0.4; } 50% { opacity: 1; } 100% { opacity: 0.4; } }

#start-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 18px auto 24px;
  max-width: 420px;
}
#start-form label {
  text-align: left;
  font-size: 13px;
  letter-spacing: 2px;
  color: var(--neon-cyan);
  text-transform: uppercase;
}
#player-name {
  padding: 14px 16px;
  font-size: 18px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  color: #fff;
  outline: none;
  transition: box-shadow 0.2s, border-color 0.2s;
}
#player-name:focus {
  border-color: var(--neon-cyan);
  box-shadow: 0 0 16px rgba(0, 240, 255, 0.5);
}

/* Botões neon */
.neon-btn {
  cursor: pointer;
  padding: 15px 22px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 3px;
  color: #021018;
  background: linear-gradient(135deg, var(--neon-cyan), var(--neon-green));
  border: none;
  border-radius: 10px;
  text-transform: uppercase;
  transition: transform 0.12s, box-shadow 0.2s;
  box-shadow: 0 0 18px rgba(0, 240, 255, 0.55);
}
.neon-btn:hover { transform: translateY(-2px); box-shadow: 0 0 28px rgba(0, 240, 255, 0.85); }
.neon-btn:active { transform: translateY(0); }

.ghost-btn {
  cursor: pointer;
  padding: 13px 20px;
  font-size: 14px;
  letter-spacing: 2px;
  background: transparent;
  color: var(--neon-magenta);
  border: 1px solid var(--neon-magenta);
  border-radius: 10px;
  text-transform: uppercase;
  transition: background 0.2s;
}
.ghost-btn:hover { background: rgba(255, 0, 212, 0.12); }

/* Top 5 na tela inicial */
.top5 { text-align: left; margin-top: 18px; }
.top5 h2 {
  text-align: center; font-size: 15px; letter-spacing: 3px;
  color: var(--neon-yellow); margin-bottom: 10px; text-transform: uppercase;
}
#top5-list { list-style: none; counter-reset: rank; }
#top5-list li {
  counter-increment: rank;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 8px 14px; margin-bottom: 5px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(0, 240, 255, 0.18);
  border-radius: 10px; font-size: 14px;
}
#top5-list li::before {
  content: counter(rank) "º";
  width: 32px; color: var(--neon-cyan); font-weight: 800;
}
#top5-list li .r-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#top5-list li .r-score { color: var(--neon-yellow); font-variant-numeric: tabular-nums; }
#top5-list li .r-time { color: var(--neon-green); font-variant-numeric: tabular-nums; }

/* Instruções */
.instructions { text-align: left; margin-top: 6px; }
.instructions h2 {
  font-size: 16px; letter-spacing: 3px; color: var(--neon-yellow);
  text-transform: uppercase; margin-bottom: 12px; text-align: center;
}
.instructions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
}
.ctrl-block {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(0, 240, 255, 0.2);
  border-radius: 12px; padding: 14px;
}
.ctrl-block h3 { font-size: 14px; color: var(--neon-cyan); margin-bottom: 8px; letter-spacing: 2px; }
.ctrl-block ul { list-style: none; font-size: 14px; line-height: 1.9; }
kbd {
  display: inline-block; min-width: 24px; text-align: center;
  padding: 2px 7px; margin-right: 6px;
  background: #111; border: 1px solid var(--neon-cyan); border-radius: 6px;
  color: var(--neon-cyan); font-size: 13px;
}
.tip {
  margin-top: 14px; text-align: center; font-size: 13px;
  color: var(--neon-green); line-height: 1.5;
}
.audio-hint { margin-top: 14px; font-size: 12px; color: #8fa9c9; }

/* Rodapé de créditos */
.credits {
  margin-top: 18px;
  text-align: center;
  font-size: 13px;
  letter-spacing: 1px;
  color: #8fa9c9;
}
.credits span {
  color: var(--neon-cyan);
  font-weight: 700;
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.6);
}

/* ================================================================
   TELA DE JOGO + HUD
   ================================================================ */
#game-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: block; background: #03010a; z-index: 1;
}

#hud {
  position: absolute; inset: 0;
  z-index: 5; pointer-events: none;
  padding: 12px;
}
.hud-row { display: flex; gap: 8px; flex-wrap: wrap; }
.hud-top { justify-content: flex-start; }
.hud-bottom { margin-top: 8px; }

.hud-card {
  background: var(--bg-panel);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  padding: 6px 12px;
  min-width: 78px;
  backdrop-filter: blur(4px);
  box-shadow: 0 0 12px rgba(0, 240, 255, 0.15);
}
/* Logo UNISUAM ao lado das contagens (HUD) */
.hud-logo {
  height: 64px;
  align-self: center;
  padding: 5px 10px;
  background: rgba(245, 250, 255, 0.92);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  box-shadow: 0 0 14px rgba(0, 240, 255, 0.3);
  object-fit: contain;
}

/* Logo de marca nas telas inicial/final */
.brand-logo {
  height: 96px;
  margin: 0 auto 14px;
  display: block;
  padding: 8px 16px;
  background: rgba(245, 250, 255, 0.95);
  border-radius: 12px;
  box-shadow: 0 0 18px rgba(0, 240, 255, 0.35);
}

.ranking-status {
  text-align: center;
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--neon-cyan);
  margin-bottom: 10px;
}

.hud-label {
  display: block; font-size: 10px; letter-spacing: 2px;
  color: var(--neon-cyan); text-transform: uppercase;
}
.hud-value { display: block; font-size: 18px; font-weight: 700; color: #fff; }

/* Velocímetro / Nitro fixos no rodapé */
#speed-panel {
  position: absolute; left: 12px; bottom: 12px;
  display: flex; gap: 12px; align-items: flex-end;
}
.speed-meter, .nitro-wrap {
  background: var(--bg-panel);
  border: 1px solid var(--glass-border);
  border-radius: 12px; padding: 8px 14px;
  backdrop-filter: blur(4px);
}
.speed-meter .hud-value { font-size: 30px; color: var(--neon-green); display: inline; }
.speed-meter .kmh { font-size: 12px; color: #9fd; margin-left: 4px; }
.nitro-wrap { min-width: 150px; }
.nitro-bar {
  width: 100%; height: 12px; margin: 4px 0;
  background: rgba(0,0,0,0.5); border-radius: 6px; overflow: hidden;
  border: 1px solid rgba(255, 230, 0, 0.4);
}
#nitro-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--neon-yellow), var(--neon-magenta));
  box-shadow: 0 0 12px var(--neon-yellow);
  transition: width 0.1s linear;
}
#nitro-state { font-size: 11px; letter-spacing: 2px; color: var(--neon-yellow); }

/* Botões de jogo */
#game-buttons {
  position: absolute; top: 12px; right: 12px;
  display: flex; gap: 8px; z-index: 6;
}
.icon-btn {
  width: 42px; height: 42px;
  font-size: 20px; cursor: pointer;
  background: var(--bg-panel);
  border: 1px solid var(--glass-border);
  border-radius: 10px; color: var(--neon-cyan);
  backdrop-filter: blur(4px);
  transition: background 0.2s, transform 0.1s;
}
.icon-btn:hover { background: rgba(0, 240, 255, 0.18); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn.off { color: #ff5a7a; border-color: #ff5a7a; }

/* Toast (mensagens flutuantes) */
#toast {
  position: absolute; top: 38%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center; font-size: clamp(18px, 4vw, 30px);
  font-weight: 800; letter-spacing: 2px;
  text-shadow: 0 0 16px currentColor;
  opacity: 0; transition: opacity 0.25s; pointer-events: none;
}
#toast.show { opacity: 1; }

/* ---------- Controles touch ---------- */
#touch-controls { display: none; }
body.touch #touch-controls {
  display: block; position: absolute; inset: 0;
  z-index: 7; pointer-events: none;
}
#joystick {
  position: absolute; left: 24px; bottom: 90px;
  width: 130px; height: 130px;
  border-radius: 50%;
  background: rgba(0, 240, 255, 0.08);
  border: 2px solid var(--glass-border);
  pointer-events: auto; touch-action: none;
}
#joystick-knob {
  position: absolute; left: 50%; top: 50%;
  width: 56px; height: 56px; margin: -28px 0 0 -28px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, var(--neon-cyan), #0078a0);
  box-shadow: 0 0 18px var(--neon-cyan);
}
#nitro-btn {
  position: absolute; right: 28px; bottom: 100px;
  width: 100px; height: 100px; border-radius: 50%;
  font-size: 18px; font-weight: 800; letter-spacing: 1px;
  color: #1a0010;
  background: radial-gradient(circle at 40% 35%, var(--neon-yellow), var(--neon-magenta));
  border: none; box-shadow: 0 0 22px var(--neon-magenta);
  pointer-events: auto; touch-action: none;
}
#nitro-btn:active { transform: scale(0.93); }

/* ================================================================
   MODAL DE PERGUNTA
   ================================================================ */
.modal {
  position: absolute; inset: 0; z-index: 20;
  display: none; align-items: center; justify-content: center;
  background: rgba(2, 0, 12, 0.78);
  backdrop-filter: blur(6px);
  padding: 16px;
}
.modal.active { display: flex; }
.modal-box {
  width: min(560px, 100%);
  background: linear-gradient(160deg, rgba(20,8,45,0.96), rgba(8,3,22,0.96));
  border: 1px solid var(--neon-magenta);
  border-radius: 16px; padding: 22px 24px;
  box-shadow: 0 0 40px rgba(255, 0, 212, 0.4);
  animation: modalIn 0.3s ease;
}
@keyframes modalIn { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.modal-tag { font-size: 12px; letter-spacing: 3px; color: var(--neon-magenta); }
.modal-timer {
  font-size: 22px; font-weight: 800; color: var(--neon-yellow);
  text-shadow: 0 0 10px var(--neon-yellow);
}
#q-text { font-size: 21px; line-height: 1.35; margin-bottom: 18px; color: #fff; }
#q-options { display: grid; gap: 10px; }
.q-opt {
  text-align: left; cursor: pointer;
  padding: 13px 16px; font-size: 16px;
  background: rgba(0, 240, 255, 0.06);
  border: 1px solid var(--glass-border);
  border-radius: 10px; color: #dff;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  font-family: var(--font);
}
.q-opt:hover { background: rgba(0, 240, 255, 0.16); }
.q-opt.sel {
  border-color: var(--neon-yellow);
  box-shadow: 0 0 14px rgba(255, 230, 0, 0.55);
  background: rgba(255, 230, 0, 0.10);
}
.q-opt .opt-key {
  display: inline-block; width: 26px; font-weight: 800; color: var(--neon-cyan);
}
.q-opt.correct { background: rgba(25,255,138,0.25); border-color: var(--neon-green); color: #fff; }
.q-opt.wrong { background: rgba(255,40,90,0.25); border-color: #ff285a; color: #fff; }
.q-opt:disabled { cursor: default; }
#q-feedback {
  margin-top: 16px; text-align: center; font-size: 16px;
  font-weight: 700; min-height: 22px;
}

/* Modal de pause */
.pause-box { text-align: center; border-color: var(--neon-cyan); box-shadow: 0 0 40px rgba(0, 240, 255, 0.4); }
#pause-title {
  font-size: 40px; letter-spacing: 6px; margin: 10px 0 22px;
  color: var(--neon-cyan); text-shadow: 0 0 18px var(--neon-cyan);
}
.pause-buttons { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.pause-buttons .neon-btn, .pause-buttons .ghost-btn { width: 100%; }

/* ================================================================
   TELA FINAL
   ================================================================ */
.end-inner {
  position: relative; z-index: 3;
  width: min(720px, 100%);
  background: var(--bg-panel);
  border: 1px solid var(--glass-border);
  border-radius: 18px; padding: 28px 26px;
  backdrop-filter: blur(8px);
  box-shadow: 0 0 40px rgba(0, 240, 255, 0.2);
  text-align: center;
}
.end-title {
  font-size: clamp(26px, 6vw, 46px);
  color: var(--neon-cyan); letter-spacing: 4px;
  text-shadow: 0 0 18px var(--neon-cyan); margin-bottom: 20px;
}
.result-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin-bottom: 22px;
}
.result-card {
  background: rgba(0,0,0,0.35);
  border: 1px solid rgba(0,240,255,0.25);
  border-radius: 12px; padding: 12px 8px;
}
.result-card span { display: block; font-size: 11px; color: var(--neon-cyan); letter-spacing: 1px; }
.result-card b { display: block; font-size: 20px; margin-top: 4px; color: #fff; }

.ranking { text-align: left; margin-bottom: 22px; }
.ranking h2 {
  text-align: center; font-size: 18px; letter-spacing: 3px;
  color: var(--neon-yellow); margin-bottom: 14px;
}
#ranking-list { list-style: none; counter-reset: rank; }
#ranking-list li {
  counter-increment: rank;
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 14px; margin-bottom: 6px;
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(0,240,255,0.18);
  border-radius: 10px; font-size: 15px;
}
#ranking-list li::before {
  content: counter(rank) "º";
  width: 38px; color: var(--neon-cyan); font-weight: 800;
}
#ranking-list li .r-name { flex: 1; }
#ranking-list li .r-time { color: var(--neon-green); font-variant-numeric: tabular-nums; }
#ranking-list li.me {
  border-color: var(--neon-magenta);
  box-shadow: 0 0 14px rgba(255,0,212,0.4);
}
.end-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ================================================================
   RESPONSIVO
   ================================================================ */
@media (max-width: 560px) {
  .instructions-grid { grid-template-columns: 1fr; }
  .result-grid { grid-template-columns: repeat(2, 1fr); }
  .hud-card { min-width: 64px; padding: 5px 9px; }
  .hud-value { font-size: 15px; }
  .speed-meter .hud-value { font-size: 22px; }
  .start-inner, .end-inner { padding: 20px 16px; }
  .hud-logo { height: 48px; padding: 3px 7px; }
  .brand-logo { height: 72px; }
}

@media (max-height: 480px) and (orientation: landscape) {
  #joystick { bottom: 16px; left: 16px; width: 110px; height: 110px; }
  #nitro-btn { bottom: 20px; right: 20px; width: 84px; height: 84px; }
}
