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

:root {
  --header-h: 52px;
  --left-w:   160px;
  --side-w:   260px;

  --bg:        #0e0e11;
  --surface:   rgba(22,22,28,0.92);
  --surface-b: rgba(32,32,40,0.96);
  --border:    rgba(255,255,255,0.14);
  --border-s:  rgba(255,255,255,0.24);
  --text:      #f0f0f0;
  --text-dim:  rgba(255,255,255,0.45);
  --text-mid:  rgba(255,255,255,0.70);

  --accent1: #ff5370;
  --accent2: #ff8c5a;
  --accent: linear-gradient(135deg, var(--accent1), var(--accent2));
  --green: #3ddc84;

  --radius:   10px;
  --radius-l: 16px;
  --blur:     blur(18px) saturate(160%);
  --shadow:   0 8px 32px rgba(0,0,0,.55);
  --font: 'Inter', system-ui, sans-serif;
}

html, body {
  height: 100%; overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

/* ─── Canvas container ──────────────────────────────────────────────────────── */
#canvas-container {
  position: fixed; inset: 0;
  overflow: hidden; cursor: crosshair;
  background: #111;
}
#canvas-wrap {
  position: absolute;
  transform-origin: 0 0;
  will-change: transform;
}
#grid-canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}
#cursor-canvas {
  position: absolute; top: 0; left: 0;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  pointer-events: none; z-index: 2;
}

/* ─── Loading overlay ───────────────────────────────────────────────────────── */
#loading-overlay {
  position: fixed; inset: 0; z-index: 500;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  transition: opacity .5s ease, visibility .5s;
}
#loading-overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.loading-inner { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.loading-logo {
  font-size: 36px; font-weight: 700; letter-spacing: -1px;
  background: var(--accent); -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.loading-bar-wrap { width: 200px; height: 3px; background: rgba(255,255,255,.1); border-radius: 2px; overflow: hidden; }
#loading-bar {
  height: 100%; width: 0%; border-radius: 2px;
  background: var(--accent);
  animation: load-progress 1.8s cubic-bezier(.4,0,.2,1) forwards;
}
@keyframes load-progress { to { width: 85%; } }
.loading-text { color: var(--text-dim); font-size: 12px; }

/* ─── Badges flottants ──────────────────────────────────────────────────────── */
#coord-badge {
  position: absolute; bottom: 14px; left: calc(var(--left-w) + 18px);
  background: var(--surface); backdrop-filter: var(--blur);
  border: 1px solid var(--border);
  color: var(--text-mid); font-family: 'SF Mono','Consolas',monospace; font-size: 11px;
  padding: 5px 10px; border-radius: 8px;
  pointer-events: none; z-index: 10;
}
#users-badge {
  position: absolute; top: 18px; left: calc(var(--left-w) + 18px);
  background: var(--surface); backdrop-filter: var(--blur);
  border: 1px solid var(--border);
  padding: 5px 11px; border-radius: 20px;
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--text-mid); z-index: 10;
}
.pulse-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green);
  animation: pulse-anim 2s infinite;
}
@keyframes pulse-anim {
  0%   { box-shadow: 0 0 0 0   rgba(61,220,132,.4); }
  70%  { box-shadow: 0 0 0 8px rgba(61,220,132,0); }
  100% { box-shadow: 0 0 0 0   rgba(61,220,132,0); }
}

/* ─── Logo + boutons (dans left-panel) ──────────────────────────────────────── */
#logo { font-size: 17px; font-weight: 700; letter-spacing: -.5px; flex: 1; white-space: nowrap; }
.logo-r { background: var(--accent); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.logo-place { color: var(--text); }
#header-right { display: flex; align-items: center; gap: 2px; }
.hdr-btn {
  display: flex; align-items: center; gap: 5px;
  background: transparent; border: 1px solid transparent;
  color: var(--text-mid); border-radius: 8px;
  padding: 6px 10px; font-size: 12px; font-weight: 500; font-family: var(--font);
  cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.hdr-btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.hdr-btn:hover { background: var(--surface-b); border-color: var(--border); color: var(--text); }
.hdr-btn--icon span { display: none; }
.hdr-btn--icon { padding: 6px 8px; }
.hdr-btn[aria-pressed="true"] { background: var(--surface-b); border-color: var(--border); }

/* ─── Panneau gauche (pseudo + palette + cooldown) ──────────────────────────── */
#left-panel {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--left-w);
  background: rgba(14,14,17,.92); backdrop-filter: var(--blur);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center;
  gap: 0;
  padding: 14px 12px 20px;
  z-index: 80;
  overflow-y: auto;
}

#left-header {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; gap: 4px;
}

.input-wrap { position: relative; display: flex; align-items: center; width: 100%; }
.input-icon {
  position: absolute; left: 9px; width: 14px; height: 14px;
  color: var(--text-dim); pointer-events: none;
}
#username-input {
  width: 100%; padding: 7px 10px 7px 30px;
  background: var(--surface-b); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; font-size: 13px; font-family: var(--font);
  outline: none; transition: border-color .2s, background .2s;
}
#username-input::placeholder { color: var(--text-dim); }
#username-input:focus { border-color: var(--accent1); background: rgba(255,83,112,.07); }

.panel-sep {
  width: 100%; height: 1px;
  background: var(--border);
  margin: 14px 0;
  flex-shrink: 0;
}

/* ─── Palette (grille 4 colonnes) ───────────────────────────────────────────── */
#palette-inline {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  width: 100%;
}

.color-swatch {
  aspect-ratio: 1;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform .12s cubic-bezier(.34,1.56,.64,1), border-color .12s, box-shadow .12s;
  position: relative;
}
.color-swatch::after {
  content: '';
  position: absolute; inset: 0;
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.3);
}
.color-swatch:hover { transform: scale(1.15); z-index: 1; }
.color-swatch.selected {
  border-color: #fff;
  transform: scale(1.18);
  box-shadow: 0 4px 14px rgba(0,0,0,.5);
  z-index: 1;
}

/* ─── Cooldown circulaire ───────────────────────────────────────────────────── */
#cooldown-wrap {
  position: relative; width: 52px; height: 52px;
  flex-shrink: 0; cursor: default;
}
#cooldown-ring { width: 52px; height: 52px; transform: rotate(-90deg); }

.ring-bg   { fill: none; stroke: rgba(255,255,255,.1); stroke-width: 3; }
.ring-fill {
  fill: none; stroke: url(#ring-gradient); stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 113.1;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset .15s linear;
  opacity: 0;
}
.ring-ready {
  fill: none; stroke: var(--green); stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 113.1; stroke-dashoffset: 0;
  opacity: 1; transition: opacity .3s;
}
#cooldown-ring defs { display: block; }
#cooldown-label {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; color: var(--text-mid);
  pointer-events: none; transition: color .3s;
}
#cooldown-label.ready  { color: var(--green); font-size: 14px; }
#cooldown-label.active { color: var(--accent1); }

/* ─── Panneau droit (activité + classement) ─────────────────────────────────── */
#side-panel {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: var(--side-w);
  background: rgba(14,14,17,.92); backdrop-filter: var(--blur);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 80;
  transform: translateX(0);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
}
#side-panel.collapsed { transform: translateX(100%); }

#panel-tabs {
  display: flex; gap: 4px;
  padding: 14px 12px 0;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  flex: 1; padding: 8px 6px; background: transparent;
  border: none; border-bottom: 2px solid transparent;
  color: var(--text-dim); font-size: 12px; font-weight: 600;
  font-family: var(--font); cursor: pointer;
  transition: color .15s, border-color .15s;
  margin-bottom: -1px; letter-spacing: .3px;
}
.tab-btn.active { color: var(--text); border-bottom-color: var(--accent1); }
.tab-btn:hover:not(.active) { color: var(--text-mid); }

.tab-content { display: none; flex: 1; overflow-y: auto; padding: 10px; }
.tab-content.active { display: flex; flex-direction: column; gap: 4px; }

/* ─── Historique ────────────────────────────────────────────────────────────── */
#history-list { list-style: none; display: flex; flex-direction: column; gap: 3px; }
.history-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 8px;
  background: rgba(255,255,255,.03); border: 1px solid transparent;
  animation: slideIn .25s cubic-bezier(.4,0,.2,1);
  transition: background .15s, border-color .15s;
}
.history-item:hover { background: rgba(255,255,255,.06); border-color: var(--border); }
@keyframes slideIn {
  from { opacity: 0; transform: translateX(8px); }
  to   { opacity: 1; transform: none; }
}
.history-dot { width: 14px; height: 14px; border-radius: 4px; flex-shrink: 0; box-shadow: inset 0 0 0 1px rgba(0,0,0,.3); }
.history-info { flex: 1; min-width: 0; }
.history-name { font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-coord { font-size: 10px; color: var(--text-dim); font-family: 'SF Mono','Consolas',monospace; }
.history-coord-link { text-decoration: underline dotted; text-decoration-color: rgba(255,255,255,.2); }
.history-item:hover .history-coord-link { color: var(--text-mid); text-decoration-color: rgba(255,255,255,.4); }

/* ─── Discord auth ───────────────────────────────────────────────────────────── */
#discord-section { width: 100%; padding: 0 4px; }

.discord-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 8px 12px;
  background: #5865F2; color: #fff;
  border-radius: var(--radius); font-size: 12px; font-weight: 600;
  text-decoration: none; transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.discord-btn:hover { background: #4752c4; }

#discord-user {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px;
  background: rgba(88,101,242,.15);
  border: 1px solid rgba(88,101,242,.35);
  border-radius: var(--radius);
}
#discord-avatar {
  width: 24px; height: 24px;
  border-radius: 50%; object-fit: cover;
  flex-shrink: 0;
}
#discord-name {
  font-size: 12px; font-weight: 600; color: var(--text);
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#discord-logout {
  font-size: 11px; color: var(--text-dim); text-decoration: none;
  flex-shrink: 0; padding: 2px 4px; border-radius: 4px;
  transition: color .15s, background .15s;
}
#discord-logout:hover { color: var(--text); background: rgba(255,255,255,.1); }

/* Badge cooldown Discord (5s) */
.cooldown-discord-badge {
  font-size: 9px; color: #5865F2; font-weight: 700;
  background: rgba(88,101,242,.15); border: 1px solid rgba(88,101,242,.3);
  border-radius: 4px; padding: 1px 5px; margin-top: 4px; text-align: center;
  letter-spacing: .5px;
}

/* ─── Classement ────────────────────────────────────────────────────────────── */
#leaderboard-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.lb-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 8px;
  background: rgba(255,255,255,.03); border: 1px solid transparent;
  transition: background .15s, border-color .15s;
}
.lb-item:hover { background: rgba(255,255,255,.06); border-color: var(--border); }
.lb-item:nth-child(1) .lb-rank { color: #ffd700; }
.lb-item:nth-child(2) .lb-rank { color: #c0c0c0; }
.lb-item:nth-child(3) .lb-rank { color: #cd7f32; }
.lb-rank { font-size: 11px; font-weight: 700; width: 20px; text-align: center; color: var(--text-dim); }
.lb-name { flex: 1; font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.lb-bar-wrap { width: 40px; height: 3px; background: rgba(255,255,255,.1); border-radius: 2px; overflow: hidden; }
.lb-bar { height: 100%; background: var(--accent); border-radius: 2px; transition: width .5s ease; }
.lb-count { font-size: 11px; font-weight: 700; min-width: 28px; text-align: right; background: var(--accent); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }

/* ─── Tooltip pixel ─────────────────────────────────────────────────────────── */
#pixel-tooltip {
  position: fixed;
  background: rgba(14,14,17,.95); backdrop-filter: var(--blur);
  border: 1px solid var(--border);
  color: var(--text); font-size: 11px; font-weight: 500;
  padding: 5px 10px; border-radius: 8px;
  pointer-events: none; display: none; z-index: 300;
  white-space: nowrap; box-shadow: 0 4px 16px rgba(0,0,0,.4);
}

/* ─── Scrollbar ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.3); }

/* ─── Large screen ──────────────────────────────────────────────────────────── */
@media (min-width: 1600px) {
  :root { --left-w: 200px; --side-w: 320px; }
}
@media (min-width: 2200px) {
  :root { --left-w: 240px; --side-w: 380px; }
}

/* ─── Barre mobile bas ──────────────────────────────────────────────────────── */
#mobile-bar {
  display: none;
}

/* ─── Mobile ────────────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  :root { --left-w: 0px; --side-w: 0px; }

  /* Canvas avec marges visibles */
  #canvas-container {
    inset: 0;
    bottom: 56px;
    padding: 8px;
  }

  /* Panneaux en overlay plein écran */
  #left-panel {
    top: 0; left: 0; right: 0; bottom: 56px;
    width: 100%; height: auto;
    border-right: none;
    transform: translateY(100%);
    transition: transform .3s cubic-bezier(.4,0,.2,1);
    overflow-y: auto;
    z-index: 200;
  }
  #left-panel.open { transform: translateY(0); }

  #side-panel {
    top: 0; left: 0; right: 0; bottom: 56px;
    width: 100%;
    transform: translateY(100%);
    transition: transform .3s cubic-bezier(.4,0,.2,1);
    z-index: 200;
  }
  #side-panel.open { transform: translateY(0); }
  #side-panel.collapsed { transform: translateY(100%); }

  /* Barre du bas */
  #mobile-bar {
    display: flex;
    position: fixed; bottom: 0; left: 0; right: 0;
    height: 56px;
    background: rgba(14,14,17,.97); backdrop-filter: var(--blur);
    border-top: 1px solid var(--border);
    z-index: 300;
    align-items: center; justify-content: space-around;
    padding: 0 12px;
  }
  .mob-btn {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    background: none; border: none; color: var(--text-dim);
    font-size: 10px; font-family: var(--font); font-weight: 500;
    cursor: pointer; padding: 6px 16px; border-radius: 8px;
    transition: color .15s, background .15s;
  }
  .mob-btn svg { width: 20px; height: 20px; }
  .mob-btn.active { color: var(--accent1); }
  .mob-btn:hover { background: rgba(255,255,255,.06); }

  /* Cooldown ring dans la barre */
  #mobile-cooldown {
    display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px;
  }

  #coord-badge { bottom: 66px; left: 12px; }
  #users-badge { top: 12px; left: 12px; }

  #palette-inline { grid-template-columns: repeat(8, 1fr); }
}

/* ─── Toast notifications ───────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 9999; pointer-events: none;
}
.toast {
  padding: 10px 18px; border-radius: 10px; font-size: 13px; font-weight: 600;
  color: #fff; opacity: 0; transform: translateY(10px);
  transition: opacity .25s, transform .25s;
  pointer-events: none; white-space: nowrap; max-width: 380px;
  text-overflow: ellipsis; overflow: hidden;
  box-shadow: 0 4px 18px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-info      { background: #2c2c3a; border: 1px solid #444; }
.toast-success   { background: #1a472a; border: 1px solid #2ecc71; }
.toast-error     { background: #4a1010; border: 1px solid #e74c3c; }
.toast-warning   { background: #4a3600; border: 1px solid #f39c12; }
.toast-broadcast { background: #1a1a4a; border: 1px solid #5865F2; }

/* ─── Bannière maintenance ──────────────────────────────────────────────────── */
#maintenance-banner {
  display: none; position: fixed; top: 0; left: 0; right: 0;
  background: linear-gradient(90deg, #f39c12, #e67e22);
  color: #000; font-weight: 700; font-size: 13px;
  align-items: center; justify-content: center; gap: 8px;
  padding: 8px 16px; z-index: 1000;
  box-shadow: 0 2px 12px rgba(243,156,18,.4);
}
