/* Hogwarts à noite: painéis de pergaminho com tinta sépia, detalhes em ouro e vinho da Grifinória */
:root {
  --bg: #070a1c;
  --hud: #f6ead0;
  --hud-muted: #c7bfa6;
  --parchment: #efe0bb;
  --parchment-edge: #c9a96a;
  --ink: #3a2716;
  --ink-muted: #6e5538;
  --gold: #e3b33c;
  --gold-ink: #8a5d0c;
  --wine: #7d1424;
  --wine-ink: #f6e2a6;
  --shield: #a8dcff;
  --shield-ink: #2a5f86;
  --red: #c8202f;
  --dark-glass: rgba(8, 10, 30, 0.55);
  --display: "Cinzel", Georgia, "Times New Roman", serif;
  --font: "Alegreya", Georgia, "Times New Roman", serif;
  /* o jogo tem um visual noturno próprio, independente do tema do sistema */
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--hud);
  font-family: var(--font);
  /* a Alegreya usa algarismos antigos por padrão (o zero parece um "o") */
  font-variant-numeric: lining-nums;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app, #app canvas {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button { pointer-events: auto; }

.hud-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: max(12px, env(safe-area-inset-top)) 16px 0;
}

/* o nível fica preso ao centro do tabuleiro (--board-center, calculado em ui.js) */
.hud-stats {
  position: absolute;
  top: calc(max(12px, env(safe-area-inset-top)) - 4px);
  left: var(--board-center, 50%);
  transform: translateX(-50%);
  text-align: center;
  line-height: 1.1;
  white-space: nowrap;
}
.hud-level {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(22px, 5vw, 30px);
  letter-spacing: 0.04em;
  color: var(--hud);
  text-shadow: 0 0 14px rgba(255, 190, 90, 0.45), 0 2px 8px rgba(0, 0, 0, 0.8);
}
.hud-best { font-size: 15px; color: var(--hud-muted); text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8); }

.hud-right { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }

/* botão de som no canto direito extremo da tela */
.corner-mute {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
}
/* tela estreita: os pomos descem para baixo do botão de som, longe do nível */
#hud.compact #hudStars {
  position: fixed;
  top: calc(max(12px, env(safe-area-inset-top)) + 50px);
  right: max(16px, env(safe-area-inset-right));
}

.stars {
  display: flex;
  align-items: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--gold);
  background: var(--dark-glass);
  border: 1px solid rgba(227, 179, 60, 0.4);
  padding: 6px 12px 6px 4px;
  border-radius: 999px;
}
.stars.pop { animation: pop 0.4s ease; }
@keyframes pop { 50% { transform: scale(1.35); } }

/* Pomo de Ouro desenhado em CSS: bolinha dourada com duas asas */
.snitch-icon {
  position: relative;
  display: inline-block;
  width: 12px;
  height: 12px;
  margin: 0 12px;
  border-radius: 50%;
  vertical-align: -1px;
  background: radial-gradient(circle at 35% 30%, #fff6c8, var(--gold) 50%, var(--gold-ink));
}
.snitch-icon::before,
.snitch-icon::after {
  content: "";
  position: absolute;
  top: -2px;
  width: 11px;
  height: 6px;
  border-radius: 50% 50% 50% 50% / 80% 80% 20% 20%;
  background: rgba(255, 255, 255, 0.85);
}
.snitch-icon::before { right: 9px; transform: rotate(-18deg); }
.snitch-icon::after { left: 9px; transform: rotate(18deg); }
.panel .snitch-icon::before, .panel .snitch-icon::after { background: rgba(110, 85, 56, 0.55); }

.icon-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(227, 179, 60, 0.45);
  background: var(--dark-glass);
  color: var(--hud);
  font-size: 18px;
  display: grid;
  place-items: center;
}
.icon-btn:hover { background: rgba(40, 30, 60, 0.75); }

.ball-count {
  position: absolute;
  left: 0; top: 0;
  font-family: var(--display);
  font-size: 20px;
  font-weight: 700;
  color: var(--hud);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8);
  will-change: transform;
}

.hint {
  position: absolute;
  left: 50%;
  top: 60%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  text-align: center;
  font-size: 18px;
  color: var(--hud);
  background: var(--dark-glass);
  border: 1px solid rgba(227, 179, 60, 0.3);
  padding: 10px 16px;
  border-radius: 14px;
  animation: breathe 1.6s ease-in-out infinite;
}
@keyframes breathe { 50% { opacity: 0.55; } }

.hud-bottom {
  position: absolute;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  gap: 8px;
}

.pill {
  border: 1px solid rgba(227, 179, 60, 0.45);
  background: var(--dark-glass);
  color: var(--hud);
  font-size: 16px;
  font-weight: 700;
  padding: 10px 16px;
  border-radius: 999px;
}
.pill:hover { background: rgba(40, 30, 60, 0.75); }
.pill.active { background: var(--gold); color: var(--ink); border-color: transparent; }

/* aviso curto no meio da tela (feitiços, combos, perigo) */
.banner {
  position: absolute;
  left: 50%;
  top: 40%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  text-align: center;
  text-wrap: balance;
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(24px, 6.5vw, 40px);
  color: var(--gold);
  text-shadow: 0 0 18px rgba(255, 200, 100, 0.65), 0 3px 0 rgba(20, 10, 0, 0.85);
  animation: banner 1.1s ease forwards;
}
@keyframes banner {
  0% { opacity: 0; transform: translateX(-50%) scale(0.6); }
  15% { opacity: 1; transform: translateX(-50%) scale(1.08); }
  25% { transform: translateX(-50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-16px); }
}

/* "Boa sorte, Laura!": letras chegam voando como um feitiço e somem em brilho */
.luck {
  position: absolute;
  left: 50%;
  top: 34%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  text-align: center;
  pointer-events: none;
  animation: luck-out 5s ease forwards;
}
.luck-line {
  display: block;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(20px, 5vw, 30px);
  letter-spacing: 0.06em;
  color: var(--hud);
  text-shadow: 0 0 12px rgba(255, 210, 120, 0.7), 0 2px 6px rgba(0, 0, 0, 0.9);
}
.luck-name {
  display: block;
  /* mesmo estilo dos feitiços (.banner), maior; em maiúsculas, que é como a Laura (4 anos) lê */
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(52px, 14vw, 96px);
  letter-spacing: 0.04em;
  line-height: 1.1;
  color: var(--gold);
  text-shadow: 0 0 18px rgba(255, 200, 100, 0.65), 0 3px 0 rgba(20, 10, 0, 0.85);
}
.luck span.l {
  display: inline-block;
  white-space: pre;
  opacity: 0;
  animation: luck-letter 0.7s cubic-bezier(0.2, 0.9, 0.3, 1.2) forwards;
  animation-delay: calc(var(--i) * 0.06s);
}
@keyframes luck-letter {
  from { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(var(--r)) scale(0.2); filter: blur(6px); }
  to { opacity: 1; transform: none; filter: none; }
}
@keyframes luck-out {
  /* sem desfoque até o fim: o texto fica nítido e parado para a leitura */
  0%, 84% { opacity: 1; transform: translateX(-50%); filter: none; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-30px) scale(1.08); filter: blur(4px); }
}

/* faíscas em volta dos nomes */
.spark {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff6cc;
  box-shadow: 0 0 6px 2px rgba(255, 210, 110, 0.9);
  opacity: 0;
  pointer-events: none;
  animation: spark 1.1s ease-out forwards;
  animation-delay: var(--d);
}
@keyframes spark {
  0% { opacity: 0; transform: translate(0, 0) scale(0); }
  25% { opacity: 1; transform: translate(calc(var(--dx) * 0.4), calc(var(--dy) * 0.4)) scale(1.2); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.2); }
}

/* ---------- Telas (pergaminho) ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(4, 6, 20, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  overflow-y: auto;
}

.panel {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 26px 22px;
  border-radius: 6px;
  color: var(--ink);
  background:
    radial-gradient(ellipse at 20% 15%, rgba(255, 255, 255, 0.35), transparent 45%),
    radial-gradient(ellipse at center, var(--parchment) 55%, var(--parchment-edge) 130%);
  border: 1px solid var(--parchment-edge);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6), inset 0 0 40px rgba(120, 80, 30, 0.25);
  text-align: center;
  animation: rise 0.25s ease;
}
.panel.wide { width: min(600px, 100%); }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }

.kicker {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
  text-wrap: balance;
}
/* "Bem-vinda de volta, Laura": o nome é escrito letra por letra, como por uma varinha */
.welcome { position: relative; margin-bottom: 4px; }
.welcome-line {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.1em;
  color: var(--wine);
  opacity: 0;
}
.welcome-name {
  position: relative;
  margin: -4px 0 0;
  /* mesma fonte dos feitiços (Cinzel), em ouro escuro para contrastar com o pergaminho */
  font-family: var(--display);
  font-weight: 900;
  font-size: 54px;
  letter-spacing: 0.04em;
  line-height: 1.15;
}
.welcome-name span.l {
  display: inline-block;
  opacity: 0;
  /* cor sólida e contrastada: depois de escrito, o nome fica parado para ser lido */
  color: #6b4306;
  text-shadow: 0 0 10px rgba(227, 179, 60, 0.55);
}
.welcome.play .welcome-line { animation: fade-in 0.6s ease forwards; }
.welcome.play .welcome-name span.l {
  animation: write 0.55s ease-out forwards;
  animation-delay: calc(0.5s + var(--i) * 0.22s);
}
@keyframes fade-in { to { opacity: 1; } }
@keyframes write {
  from { opacity: 0; transform: translateY(10px) scale(0.6) rotate(-8deg); filter: blur(5px); }
  to { opacity: 1; transform: none; }
}
/* ponta da varinha que acompanha a escrita */
.wand-tip {
  position: absolute;
  top: 50%;
  left: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fffbe0;
  box-shadow: 0 0 10px 4px rgba(255, 215, 120, 0.95), 0 0 24px 8px rgba(255, 190, 80, 0.5);
  opacity: 0;
  pointer-events: none;
}
.welcome.play .wand-tip { animation: wand var(--wand-time) ease-in-out 0.45s forwards; }
@keyframes wand {
  0% { opacity: 0; left: var(--from); top: 70%; }
  10% { opacity: 1; }
  30% { top: 30%; }
  55% { top: 65%; }
  80% { top: 35%; }
  90% { opacity: 1; }
  100% { opacity: 0; left: var(--to); top: 50%; }
}

.logo {
  margin: 0;
  font-family: var(--display);
  font-weight: 900;
  font-size: 44px;
  line-height: 1;
  color: var(--ink);
}
.logo em { display: block; font-size: 0.74em; font-style: normal; color: var(--wine); }
.edition {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.08em;
  color: var(--gold-ink);
}
.edition::before, .edition::after { content: " ✦ "; color: var(--gold); }

.title {
  margin: 0 0 4px;
  font-family: var(--display);
  font-weight: 900;
  font-size: 26px;
  line-height: 1.15;
  text-wrap: balance;
}
.sub { margin: 0 0 6px; color: var(--ink-muted); font-size: 17px; }
.sub b { color: var(--ink); }

.btn {
  border: 1px solid rgba(58, 39, 22, 0.35);
  background: rgba(58, 39, 22, 0.07);
  color: var(--ink);
  font-size: 19px;
  font-weight: 700;
  padding: 11px 16px;
  border-radius: 6px;
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:hover:not(:disabled) { background: rgba(58, 39, 22, 0.14); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary {
  font-family: var(--display);
  font-size: 21px;
  background: var(--wine);
  color: var(--wine-ink);
  border: 1px solid var(--gold);
  box-shadow: inset 0 0 0 2px rgba(227, 179, 60, 0.25), 0 4px 12px rgba(80, 10, 20, 0.35);
}
.btn.primary:hover:not(:disabled) { filter: brightness(1.12); background: var(--wine); }
.btn.small { font-size: 15px; padding: 6px 10px; }

.howto { margin-top: 8px; text-align: left; font-size: 16px; color: var(--ink-muted); }
.howto h2 { margin: 0 0 4px; font-family: var(--display); font-size: 16px; color: var(--ink); }
.howto ul { margin: 0; padding-left: 18px; display: grid; gap: 4px; }

.red { color: var(--red); }
.gold { color: var(--gold-ink); }
.shield { color: var(--shield-ink); }

.record { margin: 0; color: var(--wine); font-family: var(--display); font-size: 20px; font-weight: 900; animation: pop 0.6s ease 0.3s; }

.score { display: flex; justify-content: center; gap: 28px; margin: 6px 0 10px; }
.score div { display: flex; flex-direction: column; }
.score span { color: var(--ink-muted); font-size: 15px; }
.score b { font-family: var(--display); font-size: 36px; font-variant-numeric: tabular-nums; }

.shop-grid {
  display: grid;
  /* 8 bolas: 4×2 no computador, 2×4 no celular */
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 6px;
}
.skin {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  border-radius: 6px;
  background: rgba(58, 39, 22, 0.06);
  border: 1px solid rgba(58, 39, 22, 0.15);
}
.skin.equipped { border: 2px solid var(--wine); background: rgba(125, 20, 36, 0.08); }
.skin-ball { width: 44px; height: 44px; border-radius: 50%; box-shadow: 0 4px 10px rgba(40, 20, 0, 0.35); }
.skin-name { font-family: var(--display); font-weight: 700; font-size: 15px; line-height: 1.15; }
.skin-desc { font-size: 14px; color: var(--ink-muted); line-height: 1.15; }
.skin-spell { font-size: 14px; font-style: italic; font-weight: 700; color: var(--wine); line-height: 1.15; }
.skin .btn { width: 100%; margin-top: auto; }

/* tela "Como jogar" */
.rules .title { margin-bottom: 0; }
.rules-body { display: grid; gap: 12px; text-align: left; font-size: 16px; color: var(--ink-muted); }
.rules-body h3 { margin: 0 0 4px; font-family: var(--display); font-size: 16px; color: var(--ink); }
.rules-body p { margin: 0; }
.rules-body ul { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.rules-body b:not([class]) { color: var(--ink); }
.rules-body kbd {
  font-family: inherit;
  font-size: 14px;
  padding: 0 5px;
  border: 1px solid rgba(58, 39, 22, 0.35);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.35);
}

@media (max-width: 520px) {
  .shop-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .banner, .hint, .panel, .stars.pop, .record { animation: none; }
  .welcome.play .welcome-line, .welcome.play .welcome-name span.l, .luck span.l { animation: none; opacity: 1; }
  .luck { animation: luck-out 5s step-end forwards; }
  .spark, .wand-tip { display: none; }
}

/* Botão "Início": volta para a lista de jogos do laurinha.net (adesivo amarelo do site) */
.home-link {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding: 4px 16px 6px 10px;
  font-family: "Gluten", var(--display), cursive;
  font-weight: 800;
  font-size: 19px;
  color: #3a2a17;
  text-decoration: none;
  background: #ffd43b;
  border: 3px solid #3a2a17;
  border-radius: 999px;
  box-shadow: 3px 3px 0 #3a2a17;
  transition: transform 0.12s ease, box-shadow 0.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; }
