* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(180deg, #4cc9f0 0%, #b8f2ff 60%, #e9fff0 100%) fixed;
  color: #24204a;
  min-height: 100vh;
}
button {
  font: inherit; font-weight: bold; cursor: pointer;
  border: 3px solid #24204a; border-radius: 14px;
  background: #ffd166; color: #24204a;
  padding: 8px 16px; box-shadow: 0 4px 0 #24204a;
  transition: transform .08s, box-shadow .08s;
}
button:hover { background: #ffe08a; }
button:active { transform: translateY(3px); box-shadow: 0 1px 0 #24204a; }
button.big { font-size: 1.3rem; padding: 12px 26px; background: #06d6a0; }
button.big:hover { background: #3ee8b9; }

.title-bar { text-align: center; padding: 14px 10px 4px; }
.title-bar h1 {
  margin: 0; font-size: clamp(1.8rem, 4vw, 3rem); color: #fff; letter-spacing: 1px;
  text-shadow: 3px 3px 0 #3a0ca3, -1px -1px 0 #3a0ca3, 1px -1px 0 #3a0ca3, -1px 1px 0 #3a0ca3;
}
.title-bar h1 span { color: #ffd166; }
.tagline { margin: 4px 0 0; font-weight: bold; color: #3a0ca3; }

main { max-width: 1240px; margin: 0 auto; padding: 10px; }
.screen { display: none; }
.screen.active { display: block; }

.creator-wrap { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; }
.preview-col {
  flex: 0 0 420px; max-width: 100%;
  background: rgba(255,255,255,.85); border: 3px solid #24204a; border-radius: 20px; padding: 10px;
  position: sticky; top: 10px; text-align: center;
}
#preview { width: 100%; max-width: 400px; border-radius: 14px; border: 3px solid #24204a; background: #bde6ff; }
.name-field { display: block; font-weight: bold; margin: 8px 0 4px; }
.name-field input {
  font: inherit; font-size: 1.2rem; width: 70%; margin-left: 6px; padding: 6px 10px;
  border: 3px solid #24204a; border-radius: 12px; text-align: center;
}
.race-info { margin: 4px 0 8px; min-height: 1.4em; font-style: italic; }
.btn-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 8px 0; }
.start { width: 100%; margin-top: 4px; }
.saved-title { margin: 14px 0 6px; }
.saved-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.hero-card { position: relative; }
.hero-load { display: flex; flex-direction: column; align-items: center; padding: 4px 8px; background: #fff; font-size: .85rem; box-shadow: 0 3px 0 #24204a; }
.hero-del { position: absolute; top: -8px; right: -8px; padding: 0 7px; font-size: .8rem; border-radius: 50%; background: #ff4d6d; color: #fff; box-shadow: none; }
.muted { color: #6c6a8a; font-size: .9rem; }

.options-col { flex: 1 1 520px; min-width: 300px; }
.opt-group {
  background: rgba(255,255,255,.85); border: 3px solid #24204a; border-radius: 20px;
  padding: 6px 14px 12px; margin-bottom: 14px;
}
.opt-group h3 { margin: 6px 0; color: #7209b7; font-size: 1.3rem; }
.opt { padding: 8px 0; border-top: 2px dashed #d7d2f0; }
.opt:first-of-type { border-top: none; }
.opt-label { font-weight: bold; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 5px 12px; border-radius: 999px; background: #fff; box-shadow: 0 3px 0 #24204a; font-size: .95rem; }
.chip.selected { background: #7b5cff; color: #fff; }
.race-chips .chip { display: flex; flex-direction: column; align-items: center; border-radius: 16px; padding: 4px 8px; }
.race-chips .chip canvas { background: #e3f4ff; border-radius: 10px; }
.race-chips .chip.selected canvas { background: #fff; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.swatch { width: 30px; height: 30px; padding: 0; border-radius: 50%; box-shadow: 0 2px 0 #24204a; border-width: 2px; }
.swatch.selected { outline: 4px solid #7b5cff; outline-offset: 2px; }
.picker { display: inline-flex; align-items: center; gap: 4px; font-size: .9rem; font-weight: bold; cursor: pointer; }
.picker input { width: 40px; height: 32px; border: 2px solid #24204a; border-radius: 8px; padding: 0; cursor: pointer; background: #fff; }

.game-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.hint { font-weight: bold; color: #3a0ca3; }
.canvas-wrap { position: relative; max-width: 960px; margin: 0 auto; }
#gameCanvas { display: block; width: 100%; height: auto; border: 4px solid #24204a; border-radius: 16px; background: #9be38a; }
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(20,15,50,.45); border-radius: 16px; }
.overlay.hidden { display: none; }
.overlay-box {
  background: #fff; border: 4px solid #24204a; border-radius: 22px; padding: 18px 26px;
  max-width: 560px; text-align: center; box-shadow: 0 8px 0 #24204a;
}
.overlay-box h2 { margin: 0 0 8px; color: #7209b7; font-size: 1.9rem; }
.overlay-box p { margin: 6px 0; font-size: 1.1rem; }

.touch { display: flex; justify-content: space-between; align-items: center; max-width: 960px; margin: 12px auto 0; padding: 0 10px; user-select: none; touch-action: none; }
.dpad { display: grid; grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(3, 64px); gap: 4px; }
.dpad button { font-size: 1.5rem; padding: 0; touch-action: none; }
.dpad .up { grid-column: 2; grid-row: 1; }
.dpad .left { grid-column: 1; grid-row: 2; }
.dpad .right { grid-column: 3; grid-row: 2; }
.dpad .down { grid-column: 2; grid-row: 3; }
.dpad button.down { }
.zap { width: 120px; height: 120px; border-radius: 50%; font-size: 1.6rem; background: #ff70a6; touch-action: none; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(120px);
  background: #24204a; color: #fff; padding: 10px 20px; border-radius: 999px; font-weight: bold;
  transition: transform .25s; pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }

@media (max-width: 900px) {
  .preview-col { position: static; flex-basis: 100%; }
}
