/* ══════════════════════════════════════════════
   BASE — Variables, reset, typography, layout
══════════════════════════════════════════════ */
:root {
  --bg:        #0a0c14;
  --bg2:       #111827;
  --bg3:       #1a2035;
  --panel:     #0d1525;
  --border:    #1e3a5f;
  --border2:   #2d5a8e;
  --accent:    #00d4ff;
  --accent2:   #0099cc;
  --gold:      #ffd700;
  --gold2:     #e6a800;
  --green:     #00ff88;
  --red:       #ff4466;
  --purple:    #b44fff;
  --orange:    #ff8c00;
  --text:      #c8e6ff;
  --text-dim:  #6b8fa8;
  --text-dark: #3a5570;

  --el-fire:      #ff4500;
  --el-water:     #1e90ff;
  --el-earth:     #8b6914;
  --el-air:       #b0d4e8;
  --el-electric:  #ffd700;
  --el-dark:      #9b30ff;
  --el-light:     #fffacd;
  --el-void:      #b06aff;
  --el-nature:    #32cd32;
  --el-ice:       #87ceeb;
  --el-metal:     #a8a8a8;
  --el-psychic:   #ff69b4;

  --topbar-h: 44px;
  --navbar-h: 58px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html {
  height: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  width: 100%; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'VT323', monospace;
  font-size: 18px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Scanlines overlay */
body::before {
  content: '';
  position: fixed; inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent, transparent 2px,
    rgba(0,0,0,0.10) 2px, rgba(0,0,0,0.10) 4px
  );
  pointer-events: none;
  z-index: 9999;
}

/* ── Typography helpers ── */
.px { font-family: 'Press Start 2P', monospace; }
.mono { font-family: 'Share Tech Mono', monospace; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* ══════════════════════════════════════════════
   TOPBAR
══════════════════════════════════════════════ */
#topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  height: var(--topbar-h);
  background: var(--panel);
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
  z-index: 100;
}
#topbar.show { display: flex; }
.topbar-logo {
  font-family: 'Press Start 2P';
  font-size: 10px;
  color: var(--accent);
  letter-spacing: 2px;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.ether-badge {
  display: flex; align-items: center; gap: 4px;
  background: rgba(255,215,0,0.1);
  border: 1px solid var(--gold2);
  border-radius: 3px;
  padding: 2px 8px;
  color: var(--gold);
  font-size: 15px;
}
.topbar-username { color: var(--accent); font-size: 13px; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ══════════════════════════════════════════════
   NAV BAR
══════════════════════════════════════════════ */
#navbar {
  display: none;
  background: var(--panel);
  border-top: 2px solid var(--border);
  flex-shrink: 0;
  padding-bottom: var(--safe-bottom);
}
#navbar.show { display: flex; }
.nav-btn {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  padding: 8px 2px;
  background: none; border: none; border-top: 3px solid transparent;
  color: var(--text-dim);
  font-family: 'Press Start 2P';
  cursor: pointer;
  transition: all 0.15s;
  min-height: var(--navbar-h);
}
.nav-icon { font-size: 20px; }
.nav-label { font-size: 6px; }
.nav-btn:hover { color: var(--text); background: rgba(255,255,255,0.03); }
.nav-btn.active { color: var(--accent); border-top-color: var(--accent); background: rgba(0,212,255,0.05); }

/* ══════════════════════════════════════════════
   SCREENS
══════════════════════════════════════════════ */
.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}
.screen.active { display: flex; }

.screen-header {
  padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.screen-title {
  font-family: 'Press Start 2P';
  font-size: 10px;
  color: var(--text);
}

/* ══════════════════════════════════════════════
   BUTTONS
══════════════════════════════════════════════ */
.btn-primary {
  width: 100%;
  background: var(--accent); color: var(--bg);
  border: none; font-family: 'Press Start 2P'; font-size: 10px;
  padding: 12px; cursor: pointer; letter-spacing: 1px;
  transition: all 0.15s;
}
.btn-primary:hover { background: #00eeff; transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: var(--bg2); border: 2px solid var(--border);
  color: var(--text-dim); font-family: 'Press Start 2P'; font-size: 8px;
  padding: 9px 12px; cursor: pointer; transition: all 0.15s;
}
.btn-secondary:hover { border-color: var(--border2); color: var(--text); }

.btn-create {
  background: linear-gradient(135deg, var(--accent), var(--purple));
  color: white; border: none; font-family: 'Press Start 2P'; font-size: 8px;
  padding: 9px 12px; cursor: pointer; transition: all 0.15s;
  white-space: nowrap;
}
.btn-create:hover { opacity: 0.9; transform: translateY(-1px); }

.btn-genesis {
  background: linear-gradient(135deg, var(--purple), var(--accent));
  color: white; border: none; font-family: 'Press Start 2P'; font-size: 8px;
  padding: 10px 16px; cursor: pointer; letter-spacing: 1px;
  transition: all 0.15s;
}
.btn-genesis:hover { opacity: 0.9; }
.btn-genesis:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-small {
  background: var(--bg2); border: 2px solid var(--border);
  color: var(--text-dim); font-family: 'Press Start 2P'; font-size: 7px;
  padding: 6px 10px; cursor: pointer; transition: all 0.15s;
}
.btn-small:hover { border-color: var(--accent); color: var(--accent); }

.btn-danger {
  background: none; border: 2px solid var(--red);
  color: var(--red); font-family: 'Press Start 2P'; font-size: 7px;
  padding: 6px 10px; cursor: pointer; transition: all 0.15s;
}
.btn-danger:hover { background: rgba(255,68,102,0.1); }

/* ══════════════════════════════════════════════
   FORMS
══════════════════════════════════════════════ */
.field-label { font-size: 13px; color: var(--text-dim); margin-bottom: 5px; display: block; letter-spacing: 1px; }
.field-hint   { color: var(--text-dark); font-size: 13px; margin-top: 4px; }
.field-input {
  width: 100%;
  background: var(--bg2); border: 2px solid var(--border);
  color: var(--text); font-family: 'VT323'; font-size: 18px;
  padding: 8px 12px; outline: none; transition: border-color 0.15s;
  margin-bottom: 12px;
}
.field-input:focus { border-color: var(--accent); }

/* ══════════════════════════════════════════════
   SECTION TITLES
══════════════════════════════════════════════ */
.section-title {
  font-family: 'Press Start 2P'; font-size: 8px;
  color: var(--text-dim); margin-bottom: 10px;
  padding-bottom: 5px; border-bottom: 1px solid var(--border);
}

/* ══════════════════════════════════════════════
   BADGES
══════════════════════════════════════════════ */
.badge {
  font-size: 12px; padding: 2px 7px;
  border: 1px solid var(--border2); color: var(--text-dim);
  font-family: 'Share Tech Mono';
}
.element-badge {
  font-size: 12px; padding: 1px 5px; border-radius: 2px;
  font-family: 'Share Tech Mono'; border: 1px solid currentColor;
}
.element-badge.fire    { color: var(--el-fire); }
.element-badge.water   { color: var(--el-water); }
.element-badge.earth   { color: var(--el-earth); }
.element-badge.air     { color: var(--el-air); }
.element-badge.electric{ color: var(--el-electric); }
.element-badge.dark    { color: var(--el-dark); }
.element-badge.light   { color: var(--el-light); }
.element-badge.void    { color: var(--el-void); }
.element-badge.nature  { color: var(--el-nature); }
.element-badge.ice     { color: var(--el-ice); }
.element-badge.metal   { color: var(--el-metal); }
.element-badge.psychic { color: var(--el-psychic); }

/* ══════════════════════════════════════════════
   TOAST
══════════════════════════════════════════════ */
#toast-container {
  position: fixed; bottom: calc(var(--navbar-h) + 8px + var(--safe-bottom));
  right: 12px;
  display: flex; flex-direction: column-reverse; gap: 6px;
  z-index: 9998; pointer-events: none;
}
.toast {
  background: var(--panel); border: 2px solid var(--border2);
  padding: 9px 13px; font-size: 15px;
  min-width: 200px; max-width: 300px;
  display: flex; align-items: center; gap: 7px;
  border-left: 4px solid var(--accent);
  animation: toastIn 0.2s ease;
}
.toast.success { border-left-color: var(--green); }
.toast.error   { border-left-color: var(--red); }
@keyframes toastIn { from { transform: translateX(110%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ══════════════════════════════════════════════
   UTILITY
══════════════════════════════════════════════ */
.hidden { display: none !important; }
.loading-state { display: flex; align-items: center; justify-content: center; height: 200px; }
.spinner {
  width: 30px; height: 30px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 12px; padding: 40px 20px;
  color: var(--text-dim); text-align: center;
}
.empty-state-icon { font-size: 40px; opacity: 0.5; }
.empty-state-title { font-family: 'Press Start 2P'; font-size: 9px; color: var(--text-dim); }
.empty-state-text { font-size: 15px; max-width: 280px; line-height: 1.5; }

.rarity { color: var(--gold2); font-size: 12px; letter-spacing: 1px; }

/* Responsive — hide labels on very small screens */
@media (max-width: 360px) {
  .nav-label { display: none; }
  .topbar-username { display: none; }
}

/* ── Audio Controls ── */
#audio-controls {
  position: fixed;
  bottom: calc(var(--navbar-h) + var(--safe-bottom) + 8px);
  left: 8px;
  display: none;  /* mostrado via JS quando logado */
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 3px;
  z-index: 200;
}
#audio-controls.show { display: flex; }
#btn-audio-toggle {
  background: none; border: none; cursor: pointer;
  font-size: 16px; padding: 2px;
}
#sfx-vol, #music-vol {
  width: 60px; accent-color: var(--accent);
}
@media (max-width: 380px) {
  #sfx-vol, #music-vol { width: 40px; }
}