﻿:root {
  --bg: #1e1b2e;
  --panel: #2a2640;
  --text: #f1eefc;
  --muted: #a9a3c7;
  --accent: #ff9f6b;
  --err: #ff4d6d;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}
header { text-align: center; padding: 1.2rem 1rem 0; }
header h1 { margin: 0; font-size: 2rem; }
header p { margin: .2rem 0 0; color: var(--muted); }

.tabs { display: flex; justify-content: center; gap: .5rem; margin: 1rem 0; flex-wrap: wrap; }
.tab {
  background: var(--panel); color: var(--text); border: 2px solid transparent;
  padding: .55rem 1.1rem; border-radius: 999px; cursor: pointer; font-size: 1rem;
}
.tab:hover { border-color: var(--accent); }
.tab.active { background: var(--accent); color: #2a1a10; font-weight: 700; }

main { max-width: 900px; margin: 0 auto; padding: 0 1rem 3rem; }
.panel { display: none; }
.panel.active { display: block; }

/* ---------- Jogo ---------- */
.controls { display: flex; gap: .6rem; justify-content: center; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.controls select, .controls button {
  padding: .5rem .9rem; border-radius: 8px; border: none; font-size: 1rem;
  background: var(--panel); color: var(--text); cursor: pointer;
}
.controls button:hover { background: #3a3560; }
#status { text-align: center; min-height: 1.6rem; margin-bottom: .8rem; color: var(--muted); }
#status.win { color: #7dffb0; font-weight: 700; font-size: 1.2rem; }

.lives { display: flex; justify-content: center; gap: .5rem; margin-bottom: .4rem; font-size: 1.8rem; }
.heart { display: inline-block; transition: transform .3s, opacity .3s; }
.heart.lost { opacity: .45; transform: scale(.8); }
.hint { text-align: center; color: var(--muted); margin: .8rem 0 .2rem; }
.reveal-wrap { text-align: center; }
.link-btn { background: none; border: none; color: var(--muted); font-size: .8rem; cursor: pointer; text-decoration: underline; opacity: .6; }
.link-btn:hover { opacity: 1; }

#board, #sboard {
  --size: 7;
  --gap: 4px;
  display: grid;
  grid-template-columns: repeat(var(--size), minmax(0, 1fr));
  grid-template-rows: repeat(var(--size), minmax(0, 1fr));
  width: min(92vw, 560px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  gap: var(--gap);
  padding: var(--gap);
  box-sizing: border-box;
  background: #14121f;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
  container-type: inline-size;
}
#board.locked .cell { cursor: default; }
.cell {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  aspect-ratio: 1 / 1;
  min-width: 0; min-height: 0;
  overflow: hidden;
  box-sizing: border-box;
  cursor: pointer; user-select: none;
  border-radius: calc(100cqw / var(--size) * .045);
  color: #222;
  line-height: 1;
  transition: filter .15s, transform .15s;
}
/* camada de realce (gato fixo / erro) sem animar box-shadow */
.cell::after { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0; }
.cell.has-cat::after { background: rgba(255,255,255,.18); opacity: 1; }
/* hover só com mouse: em telas de toque ele "gruda" após o toque */
@media (hover: hover) {
  .cell:hover { filter: brightness(1.12); }
  #board:not(.locked) .cell:not(.has-cat):hover, #sboard .cell:hover { transform: scale(.96); }
}
.sym {
  position: relative; z-index: 1;                /* acima da camada ::after */
  font-size: calc(100cqw / var(--size) * .55);   /* proporcional à célula */
  line-height: 1;
  animation: pop .2s ease-out;
}
.sym.x {
  width: .75em;
  height: .75em;
  animation-duration: .12s;
}
.sym.x::before, .sym.x::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: .18em;
  border-radius: 999px;
  background: #f4f2f7;
}
.sym.x::before { transform: translateY(-50%) rotate(45deg); }
.sym.x::after { transform: translateY(-50%) rotate(-45deg); }

@keyframes pop { from { transform: scale(.2); opacity: 0; } to { transform: scale(1); } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); } 40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); } 80% { transform: translateX(4px); }
}
@keyframes errfade { 0% { opacity: 0; } 30% { opacity: 1; } 100% { opacity: 0; } }
.cell.shake { animation: shake .5s; }
.cell.shake::after { background: rgba(255,0,40,.75); animation: errfade .6s; }
#board.shake { animation: shake .5s; }

/* Sem movimento para quem pede menos animação (o realce vermelho do erro continua) */
@media (prefers-reduced-motion: reduce) {
  .cell.shake, #board.shake { animation: none; }
  .sym, .modal.open, .modal-card, .menu-drop.open, .solve-btn { animation: none; }
  .cell, .heart, .swatch { transition: none; }
}

.modal { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(10,8,25,.75); z-index: 10; }
.modal.open { display: flex; animation: fade .3s; }
.modal-card { background: var(--panel); padding: 2rem 2.5rem; border-radius: 16px; text-align: center; animation: pop .35s ease-out; max-width: 90vw; }
.modal-emoji { font-size: 4rem; }
.modal-card h2 { margin: .3rem 0; color: var(--accent); }
.modal-card button { margin-top: 1rem; padding: .6rem 1.4rem; border: none; border-radius: 999px; background: var(--accent); color: #2a1a10; font-weight: 700; font-size: 1rem; cursor: pointer; }
@keyframes fade { from { opacity: 0; } }
/* ---------- Texto (Guia e Wiki) ---------- */
.doc { background: var(--panel); padding: 1.5rem 2rem; border-radius: 12px; }
.doc h2 { margin-top: 0; color: var(--accent); }
.doc h3 { color: #ffd1b3; margin-top: 2rem; border-bottom: 1px solid #443f66; padding-bottom: .2rem; }
.doc h4 { color: #c9c2f0; margin-bottom: .2rem; }
.doc code, .doc pre { background: #17142a; border-radius: 6px; }
.doc code { padding: .1rem .35rem; }
.doc pre { padding: 1rem; overflow-x: auto; }
.doc pre code { padding: 0; }
.doc table { border-collapse: collapse; margin: 1rem 0; }
.doc th, .doc td { border: 1px solid #443f66; padding: .4rem .8rem; }
.doc .note { border-left: 4px solid var(--accent); padding: .3rem 1rem; background: #332e52; border-radius: 0 8px 8px 0; }
.doc nav ul { columns: 2; }
.guide-intro { color: var(--muted); max-width: 70ch; }
.strategy-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: 1rem; margin-top: 1.3rem; }
.strategy-card { min-width: 0; padding: 1.1rem; border: 1px solid #443f66; border-radius: 14px; background: #25213a; }
.strategy-number { color: var(--accent); font-size: .72rem; font-weight: 800; letter-spacing: .1em; }
.strategy-card h3 { margin: .35rem 0 .5rem; color: var(--text); font-size: 1.05rem; border: 0; }
.strategy-card p { margin: 0; color: var(--muted); font-size: .92rem; }
.example { margin: 1rem 0 0; padding: .85rem; border-radius: 10px; background: #1b182b; }
.example figcaption { min-height: 2.7em; margin-bottom: .7rem; color: #d8d3eb; font-size: .8rem; }
.mini-board { display: grid; width: min(100%, 230px); min-height: 48px; margin: 0 auto; overflow: hidden; border: 2px solid #625c78; border-radius: 8px; background: #625c78; gap: 2px; }
.two-options { grid-template-columns: repeat(4, 1fr); }
.four-cells { grid-template-columns: repeat(4, 1fr); }
.mini-board > span, .pair-demo > span:not(.row-label) { display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 44px; background: #302b46; color: var(--text); font-weight: 700; }
.candidate.blue { background: #5273a7 !important; }
.candidate.gold { background: #a47c3f !important; }
.candidate.green { background: #478565 !important; }
.eliminated { color: #ffb3c0 !important; font-size: 1.2rem; }
.legend { display: flex; justify-content: center; flex-wrap: wrap; gap: .35rem .8rem; margin-top: .6rem; color: var(--muted); font-size: .72rem; }
.legend > span { display: inline-flex; align-items: center; gap: .3rem; }
.legend-dot { display: inline-block; width: .65rem; height: .65rem; border-radius: 50%; background: #888; }
.legend-dot.blue { background: #5273a7; }
.legend-dot.gold { background: #a47c3f; }
.legend-dot.green { background: #478565; }
.legend-cross { color: #ffb3c0; font-style: normal; font-weight: 800; }
.pair-demo { display: grid; grid-template-columns: 1rem repeat(4, minmax(0, 1fr)); gap: 2px; width: min(100%, 230px); margin: 0 auto; overflow: hidden; border-radius: 8px; background: #625c78; }
.pair-demo .row-label { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: .7rem; }
.pair-demo > span:not(.row-label) { min-height: 38px; font-size: .75rem; }
.guide-note { margin-top: .8rem; padding: .7rem .85rem; border-left: 3px solid var(--accent); border-radius: 0 8px 8px 0; background: #332e52; color: #d8d3eb; font-size: .82rem; }
.guide-summary { margin-top: 1.2rem; }
.neighborhood { grid-template-columns: repeat(3, 1fr); width: 150px; }
.neighborhood > span { min-height: 38px; }
.blocked { color: #ffb3c0 !important; background: #492a3b !important; }
.cat-cell { background: #ffcf88 !important; font-size: 1.15rem; }

/* ---------- Layout em tela cheia: menu lateral + tabuleiro ---------- */
html, body { height: 100%; }
body { display: flex; flex-direction: column; overflow: hidden; }
header { padding: .6rem 1rem 0; }
header h1 { font-size: 1.6rem; }
header p { font-size: .9rem; line-height: 1.3; }
.tabs { margin: .6rem 0; }
main { flex: 1; min-height: 0; width: 100%; max-width: none; overflow-y: auto; padding: 0 1rem 1rem; }
.doc { max-width: 900px; margin: 0 auto; }
#game.active, #solver.active { display: flex; gap: 1.5rem; height: 100%; }
/* Coluna lateral (HUD + painel): o tabuleiro continua ocupando toda a altura à direita */
.game-side { flex: 0 0 204px; display: flex; flex-direction: column; gap: .6rem; min-width: 0; min-height: 0; align-self: center; max-height: 100%; }
.game-side .sidebar { flex: 0 1 auto; width: 100%; align-self: stretch; min-height: 0; }
.sidebar {
  flex: 0 0 220px; display: flex; flex-direction: column; gap: .8rem;
  background: var(--panel); border-radius: 16px; padding: 1.2rem; align-self: stretch; overflow-y: auto;
}
.sidebar .controls { flex-direction: column; align-items: stretch; margin: 0; }
.sidebar .controls label { display: flex; flex-direction: column; gap: .3rem; color: var(--muted); }
.sidebar .controls select, .sidebar .controls button { width: 100%; }
.sidebar .lives { margin: 0; }
.sidebar #status { margin: 0; }
.sidebar .hint { margin: 0; font-size: .85rem; }
.reveal-wrap { margin-top: auto; }
.stage { flex: 1; min-width: 0; min-height: 0; container-type: size; display: flex; align-items: center; justify-content: center; padding: 0; }
.stage #board, .stage #sboard { width: min(100cqw, 100cqh); }

/* ---------- Menu principal à esquerda + painel de controles ---------- */
body { flex-direction: row; }
.sidenav {
  flex: 0 0 210px; display: flex; flex-direction: column; gap: 1rem;
  background: var(--panel); padding: 1.2rem 1rem; overflow-y: auto;
}
.sidenav header { text-align: left; padding: 0; }
.sidenav header h1 { font-size: 1.5rem; }
.sidenav .rules {
  list-style: none; margin: 0; padding: .75rem 0 0;
  border-top: 1px solid #443f66; color: var(--muted); font-size: .85rem;
}
.sidenav .rules li { position: relative; padding: .4rem 0 .4rem 1.4rem; line-height: 1.35; }
.sidenav .rules li::before {
  content: "🐾"; position: absolute; left: 0; top: .37rem;
  font-size: .85rem;
  filter: brightness(0) invert(1);
}
.sidenav .tabs { flex-direction: column; justify-content: flex-start; margin: 0; flex-wrap: nowrap; }
.sidenav .tab { text-align: left; border-radius: 12px; background: #231f38; }
.sidenav .tab.active { background: var(--accent); }
main { padding: 1rem; min-width: 0; }
#game.active, #solver.active { align-items: center; }
.sidebar { flex: 0 0 204px; align-self: center; padding: .9rem; background: #231f38; max-height: 100%; }
.sidebar .reveal-wrap { margin-top: .4rem; }
.stage { align-self: stretch; }

/* ---------- Links ---------- */
a { color: var(--accent); text-decoration: none; border-bottom: 1px solid rgba(255,159,107,.4); transition: color .15s, border-color .15s; }
a:hover { color: #ffd1b3; border-bottom-color: #ffd1b3; }
a:visited { color: #d9a7ff; }
a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- Responsividade ---------- */
/* A página nunca rola no jogo: o tabuleiro ocupa o espaço restante e permanece quadrado. */
body { height: 100dvh; overflow: hidden; }
main { display: flex; flex-direction: column; }
.panel { flex: 0 0 auto; }
#game.active, #solver.active { flex: 1 1 auto; min-height: 0; height: auto; }
.sidebar, .stage { min-width: 0; min-height: 0; }
.doc { width: min(100%, 1000px); }
.doc pre { max-width: 100%; }
.doc table { display: block; max-width: 100%; overflow-x: auto; }

.menu-btn {
  display: none; align-items: center; justify-content: center; flex: 0 0 auto;
  width: 2.6rem; height: 2.6rem; padding: 0; border: 0; border-radius: 12px;
  background: #231f38; color: var(--text); cursor: pointer; transition: background .15s;
}
.menu-btn:hover, .menu-btn[aria-expanded="true"] { background: var(--accent); color: #2a1a10; }
.menu-btn svg { width: 1.4rem; height: 1.4rem; }
.menu-drop { display: none; }

/* Seletor de idioma (PT | EN | ES) */
.lang-switch { display: inline-flex; gap: .25rem; margin-top: .5rem; }
.lang-btn {
  min-width: 2.4rem; min-height: 2rem; padding: .15rem .5rem; border: 1px solid #4a4568; border-radius: 8px;
  background: #231f38; color: var(--muted); font-size: .75rem; font-weight: 800; letter-spacing: .06em; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.lang-btn:hover { border-color: var(--accent); color: var(--text); }
.lang-btn.active { background: var(--accent); border-color: var(--accent); color: #2a1a10; }
body.compact .lang-switch { margin-top: 0; margin-left: auto; }

/* Modo compacto (celular ou janela baixa): barra superior + menu suspenso */
body.compact { flex-direction: column; }
body.compact .sidenav {
  position: relative; z-index: 20; flex: 0 0 auto; flex-direction: row; align-items: center;
  gap: 0; padding: .5rem .75rem; overflow: visible;
}
body.compact .sidenav header { flex: 1; display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
body.compact .sidenav header h1 { font-size: 1.3rem; }
body.compact .menu-btn { display: inline-flex; }
body.compact .menu-drop.open {
  position: absolute; top: 100%; left: 0; right: 0; display: flex; flex-direction: column; gap: .9rem;
  max-height: calc(100dvh - 3.7rem); overflow-y: auto; padding: .9rem .75rem 1.1rem;
  background: var(--panel); border-top: 1px solid #443f66; border-radius: 0 0 16px 16px;
  box-shadow: 0 18px 30px rgba(0, 0, 0, .55); animation: fade .15s;
}
.menu-drop .controls { justify-content: stretch; align-items: end; margin: 0; }
.menu-drop .controls label { display: flex; flex: 1 1 100%; flex-direction: column; gap: .3rem; color: var(--muted); }
.menu-drop .controls select { width: 100%; }
.menu-drop .controls button { flex: 1; }
.menu-drop .hint { margin: 0; font-size: .85rem; text-align: left; }
.menu-drop .reveal-wrap { margin: 0; text-align: left; }
.menu-drop .rules { margin: 0; }

body.compact main { padding: .6rem; }
body.compact #game.active, body.compact #solver.active { flex-direction: column; align-items: stretch; gap: .5rem; }
body.compact .game-side { flex: 0 0 auto; align-self: stretch; max-height: none; gap: .5rem; }
body.compact .game-hud { min-height: 52px; }
body.compact .level-info { padding: .35rem 1rem .35rem .9rem; }
body.compact .level-info-value { font-size: 1.6rem; }
body.compact .sidebar {
  flex: 0 0 auto; align-self: stretch; flex-direction: row; align-items: center; justify-content: space-between;
  max-height: none; padding: .35rem .8rem; border-radius: 12px; overflow: visible;
}
body.compact .sidebar .lives { justify-content: flex-start; font-size: 1.3rem; }
body.compact .sidebar #status { font-size: .9rem; min-height: 0; }
body.compact .stage { flex: 1 1 0; width: 100%; }
body.compact .doc { padding: 1rem; }
body.compact .doc nav ul { columns: 1; }.menu-drop .controls select, .menu-drop .controls button { background: #231f38; border: 1px solid #443f66; }
.menu-drop .controls button:hover { background: #3a3560; }

#board { touch-action: none; user-select: none; -webkit-user-select: none; }

.sym.x.wrong::before, .sym.x.wrong::after { background: #b0243f; }
.dev-card { margin-top: .8rem; padding: .55rem .65rem; border: 1px solid #3b3659; border-radius: 12px; background: #1c1930; text-align: left; }
.dev-card [hidden] { display: none !important; }
.dev-head, .dev-opt { display: flex; align-items: center; justify-content: space-between; gap: .6rem; cursor: pointer; }
.dev-head { color: var(--text, #eee); font-size: .85rem; font-weight: 600; }
.dev-body { display: flex; flex-direction: column; gap: .5rem; }
.dev-body > :first-child:not([hidden]) { margin-top: .55rem; padding-top: .55rem; border-top: 1px solid #3b3659; }
.dev-note { margin: 0; color: var(--accent); font-size: .72rem; }
.dev-opt { color: var(--muted); font-size: .76rem; line-height: 1.25; }
.switch { appearance: none; -webkit-appearance: none; flex: 0 0 auto; position: relative; width: 32px; height: 18px; margin: 0; border-radius: 999px; background: #4a4568; cursor: pointer; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(14px); }
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.dev-btn { padding: .45rem .6rem; border: 1px solid #4a4568; border-radius: 8px; background: #2a2640; color: inherit; font-size: .8rem; cursor: pointer; }
.dev-btn:hover { background: #3a3560; }
.dev-head { white-space: nowrap; }
.sidebar { scrollbar-width: thin; scrollbar-color: #4a4568 transparent; }

/* ---------- Resolve Nível ---------- */
#sboard { touch-action: none; user-select: none; -webkit-user-select: none; }
#sboard .cell { background: #3a3750; }
.palette { display: grid; grid-template-columns: repeat(5, 1fr); gap: .4rem; }
.palette-title { color: var(--muted); font-size: .9rem; }
.swatch { aspect-ratio: 1; border: 2px solid transparent; border-radius: 8px; cursor: pointer; padding: 0; transition: transform .12s, border-color .12s; }
.swatch:hover { transform: scale(1.08); }
.swatch.active { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
.palette-hint { display: none; }
.s-status { color: var(--muted); font-size: .85rem; text-align: center; line-height: 1.4; }
.s-status.ok { color: #9be39b; }
.s-status.bad { color: #ff9aa8; }
.solve-btn { background: var(--accent); color: #2a1a10; font-weight: 700; border: none; border-radius: 10px; padding: .7rem; cursor: pointer; animation: pop .25s ease-out; }
.solve-btn:hover { filter: brightness(1.1); }
.solve-btn[hidden] { display: none; }
#sboard .sym.cat { animation: pop .3s ease-out; }

/* ---------- Campanha: info do nível, cronômetro, mapa e modal ---------- */
.game-hud {
  display: flex; align-items: stretch; flex: 0 0 auto; width: 100%; min-height: 64px; overflow: hidden;
  border-radius: 14px; background: linear-gradient(135deg, #ffb17f 0%, #ff8d5c 100%); color: #27170f;
  box-shadow: 0 4px 14px rgba(255, 143, 92, .25), inset 0 1px 0 rgba(255, 255, 255, .35);
}
.level-info {
  position: relative; display: flex; flex: 0 0 auto; flex-direction: column; justify-content: center; gap: .05rem;
  padding: .45rem 1.1rem .45rem .95rem; text-align: left;
}
.level-info::after {                              /* traço vertical que fecha o bloco do nível */
  content: ""; position: absolute; right: 0; top: 18%; bottom: 18%; width: 2px; border-radius: 2px;
  background: rgba(39, 23, 15, .35);
}
.level-info-label { font-size: .62rem; font-weight: 800; letter-spacing: .14em; line-height: 1.2; opacity: .8; }
.level-info-value { font-size: 1.9rem; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.score-info { min-width: 5.2rem; }
.score-info .level-info-value { display: inline-block; transform-origin: left center; }
.score-info .level-info-value.bump { animation: scoreBump .35s ease-out; }
@keyframes scoreBump { 40% { transform: scale(1.18); } }

/* Pop-out de pontos: fixo na viewport (o tabuleiro tem overflow:hidden) e sem capturar toques */
.point-pop {
  position: fixed; z-index: 5; pointer-events: none; transform: translate(-50%, -50%);
  font-weight: 900; line-height: 1; white-space: nowrap; color: #fff3b0;
  text-shadow: 0 0 3px #7a4a00, 0 1px 0 #7a4a00, 0 -1px 0 #7a4a00, 1px 0 0 #7a4a00, -1px 0 0 #7a4a00, 0 2px 8px rgba(0,0,0,.45);
  animation: floatUp .8s ease-out forwards;
}
@keyframes floatUp {
  0%   { opacity: 0; transform: translate(-50%, -30%) scale(.6); }
  15%  { opacity: 1; transform: translate(-50%, -60%) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -190%) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .point-pop { animation: fadeOnly .8s linear forwards; }
  .score-info .level-info-value.bump { animation: none; }
}
@keyframes fadeOnly { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }
/* ---------- Power-ups (barra abaixo da HUD) ---------- */
.powerups { position: relative; flex: 0 0 auto; width: 100%; }
.powerup-bar { display: flex; gap: .4rem; }
.pu-btn {
  position: relative; flex: 1 1 0; min-width: 44px; min-height: 52px; padding: .3rem .15rem;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .05rem;
  border: 2px solid #443f66; border-radius: 12px; background: #231f38; color: var(--text);
  font: inherit; cursor: pointer; touch-action: manipulation;
}
.pu-btn:active { transform: scale(.96); }
.pu-icon { font-size: 1.25rem; line-height: 1; }
.pu-label { max-width: 100%; font-size: .6rem; line-height: 1.1; text-align: center; color: var(--muted); overflow-wrap: anywhere; }
.pu-badge {
  position: absolute; top: -7px; right: -5px; min-width: 20px; padding: 0 .35rem; border-radius: 999px;
  background: var(--accent); color: #2a1a10; font-size: .7rem; font-weight: 800; line-height: 20px; text-align: center;
  font-variant-numeric: tabular-nums; box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}
.pu-btn.empty { border-style: dashed; }
.pu-btn.empty .pu-icon { opacity: .55; }
.pu-btn.empty .pu-badge { background: #ffd15c; white-space: nowrap; }
@media (hover: hover) { .pu-btn:hover { border-color: var(--accent); } }

/* Mensagem da dica: cobre a barra (sem empurrar o tabuleiro); toque para fechar */
.hint-msg {
  position: absolute; z-index: 3; top: 0; left: 0; right: 0; min-height: 100%; display: flex; align-items: center;
  padding: .4rem .7rem; border-radius: 12px; background: #fff3d6; color: #2a1a10; border: 2px solid var(--accent);
  font-size: .78rem; line-height: 1.3; cursor: pointer; box-shadow: 0 6px 18px rgba(0, 0, 0, .4); animation: fade .2s;
}
.hint-msg[hidden] { display: none; }

/* Realce temporário das casas (usa ::before: ::after já serve ao gato e ao erro) */
.cell.hint-glow::before, .cell.hint-target::before {
  content: ""; position: absolute; inset: 0; z-index: 2; pointer-events: none; border-radius: inherit;
  animation: hintPulse .8s ease-in-out infinite alternate;
}
.cell.hint-glow::before { border: 3px solid #ffd15c; background: rgba(255, 209, 92, .35); }
.cell.hint-target::before { border: 3px solid #fff; background: rgba(255, 255, 255, .5); }
@keyframes hintPulse { from { opacity: .45; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .cell.hint-glow::before, .cell.hint-target::before, .hint-msg { animation: none; }
}

/* ---------- Anúncios: banner fixo de rodapé (altura reservada) e vídeo recompensado ---------- */
:root { --ad-h: 50px; }
.ad-banner {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 4;
  height: calc(var(--ad-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  background: #17142a; border-top: 1px solid #443f66; contain: strict;
}
button:disabled, .pu-btn:disabled, .modal-card button:disabled { cursor: not-allowed; opacity: .6; }
.ad-banner-label { color: var(--muted); font-size: .7rem; letter-spacing: .12em; text-transform: uppercase; opacity: .6; }
.ad-banner .adsbygoogle { display: block; width: 100%; height: var(--ad-h); }
.ad-overlay { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; background: rgba(10, 8, 25, .92); }
.ad-overlay-card {
  display: flex; flex-direction: column; align-items: center; gap: .8rem; max-width: 90vw;
  padding: 1.6rem 2rem; border-radius: 16px; background: var(--panel); text-align: center;
}
.ad-overlay-count { color: var(--muted); font-variant-numeric: tabular-nums; }
.ad-overlay-card .modal-actions button {
  min-height: 44px; padding: .6rem 1.4rem; border: none; border-radius: 999px; background: var(--accent);
  color: #2a1a10; font-weight: 700; font-size: 1rem; cursor: pointer;
}
.ad-overlay-card .modal-actions button.secondary { background: transparent; color: var(--text); border: 2px solid #4a4568; }
.ad-overlay-card .modal-actions button[hidden] { display: none; }
.timer { color: var(--muted); font-variant-numeric: tabular-nums; text-align: center; font-size: .95rem; }
body.compact .sidebar { flex-wrap: wrap; gap: .1rem .8rem; }
body.compact .sidebar .timer { font-size: .85rem; }

.modal-actions { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }
.modal-card button.secondary { background: transparent; color: var(--text); border: 2px solid #4a4568; }
.modal-card button.secondary:hover { border-color: var(--accent); }
.modal-stars { color: #ffd15c; font-size: 2rem; letter-spacing: .15em; }

/* ---------- Páginas institucionais: links no menu lateral e modal com rolagem interna ---------- */
.legal-links { margin-top: auto; display: flex; flex-wrap: wrap; gap: .2rem .9rem; padding-top: .75rem; border-top: 1px solid #443f66; }
.legal-link {
  padding: .3rem 0; border: 0; background: none; color: var(--muted); font: inherit; font-size: .8rem;
  text-decoration: underline; cursor: pointer;
}
.legal-link:hover { color: var(--accent); }
.menu-drop .legal-links { margin-top: 0; }

.legal-dialog {
  width: min(640px, calc(100vw - 2rem)); max-height: min(85dvh, 720px); padding: 0; border: 1px solid #443f66; border-radius: 16px;
  background: var(--panel); color: var(--text); overflow: hidden;
}
.legal-dialog[open] { display: flex; flex-direction: column; animation: pop .25s ease-out; }
.legal-dialog::backdrop { background: rgba(10, 8, 25, .75); }
.legal-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .9rem 1.2rem; border-bottom: 1px solid #443f66; }
.legal-head h2 { margin: 0; font-size: 1.2rem; color: var(--accent); }
.legal-close {
  flex: 0 0 auto; width: 2.4rem; height: 2.4rem; border: 0; border-radius: 50%; background: #231f38;
  color: var(--text); font-size: 1rem; cursor: pointer;
}
.legal-close:hover { background: var(--accent); color: #2a1a10; }
.legal-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 1rem 1.2rem; font-size: .92rem; line-height: 1.55; }
.legal-body h3 { margin: 1.1rem 0 .3rem; font-size: 1rem; color: #ffd1b3; }
.legal-body p, .legal-body ul { margin: .4rem 0; }
.legal-body small { color: var(--muted); }
.legal-foot { display: flex; justify-content: flex-end; padding: .7rem 1.2rem; border-top: 1px solid #443f66; }
.legal-foot button {
  min-height: 44px; padding: .5rem 1.4rem; border-radius: 999px; background: transparent; color: var(--text);
  border: 2px solid #4a4568; font-size: 1rem; font-weight: 700; cursor: pointer;
}
.legal-foot button:hover { border-color: var(--accent); }

/* ---------- Instalação do PWA (CTA no menu, card pós-vitória, passos do iOS) ---------- */
.pwa-install[hidden], .pwa-promo[hidden] { display: none; }
.pwa-install { margin-top: auto; padding-top: .75rem; animation: pwa-in .4s ease-out; }
.pwa-install:not([hidden]) + .legal-links { margin-top: 0; }
.pwa-install-btn {
  width: 100%; min-height: 44px; padding: .65rem 1rem; border: 0; border-radius: 12px; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #ffc36b); color: #2a1a10; font: inherit; font-weight: 800; line-height: 1.25;
  box-shadow: 0 2px 10px rgba(255, 159, 107, .35); transition: transform .15s, box-shadow .15s;
}
@media (hover: hover) { .pwa-install-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(255, 159, 107, .5); } }
.pwa-install-btn:active { transform: scale(.98); }
.menu-drop .pwa-install { margin-top: 0; padding-top: 0; }

.pwa-promo { margin: 1rem 0 .2rem; padding: .7rem .9rem; border: 1px solid #4a4568; border-radius: 12px; background: #231f38; text-align: left; animation: pwa-in .45s ease-out .15s backwards; }
.pwa-promo-title { margin: 0 0 .3rem; font-size: .9rem; font-weight: 700; color: #ffd1b3; }
.pwa-promo-list { margin: 0; padding: 0; list-style: none; font-size: .82rem; color: var(--muted); line-height: 1.5; }
.modal-card .pwa-promo-btn { width: 100%; min-height: 44px; margin-top: .6rem; padding: .5rem 1rem; background: transparent; color: var(--accent); border: 2px solid var(--accent); }
.modal-card .pwa-promo-btn:hover { background: var(--accent); color: #2a1a10; }

.install-steps { margin: .6rem 0; padding: 0; list-style: none; display: grid; gap: .7rem; }
.install-steps li { display: flex; align-items: center; gap: .8rem; padding: .7rem .8rem; border-radius: 12px; background: #231f38; }
.install-step-icon { flex: 0 0 auto; display: grid; place-items: center; width: 2.75rem; height: 2.75rem; border-radius: 12px; background: var(--accent); font-size: 1.4rem; }

@keyframes pwa-in { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) {
  .pwa-install, .pwa-promo { animation: none; }
  .pwa-install-btn { transition: none; }
}

.levels-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; max-width: 900px; margin: 0 auto; }
.levels-head h2 { margin: .2rem 0 .6rem; color: var(--accent); }
.levels-total { color: #ffd15c; font-weight: 700; }
#level-map { max-width: 900px; margin: 0 auto; padding-bottom: 1.5rem; }
.level-group { margin: 1.2rem 0 .5rem; color: var(--muted); font-size: .95rem; font-weight: 600; }
.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(68px, 1fr)); gap: .5rem; }
.lv-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .1rem;
  min-height: 64px; padding: .4rem .2rem; border: 2px solid transparent; border-radius: 12px;
  background: var(--panel); color: var(--text); cursor: pointer; font: inherit;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.lv-num { font-size: 1.2rem; font-weight: 700; line-height: 1.1; }
.lv-stars { font-size: .75rem; color: #ffd15c; letter-spacing: .08em; min-height: 1em; }
.lv-diff { font-size: .6rem; color: var(--muted); }
.level-group small { font-weight: 400; opacity: .8; }

/* Ferramentas de desenvolvedor (Modo Dev, Resolve Nível, Documentação): só com ?dev na URL */
body:not(.dev-ui) [data-dev] { display: none !important; }

/* Chaves de som/vibração: discretas, ficam esmaecidas quando desligadas */
#sound-btn.off, #haptics-btn.off { opacity: .6; }
.lv-btn.done { background: #33305a; }
.lv-btn.current { border-color: var(--accent); }
.lv-btn.locked { opacity: .45; cursor: not-allowed; }
@media (hover: hover) { .lv-btn:not(:disabled):hover { border-color: var(--accent); } }

/* ---------- Mobile: toque e áreas seguras (notch / barra de gestos) ---------- */
body {
  touch-action: manipulation;                    /* sem zoom por duplo toque fora do tabuleiro */
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) calc(var(--ad-h) + env(safe-area-inset-bottom)) env(safe-area-inset-left);
}

@media (max-width: 700px) {
  /* Folga entre os controles/tabuleiro e o banner fixo (50px reservados pelo padding do body) */
  main { padding-bottom: 1.25rem; }
  #game.active, #solver.active { margin-bottom: 20px; }
  .powerups { margin-bottom: 4px; }
  #palette {
    display: grid; grid-auto-flow: column; grid-auto-columns: 44px; grid-template-columns: none;
    gap: .55rem; width: 100%; min-width: 0; padding: .35rem .2rem .65rem;
    overflow-x: auto; overscroll-behavior-x: contain; touch-action: pan-x;
    scrollbar-width: thin; scrollbar-color: #77708f transparent;
    -webkit-overflow-scrolling: touch;
  }
  #palette .swatch { width: 44px; height: 44px; min-width: 44px; aspect-ratio: auto; }
  #palette .swatch.active {
    border: 3px solid #fff; outline: 2px solid var(--accent); outline-offset: 1px;
    box-shadow: 0 0 0 3px rgba(255, 159, 107, .35);
  }
  .palette-hint { display: block; margin: -.35rem 0 0; color: var(--muted); font-size: .75rem; line-height: 1.35; }
}
