/* ---------- Cores ---------- */
:root {
  --bg: #FBF8F3;
  --surface: #FFFFFF;
  --ink: #264653;
  --muted: #6F7F86;
  --line: #E6DFD3;
  --key: #EFE9DF;
  --key-ink: #264653;

  --teal: #2A9D8F;
  --teal-forte: #1F7A70;
  --teal-soft: #E2F1EE;
  --teal-ink: #1C6B62;
  --gold: #E9C46A;
  --sand: #F4A261;
  --sand-soft: #FDEEDC;
  --sand-ink: #A4561A;
  --coral: #E76F51;
  --coral-soft: #FBE4DD;

  --given: #264653;
  --given-ink: #FFFFFF;
  --overlay: rgba(28, 44, 52, .45);
  --sombra: 0 1px 2px rgba(38, 70, 83, .06), 0 12px 32px rgba(38, 70, 83, .10);

  --t: min(46px, calc((100vw - 80px) / 7));
  --t-max: 46px;
}

/* Tela escura: segue o aparelho, a menos que a pessoa escolha no botão do topo */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1B20;
    --surface: #152830;
    --ink: #EAF1F0;
    --muted: #93A6AC;
    --line: #26404A;
    --key: #1E343D;
    --key-ink: #EAF1F0;

    --teal: #34AE9F;
    --teal-forte: #2A9D8F;
    --teal-soft: #15393B;
    --teal-ink: #86DACE;
    --sand-soft: #3A2A1B;
    --sand-ink: #F7C08E;
    --coral: #EC7F63;
    --coral-soft: #3D2420;

    --given: #DDE8E6;
    --given-ink: #0E1B20;
    --overlay: rgba(0, 0, 0, .55);
    --sombra: 0 12px 32px rgba(0, 0, 0, .4);
  }
}
:root[data-theme="dark"] {
  --bg: #0E1B20;
  --surface: #152830;
  --ink: #EAF1F0;
  --muted: #93A6AC;
  --line: #26404A;
  --key: #1E343D;
  --key-ink: #EAF1F0;

  --teal: #34AE9F;
  --teal-forte: #2A9D8F;
  --teal-soft: #15393B;
  --teal-ink: #86DACE;
  --sand-soft: #3A2A1B;
  --sand-ink: #F7C08E;
  --coral: #EC7F63;
  --coral-soft: #3D2420;

  --given: #DDE8E6;
  --given-ink: #0E1B20;
  --overlay: rgba(0, 0, 0, .55);
  --sombra: 0 12px 32px rgba(0, 0, 0, .4);
}

/* Cores do resultado de cada palavra (sem ajuda / com dica / revelada) */
:root {
  --cor-limpa: var(--teal);
  --cor-limpa-ink: #fff;
  --cor-dica: var(--gold);
  --cor-dica-ink: #264653;
  --cor-revelada: var(--coral);
  --cor-revelada-ink: #fff;
}
/* Modo daltônico: azul, laranja e rosa-lilás (paleta Okabe-Ito), que se distinguem
   nos tipos comuns de daltonismo e têm claridades bem diferentes entre si
   e das palavras dadas (azul-escuro no tema claro, quase branco no escuro). */
:root[data-daltonico] {
  --cor-limpa: #0072B2;
  --cor-dica: #E69F00;
  --cor-dica-ink: #1A1A1A;
  --cor-revelada: #CC79A7;
  --cor-revelada-ink: #1A1A1A;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
svg { display: block; }

.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 16px;
}

/* ---------- Topo ---------- */
.topo {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 60px;
  border-bottom: 1px solid var(--line);
}
.topo-esq, .topo-dir { display: flex; gap: 2px; }
.topo-dir { justify-self: end; }
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  font-size: 27px;
  letter-spacing: -.02em;
}
.logo-elo { width: 32px; height: 20px; }
.logo-elo rect { fill: none; stroke-width: 3.2; }
.elo-a { stroke: var(--teal); }
.elo-b { stroke: var(--sand); }

.icone {
  width: 40px; height: 40px;
  border: none; border-radius: 12px;
  background: transparent;
  display: grid; place-items: center;
  cursor: pointer;
  transition: background .15s;
}
.icone:hover { background: var(--key); }
.icone:focus-visible, .btn:focus-visible, .tecla:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.modal:focus { outline: none; }
.icone:disabled { opacity: .25; cursor: default; background: transparent; }
.icone svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icone svg .cheio { fill: currentColor; stroke: none; }
.icone.peq { width: 36px; height: 36px; }

.navega {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 0 4px;
}
.titulo-desafio { display: flex; align-items: center; gap: 8px; min-width: 150px; justify-content: center; }
#num { font-weight: 600; font-size: 15px; }
/* Chamada da edição especial (só aparece no dia) */
.chamada-especial {
  align-self: center;
  margin: 8px auto 0;
  padding: 7px 14px;
  border: 0;
  border-radius: 999px;
  font: inherit; font-size: 13px; font-weight: 600;
  color: var(--sand-ink); background: var(--sand-soft);
  cursor: pointer;
}
.chamada-especial.voltar { color: var(--teal-ink); background: var(--teal-soft); }
.chamada-especial[hidden] { display: none; }
.selo {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--teal-ink); background: var(--teal-soft);
  padding: 3px 8px; border-radius: 999px;
}

/* ---------- Tabuleiro ---------- */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 8px 0 12px;
}
.tabuleiro { display: flex; flex-direction: column; align-items: center; }
/* As letras encolhem quando a palavra mais longa do desafio (--n, posto pelo jogo) não cabe na tela. */
.tabuleiro { --t: min(var(--t-max), calc((min(100vw, 520px) - 44px - (var(--n, 7) - 1) * 6px) / var(--n, 7))); }

.row {
  display: flex;
  gap: 6px;
  padding: 6px;
  border-radius: 14px;
  transition: background .2s;
}
.row.ativa { background: var(--teal-soft); }
.row.aberta { cursor: pointer; }
.row.aberta:hover .tile, .row.aberta:focus-visible .tile { border-color: var(--teal); }
.row:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

.tile {
  width: var(--t);
  height: var(--t);
  border: 2px solid var(--line);
  border-radius: min(10px, calc(var(--t) * .22));
  background: var(--surface);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: calc(var(--t) * .44);
  line-height: 1;
  user-select: none;
  transition: border-color .15s, background .2s;
}
.row.ativa .tile { border-color: color-mix(in srgb, var(--teal) 30%, var(--line)); }
.row.ativa .tile.cheia { border-color: var(--ink); }
.row.ativa .tile.cursor {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal) 22%, transparent);
}
.tile.dica { background: var(--sand-soft); border-color: var(--sand); color: var(--sand-ink); }
.row.fechada .tile { background: transparent; border-style: dashed; }

.row.dada .tile { background: var(--given); border-color: var(--given); color: var(--given-ink); }
.row.resolvida.limpa .tile { background: var(--cor-limpa); border-color: var(--cor-limpa); color: var(--cor-limpa-ink); }
.row.resolvida.dica .tile { background: var(--cor-dica); border-color: var(--cor-dica); color: var(--cor-dica-ink); }
.row.resolvida.revelada .tile { background: var(--cor-revelada); border-color: var(--cor-revelada); color: var(--cor-revelada-ink); }
.row.ativa.errada { background: var(--coral-soft); }
.row.ativa.errada .tile { background: var(--coral); border-color: var(--coral); color: #fff; box-shadow: none; }

/* Ligações entre as palavras */
.link {
  position: relative;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.link::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0; left: 50%;
  width: 2px;
  background: var(--line);
  transform: translateX(-50%);
}
.pill {
  position: relative;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 18px;
  color: var(--muted);
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
  white-space: nowrap;
}
.pill.feita { color: var(--teal-ink); background: var(--teal-soft); border-color: transparent; }

/* Pista e dica */
.apoio { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.pista { font-size: 15px; color: var(--muted); text-align: center; min-height: 22px; }
.pista b { color: var(--ink); font-weight: 600; }
.lacuna {
  display: inline-block;
  width: 2.4em;
  border-bottom: 2.5px solid var(--teal);
  margin: 0 3px;
  transform: translateY(-4px);
}

/* ---------- Botões ---------- */
.btn {
  height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  border: none;
  font-weight: 600;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
  cursor: pointer;
  transition: transform .1s, background .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.primario { background: var(--teal-forte); color: #fff; }
.btn.primario:hover { background: var(--teal); }
.btn.secundario { background: var(--key); color: var(--ink); }
.btn.fantasma {
  height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  color: var(--ink);
  font-size: 14px;
}
.btn.fantasma:hover { border-color: var(--sand); }
.btn.fantasma svg { stroke: var(--sand); }
.conta {
  min-width: 20px; height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--sand-soft);
  color: var(--sand-ink);
  font-size: 12px; font-weight: 700;
  display: inline-grid; place-items: center;
}
.btn.fantasma.revelar svg { stroke: var(--coral); }
.btn.fantasma.revelar:hover { border-color: var(--coral); }
.btn.fantasma.confirmar { border-color: var(--coral); color: var(--coral); }
.btn:disabled { opacity: .4; cursor: default; }
.btn[hidden] { display: none; }
.btn.largo { width: 100%; }

/* ---------- Teclado ---------- */
.teclado {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 8px 0 calc(14px + env(safe-area-inset-bottom));
}
.tecla-linha { display: flex; gap: 5px; justify-content: center; }
.tecla {
  flex: 1;
  max-width: 44px;
  height: 54px;
  border: none;
  border-radius: 9px;
  background: var(--key);
  color: var(--key-ink);
  font-weight: 600;
  font-size: 16px;
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .08s, background .15s;
}
.tecla:active { transform: scale(.94); }
.tecla.larga { flex: 1.6; max-width: 72px; font-size: 13px; }
.tecla.enviar { background: var(--teal-forte); color: #fff; font-size: 13px; }
/* O Enviar só existe no modo difícil; no normal a vaga fica vazia, equilibrando o Apagar. */
.teclado:not(.com-enviar) .tecla.enviar { visibility: hidden; }
.tecla svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tecla-meia { flex: .5; max-width: 22px; }

/* ---------- Aviso ---------- */
.aviso {
  position: fixed;
  left: 50%;
  top: 66px;
  transform: translate(-50%, -8px);
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 12px;
  box-shadow: var(--sombra);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  width: max-content;
  max-width: calc(100vw - 32px);
  text-align: center;
  z-index: 20;
}
.aviso.vis { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Janelas ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 10;
  animation: aparece .2s ease;
}
.overlay[hidden] { display: none; }
.modal {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: calc(100dvh - 32px);
  overflow: auto;
  background: var(--surface);
  border-radius: 22px;
  padding: 26px 24px 22px;
  box-shadow: var(--sombra);
  animation: sobe .28s cubic-bezier(.2, .9, .3, 1.1);
}
.modal h2 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  font-size: 28px;
  letter-spacing: -.02em;
  margin-bottom: 8px;
}
.fechar { position: absolute; top: 12px; right: 12px; }
.lead { color: var(--muted); font-size: 15px; line-height: 1.5; }
.lead b { color: var(--ink); }

.exemplo {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 18px 0;
  padding: 14px;
  border-radius: 16px;
  background: var(--bg);
}
.row.mini { --t: 30px; padding: 0; gap: 4px; }
.row.mini .tile { border-radius: 7px; }
.exemplo .link { height: 26px; }

.passos { list-style: none; display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; }
.passos li { display: flex; gap: 12px; align-items: flex-start; font-size: 14.5px; line-height: 1.45; }
.passos b { font-weight: 600; }
.n {
  flex: none;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--teal-soft);
  color: var(--teal-ink);
  font-size: 13px; font-weight: 700;
  display: grid; place-items: center;
}
.q { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; }
.q.limpa, .quadro.limpa { background: var(--cor-limpa); }
.q.dica, .quadro.dica { background: var(--cor-dica); }
.q.revelada, .quadro.revelada { background: var(--cor-revelada); }

.modal.centro { text-align: center; }
.quadros { display: flex; justify-content: center; gap: 8px; margin: 6px 0 16px; }
.quadro { width: 40px; height: 40px; border-radius: 10px; animation: pula .5s ease both; }
.quadro:nth-child(2) { animation-delay: .08s; }
.quadro:nth-child(3) { animation-delay: .16s; }
.sub { color: var(--muted); font-size: 15px; margin-bottom: 18px; }
.lista {
  list-style: none;
  text-align: left;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
  margin-bottom: 20px;
}
.lista li { display: flex; flex-direction: column; gap: 2px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.lista b { font-weight: 600; font-size: 15px; }
.lista span { color: var(--muted); font-size: 14px; }
.acoes { display: flex; gap: 10px; }
.acoes .btn { flex: 1; }
.relogio { margin-top: 16px; font-size: 13px; color: var(--muted); }

/* Sequência no resultado */
.sequencia {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: -6px 0 18px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--sand-soft);
  color: var(--sand-ink);
  font-size: 14px;
  font-weight: 600;
}
.sequencia[hidden] { display: none; }
.sequencia svg { width: 16px; height: 16px; fill: currentColor; }

/* Estatísticas */
.numeros { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0 22px; }
.numero { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.numero b {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  font-size: 32px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.numero span { font-size: 12px; color: var(--muted); line-height: 1.25; }
.subtitulo { font-size: 14px; font-weight: 600; margin-bottom: 10px; text-align: left; }
.barras { display: flex; flex-direction: column; gap: 6px; }
.barra { display: grid; grid-template-columns: 60px 1fr; align-items: center; gap: 8px; }
.barra-rotulo { display: flex; gap: 3px; }
.barra-rotulo .q { width: 11px; height: 11px; }
.barra-rotulo .q.vazio { background: var(--line); }
.barra-trilho { height: 24px; }
.barra-cheia {
  height: 100%;
  min-width: 28px;
  border-radius: 6px;
  background: var(--key);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 8px;
  transition: width .4s ease;
}
.barra.atual .barra-cheia { background: var(--teal); color: #fff; }
.nota { margin-top: 18px; font-size: 13px; color: var(--muted); line-height: 1.45; }
.relogio b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---------- Movimento ---------- */
.pop { animation: pop .16s ease; }
.pula { animation: pula .5s ease both; }
.shake { animation: treme .4s ease; }
@keyframes pop { 0% { transform: scale(.88); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes pula { 0% { transform: translateY(0); } 35% { transform: translateY(-9px); } 70% { transform: translateY(2px); } 100% { transform: translateY(0); } }
@keyframes treme { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-7px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }
@keyframes aparece { from { opacity: 0; } }
@keyframes sobe { from { opacity: 0; transform: translateY(16px) scale(.98); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Telas baixas (celular pequeno) */
@media (max-height: 800px) {
  :root { --t: min(40px, calc((100vw - 80px) / 7)); --t-max: 40px; }
  .link { height: 24px; }
  .tecla { height: 48px; }
  main { gap: 10px; }
}

/* ---------- Opções ---------- */
.opcoes { display: flex; flex-direction: column; margin-top: 10px; }
.opcao {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.opcao:last-child { border-bottom: none; }
.opcao-texto { display: flex; flex-direction: column; gap: 3px; }
.opcao-texto b { font-size: 16px; font-weight: 600; }
.opcao-texto span { font-size: 13.5px; color: var(--muted); }
.chave {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  position: relative;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
  transition: background .2s;
}
.chave::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .2s;
}
.chave:checked { background: var(--teal-forte); }
.chave:checked::before { transform: translateX(20px); }
.chave:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

/* ---------- Modo difícil ---------- */
.selo.dificil { color: var(--sand-ink); background: var(--sand-soft); }
.selo[hidden] { display: none; }
.tile.oculta {
  width: calc(var(--t) * 2.4);
  border-style: dashed;
  background: transparent;
  color: var(--muted);
  font-size: calc(var(--t) * .38);
}
.row.aberta .tile.oculta { border-style: solid; }
.chave:disabled { opacity: .45; cursor: not-allowed; }
.opcao:has(.chave:disabled) { cursor: not-allowed; }
.stats-dificil { margin: -10px 0 18px; font-size: 13px; color: var(--muted); }
.stats-dificil:empty { display: none; }
