/* ==========================================================================
   Roda de Palavras — identidade "ondas de calor"
   Paleta extraída da arte de referência: sol amarelo no centro, laranjas
   em ondas e bolhas magenta/roxas nos cantos.
   ========================================================================== */

:root {
  /* Paleta da marca */
  --sol: #F8CC2D;
  --laranja: #F79B1E;
  --laranja-forte: #F6830E;
  --magenta: #C61F65;
  --ameixa: #9C2579;
  --roxo: #692D91;

  /* Papéis */
  --ink: #3A1450;          /* texto principal: roxo bem escuro */
  --ink-soft: #6E4A7E;
  --muted: #84697F;
  --panel: rgba(255, 251, 243, 0.94);
  --panel-border: rgba(105, 45, 145, 0.18);
  --tile-bg: #FFFFFF;
  --tile-border: #D9C6DA;

  /* Resultado das letras */
  --correct: var(--roxo);
  --present: var(--sol);
  --absent: #D6CAD5;
  --on-correct: #FFFFFF;
  --on-present: var(--ink);
  --on-absent: #5B4760;

  --brand-gradient: linear-gradient(135deg, var(--magenta) 0%, var(--ameixa) 45%, var(--roxo) 100%);

  --font-display: 'Baloo 2', 'Arial Rounded MT Bold', 'Trebuchet MS', system-ui, sans-serif;
  --font-ui: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --radius-blob: 22px 16px 24px 14px;
  --radius-tile: 12px;
  --dock-height: 0px;
  --topbar-height: 64px;

  color-scheme: light;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: inherit; }

html, body { margin: 0; min-height: 100%; }
html { background: var(--laranja); }
body { overflow-x: clip; }

body {
  font-family: var(--font-ui);
  font-size: 1.0625rem;
  line-height: 1.5;
  color: var(--ink);
  background: transparent;
  -webkit-tap-highlight-color: transparent;
}

/* Bolhas fluidas do fundo (SVG no index.html) */
.backdrop {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
}

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

:focus-visible {
  outline: 3px solid var(--roxo);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------- topo */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: min(1040px, 100%);
  min-height: var(--topbar-height);
  margin: 0 auto;
  padding: 0.75rem clamp(16px, 4vw, 32px) 0.25rem;
}

.brand,
.topbar-room:not(:empty) {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.9rem;
  border-radius: 999px;
  background: var(--panel);
  box-shadow: 0 6px 18px -10px rgba(58, 20, 80, 0.55);
  white-space: nowrap;
}

.brand {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.375rem;
  line-height: 1.2;
  color: var(--roxo);
  text-decoration: none;
}

.brand-dot {
  flex-shrink: 0;
  width: 0.75em;
  height: 0.75em;
  border-radius: 50%;
  background: var(--brand-gradient);
}

.topbar-room { font-size: 0.9375rem; color: var(--ink-soft); min-width: 0; }
.brand { min-width: 0; }

.room-code {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.125rem;
  letter-spacing: 0.08em;
  color: var(--roxo);
}

.connection-banner {
  margin: 0.5rem auto 0;
  width: fit-content;
  padding: 0.375rem 0.875rem;
  border-radius: 999px;
  background: var(--magenta);
  color: #FFFFFF;
  font-weight: 700;
}

/* ---------------------------------------------------------------- estrutura */

.app {
  display: flex;
  flex-direction: column;
  width: min(1040px, 100%);
  min-height: calc(100dvh - var(--topbar-height) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  margin: 0 auto;
  padding: 0.75rem clamp(16px, 4vw, 32px) 1.25rem;
}

.app > * { width: 100%; }
.app:has(> .screen > .dock) { padding-bottom: 0; }

/* Telas com teclado: o teclado fica preso ao rodapé */
.app > .screen { flex: 1; display: flex; flex-direction: column; }
.screen > * + * { margin-top: 1rem; }
.screen > .dock { margin-top: auto; }
.screen > .spacer { flex: 1; margin: 0; }

.loading {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.5rem;
  color: var(--ink);
}

.sheet {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-blob);
  padding: clamp(1rem, 3vw, 1.75rem);
  box-shadow: 0 18px 40px -24px rgba(58, 20, 80, 0.6);
}

.stack > * + * { margin-top: 1.25rem; }

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 800;
  line-height: 1.1;
  margin: 0;
  letter-spacing: -0.01em;
}

h2 { font-size: clamp(1.625rem, 4.5vw, 2.125rem); color: var(--roxo); }
h3 { font-size: 1.1875rem; font-weight: 700; }

p { margin: 0; max-width: 65ch; }

.muted { color: var(--muted); }
.small { font-size: 0.9375rem; }

/* ---------------------------------------------------------------- formulários */

.field { display: grid; gap: 0.375rem; margin-left: 0; margin-right: 0; padding: 0; border: 0; min-width: 0; }

.field-label,
.field label {
  font-weight: 700;
  font-size: 0.9375rem;
  color: var(--ink-soft);
}

.field legend { padding: 0; margin-bottom: 0.375rem; }

.text-input {
  width: 100%;
  max-width: 22rem;
  padding: 0.625rem 0.875rem;
  border: 2px solid var(--tile-border);
  border-radius: 14px;
  background: var(--tile-bg);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.375rem;
  line-height: 1.2;
}

.text-input::placeholder { color: #B9A4B7; font-weight: 500; }
.text-input:focus { border-color: var(--roxo); outline: none; box-shadow: 0 0 0 4px rgba(105, 45, 145, 0.18); }

.code-input { max-width: 9.5rem; text-transform: uppercase; letter-spacing: 0.15em; }

.row-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 48px;
  padding: 0.5rem 1.4rem;
  border: 0;
  border-radius: 999px;
  background: var(--brand-gradient);
  color: #FFFFFF;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 18px -10px rgba(105, 45, 145, 0.9);
  transition: transform 80ms ease, box-shadow 80ms ease;
}

.btn:active { transform: translateY(1px); box-shadow: 0 4px 10px -8px rgba(105, 45, 145, 0.9); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.btn-outline {
  background: transparent;
  color: var(--roxo);
  box-shadow: inset 0 0 0 2px var(--roxo);
}

.btn-quiet {
  min-height: 36px;
  padding: 0.25rem 0.5rem;
  background: transparent;
  color: var(--ink-soft);
  box-shadow: none;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.topbar .btn-quiet { min-height: 30px; padding: 0 0.25rem; }

/* ---------------------------------------------------------------- início */

.home { display: grid; gap: 1.75rem; }

.home-hero p { margin-top: 0.875rem; font-size: 1.1875rem; font-weight: 700; color: var(--ink); }

/* Título escrito em quadradinhos, como um palpite já resolvido */
.hero-tiles { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; }
.hero-tiles .row,
.hero-tiles .row + .row { display: flex; width: auto; margin: 0; gap: 0.3rem; }
.hero-tiles .tile {
  --size: clamp(34px, 8.5vw, 66px);
  width: var(--size);
  height: var(--size);
  font-size: calc(var(--size) * 0.56);
  box-shadow: 0 10px 20px -12px rgba(58, 20, 80, 0.7);
}
.hero-tiles .row.is-revealing .tile { animation-duration: 420ms; animation-delay: calc(var(--i) * 70ms + 200ms); }

.home-grid { display: grid; gap: 1.25rem; grid-template-columns: 1fr; }
@media (min-width: 760px) { .home-grid { grid-template-columns: 3fr 2fr; align-items: start; } }

.game-options { display: grid; gap: 0.75rem; margin-left: 0; margin-right: 0; padding: 0; border: 0; min-width: 0; }
.game-options legend { padding: 0; margin-bottom: 0.375rem; }

.game-option {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.2rem 0.75rem;
  align-items: start;
  padding: 0.875rem 1rem;
  border: 2px solid var(--tile-border);
  border-radius: 16px;
  background: var(--tile-bg);
  cursor: pointer;
}

.game-option:has(input:checked) { border-color: var(--roxo); box-shadow: inset 6px 0 0 var(--magenta); }
.game-option input { margin-top: 0.45rem; accent-color: var(--roxo); width: 1.1rem; height: 1.1rem; }
.game-option strong { font-family: var(--font-display); font-weight: 800; font-size: 1.375rem; line-height: 1.2; color: var(--roxo); }
.game-option span { grid-column: 2; color: var(--muted); font-size: 0.9375rem; }

/* ---------------------------------------------------------------- lobby */

.players { list-style: none; padding: 0; display: grid; gap: 0.25rem; }

.player {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.625rem 0.25rem;
  border-bottom: 2px dashed var(--tile-border);
}

.player-name { font-family: var(--font-display); font-weight: 700; font-size: 1.375rem; line-height: 1.2; }
.player-tag {
  margin-left: 0.5rem;
  padding: 0.05rem 0.5rem;
  border-radius: 999px;
  background: var(--sol);
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  font-weight: 700;
  vertical-align: middle;
}
.player-status { font-size: 0.9375rem; color: var(--muted); }
.player-status.is-ready { color: var(--roxo); font-weight: 700; }
.player-status.is-offline { color: var(--magenta); font-weight: 700; }
.player.is-empty .player-name { color: var(--muted); font-weight: 600; }

.stepper { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }

.stepper-btn {
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: var(--brand-gradient);
  color: #FFFFFF;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
.stepper-btn[disabled] { opacity: 0.3; cursor: not-allowed; }

.stepper-value { font-family: var(--font-display); font-weight: 800; font-size: 1.625rem; min-width: 5.5ch; color: var(--roxo); }

.length-preview { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.length-preview .tile { --size: clamp(24px, 6vw, 34px); width: var(--size); height: var(--size); border-radius: 8px; }

.note {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1875rem;
  color: var(--magenta);
}

/* ---------------------------------------------------------------- quadradinhos */

.board { container-type: inline-size; }

.row {
  --n: 5;
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  gap: clamp(3px, 1.2cqi, 7px);
  width: min(100%, calc(var(--n) * 62px));
  margin: 0 auto;
  scroll-margin-bottom: calc(var(--dock-height) + 16px);
  scroll-margin-top: 16px;
}

.row + .row { margin-top: clamp(3px, 1.2cqi, 7px); }

.tile {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 2px solid var(--tile-border);
  border-radius: var(--radius-tile);
  background: var(--tile-bg);
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: min(calc(100cqi / var(--n, 5) * 0.5), 2rem);
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
}

.tile.is-filled { border-color: var(--roxo); animation: pop 110ms ease-out; }

.tile[data-status='correct'] { background: var(--correct); border-color: var(--correct); color: var(--on-correct); }
.tile[data-status='present'] { background: var(--present); border-color: var(--present); color: var(--on-present); }
.tile[data-status='absent']  { background: var(--absent);  border-color: var(--absent);  color: var(--on-absent); }

/* Palavra em exibição (sua secreta, revelações): neutra, sem cor de resultado */
.row.is-word .tile {
  animation: none;
  border-color: var(--laranja);
  background: #FFF3D6;
  color: var(--ink);
}

/* Revelação: a única animação "de palco" do jogo */
.row.is-revealing .tile {
  animation: flip 520ms ease-in-out backwards;
  animation-delay: calc(var(--i) * 190ms);
}

.row.is-shaking { animation: shake 360ms ease-in-out; }

/* Linha fantasma: o adversário ainda não mandou o palpite */
.row.is-ghost .tile { border-style: dashed; border-color: var(--ameixa); background: transparent; opacity: 0.75; }
.row.is-ghost.is-typing .tile::after {
  content: '';
  width: 18%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--magenta);
  animation: hop 1s ease-in-out infinite;
  animation-delay: calc(var(--i) * 120ms);
}

@keyframes pop { 50% { transform: scale(1.08); } }

@keyframes flip {
  0% { transform: rotateX(0); background: var(--tile-bg); border-color: var(--roxo); color: var(--ink); }
  49.9% { transform: rotateX(90deg); background: var(--tile-bg); border-color: var(--roxo); color: var(--ink); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}

@keyframes shake {
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

@keyframes hop {
  0%, 100% { transform: translateY(20%); opacity: 0.35; }
  50% { transform: translateY(-40%); opacity: 1; }
}

@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75%, 100% { content: '...'; } }

.dots::after { content: '...'; display: inline-block; width: 3ch; text-align: left; animation: dots 1.6s steps(1) infinite; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ---------------------------------------------------------------- partida */

.status-line {
  align-self: flex-start;
  padding: 0.15rem 1.1rem 0.25rem;
  border-radius: 999px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.375rem, 4.5vw, 1.875rem);
  line-height: 1.3;
}

.status-line.is-my-turn { background: var(--brand-gradient); color: #FFFFFF; }
.status-line.is-waiting { background: var(--panel); color: var(--roxo); }

.notice {
  padding: 0.5rem 0.875rem;
  border-radius: 14px;
  background: var(--magenta);
  color: #FFFFFF;
  font-weight: 700;
}

.boards { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 860px) { .boards { grid-template-columns: 1fr 1fr; align-items: start; } }

.board-panel { padding: 1rem; }
.board-panel.is-active { border: 2px solid var(--roxo); }
.board-panel.is-first { order: -1; }
@media (min-width: 860px) { .board-panel.is-first { order: 0; } }

.board-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.board-count {
  padding: 0.05rem 0.6rem;
  border-radius: 999px;
  background: #FFF3D6;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.board-empty { text-align: center; color: var(--muted); font-size: 0.9375rem; padding: 0.5rem 0 0.75rem; }

.secret-chip { display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.875rem; color: var(--muted); }
.secret-chip .row { width: auto; gap: 2px; grid-template-columns: repeat(var(--n), 22px); margin: 0; }
.secret-chip .tile { font-size: 0.875rem; border-width: 1.5px; border-radius: 6px; }

/* Doca inferior: teclado ou tela de espera */
.dock {
  position: sticky;
  bottom: 0;
  z-index: 5;
  padding: 0.75rem clamp(6px, 2vw, 16px) calc(0.75rem + env(safe-area-inset-bottom, 0px));
  border-radius: 24px 24px 0 0;
  background: var(--panel);
  box-shadow: 0 -12px 30px -22px rgba(58, 20, 80, 0.7);
}

.waiting {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0.5rem;
  min-height: 168px;
  text-align: center;
}

.waiting-text {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.625rem, 6vw, 2.375rem);
  line-height: 1.15;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.keyboard { display: grid; gap: 6px; max-width: 560px; margin: 0 auto; user-select: none; }
.keyboard-row { display: flex; gap: 5px; justify-content: center; }

.key {
  flex: 1 1 0;
  min-width: 0;
  height: 52px;
  border: 0;
  border-radius: 10px;
  background: #FFFFFF;
  box-shadow: inset 0 0 0 2px var(--tile-border), 0 3px 0 #E6D9E6;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.125rem;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
}

.key.is-wide { flex-grow: 1.7; font-family: var(--font-ui); font-size: 0.8125rem; font-weight: 700; text-transform: none; }
.key[data-value='enter'] { background: var(--brand-gradient); color: #FFFFFF; box-shadow: none; }
.key:active { transform: translateY(2px); }
.key[data-status='correct'] { background: var(--correct); color: var(--on-correct); box-shadow: none; }
.key[data-status='present'] { background: var(--present); color: var(--on-present); box-shadow: none; }
.key[data-status='absent']  { background: var(--absent);  color: var(--on-absent);  box-shadow: none; }
.keyboard.is-disabled { opacity: 0.4; pointer-events: none; }

/* Resultado */
.result {
  display: grid;
  gap: 1rem;
  justify-items: start;
  border: 2px solid var(--roxo);
  animation: rise 320ms ease-out backwards;
}

.result h2 { font-size: clamp(2.25rem, 8vw, 3.25rem); }
.result.is-win h2 {
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.result-words { display: grid; gap: 0.75rem; justify-self: stretch; }
.result-word { display: grid; gap: 0.25rem; }
.result-word .row { margin: 0; width: min(100%, calc(var(--n) * 44px)); }
.result-word .tile { font-size: 1.375rem; }

/* ---------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px) + var(--dock-height));
  transform: translateX(-50%);
  z-index: 20;
  max-width: min(92vw, 28rem);
  padding: 0.625rem 1.125rem;
  border-radius: 999px;
  background: var(--magenta);
  color: #FFFFFF;
  font-weight: 700;
  text-align: center;
  box-shadow: 0 12px 24px -12px rgba(58, 20, 80, 0.8);
}

.toast.is-info { background: var(--roxo); }

/* ---------------------------------------------------------------- acessibilidade */

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition: none !important;
  }
  .dots::after { content: '...'; }
}

@media (max-width: 420px) {
  .key { height: 48px; font-size: 1rem; }
  .keyboard-row { gap: 4px; }
  .brand { font-size: 1.0625rem; padding: 0.25rem 0.7rem; }
  .topbar { gap: 0.5rem; }
  .room-label { display: none; }
  .key.is-wide { font-size: 0.75rem; }
  .topbar-room:not(:empty) { padding: 0.25rem 0.6rem; }
}
