/* ---------- Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

:root {
  --bg-deep: #1a1410;
  --bg-mid: #2a1f17;
  --bg-grass-1: #3d5a2a;
  --bg-grass-2: #2d4520;
  --bg-dirt-1: #6b4a2a;
  --bg-dirt-2: #4a3520;

  --c-blue: #3b82f6;
  --c-blue-glow: #60a5fa;
  --c-green: #22c55e;
  --c-green-glow: #4ade80;
  --c-purple: #a855f7;
  --c-purple-glow: #c084fc;
  --c-yellow: #eab308;
  --c-yellow-glow: #facc15;
  --c-red-error: #ef4444;

  --c-text: #f5e9d5;
  --c-text-dim: #b8a585;
  --c-text-gold: #ffd97a;
  --c-frame: #4a3520;
  --c-frame-light: #6b4a2a;
  --c-frame-shadow: #1a0f08;

  --font-pixel: "Press Start 2P", "Courier New", monospace;
}

body {
  font-family: var(--font-pixel);
  background: var(--bg-deep);
  color: var(--c-text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: none;
  font-smooth: never;
  image-rendering: pixelated;
}

img {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

kbd {
  display: inline-block;
  padding: 2px 6px;
  background: var(--c-frame);
  border: 2px solid var(--c-frame-light);
  border-bottom-width: 4px;
  border-right-width: 4px;
  color: var(--c-text-gold);
  font-family: var(--font-pixel);
  font-size: 9px;
  vertical-align: middle;
}

/* ---------- Layout ---------- */
#game-stage {
  position: relative;
  width: 100%;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  background:
    radial-gradient(ellipse at center 40%, #2d201a 0%, #15100c 70%, #0a0805 100%);
}

/* ---------- HUD ---------- */
#hud {
  display: flex;
  gap: 12px;
  padding: 16px 24px;
  flex-wrap: wrap;
  justify-content: center;
  z-index: 5;
}

.hud-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 14px;
  min-width: 100px;
  background: linear-gradient(180deg, #3d2d20, #2a1f17);
  border: 3px solid var(--c-frame-light);
  box-shadow:
    inset 2px 2px 0 rgba(255, 255, 255, 0.08),
    inset -2px -2px 0 var(--c-frame-shadow),
    0 4px 0 var(--c-frame-shadow);
}

.hud-label {
  font-size: 8px;
  color: var(--c-text-dim);
  letter-spacing: 1px;
}

.hud-value {
  font-size: 14px;
  color: var(--c-text-gold);
  font-variant-numeric: tabular-nums;
  transition: transform 200ms ease-out, color 200ms;
}

.hud-value.bump {
  transform: scale(1.3);
  color: #fff;
}

.hud-card.cd-card {
  border-color: var(--c-yellow);
  box-shadow:
    inset 2px 2px 0 rgba(255, 255, 255, 0.08),
    inset -2px -2px 0 var(--c-frame-shadow),
    0 4px 0 var(--c-frame-shadow),
    0 0 12px rgba(234, 179, 8, 0.25);
}

.cd-card .hud-value { color: var(--c-yellow-glow); }
.cd-card .hud-label { color: var(--c-yellow); }

/* ---------- Arena ---------- */
#arena {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 40px;
  overflow: hidden;
}

#background-grass {
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(
      0deg,
      transparent 0px,
      transparent 8px,
      rgba(0, 0, 0, 0.06) 8px,
      rgba(0, 0, 0, 0.06) 9px
    ),
    repeating-linear-gradient(
      90deg,
      transparent 0px,
      transparent 8px,
      rgba(0, 0, 0, 0.04) 8px,
      rgba(0, 0, 0, 0.04) 9px
    ),
    radial-gradient(ellipse 80% 60% at 50% 100%, var(--bg-grass-1) 0%, var(--bg-grass-2) 50%, var(--bg-mid) 90%);
  z-index: 0;
}

#thomas-container {
  position: relative;
  width: 320px;
  height: 480px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}

#glow-ring {
  position: absolute;
  width: 280px;
  height: 80px;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(168, 85, 247, 0.35) 0%, rgba(168, 85, 247, 0) 70%);
  opacity: 0;
  pointer-events: none;
  z-index: 1;
}

#thomas-container[data-state="challenge"] #glow-ring {
  animation: glow-pulse 1.2s ease-in-out infinite alternate;
}

@keyframes glow-pulse {
  0% { opacity: 0.5; transform: translateX(-50%) scale(0.95); }
  100% { opacity: 1; transform: translateX(-50%) scale(1.1); }
}

#thomas-sprite-wrap {
  position: relative;
  width: 100%;
  height: 360px;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 2;
}

#thomas-sprite {
  width: 720px;
  height: auto;
  transform: translateY(150px);
  filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.4));
  will-change: transform;
}

#thomas-shadow {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 140px;
  height: 18px;
  background: radial-gradient(ellipse, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0) 70%);
  z-index: 1;
}

/* ---------- Notas acima do gato ---------- */
#notes-above {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 14px;
  z-index: 3;
  min-height: 64px;
  align-items: center;
}

.note {
  width: 52px;
  height: 52px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
  transform: scale(0);
  opacity: 0;
}

.note::before {
  content: "";
  position: absolute;
  inset: 0;
  background: currentColor;
  border: 3px solid rgba(0, 0, 0, 0.4);
  box-shadow:
    inset 2px 2px 0 rgba(255, 255, 255, 0.35),
    inset -2px -2px 0 rgba(0, 0, 0, 0.3),
    0 0 16px currentColor;
  z-index: -1;
}

.note[data-color="blue"]   { color: var(--c-blue); }
.note[data-color="green"]  { color: var(--c-green); }
.note[data-color="purple"] { color: var(--c-purple); }
.note[data-color="yellow"] { color: var(--c-yellow); }

.note .glyph {
  color: #fff;
  position: relative;
  z-index: 1;
  filter: drop-shadow(0 0 4px rgba(0, 0, 0, 0.6));
}

.note.pending {
  animation: note-bob 1s ease-in-out infinite alternate;
}

.note.next-up {
  animation: note-next 0.5s ease-in-out infinite alternate;
}

@keyframes note-bob {
  0% { transform: scale(1) translateY(0); }
  100% { transform: scale(1) translateY(-4px); }
}

@keyframes note-next {
  0% { transform: scale(1) translateY(0); }
  100% { transform: scale(1.15) translateY(-6px); }
}

.note.cleared {
  pointer-events: none;
}

.note.error-flash {
  animation: note-error 0.3s ease-in-out;
}

@keyframes note-error {
  0%, 100% { color: var(--c-red-error); }
  50%      { color: #fff; }
}

/* ---------- Hint text ---------- */
#hint-text {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  z-index: 4;
}

#hint-text p {
  font-size: 11px;
  color: var(--c-text-dim);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6);
}

#hint-text strong {
  color: var(--c-text-gold);
}

#cd-seconds {
  color: var(--c-yellow-glow);
  font-variant-numeric: tabular-nums;
}

/* ---------- Skill bar ---------- */
#skill-bar {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  z-index: 5;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.4));
}

.skill {
  position: relative;
  width: 78px;
  height: 78px;
  border: 3px solid var(--c-frame-light);
  border-bottom-width: 5px;
  border-right-width: 5px;
  cursor: pointer;
  font-family: var(--font-pixel);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 0 18px;
  overflow: visible;
  transition: transform 80ms ease-out, box-shadow 180ms ease;
  color: #fff;
}

.skill:active {
  transform: translateY(2px);
}

.skill-icon {
  font-size: 38px;
  line-height: 1;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -60%);
  pointer-events: none;
  color: #fff;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.6)) drop-shadow(0 0 4px rgba(255, 255, 255, 0.4));
}

.skill-key {
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-deep);
  border: 2px solid var(--c-frame-light);
  padding: 2px 6px;
  min-height: 20px;
  font-size: 9px;
  color: var(--c-text-gold);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mouse-icon {
  display: block;
  color: var(--c-text-gold);
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.5));
}

/* Cores específicas por slot (sempre visíveis, idle e challenge) */
.skill[data-color="blue"] {
  background: linear-gradient(180deg, var(--c-blue-glow), var(--c-blue) 60%, #1e40af);
  box-shadow:
    inset 2px 2px 0 rgba(255, 255, 255, 0.35),
    inset -2px -2px 0 rgba(0, 0, 0, 0.35),
    0 0 8px rgba(59, 130, 246, 0.45);
}
.skill[data-color="green"] {
  background: linear-gradient(180deg, var(--c-green-glow), var(--c-green) 60%, #166534);
  box-shadow:
    inset 2px 2px 0 rgba(255, 255, 255, 0.35),
    inset -2px -2px 0 rgba(0, 0, 0, 0.35),
    0 0 8px rgba(34, 197, 94, 0.45);
}
.skill[data-color="purple"] {
  background: linear-gradient(180deg, var(--c-purple-glow), var(--c-purple) 60%, #6b21a8);
  box-shadow:
    inset 2px 2px 0 rgba(255, 255, 255, 0.35),
    inset -2px -2px 0 rgba(0, 0, 0, 0.35),
    0 0 8px rgba(168, 85, 247, 0.45);
}
.skill[data-color="yellow"] {
  background: linear-gradient(180deg, var(--c-yellow-glow), var(--c-yellow) 60%, #854d0e);
  box-shadow:
    inset 2px 2px 0 rgba(255, 255, 255, 0.35),
    inset -2px -2px 0 rgba(0, 0, 0, 0.35),
    0 0 8px rgba(234, 179, 8, 0.5);
}

/* Estado challenge: glow intensificado pra ficar claro que tá ativo */
#skill-bar[data-state="challenge"] .skill[data-color="blue"]   { box-shadow: inset 2px 2px 0 rgba(255,255,255,0.4), inset -2px -2px 0 rgba(0,0,0,0.35), 0 0 18px var(--c-blue-glow), 0 0 36px rgba(59, 130, 246, 0.6); }
#skill-bar[data-state="challenge"] .skill[data-color="green"]  { box-shadow: inset 2px 2px 0 rgba(255,255,255,0.4), inset -2px -2px 0 rgba(0,0,0,0.35), 0 0 18px var(--c-green-glow), 0 0 36px rgba(34, 197, 94, 0.6); }
#skill-bar[data-state="challenge"] .skill[data-color="purple"] { box-shadow: inset 2px 2px 0 rgba(255,255,255,0.4), inset -2px -2px 0 rgba(0,0,0,0.35), 0 0 18px var(--c-purple-glow), 0 0 36px rgba(168, 85, 247, 0.6); }
#skill-bar[data-state="challenge"] .skill[data-color="yellow"] { box-shadow: inset 2px 2px 0 rgba(255,255,255,0.4), inset -2px -2px 0 rgba(0,0,0,0.35), 0 0 18px var(--c-yellow-glow), 0 0 36px rgba(234, 179, 8, 0.6); }

/* Cooldown overlay (drena de cima pra baixo) — fica no slot R que é o ativador */
.cooldown-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  pointer-events: none;
  transform-origin: top;
  transform: scaleY(0);
  transition: transform 50ms linear;
}

.activator[data-cooldown="true"] .cooldown-overlay {
  transform: scaleY(1);
}

/* Indicador visual de que R é o ativador */
.activator::after {
  content: "⚡";
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 12px;
  color: #fff;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.6);
  pointer-events: none;
  opacity: 0.85;
}

/* skill ativa pulsa quando é a próxima esperada */
.skill.next-expected {
  animation: skill-pulse 0.6s ease-in-out infinite alternate;
}

@keyframes skill-pulse {
  0%   { box-shadow: 0 0 8px currentColor; transform: translateY(0); }
  100% { box-shadow: 0 0 24px currentColor, 0 0 40px currentColor; transform: translateY(-3px); }
}

/* Skill que acabou de ser acertada */
.skill.hit-flash {
  animation: skill-hit 0.25s ease-out;
}

@keyframes skill-hit {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.15); filter: brightness(1.6); }
  100% { transform: scale(1); }
}

.skill.error-flash {
  animation: skill-error 0.3s ease-in-out;
}

@keyframes skill-error {
  0%, 100% { background: linear-gradient(180deg, #3d2d20, #2a1f17); }
  50%      { background: linear-gradient(180deg, #6b1a1a, #441010); }
}

/* ---------- Tutorial ---------- */
#tutorial {
  position: fixed;
  bottom: 16px;
  right: 16px;
  max-width: 360px;
  z-index: 10;
  font-size: 10px;
}

#tutorial details {
  background: rgba(26, 20, 16, 0.92);
  border: 3px solid var(--c-frame-light);
  padding: 8px 12px;
}

#tutorial summary {
  cursor: pointer;
  color: var(--c-text-gold);
  font-size: 10px;
  list-style: none;
}

#tutorial summary::-webkit-details-marker,
#tutorial summary::marker { display: none; content: ""; }

#tutorial summary::before {
  content: ">";
  display: inline-block;
  margin-right: 6px;
  color: var(--c-text-dim);
  transition: transform 150ms ease;
}

#tutorial details[open] summary::before {
  transform: rotate(90deg);
}

.tutorial-content {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  line-height: 1.8;
}

.tutorial-content p {
  font-size: 10px;
  color: var(--c-text);
}

.legend {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-left: 8px;
}

.legend li { display: flex; align-items: center; gap: 8px; font-size: 9px; }

.dot {
  width: 16px;
  height: 16px;
  display: inline-block;
  border: 2px solid rgba(0, 0, 0, 0.4);
  box-shadow: inset 2px 2px 0 rgba(255, 255, 255, 0.3);
}

.dot.blue   { background: var(--c-blue); }
.dot.green  { background: var(--c-green); }
.dot.purple { background: var(--c-purple); }
.dot.yellow { background: var(--c-yellow); }

/* ---------- Burst de partículas ---------- */
.particle {
  position: absolute;
  width: 8px;
  height: 8px;
  pointer-events: none;
  z-index: 10;
}

/* ---------- Shake do Thomas (no erro) ---------- */
#thomas-sprite-wrap.shake { animation: shake 0.35s ease-in-out; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-8px); }
  40%      { transform: translateX(8px); }
  60%      { transform: translateX(-5px); }
  80%      { transform: translateX(3px); }
}

#thomas-sprite-wrap.pulse #thomas-sprite { animation: thomas-pulse 0.2s ease-out; }

@keyframes thomas-pulse {
  0%   { transform: translateY(150px) scale(1); }
  50%  { transform: translateY(146px) scale(1.04); }
  100% { transform: translateY(150px) scale(1); }
}

#thomas-sprite { animation: thomas-idle 2.4s ease-in-out infinite; }

@keyframes thomas-idle {
  0%, 100% { transform: translateY(150px); }
  50%      { transform: translateY(146px); }
}

/* ---------- Responsivo ---------- */
@media (max-width: 720px) {
  #thomas-container { width: 240px; height: 380px; }
  #thomas-sprite { width: 560px; }
  #thomas-sprite-wrap { height: 280px; }
  .skill { width: 56px; height: 56px; }
  .skill-icon { font-size: 24px; }
  .note { width: 40px; height: 40px; font-size: 22px; }
  #notes-above { gap: 8px; }
  .hud-card { min-width: 80px; padding: 6px 10px; }
  .hud-value { font-size: 11px; }
  .hud-label { font-size: 7px; }
}

@media (max-width: 480px) {
  #hud { padding: 8px; gap: 6px; }
  #tutorial { max-width: 280px; }
}
