/* ============================================================
   CALISTHENICS CONSTELLATION — Skyrim-inspired skill tree
   ============================================================ */

:root {
  --silver: #cfd8e3;
  --ice: #7fc7ff;
  --ice-deep: #3a9be0;
  --gold: #ffd27a;
  --gold-deep: #c9a227;
  --ember: #ff8a3c;
  --ember-deep: #e0541b;
  --bg-0: #03060e;
  --bg-1: #070c1a;
  --panel: rgba(8, 13, 26, 0.86);
  --panel-border: rgba(127, 199, 255, 0.28);
  --text: #d8e3f0;
  --text-dim: #8295ad;
  --font-display: 'Cinzel', serif;
  --font-body: 'Cormorant Garamond', serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 35%, #0a1428 0%, var(--bg-1) 45%, var(--bg-0) 100%);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  touch-action: none;
}

/* ---------- Background layers ---------- */
#bg-layers { position: fixed; inset: 0; z-index: 0; pointer-events: none; }

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

.bg-fog {
  position: absolute; inset: -20%;
  background-repeat: repeat;
  opacity: 0.5;
  mix-blend-mode: screen;
}
.fog-1 {
  background: radial-gradient(circle at 20% 30%, rgba(58,155,224,0.10), transparent 40%),
              radial-gradient(circle at 80% 60%, rgba(201,160,255,0.08), transparent 45%);
  animation: drift1 60s linear infinite alternate;
}
.fog-2 {
  background: radial-gradient(circle at 60% 20%, rgba(255,138,60,0.06), transparent 50%),
              radial-gradient(circle at 30% 80%, rgba(127,199,255,0.07), transparent 40%);
  animation: drift2 80s linear infinite alternate;
}
@keyframes drift1 { from { transform: translate3d(0,0,0) scale(1); } to { transform: translate3d(4%, -3%, 0) scale(1.1); } }
@keyframes drift2 { from { transform: translate3d(0,0,0) scale(1.05); } to { transform: translate3d(-3%, 4%, 0) scale(1); } }

.bg-vignette {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(0,0,0,0.55) 100%);
}

/* ---------- Main canvas ---------- */
#tree {
  position: fixed; inset: 0; z-index: 1;
  width: 100%; height: 100%;
  cursor: grab;
}
#tree.grabbing { cursor: grabbing; }

/* ---------- Top HUD ---------- */
#hud-top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  text-align: center; padding: 22px 16px 30px;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(3,6,14,0.85), transparent);
}
.title-block h1 {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(20px, 3.4vw, 38px);
  letter-spacing: 0.14em;
  background: linear-gradient(180deg, #fff 0%, var(--silver) 45%, var(--gold) 110%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  text-shadow: 0 0 26px rgba(127,199,255,0.25);
  display: inline-block; margin: 0 14px;
}
.rune-deco {
  font-family: var(--font-display);
  color: var(--ice); opacity: 0.6;
  font-size: clamp(16px, 2.4vw, 26px);
  text-shadow: 0 0 14px var(--ice-deep);
  vertical-align: middle;
}
.rune-deco.big { font-size: 44px; display: block; margin-bottom: 8px; }
.subtitle {
  font-style: italic; color: var(--text-dim);
  letter-spacing: 0.32em; text-transform: uppercase;
  font-size: clamp(9px, 1.2vw, 12px); margin-top: 6px;
}

/* ---------- Stats panel ---------- */
#hud-stats {
  position: fixed; top: 96px; left: 18px; z-index: 10;
  width: 230px; padding: 16px 18px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 40px rgba(0,0,0,0.6), inset 0 0 24px rgba(127,199,255,0.04);
}
#hud-stats::before, #hud-stats::after {
  content: ''; position: absolute; width: 12px; height: 12px;
  border: 1px solid var(--ice); opacity: 0.5;
}
#hud-stats::before { top: 4px; left: 4px; border-right: 0; border-bottom: 0; }
#hud-stats::after  { bottom: 4px; right: 4px; border-left: 0; border-top: 0; }
.stat { text-align: center; margin-bottom: 12px; }
.stat-value {
  font-family: var(--font-display); font-weight: 700;
  font-size: 34px; color: var(--gold);
  display: block; line-height: 1; text-shadow: 0 0 18px var(--gold-deep);
}
.stat-label {
  font-size: 11px; letter-spacing: 0.24em; text-transform: uppercase;
  color: var(--text-dim);
}
.stat-bar-wrap { display: flex; align-items: center; gap: 8px; }
.stat-bar {
  flex: 1; height: 8px; border-radius: 5px;
  background: rgba(127,199,255,0.1);
  border: 1px solid rgba(127,199,255,0.25); overflow: hidden;
}
.stat-bar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--ice-deep), var(--ice), var(--gold));
  box-shadow: 0 0 12px var(--ice); transition: width 0.7s cubic-bezier(.2,.8,.2,1);
}
.stat-pct { font-size: 12px; color: var(--silver); font-family: var(--font-display); min-width: 34px; text-align: right; }
.stat-secondary { text-align: center; margin-top: 8px; font-style: italic; color: var(--ice); font-size: 13px; opacity: 0.85; }

/* ---------- Branch legend ---------- */
#branch-legend {
  position: fixed; top: 96px; right: 18px; z-index: 10;
  width: 210px; padding: 12px 14px;
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 4px; backdrop-filter: blur(8px);
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}
.legend-item {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 6px; border-radius: 4px; cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}
.legend-item:hover { background: rgba(127,199,255,0.08); transform: translateX(2px); }
.legend-item.dimmed { opacity: 0.32; }
.legend-dot {
  width: 12px; height: 12px; border-radius: 50%;
  box-shadow: 0 0 10px currentColor; flex-shrink: 0;
}
.legend-name { font-size: 14px; letter-spacing: 0.04em; }
.legend-count { margin-left: auto; font-size: 11px; color: var(--text-dim); font-family: var(--font-display); }

/* ---------- Controls ---------- */
#controls {
  position: fixed; bottom: 22px; right: 18px; z-index: 10;
  display: flex; flex-direction: column; gap: 8px;
}
.ctrl-btn {
  width: 44px; height: 44px; border-radius: 4px;
  background: var(--panel); border: 1px solid var(--panel-border);
  color: var(--silver); font-size: 16px; cursor: pointer;
  backdrop-filter: blur(8px);
  transition: all 0.2s; display: grid; place-items: center;
}
.ctrl-btn:hover {
  color: var(--gold); border-color: var(--gold);
  box-shadow: 0 0 16px rgba(255,210,122,0.4); transform: translateY(-2px);
}
.ctrl-btn:active { transform: translateY(0); }

/* ---------- Detail panel ---------- */
#detail-panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 30;
  width: min(420px, 92vw); padding: 28px 26px 100px;
  background: linear-gradient(160deg, rgba(10,16,32,0.97), rgba(4,7,16,0.98));
  border-left: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  box-shadow: -20px 0 60px rgba(0,0,0,0.7);
  overflow-y: auto;
  transform: translateX(0); transition: transform 0.45s cubic-bezier(.16,1,.3,1);
}
#detail-panel.hidden { transform: translateX(105%); }
#detail-panel::-webkit-scrollbar { width: 6px; }
#detail-panel::-webkit-scrollbar-thumb { background: var(--ice-deep); border-radius: 3px; }

#detail-close {
  position: absolute; top: 16px; right: 16px;
  width: 34px; height: 34px; border-radius: 4px;
  background: transparent; border: 1px solid var(--panel-border);
  color: var(--text-dim); cursor: pointer; font-size: 15px; transition: all 0.2s;
}
#detail-close:hover { color: var(--ember); border-color: var(--ember); }

.detail-rune {
  font-family: var(--font-display); font-size: 50px; text-align: center;
  color: var(--ice); text-shadow: 0 0 26px currentColor; margin-bottom: 4px;
}
.detail-branch {
  display: block; text-align: center;
  font-size: 11px; letter-spacing: 0.3em; text-transform: uppercase; color: var(--text-dim);
}
#detail-name {
  font-family: var(--font-display); font-weight: 700;
  font-size: 26px; text-align: center; margin: 6px 0 10px;
  color: #fff; text-shadow: 0 0 24px rgba(127,199,255,0.35);
}
.detail-tier {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin-bottom: 16px; font-family: var(--font-display);
  font-size: 13px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--gold);
}
.tier-pips { display: inline-flex; gap: 4px; }
.tier-pips i { font-size: 9px; color: var(--gold); text-shadow: 0 0 8px var(--gold-deep); }
.tier-pips i.empty { color: rgba(255,210,122,0.18); text-shadow: none; }

.detail-desc {
  font-size: 17px; line-height: 1.5; color: var(--text);
  font-style: italic; text-align: center; margin-bottom: 22px;
  padding-bottom: 18px; border-bottom: 1px solid rgba(127,199,255,0.12);
}
.detail-section { margin-bottom: 18px; }
.detail-section h3 {
  font-family: var(--font-display); font-size: 12px; font-weight: 600;
  letter-spacing: 0.18em; text-transform: uppercase; color: var(--ice);
  margin-bottom: 8px; display: flex; align-items: center; gap: 8px;
}
.detail-section h3 i { color: var(--gold); }
.detail-section ul { list-style: none; }
.detail-section li {
  font-size: 16px; line-height: 1.45; padding: 4px 0 4px 20px; position: relative; color: var(--text);
}
.detail-section li::before {
  content: '\\2726'; position: absolute; left: 0; color: var(--ice-deep); font-size: 11px; top: 7px;
}
.detail-phase span { font-size: 16px; color: var(--gold); font-style: italic; }

.prereq-list li { cursor: pointer; transition: color 0.2s; }
.prereq-list li:hover { color: var(--gold); }
.prereq-list li.met::before { content: '\\f00c'; font-family: 'Font Awesome 6 Free'; font-weight: 900; color: #4ade80; }
.prereq-list li.unmet::before { content: '\\f023'; font-family: 'Font Awesome 6 Free'; font-weight: 900; color: var(--ember); }

.unlock-btn {
  position: absolute; bottom: 24px; left: 26px; right: 26px;
  padding: 14px; border-radius: 4px; cursor: pointer;
  font-family: var(--font-display); font-weight: 700; font-size: 14px;
  letter-spacing: 0.16em; text-transform: uppercase;
  background: linear-gradient(180deg, var(--gold), var(--gold-deep));
  color: #1a1306; border: 1px solid var(--gold);
  box-shadow: 0 0 26px rgba(255,210,122,0.45); transition: all 0.2s;
}
.unlock-btn:hover { box-shadow: 0 0 40px rgba(255,210,122,0.7); transform: translateY(-2px); }
.unlock-btn.locked {
  background: rgba(40,50,70,0.6); color: var(--text-dim);
  border-color: rgba(127,199,255,0.2); box-shadow: none; cursor: not-allowed;
}
.unlock-btn.unlocked {
  background: linear-gradient(180deg, rgba(74,222,128,0.25), rgba(20,80,40,0.4));
  color: #aef5c4; border-color: rgba(74,222,128,0.5); box-shadow: 0 0 22px rgba(74,222,128,0.3);
}
.locked-hint {
  position: absolute; bottom: 70px; left: 26px; right: 26px;
  text-align: center; font-size: 13px; font-style: italic; color: var(--ember);
}

/* ---------- Tooltip ---------- */
#tooltip {
  position: fixed; z-index: 40; pointer-events: none;
  padding: 8px 12px; border-radius: 4px;
  background: rgba(6,10,20,0.95); border: 1px solid var(--panel-border);
  font-family: var(--font-display); font-size: 13px; color: #fff;
  box-shadow: 0 6px 24px rgba(0,0,0,0.7); max-width: 220px;
  transition: opacity 0.15s;
}
#tooltip .tt-tier { display: block; font-size: 10px; letter-spacing: 0.2em; color: var(--gold); margin-top: 2px; }
#tooltip .tt-status { display: block; font-size: 11px; margin-top: 3px; font-style: italic; font-family: var(--font-body); }

/* ---------- Intro overlay ---------- */
#intro {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: radial-gradient(ellipse at center, rgba(7,12,26,0.96), rgba(3,6,14,0.99));
  backdrop-filter: blur(4px);
  transition: opacity 0.8s ease; text-align: center; padding: 20px;
}
#intro.gone { opacity: 0; pointer-events: none; }
.intro-inner { max-width: 560px; animation: introRise 1.2s cubic-bezier(.16,1,.3,1); }
@keyframes introRise { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }
.intro-inner h1 {
  font-family: var(--font-display); font-weight: 900;
  font-size: clamp(28px, 6vw, 56px); letter-spacing: 0.1em;
  background: linear-gradient(180deg, #fff, var(--silver) 50%, var(--gold));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  text-shadow: 0 0 40px rgba(127,199,255,0.3); margin-bottom: 18px;
}
.intro-inner p {
  font-size: 19px; line-height: 1.6; color: var(--text-dim);
  font-style: italic; margin-bottom: 30px;
}
#intro-enter {
  font-family: var(--font-display); font-weight: 700; font-size: 15px;
  letter-spacing: 0.2em; text-transform: uppercase;
  padding: 14px 40px; cursor: pointer; border-radius: 4px;
  background: transparent; color: var(--gold);
  border: 1px solid var(--gold);
  box-shadow: 0 0 30px rgba(255,210,122,0.25), inset 0 0 20px rgba(255,210,122,0.06);
  transition: all 0.3s;
}
#intro-enter:hover {
  background: rgba(255,210,122,0.12);
  box-shadow: 0 0 50px rgba(255,210,122,0.5), inset 0 0 30px rgba(255,210,122,0.12);
  transform: scale(1.04);
}
.intro-hint { display: block; margin-top: 26px; font-size: 13px; letter-spacing: 0.14em; color: var(--text-dim); opacity: 0.7; }

.hidden { display: none !important; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  #hud-stats { top: auto; bottom: 22px; left: 12px; width: 180px; padding: 12px; }
  #branch-legend { display: none; }
  #controls { bottom: 22px; right: 12px; }
  #hud-top { padding: 14px 12px 24px; }
  .title-block h1 { letter-spacing: 0.08em; }
}

/* toast */
#toast {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%) scale(0.8);
  z-index: 60; pointer-events: none; opacity: 0;
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(22px, 4vw, 40px); letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--gold); text-shadow: 0 0 40px var(--gold-deep), 0 0 80px var(--ember);
  transition: opacity 0.4s, transform 0.6s cubic-bezier(.16,1,.3,1);
}
#toast.show { opacity: 1; transform: translate(-50%,-50%) scale(1); }
