:root {
  --bg: #fbfaf9;
  --surface: #ffffff;
  --border: #ebe7e3;
  --text: #2b2b2e;
  --muted: #8a8a90;
  --rose: #f3dfe6;
  --rose-strong: #c0607f;
  --violet: #e6def5;
  --violet-strong: #8a6fc0;
  --beige: #f1e9e0;
  --brown: #8b6f5c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(60,40,40,.04), 0 8px 24px rgba(60,40,40,.05);
  --ease: cubic-bezier(.22,.8,.3,1);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: Inter, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}
h1, h2 { font-weight: 600; letter-spacing: -.01em; margin: 0; }
h2 { font-size: 20px; }
.muted { color: var(--muted); }
.center { text-align: center; padding: 28px 0; }
.hidden { display: none !important; }

/* ---------- Boutons / inputs ---------- */
.btn {
  font: inherit; cursor: pointer;
  padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: background .2s, transform .15s, border-color .2s;
}
.btn:hover { background: var(--beige); }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--violet-strong); border-color: var(--violet-strong); color: #fff; width: 100%; }
.btn-primary:hover { background: #7a5eb0; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); padding: 6px 10px; }
input {
  font: inherit; color: var(--text);
  padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface);
  outline: none; transition: border-color .2s, box-shadow .2s;
}
input:focus { border-color: var(--violet-strong); box-shadow: 0 0 0 3px var(--violet); }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}

/* ---------- Login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(900px 400px at 20% -10%, var(--rose), transparent 60%),
              radial-gradient(800px 400px at 100% 110%, var(--violet), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 380px; padding: 36px 30px; text-align: center; animation: rise .6s var(--ease); }
.login-card h1 { margin: 14px 0 4px; font-size: 24px; }
.login-card .btn-primary { margin-top: 22px; }
.logo { width: 46px; height: 46px; margin: 0 auto; display: grid; place-items: center;
  border-radius: 14px; background: linear-gradient(135deg, var(--rose), var(--violet));
  color: var(--violet-strong); font-weight: 700; font-size: 20px; }
.logo.sm { width: 30px; height: 30px; border-radius: 9px; font-size: 14px; margin: 0; }
.divider { display: flex; align-items: center; gap: 12px; margin: 22px 0 16px; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.code-form { display: flex; gap: 8px; }
.code-form input { flex: 1; min-width: 0; }
.error-text { color: var(--rose-strong); min-height: 20px; margin: 12px 0 0; font-size: 14px; }

/* ---------- Topbar / onglets ---------- */
.topbar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px;
  padding: 14px 28px; background: rgba(255,255,255,.85); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.tabs { position: relative; display: flex; gap: 4px; background: var(--beige); padding: 4px; border-radius: 12px; }
.tab { position: relative; z-index: 1; font: inherit; cursor: pointer; border: 0; background: transparent;
  padding: 8px 18px; border-radius: 9px; color: var(--muted); transition: color .3s; }
.tab.active { color: var(--text); }
.tab.locked { display: none; }
.tab-indicator { position: absolute; top: 4px; bottom: 4px; left: 0; width: 0; background: var(--surface);
  border-radius: 9px; box-shadow: 0 1px 3px rgba(0,0,0,.08); transition: transform .45s var(--ease), width .45s var(--ease); }
.who { display: flex; align-items: center; justify-content: flex-end; gap: 10px; color: var(--muted); font-size: 14px; }
.badge { padding: 3px 10px; border-radius: 999px; font-size: 12px; background: var(--rose); color: var(--rose-strong); }
.badge.ro { background: var(--violet); color: var(--violet-strong); }

/* ---------- Panneaux (transition smooth) ---------- */
.panels { display: grid; max-width: 1200px; margin: 0 auto; padding: 28px; }
.panel {
  grid-area: 1 / 1; min-width: 0;
  opacity: 0; visibility: hidden; transform: translateY(14px) scale(.995);
  transition: opacity .4s var(--ease), transform .5s var(--ease), visibility 0s .4s;
  pointer-events: none;
}
.panel.active { opacity: 1; visibility: visible; transform: none; pointer-events: auto;
  transition: opacity .45s var(--ease) .05s, transform .5s var(--ease) .05s, visibility 0s; }
.panel-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }

.segmented { display: flex; gap: 2px; background: var(--beige); padding: 3px; border-radius: 10px; }
.segmented button { font: inherit; font-size: 14px; cursor: pointer; border: 0; background: transparent; color: var(--muted);
  padding: 6px 14px; border-radius: 8px; transition: background .25s, color .25s; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.segmented button:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- Stats / donut ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.stat-text { padding: 26px; display: flex; flex-direction: column; justify-content: center; gap: 10px; font-size: 17px; }
.stat-text b { font-size: 28px; font-weight: 600; color: var(--violet-strong); }
.donut-card { padding: 20px; display: flex; flex-wrap: wrap; align-items: center; gap: 24px; justify-content: center; }
#donut { width: 170px; height: 170px; flex: none; }
#donut svg { width: 100%; height: 100%; }
#donut circle.seg { transition: stroke-dasharray .8s var(--ease), stroke-dashoffset .8s var(--ease); }
.legend { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, auto); gap: 6px 26px; font-size: 14px; }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend span { color: var(--muted); margin-left: auto; padding-left: 14px; }

/* ---------- Tableau ---------- */
.table-card { overflow: auto; max-height: 56vh; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 18px; white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface); color: var(--muted); font-weight: 500; font-size: 13px; border-bottom: 1px solid var(--border); }
tbody tr { border-bottom: 1px solid var(--border); transition: background .2s; }
tbody tr:last-child { border-bottom: 0; }
tbody tr:hover { background: var(--bg); }
td.mono, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; color: var(--muted); }
.rank { padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; color: #fff; }

/* ---------- Split (users / erreurs) ---------- */
.split { display: grid; grid-template-columns: 300px 1fr; gap: 16px; height: 68vh; }
.side { display: flex; flex-direction: column; overflow: hidden; }
.search { margin: 12px; }
.list { list-style: none; margin: 0; padding: 0 8px 8px; overflow: auto; flex: 1; }
.list li { padding: 10px 12px; border-radius: 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px;
  transition: background .2s, transform .2s; }
.list li:hover { background: var(--beige); }
.list li.active { background: var(--rose); color: var(--rose-strong); }
.list li small { color: var(--muted); }
.detail { padding: 26px; overflow: auto; }
.detail h3 { margin: 0 0 4px; font-size: 20px; }
.detail .fade { animation: rise .45s var(--ease); }
.medal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-top: 18px; }
.medal { padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); display: grid; gap: 6px; }
.medal .row { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.info { background: var(--beige); border-radius: 12px; padding: 16px 18px; margin: 16px 0; color: #5a4a3e; }
pre.trace { background: #2b2b2e; color: #eee7e0; padding: 18px; border-radius: 12px; overflow: auto;
  font-size: 13px; line-height: 1.55; margin: 0; }

/* ---------- Toast & animations ---------- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); opacity: 0;
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px;
  pointer-events: none; transition: all .35s var(--ease); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .topbar { grid-template-columns: 1fr; justify-items: center; padding: 12px; }
  .who { justify-content: center; }
  .stats, .split { grid-template-columns: 1fr; }
  .split { height: auto; }
  .side { max-height: 260px; }
  .panels { padding: 16px; }
  .donut-card { flex-direction: column; }
}
