/* ==========================================================================
   Vincol Pneus • Damas 3D — estilos (mobile first)
   ========================================================================== */
:root {
  --bg: #111114;
  --surface: rgba(28, 28, 33, 0.94);
  --surface-2: #26262d;
  --glass: rgba(17, 17, 20, 0.72);
  --line: rgba(255, 255, 255, 0.09);
  --text: #f5f5f7;
  --muted: #b0b0ba;
  --red: #ff3131; /* vermelho oficial da Vincol */
  --red-btn: #d61f1f; /* vermelho escuro Vincol com contraste >= 4.5:1 com branco */
  --red-text: #ff6b6b; /* vermelho claro para textos pequenos sobre fundo escuro */
  --red-soft: rgba(255, 49, 49, 0.16);
  --silver: #dde3ea;
  --gold: #ffd54f;
  --radius: 20px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  --footer-h: 22px;
  --dock-h: 62px;
  --hud-h: 52px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

button:focus-visible,
#canvas-container:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

#canvas-container:focus-visible {
  outline-offset: -3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none !important;
}

/* Ícones SVG embutidos (herdam a cor do texto) */
.icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
  fill: currentColor;
}

#canvas-container {
  position: fixed;
  inset: 0;
  height: 100dvh;
  z-index: 1;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#canvas-container canvas {
  display: block;
  touch-action: none;
}

/* --------------------------------------------------------------------------
   Placar superior
   -------------------------------------------------------------------------- */
.hud {
  position: fixed;
  z-index: 10;
  top: calc(8px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 16px));
  height: var(--hud-h);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 16px;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}

.hud-side {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 12px;
  border: 1px solid transparent;
  transition: background 0.25s, border-color 0.25s;
  min-width: 0;
}

.hud-side.right {
  justify-content: flex-end;
}

.hud-side.turn {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.16);
}

.hud-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: none;
  box-shadow: inset 0 0 0 3px #1f1f24;
}

.hud-dot.silver {
  background: var(--silver);
}

.hud-dot.red {
  background: var(--red);
}

.hud-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-side.turn .hud-name {
  color: var(--text);
}

.hud-count {
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
}

.hud-timer {
  font-size: 16px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
}

.hud-level {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--red-text);
}

/* --------------------------------------------------------------------------
   Mensagens
   -------------------------------------------------------------------------- */
.toast {
  position: fixed;
  z-index: 10;
  top: calc(var(--hud-h) + 16px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 24px));
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  text-align: center;
  color: var(--text);
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 14px;
  pointer-events: none;
  transition: opacity 0.25s;
}

.toast.flash {
  animation: toast-pop 0.3s ease;
}

@keyframes toast-pop {
  from {
    transform: translateX(-50%) scale(0.96);
    opacity: 0.4;
  }
  to {
    transform: translateX(-50%) scale(1);
    opacity: 1;
  }
}

/* Botão "Encerrar jogada" (captura em cadeia), logo acima da barra de ações */
.chain-end {
  position: fixed;
  z-index: 11;
  left: 50%;
  bottom: calc(var(--footer-h) + var(--dock-h) + 16px + var(--safe-bottom));
  transform: translateX(-50%);
  box-shadow: var(--shadow);
  animation: fade-in 0.2s ease;
}

@media (max-height: 520px) and (orientation: landscape) {
  .chain-end {
    left: auto;
    right: calc(88px + env(safe-area-inset-right, 0px));
    bottom: calc(var(--footer-h) + 10px + var(--safe-bottom));
    transform: none;
  }
}

/* --------------------------------------------------------------------------
   Barra de ações
   -------------------------------------------------------------------------- */
.dock {
  position: fixed;
  z-index: 10;
  bottom: calc(var(--footer-h) + 6px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: min(440px, calc(100vw - 16px));
  height: var(--dock-h);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 6px;
  gap: 4px;
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.dock-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  transition: background 0.15s, color 0.15s, transform 0.1s;
}

.dock-btn .icon {
  width: 23px;
  height: 23px;
}

.dock-btn:active {
  transform: scale(0.94);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.dock-btn:disabled {
  opacity: 0.35;
  pointer-events: none;
}

@media (hover: hover) {
  .dock-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
  }
}

/* --------------------------------------------------------------------------
   Telas sobrepostas (início, ranking, fim de jogo)
   -------------------------------------------------------------------------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-top)) 16px calc(var(--footer-h) + 12px + var(--safe-bottom));
  background: rgba(8, 8, 10, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  overflow-y: auto;
  animation: fade-in 0.25s ease;
}

/* No celular, desfoque de tela cheia sobre o 3D custa caro na GPU: fundo sólido no lugar */
@media (pointer: coarse) {
  .overlay {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(8, 8, 10, 0.84);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

.card {
  width: min(400px, 100%);
  margin: auto;
  padding: 24px 20px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: card-in 0.3s cubic-bezier(0.2, 0, 0, 1.2);
}

@keyframes card-in {
  from {
    transform: translateY(12px) scale(0.97);
    opacity: 0;
  }
}

/* Marca */
.brand {
  text-align: center;
  margin-bottom: 20px;
}

.brand-logo {
  display: grid;
  place-items: center;
  height: 96px;
  margin: -4px -4px 16px;
  background: var(--red);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(255, 49, 49, 0.28);
}

.brand-logo img {
  width: auto;
  height: 74px;
  max-width: 80%;
  object-fit: contain;
}

.brand h1 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.3px;
}

.brand p {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}

/* Campos */
.field {
  display: block;
  margin-bottom: 16px;
}

.field-label {
  display: block;
  margin-bottom: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.field input {
  width: 100%;
  height: 50px;
  padding: 0 16px;
  font-size: 16px; /* 16px evita o zoom automático do iPhone */
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.field input:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px var(--red-soft);
}

.field input.invalid {
  border-color: var(--red);
}

.field-error {
  display: block;
  min-height: 16px;
  margin-top: 5px;
  font-size: 12px;
  color: #ff8a80;
}

/* Seletor segmentado */
.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 14px;
}

.segmented.four {
  grid-template-columns: repeat(4, 1fr);
}

.seg {
  height: 40px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  transition: background 0.2s, color 0.2s;
}

.seg.active {
  background: var(--text);
  color: #111114;
}

/* Botões */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 46px;
  padding: 0 18px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 700;
  transition: transform 0.1s, filter 0.2s, background 0.2s;
}

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

.btn.primary {
  background: var(--red-btn);
  color: #fff;
}

.btn.primary:active {
  filter: brightness(0.92);
}

.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

.btn.big {
  height: 54px;
  font-size: 17px;
}

.start-card .btn {
  width: 100%;
  margin-top: 6px;
}

.hint {
  margin-top: 14px;
  font-size: 12px;
  line-height: 1.45;
  text-align: center;
  color: var(--muted);
}

/* Ranking */
.ranking-card {
  display: flex;
  flex-direction: column;
  height: min(620px, 100%);
  max-height: 100%;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.card-head h2 {
  font-size: 22px;
  font-weight: 800;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--muted);
}

.icon-btn:active {
  background: rgba(255, 255, 255, 0.08);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  margin-bottom: 12px;
  flex: none;
}

.tab {
  height: 40px;
  padding: 0;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
}

.tab.active {
  background: var(--text);
  color: #111114;
}

.ranking-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  margin: 0 -6px;
  padding: 0 6px;
}

.rank-row {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
}

.rank-row.me {
  background: var(--red-soft);
  border-radius: 12px;
  border-bottom-color: transparent;
}

.rank-pos {
  font-size: 15px;
  font-weight: 800;
  text-align: center;
  color: var(--muted);
}

.rank-row:nth-child(1) .rank-pos {
  color: var(--gold);
}

.rank-row:nth-child(2) .rank-pos {
  color: var(--silver);
}

.rank-row:nth-child(3) .rank-pos {
  color: #d7a374;
}

.rank-name {
  min-width: 0;
}

.rank-name b {
  display: block;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rank-name small {
  font-size: 11.5px;
  color: var(--muted);
}

.rank-time {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.rank-time b {
  display: block;
  font-size: 15px;
  font-weight: 800;
}

.rank-time small {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--red-text);
}

.ranking-note {
  flex: none;
  margin-top: 10px;
  font-size: 11.5px;
  text-align: center;
  color: var(--muted);
}

.ranking-empty {
  padding: 30px 0;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* Fim de jogo */
.gameover-card {
  text-align: center;
}

.gameover-icon {
  width: 56px;
  height: 56px;
  color: var(--gold);
}

.gameover-card h2 {
  margin-top: 6px;
  font-size: 24px;
  font-weight: 800;
}

.gameover-detail {
  margin-top: 8px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
}

.gameover-detail b {
  color: var(--text);
}

.gameover-count {
  margin: 14px 0 16px;
  font-size: 13px;
  color: var(--muted);
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.row.single {
  grid-template-columns: 1fr;
  margin-top: 16px;
}

/* --------------------------------------------------------------------------
   Rodapé
   -------------------------------------------------------------------------- */
.site-footer {
  position: fixed;
  z-index: 20; /* abaixo das telas sobrepostas (30) para nunca cobrir botões */
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--footer-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: rgba(245, 245, 247, 0.78);
  pointer-events: none;
  text-align: center;
  /* legível mesmo sobre as faixas brancas da pista */
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.95), 0 0 6px rgba(0, 0, 0, 0.8);
}

.site-footer strong {
  margin: 0 3px;
  color: rgba(245, 245, 247, 0.85);
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   Ajustes por tamanho de tela
   -------------------------------------------------------------------------- */
/* Telas baixas: compacta a tela inicial para caber sem rolar */
@media (max-height: 720px) {
  .card {
    padding: 18px 16px 16px;
  }
  .brand {
    margin-bottom: 14px;
  }
  .field {
    margin-bottom: 12px;
  }
  .field input {
    height: 46px;
  }
  .btn.big {
    height: 50px;
  }
  .hint {
    margin-top: 10px;
    font-size: 11.5px;
  }
}

@media (max-height: 680px) {
  .hint {
    display: none;
  }
}

/* Celulares bem estreitos (ex.: 320px) */
@media (max-width: 359px) {
  .hud-name {
    display: none;
  }
  .seg,
  .tab {
    font-size: 12px;
  }
  .brand-logo {
    height: 80px;
  }
  .brand-logo img {
    height: 60px;
  }
}

/* Celular deitado: barra de ações vai para a lateral */
@media (max-height: 520px) and (orientation: landscape) {
  :root {
    --hud-h: 44px;
    --footer-h: 18px;
  }
  .hud {
    top: calc(6px + var(--safe-top));
    width: min(420px, calc(100vw - 190px)); /* não encosta na barra lateral */
  }
  .toast {
    top: calc(var(--hud-h) + 10px + var(--safe-top));
    font-size: 12px;
    padding: 6px 12px;
  }
  .dock {
    left: auto;
    right: calc(8px + env(safe-area-inset-right, 0px));
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
    width: 68px;
    height: auto;
    grid-template-columns: 1fr;
    grid-auto-rows: 54px;
  }
  .site-footer {
    font-size: 10px;
  }

  /* Tela inicial em 2 colunas: marca e botões à esquerda, campos à direita */
  .overlay {
    padding: calc(8px + var(--safe-top)) calc(12px + env(safe-area-inset-right, 0px))
      calc(var(--footer-h) + 6px + var(--safe-bottom)) calc(12px + env(safe-area-inset-left, 0px));
  }
  .start-card {
    width: min(720px, 100%);
    display: grid;
    grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
    grid-template-areas: 'brand fields' 'actions fields';
    align-content: start;
    column-gap: 18px;
    padding: 14px 16px;
  }
  .start-card .brand {
    grid-area: brand;
    margin-bottom: 6px;
  }
  .start-card .brand-logo {
    height: 58px;
    margin: 0 0 8px;
  }
  .start-card .brand-logo img {
    height: 44px;
  }
  .start-card .brand h1 {
    font-size: 18px;
  }
  .start-card .brand p {
    font-size: 12px;
    margin-top: 2px;
  }
  .start-fields {
    grid-area: fields;
  }
  .start-actions {
    grid-area: actions;
  }
  .start-card .field {
    margin-bottom: 6px;
  }
  .start-card .field-label {
    margin-bottom: 4px;
    font-size: 11px;
  }
  .start-card .field input {
    height: 40px;
  }
  .start-card .field-error {
    min-height: 14px;
    margin-top: 2px;
  }
  .start-card .seg {
    height: 38px;
  }
  .start-card .btn,
  .start-card .btn.big {
    height: 40px;
    font-size: 15px;
    margin-top: 6px;
  }
  .start-card .hint {
    display: none;
  }
  .ranking-card {
    height: 100%;
  }
  .ranking-note {
    display: none;
  }
}
