/* style.css — Castle Siege */
:root {
  --gold: #e0b030;
  --gold-bright: #f4d870;
  --gold-dim: #b89020;
  --gold-deep: #8a6010;
  --panel: rgba(22, 18, 32, 0.92);
  --panel-light: rgba(38, 32, 52, 0.95);
  --panel-border: rgba(224, 176, 48, 0.22);
  --panel-border-bright: rgba(224, 176, 48, 0.45);
  --text: #ece4d4;
  --text-dim: #a89878;
  --text-faint: #786858;
  --danger: #d04840;
  --success: #4a9a4a;
  --accent: #d4a843;
  --bg-dark: #0e0a18;
  --bg-darker: #060410;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-glow: 0 0 40px rgba(208, 160, 32, 0.15);
}

html[data-theme="light"] {
  --panel: rgba(248, 244, 234, 0.95);
  --panel-light: rgba(255, 252, 244, 0.98);
  --panel-border: rgba(140, 100, 20, 0.25);
  --panel-border-bright: rgba(140, 100, 20, 0.45);
  --text: #2a2010;
  --text-dim: #6a5a3a;
  --text-faint: #9a8a6a;
  --bg-dark: #e8e0d0;
  --bg-darker: #d0c8b8;
  --shadow-glow: 0 0 40px rgba(180, 130, 30, 0.1);
}

html { color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-darker);
  color: var(--text);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#cv {
  position: absolute;
  inset: 0;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

/* HUD */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}
#hud.hidden { display: none; }

.hud-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 14px 18px;
  gap: 12px;
}

.hud-left, .hud-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.hud-stat {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  min-width: 56px;
  justify-content: center;
  box-shadow: 0 2px 12px rgba(0,0,0,0.25);
  transition: transform 0.2s, box-shadow 0.2s;
}

.hud-stat.gold { color: var(--gold-bright); }
.hud-stat.best { color: var(--text-dim); }
.hud-stat .hud-icon { font-size: 15px; opacity: 0.85; }
.hud-stat .hud-label {
  font-size: 10px;
  font-weight: 700;
  opacity: 0.5;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-right: 2px;
}

.hud-center {
  flex: 1;
  display: flex;
  justify-content: center;
  max-width: 400px;
}

.castle-bar {
  position: relative;
  width: 100%;
  max-width: 320px;
  height: 30px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 12px rgba(0,0,0,0.25);
}

.castle-bar-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 100%;
  background: linear-gradient(90deg, #4ade60, #22c55e);
  transition: width 0.35s cubic-bezier(0.4,0,0.2,1), background 0.3s ease;
}

.castle-bar-icon {
  position: absolute;
  left: 10px;
  font-size: 14px;
  z-index: 2;
  opacity: 0.6;
}

.castle-bar span {
  position: relative;
  z-index: 1;
  font-size: 13px;
  font-weight: 700;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.mute-btn {
  pointer-events: auto;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  width: 38px;
  height: 38px;
  font-size: 18px;
  color: var(--text);
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: opacity 0.2s, transform 0.15s;
  box-shadow: 0 2px 12px rgba(0,0,0,0.25);
}
.mute-btn:hover { opacity: 0.85; transform: scale(1.05); }
.mute-btn:active { transform: scale(0.95); }
.mute-btn.muted { opacity: 0.4; }

/* Boss bar */
.boss-bar {
  position: absolute;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  width: min(440px, 82%);
  text-align: center;
  pointer-events: none;
  animation: bossIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes bossIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-12px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.boss-bar.hidden { display: none; }
.boss-bar #bossName {
  display: block;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #ff5040;
  text-shadow: 0 0 14px rgba(255,60,60,0.6), 0 2px 4px rgba(0,0,0,0.8);
  margin-bottom: 5px;
}
.boss-bar-track {
  height: 12px;
  background: rgba(20,8,8,0.85);
  border: 1px solid rgba(255,60,60,0.4);
  border-radius: 7px;
  overflow: hidden;
  box-shadow: 0 0 20px rgba(255,40,40,0.2), inset 0 1px 2px rgba(0,0,0,0.5);
}
.boss-bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ff2020, #ff7040);
  transition: width 0.2s ease;
  box-shadow: 0 0 12px rgba(255,40,40,0.6);
}

/* Combo */
.combo {
  position: absolute;
  top: 115px;
  left: 50%;
  transform: translateX(-50%) scale(0.8);
  font-size: 26px;
  font-weight: 900;
  color: var(--gold-bright);
  text-shadow: 0 0 20px rgba(244,216,112,0.7), 0 2px 6px rgba(0,0,0,0.9);
  letter-spacing: 0.06em;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}
.combo.show { opacity: 1; transform: translateX(-50%) scale(1); }
.combo.hidden { display: none; }

/* Wave banner */
.wave-banner {
  position: absolute;
  top: 42%;
  left: 50%;
  transform: translateX(-50%) scale(0.9);
  font-size: clamp(28px, 6vw, 42px);
  font-weight: 900;
  color: var(--gold-bright);
  text-shadow: 0 0 30px rgba(244,216,112,0.5), 0 3px 10px rgba(0,0,0,0.95);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity 0.4s, transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
  white-space: nowrap;
}
.wave-banner.show { opacity: 1; transform: translateX(-50%) scale(1); }
.wave-banner.hidden { display: none; }

/* Charge meter */
.charge-meter {
  position: absolute;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  width: min(220px, 60%);
  height: 8px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  overflow: hidden;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
}
.charge-meter.hidden { display: none; }
.charge-meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #f4d870, #ff8030);
  transition: width 0.05s linear;
  box-shadow: 0 0 8px rgba(244,216,112,0.5);
}

/* Hint */
.hint {
  position: absolute;
  bottom: 46px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.05em;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
  pointer-events: none;
  opacity: 0.7;
  transition: opacity 0.6s;
  white-space: nowrap;
}
.hint.fade { opacity: 0; }

/* Screens */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(12,8,22,0.78) 0%, rgba(6,4,14,0.95) 100%);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 20;
  padding: 24px;
  animation: fadeIn 0.4s ease;
}
html[data-theme="light"] .screen {
  background: radial-gradient(ellipse at center, rgba(245,240,228,0.78) 0%, rgba(222,214,198,0.95) 100%);
}
.screen.hidden { display: none; }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.screen-inner {
  text-align: center;
  max-width: 560px;
  width: 100%;
}

/* Title */
.title-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 6px;
}

.title-ornament {
  flex: 0 1 60px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold-dim), var(--gold));
  border-radius: 2px;
}
.title-ornament.left { background: linear-gradient(90deg, transparent, var(--gold)); }
.title-ornament.right { background: linear-gradient(90deg, var(--gold), transparent); }

.game-title {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(38px, 9vw, 68px);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0;
  background: linear-gradient(180deg, #f8e090 0%, #d4a020 45%, #8a6010 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.6));
  line-height: 1.05;
  white-space: nowrap;
}

.game-subtitle {
  font-size: 15px;
  color: var(--text-dim);
  margin: 6px 0 30px;
  letter-spacing: 0.03em;
  font-weight: 500;
}

.how-to {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 22px 26px;
  margin-bottom: 28px;
  text-align: left;
  box-shadow: var(--shadow-glow);
}

.how-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 7px 0;
  font-size: 14px;
  color: var(--text);
}
.how-row + .how-row {
  border-top: 1px solid rgba(224,176,48,0.08);
}

.how-text { flex: 1; }

.how-key {
  display: inline-block;
  min-width: 74px;
  text-align: center;
  background: rgba(224,176,48,0.12);
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 700;
  color: var(--gold-bright);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  flex-shrink: 0;
}

.screen-foot {
  margin-top: 18px;
  font-size: 12px;
  color: var(--text-faint);
  letter-spacing: 0.05em;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 15px 40px;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.05em;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.15s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.2s, opacity 0.15s;
  font-family: inherit;
  pointer-events: auto;
  position: relative;
}

.btn-primary {
  background: linear-gradient(180deg, #f4d870 0%, #d4a020 50%, #b88810 100%);
  color: #1a1208;
  box-shadow: 0 6px 24px rgba(208,160,32,0.4), inset 0 1px 0 rgba(255,255,255,0.4), inset 0 -2px 4px rgba(0,0,0,0.15);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 32px rgba(208,160,32,0.55), inset 0 1px 0 rgba(255,255,255,0.5), inset 0 -2px 4px rgba(0,0,0,0.15);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 3px 12px rgba(208,160,32,0.3), inset 0 1px 0 rgba(255,255,255,0.2), inset 0 2px 6px rgba(0,0,0,0.2);
}

/* Shop */
.shop-inner { max-width: 600px; }

.shop-title {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(26px, 5.5vw, 38px);
  font-weight: 800;
  color: var(--gold-bright);
  margin: 0 0 4px;
  letter-spacing: 0.04em;
  text-shadow: 0 0 20px rgba(244,216,112,0.2);
}

.shop-gold {
  font-size: 18px;
  color: var(--gold-bright);
  margin: 0 0 22px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.shop-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}

.shop-item {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 14px 18px;
  cursor: pointer;
  transition: transform 0.15s cubic-bezier(0.34,1.56,0.64,1), border-color 0.15s, background 0.15s, box-shadow 0.15s;
  text-align: left;
  pointer-events: auto;
  position: relative;
  overflow: hidden;
}

.shop-item::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--gold);
  opacity: 0;
  transition: opacity 0.15s;
}

.shop-item:hover:not(.disabled) {
  transform: translateX(4px);
  border-color: var(--panel-border-bright);
  background: var(--panel-light);
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.shop-item:hover:not(.disabled)::before { opacity: 1; }

html[data-theme="light"] .shop-item:hover:not(.disabled) {
  background: rgba(255,252,244,0.98);
}

.shop-item:active:not(.disabled) {
  transform: translateX(2px) scale(0.99);
}

.shop-item.disabled { opacity: 0.4; cursor: not-allowed; }
.shop-item.maxed { opacity: 0.55; cursor: default; }

.shop-icon {
  font-size: 26px;
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(224,176,48,0.1);
  border: 1px solid var(--panel-border);
  border-radius: 11px;
  flex-shrink: 0;
  color: var(--gold-bright);
}

.shop-info { flex: 1; min-width: 0; }

.shop-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
  letter-spacing: 0.01em;
}

.shop-desc {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 3px;
}

.shop-level {
  font-size: 10px;
  color: var(--gold-dim);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.shop-cost {
  font-size: 17px;
  font-weight: 800;
  color: var(--gold-bright);
  white-space: nowrap;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.cost-coin { font-size: 13px; opacity: 0.8; }

/* Game over */
.end-crest {
  font-size: 48px;
  margin-bottom: 8px;
  opacity: 0.5;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.5));
}

.end-title {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(34px, 7.5vw, 54px);
  font-weight: 800;
  color: var(--danger);
  margin: 0 0 8px;
  letter-spacing: 0.04em;
  text-shadow: 0 0 28px rgba(208,72,64,0.4), 0 2px 8px rgba(0,0,0,0.6);
}

.end-text {
  font-size: 16px;
  color: var(--text-dim);
  margin: 0 0 8px;
}

.end-stat {
  font-size: 20px;
  color: var(--gold-bright);
  font-weight: 700;
  margin: 0 0 30px;
  letter-spacing: 0.02em;
}

/* Responsive */
@media (max-width: 480px) {
  .hud-top { padding: 8px 10px; gap: 6px; }
  .hud-stat { padding: 5px 10px; font-size: 15px; min-width: 44px; gap: 5px; }
  .hud-stat .hud-icon { font-size: 13px; }
  .hud-stat .hud-label { font-size: 9px; }
  .castle-bar { height: 26px; }
  .castle-bar span { font-size: 11px; }
  .castle-bar-icon { font-size: 12px; left: 8px; }
  .mute-btn { width: 34px; height: 34px; font-size: 15px; }
  .shop-item { padding: 11px 14px; gap: 12px; }
  .shop-icon { width: 42px; height: 42px; font-size: 22px; }
  .shop-name { font-size: 14px; }
  .shop-desc { font-size: 11px; }
  .shop-cost { font-size: 15px; }
  .btn { padding: 13px 30px; font-size: 15px; }
  .how-to { padding: 18px 20px; }
  .how-row { font-size: 13px; gap: 10px; }
  .how-key { min-width: 60px; font-size: 10px; padding: 4px 8px; }
  .combo { font-size: 22px; top: 92px; }
  .boss-bar { top: 56px; }
  .charge-meter { bottom: 22px; }
  .hint { bottom: 40px; font-size: 11px; }
  .title-ornament { flex: 0 1 30px; }
}

@media (max-width: 360px) {
  .hud-left, .hud-right { gap: 4px; }
  .hud-stat { padding: 4px 8px; font-size: 13px; }
  .game-title { font-size: clamp(30px, 10vw, 44px); }
  .title-ornament { display: none; }
}

