/* ===== COUNT RUSH KINGDOM — STYLES ===== */

@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@700;900&family=MedievalSharp&display=swap');

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

:root {
  --gold: #ffd700;
  --gold-dark: #b8860b;
  --green: #00e676;
  --green-dark: #00c853;
  --red: #ff1744;
  --red-dark: #c62828;
  --bg-dark: #0a0612;
  --bg-mid: #1a1028;
  --panel: rgba(10,6,18,0.92);
  --text-light: #f0e6c8;
  --text-gold: #ffd700;
  --shadow-glow: 0 0 24px rgba(255,215,0,0.5);
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #000;
  font-family: 'Cinzel', serif;
  color: var(--text-light);
}

#game-wrapper {
  position: relative;
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: #000;
}

#gameCanvas {
  display: block;
  touch-action: none;
  cursor: none;
}

/* ===== SCREENS ===== */
.screen {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 20;
}

.hidden { display: none !important; }

/* ===== START SCREEN ===== */
#start-screen {
  flex-direction: column;
  background: linear-gradient(180deg, #050218 0%, #0a0612 40%, #1a0a1a 100%);
}

#startCanvas {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
}

#start-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 20px;
}

#game-logo {
  text-align: center;
  text-shadow: 0 0 40px rgba(255,215,0,0.8), 0 0 80px rgba(255,150,0,0.4);
  animation: logoFloat 3s ease-in-out infinite;
}

@keyframes logoFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

#logo-crown {
  font-size: clamp(2.5rem, 6vw, 5rem);
  color: var(--gold);
  animation: crownSpin 6s ease-in-out infinite;
  display: inline-block;
}

@keyframes crownSpin {
  0%, 100% { transform: rotate(-5deg) scale(1); }
  50% { transform: rotate(5deg) scale(1.1); }
}

#logo-title {
  font-size: clamp(2.5rem, 7vw, 6rem);
  font-weight: 900;
  color: var(--gold);
  letter-spacing: 6px;
  line-height: 1;
  -webkit-text-stroke: 2px var(--gold-dark);
  text-shadow: 0 0 30px #ffd700, 0 4px 0 #7a5700, 0 0 80px rgba(255,215,0,0.6);
}

#logo-subtitle {
  font-size: clamp(1.4rem, 4vw, 3.2rem);
  font-weight: 700;
  letter-spacing: 12px;
  color: #e0c870;
  text-shadow: 0 0 20px rgba(255,200,0,0.5);
}

#logo-tagline {
  font-size: clamp(0.7rem, 1.8vw, 1rem);
  letter-spacing: 3px;
  color: rgba(240,230,200,0.7);
  margin-top: 6px;
  font-weight: 400;
}

/* ===== BUTTONS ===== */
.btn-primary {
  background: linear-gradient(135deg, #c8960c 0%, #ffd700 50%, #c8960c 100%);
  color: #1a0800;
  border: 3px solid #7a5700;
  padding: 14px 48px;
  font-size: clamp(0.9rem, 2.5vw, 1.3rem);
  font-family: 'Cinzel', serif;
  font-weight: 700;
  letter-spacing: 3px;
  border-radius: 6px;
  cursor: pointer;
  text-transform: uppercase;
  box-shadow: 0 4px 20px rgba(255,200,0,0.5), inset 0 1px 0 rgba(255,255,200,0.4);
  transition: all 0.2s;
  text-shadow: 0 1px 0 rgba(255,255,255,0.3);
}

.btn-primary:hover, .btn-primary:active {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 8px 30px rgba(255,200,0,0.7), inset 0 1px 0 rgba(255,255,200,0.4);
  background: linear-gradient(135deg, #daa520 0%, #ffe433 50%, #daa520 100%);
}

.btn-secondary {
  background: rgba(255,255,255,0.07);
  color: var(--text-light);
  border: 2px solid rgba(255,215,0,0.4);
  padding: 10px 36px;
  font-size: clamp(0.8rem, 2vw, 1rem);
  font-family: 'Cinzel', serif;
  font-weight: 700;
  letter-spacing: 2px;
  border-radius: 6px;
  cursor: pointer;
  text-transform: uppercase;
  transition: all 0.2s;
}

.btn-secondary:hover, .btn-secondary:active {
  background: rgba(255,215,0,0.12);
  border-color: rgba(255,215,0,0.7);
  transform: translateY(-1px);
}

.btn-icon {
  background: rgba(255,255,255,0.08);
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 50%;
  width: 44px; height: 44px;
  font-size: 1.3rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}

.btn-icon:hover { background: rgba(255,255,255,0.16); transform: scale(1.1); }

#start-bottom {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-top: 4px;
}

#highscore-display {
  font-size: 0.85rem;
  letter-spacing: 2px;
  color: var(--gold);
  opacity: 0.8;
}

/* ===== LEVEL SELECT ===== */
#level-select-screen {
  background: linear-gradient(180deg, #050218 0%, #0a0612 100%);
}

#level-select-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 20px;
  max-width: 700px;
  width: 100%;
}

#level-select-content h2 {
  font-size: clamp(1.4rem, 4vw, 2.4rem);
  color: var(--gold);
  letter-spacing: 6px;
  text-shadow: var(--shadow-glow);
}

#level-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  width: 100%;
}

.level-btn {
  background: var(--panel);
  border: 2px solid rgba(255,215,0,0.3);
  border-radius: 10px;
  padding: 12px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
  color: var(--text-light);
  font-family: 'Cinzel', serif;
}

.level-btn:hover:not(.locked) {
  border-color: var(--gold);
  background: rgba(255,215,0,0.1);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(255,215,0,0.3);
}

.level-btn.locked {
  opacity: 0.4;
  cursor: not-allowed;
}

.level-btn.completed {
  border-color: rgba(0,230,118,0.5);
}

.level-num {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gold);
}

.level-theme {
  font-size: 0.6rem;
  letter-spacing: 1px;
  color: rgba(240,230,200,0.6);
  text-align: center;
}

.level-stars {
  font-size: 0.75rem;
  letter-spacing: 1px;
}

.level-lock-icon {
  font-size: 1.1rem;
  color: rgba(255,255,255,0.3);
}

/* ===== HUD ===== */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 10px 16px 0;
  pointer-events: none;
}

#hud-left, #hud-right {
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: all;
}

#army-display {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0,0,0,0.6);
  border: 2px solid var(--gold);
  border-radius: 8px;
  padding: 4px 12px;
  box-shadow: 0 0 12px rgba(255,215,0,0.3);
}

#army-icon { font-size: 1.4rem; }

#army-count {
  font-size: clamp(1.4rem, 4vw, 2.2rem);
  font-weight: 900;
  color: var(--gold);
  text-shadow: 0 0 10px rgba(255,215,0,0.8);
  min-width: 50px;
  text-align: center;
  transition: transform 0.2s;
}

#army-count.pulse {
  animation: armyPulse 0.4s ease-out;
}

@keyframes armyPulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.4); }
  100% { transform: scale(1); }
}

#score-display {
  font-size: 0.7rem;
  letter-spacing: 2px;
  color: rgba(255,215,0,0.8);
  padding: 2px 8px;
  background: rgba(0,0,0,0.5);
  border-radius: 4px;
}

#hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
  margin: 0 12px;
}

#level-label {
  font-size: 0.75rem;
  letter-spacing: 3px;
  color: rgba(255,255,255,0.7);
  background: rgba(0,0,0,0.5);
  padding: 3px 10px;
  border-radius: 4px;
}

#progress-bar-wrap {
  width: 100%;
  height: 8px;
  background: rgba(0,0,0,0.5);
  border-radius: 4px;
  border: 1px solid rgba(255,215,0,0.3);
  overflow: hidden;
}

#progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green-dark), var(--green));
  border-radius: 4px;
  transition: width 0.3s ease;
  box-shadow: 0 0 8px rgba(0,230,118,0.6);
}

#hud-right {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

#pause-btn, #sound-btn {
  background: rgba(0,0,0,0.6);
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  width: 40px; height: 40px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
  color: white;
}

#pause-btn:hover, #sound-btn:hover {
  background: rgba(255,255,255,0.15);
}

/* ===== POPUP ===== */
#popup-msg {
  position: absolute;
  top: 25%;
  left: 50%;
  transform: translateX(-50%) translateY(-50%);
  font-size: clamp(1.2rem, 4vw, 2.4rem);
  font-weight: 900;
  color: var(--gold);
  text-shadow: 0 0 20px #ffd700, 0 2px 0 #000, 0 0 60px rgba(255,200,0,0.7);
  letter-spacing: 3px;
  pointer-events: none;
  z-index: 15;
  white-space: nowrap;
  opacity: 0;
  text-align: center;
}

#popup-msg.show {
  animation: popupAnim 1.5s ease-out forwards;
}

@keyframes popupAnim {
  0% { opacity: 0; transform: translateX(-50%) translateY(-40%) scale(0.6); }
  15% { opacity: 1; transform: translateX(-50%) translateY(-50%) scale(1.1); }
  30% { transform: translateX(-50%) translateY(-50%) scale(1); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-70%) scale(0.9); }
}

/* ===== TUTORIAL ===== */
#tutorial-overlay {
  position: absolute;
  inset: 0;
  z-index: 25;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
}

#tutorial-box {
  background: var(--panel);
  border: 2px solid var(--gold);
  border-radius: 16px;
  padding: 28px;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 0 40px rgba(255,215,0,0.3);
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

#tutorial-title {
  font-size: 1.4rem;
  letter-spacing: 4px;
  color: var(--gold);
  text-shadow: var(--shadow-glow);
}

#tutorial-steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.tut-step {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--text-light);
  line-height: 1.4;
}

.tut-icon {
  font-size: 1.4rem;
  min-width: 32px;
  text-align: center;
}

/* ===== PAUSE SCREEN ===== */
#pause-screen {
  background: rgba(5,2,24,0.95);
  z-index: 18;
}

#pause-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 24px;
  background: var(--panel);
  border: 2px solid rgba(255,215,0,0.4);
  border-radius: 16px;
  min-width: 280px;
  box-shadow: 0 0 40px rgba(255,215,0,0.2);
}

#pause-content h2 {
  color: var(--gold);
  font-size: 1.6rem;
  letter-spacing: 4px;
}

#pause-army-display {
  text-align: center;
}

#pause-army-label {
  font-size: 0.7rem;
  letter-spacing: 3px;
  color: rgba(255,255,255,0.5);
  margin-bottom: 4px;
}

#pause-army-count {
  font-size: 2.5rem;
  font-weight: 900;
  color: var(--gold);
  text-shadow: 0 0 20px rgba(255,215,0,0.7);
}

#pause-army-canvas-wrap {
  margin-top: 8px;
}

/* ===== BATTLE SCREEN ===== */
#battle-screen {
  flex-direction: column;
  background: #000;
}

#battleCanvas {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
}

#battle-hud {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 16px 30px;
  background: linear-gradient(180deg, rgba(0,0,0,0.8) 0%, transparent 100%);
}

#battle-your-count, #battle-enemy-count {
  font-size: clamp(1.5rem, 5vw, 3rem);
  font-weight: 900;
  text-align: center;
  text-shadow: 0 0 20px currentColor;
}

#battle-your-count { color: var(--green); }
#battle-enemy-count { color: var(--red); }
#battle-your-count small, #battle-enemy-count small {
  display: block;
  font-size: 0.45em;
  letter-spacing: 3px;
  opacity: 0.8;
}

#battle-vs {
  font-size: clamp(1.2rem, 3vw, 2rem);
  color: var(--gold);
  letter-spacing: 4px;
  font-weight: 900;
  text-shadow: var(--shadow-glow);
}

#battle-result {
  position: absolute;
  bottom: 0;
  left: 0; right: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px;
  background: linear-gradient(0deg, rgba(0,0,0,0.95) 0%, rgba(0,0,0,0.6) 100%);
}

#battle-result-text {
  font-size: clamp(1.4rem, 4vw, 2.4rem);
  font-weight: 900;
  letter-spacing: 4px;
  text-align: center;
}

#battle-result-text.victory { color: var(--gold); text-shadow: 0 0 30px #ffd700, 0 0 80px rgba(255,215,0,0.5); }
#battle-result-text.defeat { color: var(--red); text-shadow: 0 0 30px #ff1744; }

#battle-stars {
  font-size: 1.8rem;
  letter-spacing: 4px;
  animation: starsPop 0.6s ease-out;
}

@keyframes starsPop {
  0% { transform: scale(0); opacity: 0; }
  60% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(1); }
}

#battle-score-display {
  font-size: 0.9rem;
  color: var(--gold);
  letter-spacing: 3px;
  opacity: 0.9;
}

/* ===== GAME OVER ===== */
#gameover-screen {
  background: rgba(10,0,0,0.97);
}

#gameover-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 32px;
  background: var(--panel);
  border: 2px solid var(--red-dark);
  border-radius: 16px;
  min-width: 280px;
  box-shadow: 0 0 40px rgba(255,0,0,0.2);
}

#gameover-icon { font-size: 3rem; animation: skull 2s ease-in-out infinite; }

@keyframes skull {
  0%, 100% { transform: rotate(-5deg); }
  50% { transform: rotate(5deg); }
}

#gameover-content h2 {
  color: var(--red);
  font-size: 1.6rem;
  letter-spacing: 3px;
  text-shadow: 0 0 20px rgba(255,0,0,0.6);
}

#gameover-msg {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.6);
  text-align: center;
  font-family: sans-serif;
}

#gameover-score {
  font-size: 1.2rem;
  color: var(--gold);
  letter-spacing: 3px;
}

#final-score { color: var(--gold); }

/* ===== SHAKE ANIMATION ===== */
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(-6px, -4px); }
  20% { transform: translate(6px, 4px); }
  30% { transform: translate(-8px, 2px); }
  40% { transform: translate(8px, -2px); }
  50% { transform: translate(-4px, 6px); }
  60% { transform: translate(4px, -6px); }
  70% { transform: translate(-6px, 2px); }
  80% { transform: translate(6px, -2px); }
  90% { transform: translate(-2px, 4px); }
}

#game-wrapper.shake {
  animation: shake 0.5s ease-out;
}

/* ===== MOBILE ===== */
@media (max-width: 600px) {
  #level-grid { grid-template-columns: repeat(3, 1fr); }
  #battle-hud { padding: 10px 16px; }
  #hud { padding: 6px 10px 0; }
  .btn-primary { padding: 12px 32px; }
  .btn-secondary { padding: 9px 24px; }
}

@media (max-width: 400px) {
  #level-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #000; }
::-webkit-scrollbar-thumb { background: rgba(255,215,0,0.3); border-radius: 3px; }
