* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: #fdeef8;
  color: #6b3570;
  font-family: 'Segoe UI', system-ui, sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100dvh;
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0)
           env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}

#game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: min(400px, 100%);
  padding: 0 10px;
}

/* HUD */
#hud {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 12px;
  background: #fff0f8;
  border-radius: 12px;
  border: 1.5px solid #f0b8d8;
}

.hud-label {
  font-size: 12px;
  font-weight: bold;
  color: #c070a8;
  text-transform: uppercase;
  letter-spacing: 1px;
}

#hp-section {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

#hp-bar-bg {
  flex: 1;
  height: 14px;
  background: #f8e0f0;
  border-radius: 7px;
  overflow: hidden;
  border: 1px solid #f0b8d8;
}

#hp-bar {
  height: 100%;
  width: 100%;
  background: #80d8a0;
  border-radius: 7px;
  transition: width 0.3s ease, background-color 0.3s ease;
}

#hp-text {
  font-size: 13px;
  font-weight: bold;
  width: 28px;
  text-align: right;
  color: #a06080;
}

#level-section {
  font-size: 13px;
  font-weight: bold;
  color: #a060b0;
  white-space: nowrap;
}

#solved-section {
  display: flex;
  align-items: center;
  gap: 6px;
}

#pips {
  display: flex;
  gap: 4px;
  align-items: center;
}

.pip {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #f8e8f4;
  border: 1.5px solid #e0b8d8;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.pip.filled {
  background: #f070b0;
  border-color: #f070b0;
  box-shadow: 0 0 5px #f070b066;
}

#level-display {
  color: #c060a0;
}

/* Canvas */
#game-canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
  border: 2px solid #f0b8d8;
  background: #fff0f8;
}

/* Input */
#input-section {
  display: flex;
  gap: 8px;
  width: 100%;
}

#answer-input {
  flex: 1;
  padding: 10px 14px;
  font-size: 16px;
  background: #fff5fb;
  color: #6b3570;
  border: 2px solid #e0a8d0;
  border-radius: 10px;
  outline: none;
  transition: border-color 0.2s;
  touch-action: manipulation;
  /* hide number input spinners */
  -moz-appearance: textfield;
}
#answer-input::-webkit-outer-spin-button,
#answer-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
}
#answer-input:focus {
  border-color: #d060a8;
}
#answer-input.wrong-flash {
  border-color: #e05080;
  background: #fff0f4;
  animation: wrong-shake 0.35s ease;
}

@keyframes wrong-shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-6px); }
  40%       { transform: translateX(6px); }
  60%       { transform: translateX(-4px); }
  80%       { transform: translateX(4px); }
}

#submit-btn {
  padding: 10px 20px;
  font-size: 16px;
  font-weight: bold;
  background: #f0b8d8;
  color: #7a3060;
  border: 2px solid #d060a8;
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.2s;
}
#submit-btn:hover {
  background: #e898c8;
}

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(253, 230, 248, 0.95);
  backdrop-filter: blur(4px);
  z-index: 10;
}

.overlay.hidden {
  display: none;
}

.overlay h1 {
  font-size: 48px;
  color: #c050a0;
  text-shadow: 0 0 18px #f090d088;
}

.overlay h2 {
  font-size: 36px;
  color: #9b48b8;
  text-shadow: 0 0 14px #c898e888;
}

.overlay p {
  font-size: 16px;
  color: #8b6090;
  max-width: 320px;
  text-align: center;
}

.overlay .hint {
  font-size: 14px;
  color: #b898b8;
}

.overlay button {
  margin-top: 8px;
  padding: 12px 32px;
  font-size: 18px;
  font-weight: bold;
  background: #f0d0f0;
  color: #7a3060;
  border: 2px solid #d080d0;
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.2s, transform 0.1s;
}
.overlay button:hover {
  background: #e8b8e8;
  transform: scale(1.04);
}

/* Difficulty buttons */
#diff-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 4px;
}

.diff-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 20px;
  min-width: 96px;
  font-weight: bold;
  border-radius: 12px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s, box-shadow 0.12s;
  margin-top: 0;
}
.diff-btn:hover { transform: scale(1.06); }

.diff-name { font-size: 15px; }
.diff-ops  { font-size: 13px; opacity: 0.85; letter-spacing: 2px; }

.diff-easy   { background: #d8f5e4; color: #2d8050; border: 2px solid #78c898; }
.diff-easy:hover   { box-shadow: 0 0 14px #78c89866; }
.diff-medium { background: #d8ebff; color: #2060a8; border: 2px solid #88b8f0; }
.diff-medium:hover { box-shadow: 0 0 14px #88b8f066; }
.diff-hard   { background: #ffd8e8; color: #a03060; border: 2px solid #f090b0; }
.diff-hard:hover   { box-shadow: 0 0 14px #f090b066; }

/* Game-over stats */
#game-over-stats {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
#game-over-stats p { font-size: 17px; }
#game-over-stats strong { color: #c050a0; }

#go-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}
#go-buttons button { margin-top: 0; }
#change-diff-btn {
  background: #f5e8f8;
  border-color: #d0a8d8;
  color: #9060a0;
  font-size: 15px;
  padding: 10px 20px;
}
#change-diff-btn:hover { background: #eed8f5; }

/* Small screens */
@media (max-width: 380px) {
  #game-container { gap: 8px; }
  #hud { gap: 10px; padding: 6px 10px; }
  .pip { width: 8px; height: 8px; }
  #pips { gap: 3px; }
}

