:root {
  --bg1: #8ec5ff;
  --bg2: #c9e7ff;
  --ink: #23305a;
  --ink-soft: #5a6890;
  --white: #ffffff;
  --primary: #ff7a45;
  --primary-dark: #e35d27;
  --blue: #5b8def;
  --green: #4cc46d;
  --yellow: #ffc83d;
  --purple: #9b6bff;
  --pink: #ff6fa8;
  --card-back-1: #7b5cff;
  --card-back-2: #a98bff;
  --radius: 22px;
  --shadow: 0 6px 0 rgba(35, 48, 90, .18), 0 12px 24px rgba(35, 48, 90, .14);
  --font: "Baloo 2", "Comic Sans MS", "Trebuchet MS", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg1), var(--bg2));
  min-height: 100dvh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}
button { font-family: inherit; color: inherit; cursor: pointer; border: 0; background: none; touch-action: manipulation; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input { -webkit-user-select: text; user-select: text; }
button:focus-visible, input:focus-visible { outline: 4px solid var(--yellow); outline-offset: 3px; }

/* Bolhas de fundo */
.bg-blobs { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.bg-blobs span { position: absolute; border-radius: 50%; opacity: .35; filter: blur(2px); animation: float 14s ease-in-out infinite; }
.bg-blobs span:nth-child(1) { width: 320px; height: 320px; background: #fff; top: -80px; left: -80px; }
.bg-blobs span:nth-child(2) { width: 220px; height: 220px; background: var(--yellow); bottom: 10%; right: -60px; animation-delay: -4s; }
.bg-blobs span:nth-child(3) { width: 180px; height: 180px; background: var(--pink); bottom: -60px; left: 20%; animation-delay: -8s; }
@keyframes float { 50% { transform: translateY(-30px) scale(1.05); } }

/* Topo */
.topbar { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.15rem; }
.brand-icon { display: inline-flex; align-items: center; }
.glasses-icon { display: block; width: 44px; height: auto; overflow: visible; transform: rotate(-6deg); transition: transform .2s; }
@media (hover: hover) { .brand:hover .glasses-icon { transform: rotate(4deg) scale(1.08); } }
.publisher { display: inline-flex; align-items: center; }
.publisher img { display: block; height: 24px; width: auto; }
.brand-text { white-space: nowrap; }
@media (max-width: 400px) {
  .publisher img { height: 19px; }
  .glasses-icon { width: 36px; }
  .brand { gap: 6px; }
  .brand .brand-text { font-size: .95rem; }
  .topbar .icon-btn { width: 40px; height: 40px; font-size: 1.15rem; }
}
.topbar-actions { display: flex; gap: 8px; justify-self: end; }
.brand { justify-self: center; }
.publisher { justify-self: start; }
.icon-btn { width: 46px; height: 46px; border-radius: 50%; background: var(--white); font-size: 1.35rem; box-shadow: 0 4px 0 rgba(35,48,90,.15); transition: transform .1s; display: grid; place-items: center; }
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(35,48,90,.15); }
.icon-btn.small { width: 40px; height: 40px; font-size: 1.1rem; }

main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.screen { display: none; flex: 1; min-height: 0; }
.screen.active { display: flex; flex-direction: column; animation: pop-in .35s ease; }
@keyframes pop-in { from { opacity: 0; transform: translateY(14px); } }

/* Início */
.home { margin: auto; text-align: center; padding: 16px 16px 32px; max-width: 520px; width: 100%; }
.hero-cards { display: flex; justify-content: center; gap: 10px; margin-bottom: 10px; }
.mini-card { width: 64px; height: 80px; border-radius: 14px; background: var(--white); display: grid; place-items: center; font-size: 2.2rem; box-shadow: var(--shadow); animation: bob 3s ease-in-out infinite; }
.mini-card.c1 { transform: rotate(-8deg); }
.mini-card.c2 { animation-delay: -.7s; }
.mini-card.c3 { animation-delay: -1.4s; }
.mini-card.c4 { transform: rotate(8deg); animation-delay: -2.1s; }
@keyframes bob { 50% { translate: 0 -10px; } }
h1 { font-size: clamp(2.6rem, 11vw, 4rem); line-height: .95; margin: 10px 0 6px; color: var(--white); text-shadow: 0 4px 0 var(--blue), 0 8px 0 rgba(35,48,90,.2); }
h1 span { color: var(--yellow); }
.lead { font-size: 1.2rem; margin: 0 0 22px; font-weight: 700; color: var(--ink); }
.home-buttons { display: grid; gap: 14px; }
.big-btn { display: flex; align-items: center; gap: 14px; padding: 14px 20px; border-radius: var(--radius); text-align: left; color: var(--white); box-shadow: var(--shadow); transition: transform .12s; }
@media (hover: hover) { .big-btn:hover { transform: translateY(-2px) scale(1.01); } }
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(35,48,90,.2); }
.big-btn strong { display: block; font-size: 1.45rem; line-height: 1.1; }
.big-btn small { font-size: 1rem; opacity: .92; }
.big-btn-icon { font-size: 2.6rem; width: 64px; height: 64px; background: rgba(255,255,255,.25); border-radius: 18px; display: grid; place-items: center; flex-shrink: 0; }
.btn-solo { background: linear-gradient(135deg, var(--primary), #ffa04d); }
.btn-multi { background: linear-gradient(135deg, var(--purple), #c18bff); }
.progress-pill { margin-top: 20px; display: inline-flex; gap: 8px; align-items: center; background: rgba(255,255,255,.7); padding: 6px 14px; border-radius: 99px; font-weight: 700; color: var(--ink-soft); }

/* Painel de configuração */
.panel { background: var(--white); border-radius: 28px; box-shadow: var(--shadow); padding: 20px 18px 22px; margin: 8px auto 24px; width: calc(100% - 32px); max-width: 640px; }
.panel h2 { margin: 0 0 6px; font-size: 1.8rem; text-align: center; }
.panel h3 { margin: 16px 0 8px; font-size: 1.15rem; color: var(--ink-soft); }
.choice-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.choice { position: relative; background: #f1f5ff; border-radius: 18px; padding: 12px 6px; font-weight: 800; font-size: 1.05rem; display: flex; flex-direction: column; align-items: center; gap: 2px; border: 4px solid transparent; transition: transform .12s, border-color .12s; line-height: 1.1; }
.choice small { font-weight: 600; color: var(--ink-soft); font-size: .85rem; }
.choice-icon { font-size: 2.1rem; }
@media (hover: hover) { .choice:hover:not(:disabled) { transform: translateY(-2px); } }
.choice.selected { border-color: var(--blue); background: #e3edff; }
.choice:disabled { opacity: .55; cursor: not-allowed; filter: grayscale(.7); }
.choice .lock { position: absolute; top: 4px; right: 6px; font-size: 1rem; }
.choice .done { position: absolute; top: 4px; right: 6px; font-size: .95rem; }

.count-row { display: flex; gap: 10px; margin-bottom: 10px; }
.count-row button { flex: 1; padding: 8px; border-radius: 14px; background: #f1f5ff; font-weight: 800; font-size: 1.3rem; border: 4px solid transparent; }
.count-row button.selected { border-color: var(--purple); background: #efe6ff; }
.player-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.player-avatar { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 1.5rem; flex-shrink: 0; }
.player-row input { flex: 1; min-width: 0; font: inherit; font-weight: 700; font-size: 1.05rem; padding: 8px 12px; border-radius: 14px; border: 3px solid #dbe4ff; color: var(--ink); }
.type-toggle { display: flex; background: #f1f5ff; border-radius: 14px; padding: 3px; flex-shrink: 0; }
.type-toggle button { padding: 6px 8px; border-radius: 11px; font-size: 1.2rem; }
.type-toggle button.on { background: var(--white); box-shadow: 0 2px 6px rgba(0,0,0,.12); }

.setup-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 22px; }
.btn { padding: 12px 22px; border-radius: 18px; font-weight: 800; font-size: 1.15rem; transition: transform .1s; }
.btn:active { transform: translateY(3px); }
.btn.primary { background: var(--green); color: var(--white); box-shadow: 0 5px 0 #33994f; }
.btn.primary:active { box-shadow: 0 2px 0 #33994f; }
.btn.secondary { background: var(--blue); color: var(--white); box-shadow: 0 5px 0 #3c6dc8; }
.btn.ghost { background: #eef2fb; color: var(--ink); box-shadow: 0 5px 0 #d3dbef; }

/* Jogo */
#screen-game { padding: 0 12px 12px; }
.game-top { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.hud { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; }
.hud-item { background: var(--white); border-radius: 16px; padding: 4px 12px; display: flex; flex-direction: column; align-items: center; line-height: 1.05; box-shadow: 0 3px 0 rgba(35,48,90,.12); min-width: 68px; }
.hud-item span { font-size: .75rem; font-weight: 700; color: var(--ink-soft); }
.hud-item b { font-size: 1.25rem; }
.level-badge { flex-direction: row; gap: 4px; font-weight: 800; font-size: 1.05rem; padding: 10px 14px; }
.hud-buttons { display: flex; gap: 6px; }

.scoreboard { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.score-chip { display: flex; align-items: center; gap: 6px; background: var(--white); border-radius: 99px; padding: 4px 12px 4px 4px; font-weight: 800; box-shadow: 0 3px 0 rgba(35,48,90,.12); border: 3px solid transparent; transition: transform .2s; }
.score-chip .av { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: 1.1rem; }
.score-chip .pts { background: #f1f5ff; border-radius: 99px; padding: 0 8px; }
.score-chip.current { transform: scale(1.08); border-color: currentColor; }
.score-chip.current .nm::after { content: " 👈"; }

.board-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.board { display: grid; justify-content: center; align-content: center; --card-w: 90px; }

.card { width: var(--card-w); height: var(--card-h, calc(var(--card-w) * 1.25)); perspective: 800px; padding: 0; touch-action: manipulation; }
.card-inner { position: relative; width: 100%; height: 100%; transition: transform .45s cubic-bezier(.3,1.4,.6,1); transform-style: preserve-3d; }
.card.flipped .card-inner, .card.matched .card-inner { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; border-radius: calc(var(--card-w) * .16); backface-visibility: hidden; -webkit-backface-visibility: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; box-shadow: 0 4px 0 rgba(35,48,90,.2); }
.face.back {
  background:
    radial-gradient(circle at 50% 50%, rgba(255,255,255,.28) 0 22%, transparent 23%),
    repeating-linear-gradient(45deg, var(--card-back-1) 0 10px, var(--card-back-2) 10px 20px);
  border: 4px solid var(--white);
  color: var(--white);
  font-weight: 800;
  font-size: calc(var(--card-w) * .42);
  text-shadow: 0 3px 0 rgba(0,0,0,.15);
}
.face.front { background: var(--white); transform: rotateY(180deg); border: 4px solid #e6ecff; }
.face.front .emo { font-size: calc(var(--card-w) * .52); line-height: 1; }
.face.front .nm { font-size: max(10px, calc(var(--card-w) * .14)); font-weight: 800; margin-top: calc(var(--card-w) * .05); text-align: center; line-height: 1; padding: 0 3px; }
@media (hover: hover) { .card:not(.flipped):not(.matched):hover .card-inner { transform: translateY(-4px) rotate(-1.5deg); } }
.card.matched .face.front { border-color: var(--green); background: #effcf2; animation: bounce .5s ease; }
.card.wrong .face.front { border-color: var(--pink); animation: shake .4s ease; }
@keyframes bounce { 40% { transform: rotateY(180deg) scale(1.12); } }
@keyframes shake { 25% { translate: -5px 0; } 75% { translate: 5px 0; } }
.card.matched { cursor: default; }

.found-toast { position: fixed; left: 50%; bottom: 24px; translate: -50% 0; background: var(--white); padding: 8px 20px; border-radius: 99px; font-weight: 800; font-size: 1.2rem; box-shadow: var(--shadow); opacity: 0; transition: opacity .2s, transform .2s; transform: translateY(20px); pointer-events: none; z-index: 20; }
.found-toast.show { opacity: 1; transform: none; }

.turn-banner { position: fixed; top: 40%; left: 50%; translate: -50% -50%; z-index: 30; background: var(--white); padding: 14px 28px; border-radius: 24px; font-weight: 800; font-size: 1.7rem; box-shadow: var(--shadow); opacity: 0; transform: scale(.6); transition: opacity .25s, transform .25s cubic-bezier(.3,1.6,.6,1); pointer-events: none; white-space: nowrap; }
.turn-banner.show { opacity: 1; transform: scale(1); }

/* Modais */
.modal { position: fixed; inset: 0; background: rgba(35,48,90,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal[hidden] { display: none; }
.modal-box { background: var(--white); border-radius: 28px; padding: 22px 20px; width: 100%; max-width: 440px; text-align: center; box-shadow: var(--shadow); animation: pop .35s cubic-bezier(.3,1.5,.6,1); max-height: 90dvh; overflow: auto; }
@keyframes pop { from { transform: scale(.7); opacity: 0; } }
.modal-box h2 { margin: 0 0 6px; font-size: 1.9rem; }
.result-emoji { font-size: 3.6rem; line-height: 1; }
.stars { font-size: 2.4rem; letter-spacing: 4px; margin: 4px 0; }
.stars .off { filter: grayscale(1); opacity: .3; }
.result-stats { display: flex; justify-content: center; gap: 10px; margin: 8px 0 4px; }
.result-stats div { background: #f1f5ff; border-radius: 14px; padding: 6px 12px; font-weight: 700; }
.result-stats b { display: block; font-size: 1.3rem; }
.result-msg { font-weight: 700; color: var(--ink-soft); margin: 8px 0 0; }
.unlock-msg { background: #fff6d8; border-radius: 14px; padding: 8px; font-weight: 800; margin-top: 10px; }
.ranking { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; }
.ranking li { display: flex; align-items: center; gap: 10px; background: #f1f5ff; border-radius: 14px; padding: 6px 12px; font-weight: 800; font-size: 1.1rem; }
.ranking li .pos { width: 30px; font-size: 1.4rem; }
.ranking li .pts { margin-left: auto; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 18px; }
.help { text-align: left; }
.help h2 { text-align: center; }
.help ol { padding-left: 22px; font-size: 1.1rem; margin: 8px 0; }
.help ol li { margin-bottom: 4px; }
.help-levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.help-levels div { background: #f1f5ff; border-radius: 14px; padding: 8px 4px; text-align: center; display: flex; flex-direction: column; font-size: .95rem; }
.help-levels span { font-size: 1.6rem; }
.help .modal-actions { justify-content: center; }

/* Confete */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (max-width: 480px) {
  .brand-text { font-size: 1rem; }
  .hud-item { min-width: 58px; padding: 3px 8px; }
  .hud-item b { font-size: 1.1rem; }
  .level-badge { padding: 8px 10px; font-size: .95rem; }
  .choice { font-size: .95rem; }
  .choice-icon { font-size: 1.8rem; }
  .face.back { border-width: 3px; }
  .face.front { border-width: 3px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

@media (max-width: 370px) {
  .publisher img { height: 16px; }
  .brand .brand-text { font-size: .85rem; }
  .glasses-icon { width: 30px; }
  .topbar .icon-btn { width: 36px; height: 36px; font-size: 1rem; }
  .topbar-actions { gap: 6px; }
}

@media (max-width: 480px) {
  .topbar { grid-template-columns: auto 1fr auto; gap: 6px; }
}

/* ---------- Celular ---------- */
body.in-game { overflow: hidden; }
.score-chip .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

@media (max-width: 480px) {
  #screen-game { padding-bottom: max(8px, env(safe-area-inset-bottom, 0px)); }
  .game-top { gap: 6px; margin-bottom: 6px; }
  .hud { flex-wrap: nowrap; gap: 5px; }
  .hud-item { min-width: 0; padding: 3px 8px; border-radius: 12px; }
  .hud-item span { font-size: .68rem; }
  .hud-item b { font-size: 1rem; font-variant-numeric: tabular-nums; }
  .level-badge { padding: 7px 9px; font-size: .95rem; }
  .hud-buttons { gap: 5px; }
  .hud .icon-btn.small { width: 36px; height: 36px; font-size: 1rem; }
  .scoreboard { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 5px; }
  .score-chip { padding: 2px 8px 2px 2px; font-size: .92rem; min-width: 0; border-width: 2px; }
  .score-chip .av { width: 26px; height: 26px; font-size: .95rem; flex-shrink: 0; }
  .score-chip .pts { margin-left: auto; flex-shrink: 0; }
  .score-chip.current { transform: none; background: #fff8e0; }
  .score-chip.current .nm::after { content: ""; }
  .panel { width: calc(100% - 24px); padding: 16px 14px 18px; border-radius: 24px; }
  .panel h2 { font-size: 1.5rem; }
  .panel h3 { margin: 12px 0 6px; font-size: 1.05rem; }
  .choice { padding: 10px 4px; border-width: 3px; }
  .player-avatar { width: 38px; height: 38px; font-size: 1.3rem; }
  .type-toggle button { padding: 6px 7px; }
  .setup-actions { position: sticky; bottom: 0; background: var(--white); padding-top: 10px; padding-bottom: max(4px, env(safe-area-inset-bottom, 0px)); margin-top: 14px; }
  .setup-actions .btn { flex: 1; padding: 12px 10px; }
  .home { padding-top: 4px; }
  .mini-card { width: 56px; height: 70px; font-size: 1.9rem; }
  .big-btn { padding: 12px 14px; }
  .big-btn strong { font-size: 1.3rem; }
  .big-btn-icon { width: 56px; height: 56px; font-size: 2.2rem; }
  .turn-banner { font-size: 1.3rem; padding: 12px 20px; max-width: calc(100vw - 32px); white-space: normal; text-align: center; }
  .found-toast { bottom: max(14px, env(safe-area-inset-bottom, 0px)); font-size: 1.05rem; padding: 6px 16px; }
  .modal-box { padding: 18px 14px; border-radius: 24px; }
  .modal-box h2 { font-size: 1.55rem; }
  .modal-actions .btn { flex: 1 1 auto; }
}
@media (max-width: 400px) {
  .lvl-name { display: none; }
  .scoreboard { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Celular deitado (pouca altura) */
@media (max-height: 520px) and (orientation: landscape) {
  .topbar { padding-top: max(4px, env(safe-area-inset-top, 0px)); padding-bottom: 4px; }
  .topbar .icon-btn { width: 36px; height: 36px; font-size: 1rem; }
  .publisher img { height: 18px; }
  .glasses-icon { width: 32px; }
  .brand .brand-text { font-size: 1rem; }
  #screen-game { padding-bottom: max(6px, env(safe-area-inset-bottom, 0px)); }
  .game-top { flex-direction: row; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px; margin-bottom: 6px; }
  .hud { flex-wrap: nowrap; gap: 5px; }
  .hud-item { min-width: 0; padding: 2px 8px; }
  .hud-item span { font-size: .65rem; }
  .hud-item b { font-size: .95rem; }
  .level-badge { padding: 6px 9px; font-size: .9rem; }
  .hud .icon-btn.small { width: 32px; height: 32px; font-size: .9rem; }
  .scoreboard { display: flex; flex-wrap: nowrap; gap: 5px; }
  .score-chip { padding: 1px 8px 1px 1px; font-size: .85rem; border-width: 2px; max-width: 150px; }
  .score-chip .av { width: 24px; height: 24px; font-size: .9rem; flex-shrink: 0; }
  .score-chip.current { transform: none; background: #fff8e0; }
  .score-chip.current .nm::after { content: ""; }
  .home { padding-top: 0; }
  .hero-cards { display: none; }
  h1 { font-size: 2.4rem; }
  .home-buttons { grid-template-columns: 1fr 1fr; }
  .big-btn { padding: 10px 12px; gap: 10px; }
  .big-btn-icon { width: 48px; height: 48px; font-size: 1.8rem; }
  .big-btn strong { font-size: 1.2rem; }
  .lead { margin-bottom: 12px; }
  .panel { margin-top: 4px; }
  .modal-box { max-height: calc(100dvh - 24px); padding: 14px; }
  .result-emoji { font-size: 2.4rem; }
  .stars { font-size: 1.8rem; }
  .modal-actions { margin-top: 10px; }
}
