:root {
  --bg: #0A0A12;
  --bg-panel: rgba(20, 20, 31, 0.82);
  --bg-panel-solid: #14141F;
  --bg-panel-2: rgba(27, 27, 41, 0.92);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #F3EFE6;
  --text-dim: #A9A6B8;
  --ember: #FF7A3D;
  --ember-dim: #C75A28;
  --jade: #2DD4A7;
  --jade-dim: #1F9878;
  --gold: #F4C95D;
  --danger: #FF4757;
  --shadow: rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%; width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Inter, system-ui, -apple-system, sans-serif;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
}

#app { position: fixed; inset: 0; }
.screen { position: absolute; inset: 0; display: none; }
.screen.active { display: block; }

.wordmark {
  font-weight: 900;
  letter-spacing: 4px;
  background: linear-gradient(90deg, var(--ember), var(--gold));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.wordmark .slash { color: var(--jade); -webkit-text-fill-color: var(--jade); }
.tagline { color: var(--text-dim); letter-spacing: 3px; font-size: 11px; text-transform: uppercase; }

button { font-family: inherit; }

/* ===== Shared: preview backdrop ===== */
.scene-backdrop { position: absolute; inset: 0; }
.scene-backdrop canvas { width: 100%; height: 100%; display: block; }
.backdrop-veil {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(10,10,18,0.35) 0%, rgba(10,10,18,0.55) 55%, rgba(10,10,18,0.92) 100%);
  pointer-events: none;
}

/* ===== MAIN MENU ===== */
#screen-menu .menu-frame {
  position: relative; z-index: 2; height: 100%;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 28px 40px;
}
.menu-top { display: flex; justify-content: space-between; align-items: flex-start; }
.menu-logo .wordmark { font-size: 34px; }
.menu-logo .tagline { margin-top: 2px; }

.profile-chip {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-panel); border: 1px solid var(--border-strong);
  border-radius: 999px; padding: 6px 16px 6px 6px; cursor: pointer;
  backdrop-filter: blur(8px);
  transition: border-color .15s, transform .1s;
}
.profile-chip:hover { border-color: var(--ember); }
.profile-chip:active { transform: scale(0.97); }
.chip-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px; color: #14100b;
}
.chip-meta { display: flex; flex-direction: column; line-height: 1.2; text-align: left; }
.chip-name { font-size: 13px; font-weight: 700; }
.chip-rank { font-size: 10px; color: var(--gold); letter-spacing: 1px; text-transform: uppercase; }

.menu-nav { display: flex; flex-direction: column; gap: 4px; max-width: 320px; }
.menu-nav-item {
  display: flex; align-items: center; gap: 14px;
  background: transparent; border: none; color: var(--text-dim);
  padding: 12px 6px; font-size: 22px; font-weight: 800; letter-spacing: 1px;
  text-align: left; cursor: pointer; position: relative;
  transition: color .15s, transform .15s;
}
.menu-nav-item::before {
  content: ""; width: 4px; height: 0; background: var(--ember);
  transition: height .18s; border-radius: 2px;
}
.menu-nav-item:hover, .menu-nav-item:focus-visible { color: var(--text); transform: translateX(6px); }
.menu-nav-item:hover::before { height: 28px; }
.menu-nav-item.primary { color: var(--ember); font-size: 26px; }

.menu-bottom { display: flex; justify-content: space-between; align-items: flex-end; }
.server-status { font-size: 11px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--danger); }
.dot.ok { background: var(--jade); box-shadow: 0 0 8px var(--jade); }

/* ===== Generic panel / card / modal primitives ===== */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  backdrop-filter: blur(10px);
  box-shadow: 0 16px 50px var(--shadow);
}

.subscreen {
  position: absolute; inset: 0; z-index: 3;
  display: flex; flex-direction: column;
  padding: 24px 40px;
}
.subscreen-header { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.back-btn {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--bg-panel-2); border: 1px solid var(--border-strong);
  color: var(--text); cursor: pointer; font-size: 16px;
}
.subscreen-title { font-size: 22px; font-weight: 800; letter-spacing: 2px; }

.btn {
  border: none; border-radius: 10px; padding: 12px 20px;
  font-weight: 800; letter-spacing: 1px; font-size: 13px; cursor: pointer;
  transition: filter .15s, transform .1s;
}
.btn:active { transform: scale(0.97); }
.btn-ember { background: linear-gradient(90deg, var(--ember), var(--ember-dim)); color: #14100b; }
.btn-jade { background: linear-gradient(90deg, var(--jade), var(--jade-dim)); color: #06231a; }
.btn-ghost { background: var(--bg-panel-2); border: 1px solid var(--border-strong); color: var(--text); }
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; filter: none; }

/* ===== PROFILE screen ===== */
#screen-profile .profile-layout { position: relative; z-index: 2; flex: 1; display: flex; gap: 24px; overflow: hidden; }
.profile-hero { flex: 0 0 300px; padding: 24px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.hero-avatar {
  width: 110px; height: 110px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 38px; font-weight: 900; color: #14100b;
  box-shadow: 0 0 40px var(--shadow);
  border: 3px solid var(--gold);
}
.hero-name { font-size: 24px; font-weight: 800; margin-top: 14px; }
.hero-rank { color: var(--gold); font-weight: 800; letter-spacing: 2px; margin-top: 4px; }
.hero-percentile { color: var(--text-dim); font-size: 12px; margin-top: 2px; }
.hero-title-badge {
  margin-top: 12px; padding: 5px 14px; border-radius: 999px;
  border: 1px solid var(--jade); color: var(--jade); font-size: 11px; letter-spacing: 1px;
}

.profile-stats { flex: 1; padding: 24px; overflow-y: auto; }
.stat-row { margin-bottom: 16px; }
.stat-row-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 1px; }
.stat-row-label span:last-child { color: var(--text); font-weight: 700; }
.stat-bar-track { height: 8px; border-radius: 4px; background: var(--bg-panel-2); overflow: hidden; }
.stat-bar-fill { height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--jade), var(--gold)); }

.profile-highlights { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 24px; }
.highlight-card { background: var(--bg-panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.highlight-value { font-size: 24px; font-weight: 900; color: var(--gold); }
.highlight-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; margin-top: 2px; }

/* ===== CUSTOMIZE screen ===== */
#screen-customize .customize-layout { position: relative; z-index: 2; flex: 1; display: flex; gap: 20px; overflow: hidden; }
.customize-preview { flex: 1; border-radius: 14px; overflow: hidden; position: relative; }
.customize-controls { flex: 0 0 320px; padding: 20px; overflow-y: auto; }
.control-group { margin-bottom: 22px; }
.control-group-title { font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--text-dim); margin-bottom: 10px; }
.swatch-row { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer; border: 2px solid transparent;
  transition: transform .1s, border-color .15s;
}
.swatch:hover { transform: scale(1.1); }
.swatch.selected { border-color: #fff; }
.title-select { display: flex; flex-direction: column; gap: 8px; }
.title-option {
  background: var(--bg-panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-size: 13px; cursor: pointer; text-align: left; color: var(--text-dim);
}
.title-option.selected { border-color: var(--gold); color: var(--gold); }
.name-field {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--bg-panel-2); color: var(--text); font-size: 14px; margin-bottom: 4px;
}

/* ===== LOBBY screen ===== */
#screen-lobby .lobby-layout { position: relative; z-index: 2; flex: 1; display: flex; gap: 20px; overflow: hidden; }
.lobby-main { flex: 1; display: flex; flex-direction: column; padding: 20px; }
.lobby-code-row { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.lobby-code {
  font-size: 28px; font-weight: 900; letter-spacing: 6px; color: var(--gold);
  background: var(--bg-panel-2); border: 1px dashed var(--gold); border-radius: 10px; padding: 10px 18px;
}
.lobby-members { flex: 1; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.lobby-member-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px;
}
.lobby-member-name { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.host-tag { font-size: 10px; color: var(--gold); border: 1px solid var(--gold); border-radius: 6px; padding: 2px 6px; }
.ready-tag { font-size: 11px; font-weight: 800; letter-spacing: 1px; }
.ready-tag.ready { color: var(--jade); }
.ready-tag.notready { color: var(--text-dim); }
.lobby-actions { display: flex; gap: 10px; margin-top: 18px; }
.lobby-side { flex: 0 0 280px; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.join-code-input {
  width: 100%; padding: 12px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--bg-panel-2); color: var(--text); font-size: 20px; letter-spacing: 4px; text-align: center; text-transform: uppercase;
}

/* ===== Overlay-style small modal ===== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: rgba(6,6,12,0.7); backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }
.modal-card { width: 360px; padding: 28px 30px; text-align: center; }
.modal-card h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: 2px; }
.modal-card p { color: var(--text-dim); font-size: 13px; margin-bottom: 18px; }
.modal-card input { width: 100%; padding: 12px 14px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--bg-panel-2); color: var(--text); font-size: 14px; margin-bottom: 14px; }

/* ===== MATCH SCREEN + HUD ===== */
#screen-match { background: #000; }
#arena-canvas { width: 100%; height: 100%; display: block; }

#hud { position: absolute; inset: 0; z-index: 5; pointer-events: none; }
#hud a, #hud button, .clickable { pointer-events: auto; }

.hud-top {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 16px 20px;
}
.hud-logo-block { display: flex; align-items: center; gap: 10px; }
.hud-logo-block .wordmark { font-size: 18px; }
.hud-logo-block .tagline { font-size: 9px; }
.hud-profile-mini {
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 800; color: #14100b;
  border: 2px solid var(--gold);
}

.hud-center-panel {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--bg-panel); border: 1px solid var(--border-strong); border-radius: 12px;
  padding: 8px 26px; backdrop-filter: blur(8px);
}
.hud-phase-pill {
  padding: 3px 14px; border-radius: 999px; font-weight: 800; letter-spacing: 2px; font-size: 11px;
  border: 1px solid var(--border);
}
.phase-READ { background: rgba(244,201,93,0.14); color: var(--gold); border-color: var(--gold); }
.phase-SHIFT { background: rgba(45,212,167,0.14); color: var(--jade); border-color: var(--jade); }
.phase-CLASH { background: rgba(255,122,61,0.16); color: var(--ember); border-color: var(--ember); }
.hud-timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 22px; }
.hud-round { font-size: 10px; color: var(--text-dim); letter-spacing: 1px; }

.hud-top-right { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 10px; cursor: pointer;
  background: var(--bg-panel); border: 1px solid var(--border-strong); color: var(--text);
  display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.ping-badge { font-size: 11px; color: var(--jade); display: flex; align-items: center; gap: 5px; }

.hud-left { position: absolute; left: 16px; top: 90px; width: 210px; display: flex; flex-direction: column; gap: 10px; }
.minimap-panel { padding: 10px; }
#minimap-canvas { width: 100%; aspect-ratio: 1/1; display: block; border-radius: 8px; }
.objective-panel { padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start; }
.objective-icon { color: var(--gold); font-size: 18px; }
.objective-title { font-weight: 800; font-size: 12px; letter-spacing: 1px; }
.objective-desc { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

.hud-right { position: absolute; right: 16px; top: 90px; width: 220px; padding: 12px; max-height: 60vh; overflow: hidden; }
.hud-right .panel-title { font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--text-dim); margin-bottom: 8px; }
#hud-leaderboard { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
#hud-leaderboard li {
  display: flex; justify-content: space-between; align-items: center; gap: 6px;
  background: var(--bg-panel-2); border-radius: 8px; padding: 6px 10px; font-size: 12px;
}
#hud-leaderboard li.self { border: 1px solid var(--ember); }
#hud-leaderboard .rank { color: var(--gold); font-weight: 800; width: 18px; }

.echo-toast {
  position: absolute; right: 16px; top: calc(90px + 220px + 12px); width: 220px;
  padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start; opacity: 0; transition: opacity .3s;
}
.echo-toast.show { opacity: 1; }
.echo-toast-icon { color: var(--jade); font-size: 16px; }
.echo-toast-title { font-weight: 800; font-size: 11px; letter-spacing: 1px; color: var(--jade); }
.echo-toast-desc { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

.hud-bottom-left {
  position: absolute; left: 16px; bottom: 16px; display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
}
.status-avatar { width: 46px; height: 46px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-weight: 900; color: #14100b; font-size: 16px; }
.status-meta { min-width: 150px; }
.status-name { font-weight: 700; font-size: 13px; }
.status-bar-track { width: 160px; height: 8px; border-radius: 4px; background: var(--bg-panel-2); overflow: hidden; margin-top: 4px; }
.status-bar-fill { height: 100%; background: linear-gradient(90deg, var(--jade), #7fe9ff); border-radius: 4px; }
.status-level { font-size: 10px; color: var(--gold); margin-top: 2px; }

.hud-abilities { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; gap: 10px; }
.ability-hex { width: 58px; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; }
.ability-hex-icon {
  width: 56px; height: 56px; border-radius: 14px;
  background: var(--bg-panel); border: 1px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center; font-size: 22px;
  position: relative; overflow: hidden;
}
.ability-hex-icon .cd-overlay {
  position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.65);
  transition: height .1s linear;
}
.ability-hex-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }
.ability-hex-key { font-size: 9px; color: var(--text-dim); background: var(--bg-panel-2); border-radius: 4px; padding: 1px 5px; }
.ability-hex.cooling .ability-hex-icon { border-color: var(--border); }
.ability-hex.active .ability-hex-icon { border-color: var(--ember); box-shadow: 0 0 14px rgba(255,122,61,0.5); }

/* mobile controls */
.mobile-only { display: none; }
body.is-mobile .mobile-only { display: block; }
body.is-mobile .hud-abilities { display: none; }
body.is-mobile .hud-right { display: none; }

#joystick-zone { position: absolute; left: 20px; bottom: 20px; width: 130px; height: 130px; }
.joystick-base { width: 100%; height: 100%; border-radius: 50%; background: var(--bg-panel); border: 1px solid var(--border-strong); }
.joystick-nub {
  position: absolute; width: 54px; height: 54px; border-radius: 50%;
  background: radial-gradient(circle, var(--ember), var(--ember-dim));
  left: 38px; top: 38px; box-shadow: 0 0 16px rgba(255,122,61,0.6);
  touch-action: none;
}

#mobile-abilities { position: absolute; right: 16px; bottom: 16px; display: grid; grid-template-columns: repeat(2, 62px); gap: 10px; }
.mobile-ability-btn {
  width: 62px; height: 62px; border-radius: 50%;
  background: var(--bg-panel); border: 1px solid var(--border-strong);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 20px; color: var(--text); position: relative;
}
.mobile-ability-btn span { font-size: 8px; color: var(--text-dim); margin-top: 2px; }

#shift-flash {
  position: absolute; inset: 0; background: radial-gradient(circle, rgba(45,212,167,0.35), transparent 70%);
  opacity: 0; pointer-events: none; transition: opacity .4s;
}
#shift-flash.show { opacity: 1; }

/* ===== Match over ===== */
#match-over { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: rgba(10,10,18,0.85); }
#match-over.hidden { display: none; }
#match-over .card { width: 400px; padding: 28px 32px; }
#match-over h2 { color: var(--gold); margin-top: 0; letter-spacing: 2px; }
#match-over ol { padding-left: 20px; }
#match-over li { margin-bottom: 6px; }

.hidden { display: none !important; }

/* Loading */
#loading-veil {
  position: fixed; inset: 0; z-index: 200; background: var(--bg);
  display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 14px;
}
.loading-spinner {
  width: 46px; height: 46px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--ember);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 820px) {
  .hud-right, .hud-left { display: none; }
  .customize-controls, .lobby-side { display: none; }
  .profile-stats { padding: 14px; }
}
