/* ============================================================
   SHADOW KEEP — style.css
   Dark gothic tower-defense UI
   ============================================================ */

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

/* ── Reset & vars ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #04060d;
  --surface:   #0c1018;
  --surface2:  #111720;
  --surface3:  #181f2c;
  --border:    #222c3e;
  --border-hi: #2e3f58;
  --gold:      #f0c040;
  --gold-dim:  #9a7a18;
  --teal:      #00b4d8;
  --teal-dim:  #0077a0;
  --red:       #e63946;
  --green:     #52b788;
  --text:      #dde4ee;
  --text-muted:#6e7f96;
  --sb-w:      260px;
  --topbar-h:  50px;
}

/* ── Body ─────────────────────────────────────────────────── */
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Rajdhani', sans-serif;
  font-size: 14px;
  overflow: hidden;
  user-select: none;
}

/* ── App shell ────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Main Menu ────────────────────────────────────────────── */
#main-menu {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

#menu-content {
  display: flex;
  flex-direction: column;
  gap: 30px;
  width: 100%;
  max-width: 600px;
  padding: 40px;
  background: var(--surface);
  border: 1px solid var(--border-hi);
  border-radius: 12px;
  box-shadow: 0 0 60px rgba(0,0,0,0.8), inset 0 1px 0 rgba(255,255,255,0.05);
  text-align: center;
}

.menu-title {
  font-family: 'Cinzel', serif;
  font-size: 42px;
  font-weight: 900;
  color: var(--gold);
  letter-spacing: 8px;
  text-shadow: 0 0 30px rgba(240,192,64,0.4);
  margin-bottom: 10px;
}

.menu-section h2 {
  font-family: 'Cinzel', serif;
  font-size: 16px;
  color: var(--teal);
  letter-spacing: 3px;
  margin-bottom: 15px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 15px;
}

.menu-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 15px;
  cursor: pointer;
  transition: all 0.2s;
}

.menu-card:hover {
  background: var(--surface3);
  border-color: var(--teal-dim);
  box-shadow: 0 0 15px rgba(0, 180, 216, 0.15);
}

.menu-card.active {
  background: var(--surface3);
  border-color: var(--gold);
  box-shadow: 0 0 20px rgba(240, 192, 64, 0.25);
}

.menu-card h3 {
  font-family: 'Cinzel', serif;
  font-size: 16px;
  color: var(--text);
  margin-bottom: 8px;
  letter-spacing: 1px;
}

.menu-card.active h3 {
  color: var(--gold);
}

.menu-card p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.menu-play-btn {
  margin-top: 20px;
  padding: 18px 40px;
  background: linear-gradient(150deg, #141a28, #0f1520);
  border: 1px solid var(--gold);
  border-radius: 8px;
  color: var(--gold);
  font-family: 'Cinzel', serif;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 4px;
  cursor: pointer;
  transition: all 0.2s;
  align-self: center;
}

.menu-play-btn:hover {
  background: linear-gradient(150deg, #1e2840, #192030);
  box-shadow: 0 0 30px rgba(240, 192, 64, 0.3);
  transform: translateY(-2px);
}

/* ── Top bar ──────────────────────────────────────────────── */
#topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 10;
}

#topbar::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(240,192,64,0.35), transparent);
}

#game-title {
  font-family: 'Cinzel', serif;
  font-size: 19px;
  font-weight: 900;
  letter-spacing: 5px;
  color: var(--gold);
  text-shadow: 0 0 24px rgba(240,192,64,0.5), 0 0 60px rgba(240,192,64,0.15);
}

/* Stats */
#stats-bar { display: flex; gap: 28px; align-items: center; }

.stat {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.stat-lbl {
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-val {
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}

.stat-val.gold  { color: var(--gold); text-shadow: 0 0 12px rgba(240,192,64,0.5); }
.stat-val.lives { color: var(--green); text-shadow: 0 0 12px rgba(82,183,136,0.4); }

.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Main layout ──────────────────────────────────────────── */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ── Canvas Area ──────────────────────────────────────────── */
#canvas-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #020408;
  overflow: hidden;
  padding: 10px;
}

#gameCanvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 960 / 640;
  object-fit: contain;
  cursor: crosshair;
  background: #070b14;
  image-rendering: pixelated;
  box-shadow: 0 0 40px rgba(0,0,0,0.5);
}

/* ── Sidebar ──────────────────────────────────────────────── */
#sidebar {
  width: var(--sb-w);
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}

.sb-section {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sb-divider {
  height: 1px;
  background: var(--border);
  flex-shrink: 0;
}

.sb-heading {
  font-family: 'Cinzel', serif;
  font-size: 10px;
  letter-spacing: 3px;
  color: var(--gold-dim);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

/* ── Tower cards ──────────────────────────────────────────── */
#tower-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.tower-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 6px;
  cursor: pointer;
  transition: border-color 0.13s, box-shadow 0.13s, background 0.13s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.tower-card:hover {
  border-color: var(--teal-dim);
  background: var(--surface3);
  box-shadow: 0 0 14px rgba(0,180,216,0.18);
}

.tower-card.active {
  border-color: var(--gold);
  background: var(--surface3);
  box-shadow: 0 0 20px rgba(240,192,64,0.28);
}

.tower-card.cant-afford {
  opacity: 0.38;
  pointer-events: none;
}

.tc-icon { font-size: 22px; line-height: 1; }
.tc-name { font-size: 10px; font-weight: 700; letter-spacing: 0.5px; text-align: center; color: var(--text); }
.tc-cost { font-size: 12px; font-weight: 700; color: var(--gold); }

/* ── Tower info box ───────────────────────────────────────── */
#tower-info-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  gap: 6px;
}

.info-title {
  font-family: 'Cinzel', serif;
  font-size: 13px;
  color: var(--teal);
  font-weight: 700;
}

.info-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.info-cost {
  font-size: 14px;
  font-weight: 700;
  color: var(--gold);
  min-height: 18px;
}

/* ── Placed tower info ────────────────────────────────────── */
#placed-info {
  display: none;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  margin-top: 6px;
}

.placed-name {
  font-family: 'Cinzel', serif;
  font-size: 12px;
  color: var(--gold);
  font-weight: 700;
}

.placed-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.placed-stats-grid span:nth-child(odd)  { color: var(--text-muted); font-size: 10px; letter-spacing: 1px; align-self: center; }
.placed-stats-grid span:nth-child(even) { color: var(--text); font-weight: 600; }

/* ── Branching Upgrades ───────────────────────────────────── */
.upgrade-paths {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.upg-btn {
  background: rgba(20, 25, 36, 0.8);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
  display: grid;
  grid-template-areas: 
    "name cost"
    "desc desc";
  grid-template-columns: 1fr auto;
  gap: 4px;
}

.upg-btn:hover {
  background: rgba(30, 40, 60, 0.9);
  border-color: var(--teal-dim);
  box-shadow: 0 0 15px rgba(0, 180, 216, 0.15);
  transform: translateY(-1px);
}

.upg-name {
  grid-area: name;
  font-family: 'Cinzel', serif;
  font-size: 11px;
  font-weight: 700;
  color: var(--gold);
}

.upg-cost {
  grid-area: cost;
  font-size: 11px;
  font-weight: 700;
  color: #ffb703;
}

.upg-desc {
  grid-area: desc;
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.3;
}

/* ── Placed btn (Sell) ────────────────────────────────────── */
.placed-btns {
  display: flex;
  margin-top: 4px;
}

.placed-btns button {
  width: 100%;
  padding: 8px 0;
  border-radius: 5px;
  font-family: 'Rajdhani', sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  border: 1px solid;
}

#sell-btn {
  background: rgba(230,57,70,0.1);
  border-color: rgba(230,57,70,0.5);
  color: var(--red);
}
#sell-btn:hover {
  background: rgba(230,57,70,0.25);
  box-shadow: 0 0 12px rgba(230,57,70,0.2);
}

/* ── Wave button ──────────────────────────────────────────── */
#start-wave-btn {
  width: 100%;
  padding: 11px;
  background: linear-gradient(150deg, #141a28, #0f1520);
  border: 1px solid var(--gold-dim);
  border-radius: 7px;
  color: var(--gold);
  font-family: 'Cinzel', serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s, border-color 0.2s;
}
#start-wave-btn:hover:not(:disabled) {
  background: linear-gradient(150deg, #1e2840, #192030);
  border-color: var(--gold);
  box-shadow: 0 0 20px rgba(240,192,64,0.22);
}
#start-wave-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.wave-prog {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  min-height: 14px;
  letter-spacing: 0.5px;
}

/* ── Tips ─────────────────────────────────────────────────── */
.tips p {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.6;
  padding-left: 8px;
  border-left: 2px solid var(--border);
}

/* ── Overlay ──────────────────────────────────────────────── */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 4, 10, 0.88);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
#overlay.hidden { display: none; }

#overlay-box {
  background: var(--surface);
  border: 1px solid var(--border-hi);
  border-radius: 14px;
  padding: 48px 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  box-shadow:
    0 0 80px rgba(240,192,64,0.08),
    inset 0 1px 0 rgba(255,255,255,0.06);
}

#overlay-title {
  font-family: 'Cinzel', serif;
  font-size: 38px;
  font-weight: 900;
  color: var(--gold);
  letter-spacing: 6px;
  text-shadow: 0 0 40px rgba(240,192,64,0.55);
}

#overlay-msg {
  font-size: 15px;
  color: var(--text-muted);
  text-align: center;
  max-width: 360px;
  line-height: 1.6;
}

#overlay-btn {
  padding: 13px 36px;
  background: linear-gradient(150deg, #181e2e, #10161f);
  border: 1px solid var(--gold);
  border-radius: 7px;
  color: var(--gold);
  font-family: 'Cinzel', serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 3px;
  cursor: pointer;
  transition: box-shadow 0.2s, background 0.2s;
  margin-top: 6px;
}
#overlay-btn:hover {
  background: linear-gradient(150deg, #222e48, #1a2438);
  box-shadow: 0 0 28px rgba(240,192,64,0.35);
}

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 5px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 3px; }

/* ── Canvas cursor states ─────────────────────────────────── */
#gameCanvas.placing { cursor: cell; }
