/* Bloquinhos Mágicos: visual "Caderno de adesivos" do laurinha.net.
   O fundo (--bg, --dot) muda com o tema escolhido para a rodada. */
:root {
  --bg: #ffd43b;
  --dot: #f5bf0a;
  --ink: #3a2a17;
  --paper: #fffdf5;
  --y: #ffd43b;
  --pink: #ff6f91;
  --sky: #4cc3ff;
  --leaf: #4ccf7a;
  --orange: #ff9f1c;
  --display: "Gluten", "Comic Sans MS", cursive;
  --body: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  background-image: radial-gradient(var(--dot) 2.2px, transparent 2.6px);
  background-size: 26px 26px;
  color: var(--ink);
  font-family: var(--body);
  font-weight: 700;
  font-size: 17px;
  line-height: 1.35;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  transition: background-color .4s ease;
}
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- área do jogo ---------- */
.app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  max-width: 560px; margin: 0 auto;
  padding: calc(10px + var(--safe-t)) calc(10px + var(--safe-r)) calc(10px + var(--safe-b)) calc(10px + var(--safe-l));
}

.hud { display: flex; gap: 8px; align-items: stretch; width: 100%; }
.chip {
  display: grid; align-content: center; justify-items: center;
  min-width: 64px; padding: 2px 10px 4px;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 14px;
  box-shadow: 3px 3px 0 var(--ink);
}
.chip .lbl { font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: .05em; opacity: .7; }
.chip b { font-family: var(--display); font-weight: 800; font-size: 26px; line-height: 1.05; font-variant-numeric: tabular-nums; }
.chip.score { flex: 1; }
.chip.next canvas { width: 56px; height: 30px; display: block; }
.icon-btn {
  flex: none; width: 56px; padding: 0;
  display: grid; place-items: center;
  background: var(--y); border: 3px solid var(--ink); border-radius: 14px; box-shadow: 3px 3px 0 var(--ink);
  touch-action: none;
}
.icon-btn svg { width: 28px; height: 28px; fill: var(--ink); }
.icon-btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }

.board-area {
  position: relative; flex: 1; min-height: 0; width: 100%;
  display: grid; place-items: center;
  touch-action: none;
}
.board {
  box-sizing: content-box; display: block;
  border: 4px solid var(--ink); border-radius: 12px;
  box-shadow: 6px 6px 0 var(--ink);
}

/* Botões grandes de toque */
.pad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; width: 100%; }
.pad button {
  height: 66px; padding: 0;
  display: grid; place-items: center;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 18px;
  box-shadow: 4px 4px 0 var(--ink);
  touch-action: none;
  transition: transform .06s ease, box-shadow .06s ease;
}
.pad button svg { width: 34px; height: 34px; fill: none; stroke: var(--ink); stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; }
.pad .rot { background: var(--pink); }
.pad .rot svg { stroke: var(--paper); }
.pad [data-act="drop"] { background: var(--sky); }
.pad button.on { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.no-pad .pad { display: none; }

/* Mensagem rápida no meio do tabuleiro ("Uau!", "Nível 2!") */
.toast {
  position: absolute; left: 0; right: 0; top: 32%;
  text-align: center; pointer-events: none;
  font-family: var(--display); font-weight: 800; font-size: clamp(34px, 10vw, 54px); line-height: 1;
  color: var(--paper); -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill;
  text-shadow: 4px 4px 0 var(--ink);
  opacity: 0;
}
.toast.show { animation: pop 1.1s ease forwards; }
@keyframes pop {
  0%   { opacity: 0; transform: scale(.4) rotate(-8deg); }
  18%  { opacity: 1; transform: scale(1.15) rotate(3deg); }
  30%  { transform: scale(1) rotate(-2deg); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(-30px) rotate(-2deg); }
}

/* ---------- botão Início (adesivo amarelo do site) ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center;
  padding: calc(12px + var(--safe-t)) 16px 18px calc(16px + var(--safe-l));
  background: linear-gradient(rgba(58, 42, 23, .35), rgba(58, 42, 23, 0));
  pointer-events: none;
}
.topbar .home-link { pointer-events: auto; }
.home-link {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 16px 6px 10px;
  font-family: var(--display); font-weight: 800; font-size: 20px;
  color: #3a2a17; text-decoration: none;
  background: #ffd43b; border: 3px solid #3a2a17; border-radius: 999px;
  box-shadow: 3px 3px 0 #3a2a17;
  transition: transform .12s ease, box-shadow .12s ease;
}
.home-link svg { width: 22px; height: 22px; }
.home-link:hover, .home-link:focus-visible { transform: translate(-1px, -2px); box-shadow: 4px 5px 0 #3a2a17; outline: none; }
.home-link:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #3a2a17; }

/* ---------- telas (menus) ---------- */
.screen {
  position: fixed; inset: 0; z-index: 5;
  display: grid; justify-items: center; align-items: safe center;
  overflow-y: auto; overscroll-behavior: contain;
  padding: calc(76px + var(--safe-t)) 14px calc(20px + var(--safe-b));
  background: rgba(58, 42, 23, .38);
  touch-action: pan-y;
}
.screen-card {
  display: grid; gap: 12px; justify-items: center; text-align: center;
  width: min(420px, 100%);
  padding: 22px 18px;
  color: var(--ink); background: var(--paper);
  border: 4px solid var(--ink); border-radius: 24px; box-shadow: 7px 7px 0 var(--ink);
  transform: rotate(-1deg);
  animation: card-in .25s ease;
}

@keyframes card-in { from { transform: rotate(-4deg) scale(.92); opacity: 0; } }
.screen-card h1 { margin: 0; font-family: var(--display); font-weight: 800; font-size: 40px; line-height: 1.05; }
.screen-card p { margin: 0; }
.logo { font-size: clamp(34px, 10vw, 44px) !important; line-height: .95 !important; }
#scrStart .screen-card { gap: 10px; }
.logo span { color: var(--pink); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; }
.big { font-size: 21px; font-weight: 900; }
.muted { font-size: 16px; opacity: .75; }
.hello b { font-family: var(--display); font-weight: 800; font-size: 26px; }
.error { color: #d62839; font-weight: 900; min-height: 1.2em; }
.row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
kbd {
  font-family: inherit; font-size: .9em; padding: 0 6px; border: 2px solid var(--ink); border-radius: 7px; background: var(--y);
}
.kbd-hint { font-size: 14px; opacity: .8; }
@media (hover: none) { .kbd-hint { display: none; } }

.btn {
  display: inline-block; min-width: 200px;
  font-family: var(--display); font-weight: 800; font-size: 24px;
  color: var(--paper); background: var(--pink);
  border: 3px solid var(--ink); border-radius: 14px;
  padding: 6px 22px 8px; box-shadow: 4px 4px 0 var(--ink);
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn.play { font-size: clamp(26px, 7.5vw, 32px); min-width: 240px; padding: 8px 24px 10px; }
.btn.small { min-width: 0; font-size: 18px; padding: 4px 14px 6px; }
.btn.alt { background: var(--sky); color: var(--ink); }
.btn.danger { background: #ff5a5a; }
.btn.toggle { background: var(--leaf); color: var(--ink); min-width: 260px; font-size: 21px; }
.btn.toggle[aria-pressed="false"] { background: #e6ddcc; }
.btn:hover, .btn:focus-visible { transform: translate(-1px, -2px); box-shadow: 5px 6px 0 var(--ink); outline: none; }
.btn:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--ink); }

/* Perfis */
.profile-list { display: grid; gap: 10px; width: 100%; }
.profile { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: stretch; }
.profile .pick {
  display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 10px; text-align: left;
  padding: 6px 12px; background: var(--y); border: 3px solid var(--ink); border-radius: 16px; box-shadow: 3px 3px 0 var(--ink);
}
.profile:nth-child(even) .pick { background: #bfe9ff; }
.profile .pet { font-size: 36px; line-height: 1; }
.profile .nm { font-family: var(--display); font-weight: 800; font-size: 24px; line-height: 1.05; overflow-wrap: anywhere; }
.profile .best { display: block; font-size: 14px; font-weight: 900; opacity: .75; }
.profile .del {
  width: 52px; display: grid; place-items: center; padding: 0;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 14px; box-shadow: 3px 3px 0 var(--ink);
}
.profile .del svg { width: 24px; height: 24px; fill: none; stroke: var(--ink); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.profile button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }

.name-input {
  width: 100%; padding: 8px 12px;
  font-family: var(--display); font-weight: 800; font-size: 28px; text-align: center; text-transform: uppercase;
  color: var(--ink); background: #fff; border: 3px solid var(--ink); border-radius: 14px;
  -webkit-user-select: text; user-select: text;
}
.name-input:focus { outline: 4px solid var(--sky); outline-offset: 1px; }
.pet-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: 100%; }
.pet-picker button {
  font-size: 34px; line-height: 1; padding: 8px 0;
  background: #fff; border: 3px solid var(--ink); border-radius: 14px;
}
.pet-picker button[aria-checked="true"] { background: var(--y); box-shadow: 0 0 0 4px var(--pink); }

/* Escolha das cores */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 8px 6px; width: 100%; }
.theme {
  display: grid; justify-items: center; gap: 3px; padding: 0;
  background: none; border: 0; font-size: 11px; font-weight: 900; line-height: 1.1;
}
.theme .sw {
  width: 46px; height: 46px; border-radius: 14px;
  border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--ink);
  display: grid; place-items: center;
  font-family: var(--display); font-size: 28px; color: var(--paper); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill;
  transition: transform .12s ease;
}
.theme[aria-checked="true"] .sw { transform: scale(1.12) rotate(-4deg); box-shadow: 0 0 0 4px var(--paper), 0 0 0 7px var(--pink); }

/* Som */
.vol { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; width: 100%; font-weight: 900; }
.vol input { width: 100%; accent-color: var(--pink); height: 32px; }
.vol b { min-width: 3.2em; text-align: right; }

/* Ranking */
.rank-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; width: 100%; }
.rank-list li {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 8px; align-items: center; text-align: left;
  padding: 6px 10px; border: 3px solid var(--ink); border-radius: 14px; background: #fff;
}
.rank-list li.me { background: var(--y); }
.rank-list .pos { font-family: var(--display); font-size: 26px; text-align: center; }
.rank-list .who { font-family: var(--display); font-size: 21px; line-height: 1.1; overflow-wrap: anywhere; }
.rank-list .tops { display: block; font-family: var(--body); font-size: 13px; font-weight: 800; opacity: .7; }
.rank-list .pts { font-family: var(--display); font-size: 22px; }
.rank-list .empty { display: block; text-align: center; grid-template-columns: 1fr; }

@media (max-width: 480px) {
  .board { border-width: 3px; box-shadow: 4px 4px 0 var(--ink); }
}
/* Celular (tela baixa): placar numa faixa fininha e menos margem, para sobrar altura
   e o tabuleiro (sempre 10 × 20) ficar mais largo. */
@media (max-height: 760px) {
  .app {
    gap: 6px;
    padding: calc(6px + var(--safe-t)) calc(6px + var(--safe-r)) calc(6px + var(--safe-b)) calc(6px + var(--safe-l));
  }
  .hud { gap: 6px; }
  .chip { min-width: 54px; padding: 1px 8px 2px; border-radius: 12px; }
  .chip .lbl { font-size: 10px; line-height: 1.1; }
  .chip b { font-size: 20px; line-height: 1; }
  .chip.next canvas { width: 48px; height: 20px; }
  .icon-btn { width: 48px; border-radius: 12px; }
  .icon-btn svg { width: 24px; height: 24px; }
  .pad { gap: 6px; }
  .pad button { height: 56px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .toast.show { opacity: 1; animation: none !important; }
}
