:root {
  --fundo: #fff4e6;
  --texto: #3b2416;
  --suave: #8a6a55;
  --cartao: #ffe6c7;
  --cartao-2: #ffd8a8;
  --borda: #f0c48f;
  --destaque: #e8833a;
  --destaque-texto: #ffffff;
  --botao: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fundo: #1d1922;
    --texto: #f6e9dc;
    --suave: #b8a596;
    --cartao: #2c2531;
    --cartao-2: #3a3040;
    --borda: #4d4053;
    --destaque: #f0954e;
    --destaque-texto: #1d1922;
    --botao: #2c2531;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--fundo);
  color: var(--texto);
  font-family: system-ui, "Segoe UI", sans-serif;
}

main {
  max-width: 920px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

header { text-align: center; }
h1 { margin: 0 0 6px; font-size: clamp(1.8rem, 5vw, 2.6rem); }
.dica { margin: 0 auto 18px; max-width: 620px; color: var(--suave); line-height: 1.45; }

.cartao {
  background: radial-gradient(circle at 50% 20%, var(--cartao-2), var(--cartao) 70%);
  border: 2px solid var(--borda);
  border-radius: 20px;
  padding: 16px 16px 8px;
}

#palco {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Gato */
.pelo { fill: #f4a259; stroke: #c97b34; stroke-width: 4; }
.barriga { fill: #fde2c0; }
.rosa { fill: #ffb3c1; }
.listra { fill: none; stroke: #c97b34; stroke-width: 5; stroke-linecap: round; }
.olho { fill: #2b1d14; }
.olho-feliz { fill: none; stroke: #2b1d14; stroke-width: 5; stroke-linecap: round; display: none; }
.bochecha { fill: #ff8fa3; opacity: .45; }
.nariz { fill: #e86a7f; }
.boca { fill: none; stroke: #2b1d14; stroke-width: 3; stroke-linecap: round; }
.boca-aberta { fill: #8c2f3f; display: none; }
.bigode { stroke: #7a5a44; stroke-width: 2; stroke-linecap: round; }
.contorno-grosso { fill: none; stroke: #c97b34; stroke-width: 30; stroke-linecap: round; }
.pelo-grosso { fill: none; stroke: #f4a259; stroke-width: 23; stroke-linecap: round; }
.dedos { fill: none; stroke: #c97b34; stroke-width: 2; stroke-linecap: round; }

#rabo {
  transform-origin: 505px 255px;
  animation: rabo 2.4s ease-in-out infinite;
}
.tocando #rabo { animation-duration: .9s; }

#cabeca {
  cursor: pointer;
  transform-origin: 420px 195px;
  transition: transform .2s ease;
}

.olho-aberto {
  transform-box: fill-box;
  transform-origin: center;
  animation: piscar 4.5s infinite;
}
.tocando .olho-aberto, .miando .olho-aberto { display: none; }
.tocando .olho-feliz, .miando .olho-feliz { display: inline; }
.miando .boca { display: none; }
.miando .boca-aberta { display: inline; }

.orelha { transform-box: fill-box; }
.orelha-esq { transform-origin: 100% 100%; }
.orelha-dir { transform-origin: 0% 100%; }
.miando .orelha-esq { animation: orelha-esq .25s ease-in-out 3; }
.miando .orelha-dir { animation: orelha-dir .25s ease-in-out 3; }

/* Piano */
.marca {
  fill: #e9c98b;
  font: italic 700 16px Georgia, serif;
  letter-spacing: 2px;
  text-anchor: middle;
  pointer-events: none;
}
.tecla { cursor: pointer; }
.branca rect { fill: url(#grad-branca); stroke: #9a8f86; stroke-width: 1.5; }
.preta rect { fill: url(#grad-preta); stroke: #000; stroke-width: 1; }
.branca.ativa rect { fill: #ffd59e; }
.preta.ativa rect { fill: #e8833a; }
.tecla rect { transition: fill .08s; }

.rotulo {
  font: 600 15px system-ui, sans-serif;
  fill: #9a8f86;
  text-anchor: middle;
  pointer-events: none;
}
.preta .rotulo { fill: #d8d8d8; font-size: 12px; }
#palco:not(.com-rotulos) .rotulo { display: none; }

.nota-voando {
  font-size: 34px;
  text-anchor: middle;
  pointer-events: none;
  transform-box: fill-box;
  transform-origin: center;
  animation: subir 1.4s ease-out forwards;
}

/* Controles */
.controles {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  align-items: center;
  justify-content: center;
  margin-top: 18px;
}

button {
  font: inherit;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  border: 2px solid var(--destaque);
  background: var(--botao);
  color: var(--texto);
  cursor: pointer;
}
button:hover { background: var(--cartao-2); }
#botao-melodia { background: var(--destaque); color: var(--destaque-texto); }
#botao-melodia:hover { filter: brightness(1.08); }
button:focus-visible, input:focus-visible { outline: 3px solid var(--destaque); outline-offset: 2px; }

.volume, .opcao { display: flex; align-items: center; gap: 8px; color: var(--suave); }
.volume input { accent-color: var(--destaque); width: 130px; }
.opcao input { accent-color: var(--destaque); width: 18px; height: 18px; }

/* Animações */
@keyframes rabo {
  0%, 100% { transform: rotate(-6deg); }
  50% { transform: rotate(8deg); }
}
@keyframes piscar {
  0%, 92%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(.1); }
}
@keyframes orelha-esq {
  50% { transform: rotate(-12deg); }
}
@keyframes orelha-dir {
  50% { transform: rotate(12deg); }
}
@keyframes subir {
  from { transform: translate(0, 0) scale(.6); opacity: 0; }
  15% { opacity: 1; }
  to { transform: translate(var(--dx), -170px) rotate(var(--giro)) scale(1.1); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  #rabo, .olho-aberto, .orelha, .nota-voando { animation: none !important; }
  .nota-voando { display: none; }
  #cabeca { transition: none; }
}
