/* ============================================================
   REALM DEFENDERS — Dark Fantasy Theme
   ============================================================ */

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

:root {
  --bg:       #0d1117;
  --bg2:      #161b22;
  --bg3:      #1c2333;
  --border:   #30363d;
  --text:     #c9d1d9;
  --text-dim: #8b949e;
  --gold:     #f39c12;
  --blue:     #2980b9;
  --green:    #27ae60;
  --red:      #c0392b;
  --purple:   #8e44ad;
  --accent:   #f39c12;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Courier New', monospace;
  font-size: 13px;
  overflow: hidden;
  user-select: none;
}

/* ─── SCROLLBAR ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ─── BUTTONS ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 6px 14px; border: 1px solid transparent;
  border-radius: 4px; cursor: pointer; font-family: inherit;
  font-size: 12px; font-weight: bold; transition: all 0.15s; gap: 4px;
}
.btn:active { transform: scale(0.97); }
.btn-primary  { background: var(--blue);   border-color: #1a5276; color: #fff; }
.btn-primary:hover  { background: #3498db; }
.btn-gold     { background: #8a6000;       border-color: var(--gold); color: var(--gold); }
.btn-gold:hover     { background: #a07000; }
.btn-danger   { background: #6b1e1e;       border-color: var(--red); color: #e88; }
.btn-danger:hover   { background: #7d2222; }
.btn-outline  { background: transparent;   border-color: var(--border); color: var(--text-dim); }
.btn-outline:hover  { border-color: var(--blue); color: var(--text); }
.btn-disabled { background: #2a2a2a; border-color: #333; color: #555; cursor: not-allowed; }
.btn-google   { background: #2d2d2d; border-color: #555; color: #ddd; width: 100%; }
.btn-google:hover { background: #3d3d3d; }
.btn-sm       { padding: 3px 8px; font-size: 11px; }
.btn-block    { display: flex; width: 100%; }
.mt4          { margin-top: 4px; }
.mt8          { margin-top: 8px; }

/* ─── LOGIN SCREEN ───────────────────────────────────────── */
#login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #1a2a3a 0%, #0d1117 100%);
  z-index: 1000;
}

.login-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.8);
  text-align: center;
}

.login-title {
  font-size: 24px; font-weight: bold;
  color: var(--gold); letter-spacing: 2px;
  text-shadow: 0 0 20px rgba(243,156,18,0.5);
  margin-bottom: 6px;
}

.login-sub { color: var(--text-dim); margin-bottom: 24px; font-size: 12px; }

.login-form { display: flex; flex-direction: column; gap: 10px; }

.login-form input {
  padding: 10px 14px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); font-family: inherit;
  font-size: 13px; outline: none;
}
.login-form input:focus { border-color: var(--blue); }

.login-btns { display: flex; gap: 8px; }
.login-btns .btn { flex: 1; padding: 10px; }

.auth-error { color: #e74c3c; font-size: 11px; min-height: 16px; }

/* ─── LOADING ─────────────────────────────────────────────── */
#loading-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,0.9);
  display: flex; align-items: center; justify-content: center;
}
.loading-inner { text-align: center; }
.loading-spinner {
  width: 40px; height: 40px; margin: 0 auto 16px;
  border: 3px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── GAME CONTAINER ─────────────────────────────────────── */
#game-container {
  display: flex; flex-direction: column;
  height: 100vh; width: 100vw; overflow: hidden;
}

/* ─── TOP HUD ────────────────────────────────────────────── */
#top-hud {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  padding: 6px 12px; height: 44px; flex-shrink: 0;
}

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

.hud-chip {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 12px; padding: 3px 10px; font-size: 12px;
}
.hud-chip b { color: var(--gold); }

.xp-bar-wrap { display: flex; align-items: center; gap: 6px; }
.xp-bar-bg {
  width: 120px; height: 8px; background: var(--bg3);
  border: 1px solid var(--border); border-radius: 4px; overflow: hidden;
}
.xp-bar-fill { height: 100%; background: var(--purple); border-radius: 4px; transition: width 0.3s; }
.xp-text { font-size: 10px; color: var(--text-dim); }

/* ─── MAIN AREA ──────────────────────────────────────────── */
#main-area {
  display: flex; flex: 1; min-height: 0; overflow: hidden;
}

#canvas-wrap {
  flex: 1; display: flex; align-items: flex-start;
  overflow: hidden; background: #0a0f14;
}

#game-canvas {
  display: block;
  max-width: 100%; max-height: 100%;
  image-rendering: pixelated;
  cursor: default;
}

/* ─── RIGHT PANEL ────────────────────────────────────────── */
#right-panel {
  width: 240px; flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--bg2); border-left: 1px solid var(--border);
  overflow-y: auto;
}

.panel {
  padding: 10px; border-bottom: 1px solid var(--border);
}
.panel-title {
  font-size: 11px; font-weight: bold; letter-spacing: 1px;
  color: var(--text-dim); margin-bottom: 8px; text-transform: uppercase;
}

/* Wave panel */
.wave-label {
  font-size: 28px; font-weight: bold; color: var(--gold);
  text-align: center; margin: 6px 0 2px;
  text-shadow: 0 0 10px rgba(243,156,18,0.4);
}
.wave-sublabel {
  text-align: center; font-size: 10px; color: var(--text-dim);
  margin-bottom: 10px; letter-spacing: 0.5px;
}
.game-complete-msg {
  text-align: center; padding: 10px 6px; background: #1a1200;
  border: 1px solid var(--gold); border-radius: 6px; margin-bottom: 8px;
  color: var(--gold); font-size: 13px; font-weight: bold; line-height: 1.6;
}
#wave-controls { display: flex; flex-direction: column; gap: 6px; }
.wave-running-text { color: var(--text-dim); font-size: 11px; margin-bottom: 6px; }
.result-banner { text-align: center; padding: 8px 0; font-size: 15px; font-weight: bold; }
.result-won  { color: var(--green); }
.result-lost { color: var(--red); }

/* Char sidebar */
.char-card {
  display: flex; align-items: center; gap: 6px;
  padding: 6px; border-radius: 6px; margin-bottom: 6px;
  background: var(--bg3); border: 1px solid var(--border);
}
.char-card.on-field { border-color: #27ae60; }

.char-icon {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: bold; font-size: 14px; flex-shrink: 0;
  color: #fff;
}
.char-info { flex: 1; min-width: 0; }
.char-name { font-size: 11px; font-weight: bold; display: block; }
.char-name small { font-weight: normal; color: var(--gold); }
.char-hp-bar {
  height: 3px; background: #333; border-radius: 2px; margin: 3px 0 1px;
}
.char-hp-bar div { height: 100%; background: var(--green); border-radius: 2px; }
.char-hp-text { font-size: 9px; color: var(--text-dim); }
.char-actions { display: flex; flex-direction: column; gap: 3px; }

/* ─── BOTTOM BAR ─────────────────────────────────────────── */
#bottom-bar {
  background: var(--bg2); border-top: 1px solid var(--border);
  padding: 4px 12px; font-size: 10px; color: var(--text-dim);
  flex-shrink: 0;
}

/* ─── MODALS ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,0.75);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(2px);
}

.modal-box {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden;
  display: flex; flex-direction: column;
  max-height: 90vh; min-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.8);
}
.modal-large { width: 880px; max-width: 96vw; }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--bg3);
  border-bottom: 1px solid var(--border);
  font-weight: bold; font-size: 14px;
}
.modal-close {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; font-size: 16px; padding: 2px 6px; border-radius: 4px;
}
.modal-close:hover { background: var(--bg2); color: var(--text); }

.modal-body { padding: 14px; overflow-y: auto; flex: 1; }

/* ─── INVENTORY MODAL ────────────────────────────────────── */
.inv-layout { display: flex; gap: 14px; }
.inv-left { width: 240px; flex-shrink: 0; }
.inv-right { flex: 1; }

.inv-char-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
.inv-tab {
  padding: 4px 8px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 4px; cursor: pointer; font-family: inherit; font-size: 11px; color: var(--text-dim);
}
.inv-tab.active { background: var(--bg); color: var(--text); }

.inv-equip-panel { background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; padding: 8px; }
.eq-header { font-weight: bold; font-size: 12px; margin-bottom: 8px; }
.eq-slot { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
.slot-empty { color: var(--text-dim); font-size: 11px; }
.eq-slot-label { color: var(--text-dim); font-size: 10px; min-width: 56px; flex-shrink: 0; }
.item-name { font-size: 11px; font-weight: bold; }
.item-stats { font-size: 10px; color: var(--text-dim); flex: 1; }

.inv-count-row { font-size: 11px; color: var(--text-dim); margin-bottom: 8px; }

.inv-grid {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px;
}

.inv-cell {
  aspect-ratio: 1; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 4px; display: flex; align-items: center; justify-content: center;
  position: relative; cursor: pointer; transition: border-color 0.15s;
}
.inv-cell:hover { border-color: var(--blue); }
.inv-cell:hover .item-tooltip { display: block; }

.item-icon {
  width: 100%; height: 100%; display: flex; align-items: center;
  justify-content: center; font-size: 14px; font-weight: bold;
  border-radius: 3px;
}
.item-icon.empty { color: #333; font-size: 10px; }
.item-icon.empty::before { content: '·'; }

.item-tooltip {
  display: none; position: absolute; bottom: calc(100% + 6px); left: 0;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px; min-width: 150px; z-index: 100;
  font-size: 11px; line-height: 1.5; white-space: nowrap;
  box-shadow: 0 8px 20px rgba(0,0,0,0.7);
}
.item-tooltip b { display: block; margin-bottom: 4px; }

/* ─── SKILL WHEEL ────────────────────────────────────────── */
.skill-layout { display: flex; gap: 14px; align-items: flex-start; }
.skill-canvas-wrap { flex-shrink: 0; }
#skill-canvas { display: block; border: 1px solid var(--border); border-radius: 8px; }
.skill-detail-wrap { flex: 1; }
.skill-detail { display: flex; flex-direction: column; gap: 8px; }

.skill-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px;
}
.skill-icon { font-size: 20px; flex-shrink: 0; width: 28px; text-align: center; }
.skill-info { flex: 1; }
.skill-info b { font-size: 12px; }
.skill-info p { color: var(--text-dim); font-size: 10px; margin-top: 2px; }
.skill-level { color: var(--gold); font-size: 10px; font-weight: normal; }

/* ─── CHARS MODAL ────────────────────────────────────────── */
.chars-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.char-detail-card {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 8px;
}

.char-detail-header {
  display: flex; align-items: center; gap: 10px;
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
  border-color: var(--border);
}
.char-detail-icon {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: bold; font-size: 16px; color: #fff; flex-shrink: 0;
}

.char-xp-bar {
  width: 100px; height: 4px; background: #333; border-radius: 2px; margin: 3px 0 1px;
}
.char-xp-bar div { height: 100%; background: var(--purple); border-radius: 2px; }

.char-stats-grid {
  display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 11px;
}
.char-stats-grid span:nth-child(odd) { color: var(--text-dim); }

.char-equip-summary { display: flex; flex-direction: column; gap: 3px; }
.ceq-slot { display: flex; gap: 6px; font-size: 11px; }
.ceq-label { color: var(--text-dim); width: 50px; flex-shrink: 0; }
.ceq-item { }

.char-card-footer { display: flex; gap: 6px; }

/* Unlock section */
.unlock-section { grid-column: 1 / -1; margin-top: 4px; }
.unlock-section h3 { margin-bottom: 8px; color: var(--text-dim); font-size: 12px; }
.unlock-card {
  display: flex; align-items: center; gap: 10px;
  padding: 8px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; margin-bottom: 6px;
}

/* ─── TOAST ──────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bg3); border: 1px solid var(--gold);
  color: var(--text); padding: 8px 20px; border-radius: 20px;
  font-size: 12px; z-index: 9999;
  opacity: 0; transition: opacity 0.2s, transform 0.2s;
  pointer-events: none; white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
