:root {
  --panel: rgba(58, 18, 92, 0.88);
  --text: #ffffff;
  --muted: #aab4d4;
  --accent: #ffcc33;
  --accent-dark: #c99a12;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0e1630;
  color: var(--text);
  font-family: 'Fredoka', system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }

/* ---------- Overlay screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  padding: 16px;
  overflow-y: auto;
  background: rgba(8, 12, 30, 0.3);
  z-index: 10;
}

.panel {
  margin: auto;
  width: min(460px, 100%);
  padding: 24px 20px;
  text-align: center;
  background: var(--panel);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}
.panel.small { width: min(380px, 100%); }

h1 {
  margin: 0;
  font-size: clamp(38px, 9vw, 54px);
  line-height: 1;
  font-weight: 700;
}
h1 span { color: var(--accent); margin-left: 6px; }

h2 { margin: 18px 0 8px; font-size: 18px; font-weight: 600; color: var(--muted); }
.big-title { font-size: 36px; color: var(--text); margin: 4px 0 14px; }

.tag { margin: 6px 0 0; color: var(--muted); }
.best { margin: 14px 0 4px; color: var(--muted); }
.best b { color: var(--accent); }
.help { margin: 8px 0 0; font-size: 13px; color: var(--muted); line-height: 1.5; }

/* ---------- Character cards ---------- */
.char-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 10px;
  margin: 8px 0 12px;
}
.card {
  position: relative;
  padding: 10px 6px 8px;
  color: inherit;
  font: inherit;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid transparent;
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}
.card:hover { background: rgba(255, 255, 255, 0.1); }
.card:active { transform: scale(0.96); }
.card.selected { border-color: var(--accent); background: rgba(255, 204, 51, 0.14); }
.card canvas { display: block; width: 64px; height: 64px; margin: 0 auto 6px; }
.card .name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .warn { font-size: 11px; color: #ff8a8a; }
.card .del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 15px;
  line-height: 21px;
}
.card .del:hover { background: #e63946; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  font-size: 17px;
  padding: 12px 20px;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  background: var(--accent);
  color: #2a1d00;
}
.btn.big {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 14px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 1px;
  box-shadow: 0 6px 0 var(--accent-dark);
}
.btn.big:active { transform: translateY(3px); box-shadow: 0 3px 0 var(--accent-dark); }
.btn.ghost {
  width: 100%;
  background: transparent;
  color: var(--text);
  border: 2px dashed rgba(255, 255, 255, 0.35);
}
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn.secondary { background: rgba(255, 255, 255, 0.12); color: var(--text); }
.btn.wide { display: block; width: 100%; margin-top: 12px; }

.row { display: flex; gap: 10px; margin-top: 14px; }
.row .btn { flex: 1; }

.icon-btn {
  pointer-events: auto;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 12px;
  background: rgba(10, 16, 40, 0.55);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}
.mute {
  position: fixed;
  left: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 20;
}

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.hud-left { position: absolute; left: 16px; top: max(12px, env(safe-area-inset-top)); }
.hud-right {
  position: absolute;
  right: 16px;
  top: max(12px, env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.hearts { display: flex; gap: 4px; font-size: 24px; line-height: 1; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.35)); }
.hearts .lost { opacity: 0.25; filter: grayscale(1); }
.score { font-size: 38px; font-weight: 700; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35); }
.mult {
  display: inline-block;
  margin-top: 2px;
  padding: 2px 10px;
  border-radius: 999px;
  background: #ff5a5f;
  font-weight: 700;
  font-size: 14px;
}
.coins {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px 4px 6px;
  border-radius: 999px;
  background: rgba(10, 16, 40, 0.55);
  font-size: 20px;
  font-weight: 600;
}
.coin-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff3b0, #ffcc33 45%, #e09a00);
}
.powers { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.power-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(10, 16, 40, 0.55);
  font-size: 14px;
}
.power-chip .bar { width: 50px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.2); overflow: hidden; }
.power-chip .bar i { display: block; height: 100%; background: #7df9ff; }

/* ---------- Game over ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0 4px; }
.stats div { padding: 10px 4px; border-radius: 14px; background: rgba(255, 255, 255, 0.07); }
.stats span { display: block; font-size: 13px; color: var(--muted); }
.stats b { font-size: 24px; }
.badge {
  display: inline-block;
  margin-bottom: 10px;
  padding: 4px 14px;
  border-radius: 999px;
  background: var(--accent);
  color: #2a1d00;
  font-weight: 700;
  animation: pop 0.6s ease-out;
}
@keyframes pop { 0% { transform: scale(0.4); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }

/* ---------- Crop editor ---------- */
#cropCanvas {
  display: block;
  width: min(280px, 72vw);
  height: auto;
  aspect-ratio: 1;
  margin: 10px auto;
  border-radius: 16px;
  background: #000;
  touch-action: none;
  cursor: grab;
}
#cropCanvas:active { cursor: grabbing; }
.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0;
  font-size: 15px;
  color: var(--muted);
  text-align: left;
}
.field input[type="range"] { flex: 1; accent-color: var(--accent); }
.field input[type="text"] {
  flex: 1;
  font: inherit;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  user-select: text;
  -webkit-user-select: text;
}
.field input[type="color"] { width: 48px; height: 32px; border: none; background: none; padding: 0; cursor: pointer; }
