:root {
  --bg: #0d1017; --panel: #151a23; --panel-2: #1c222d; --panel-3: #232b38;
  --line: #262f3d; --line-2: #333f52;
  --fg: #e8edf4; --fg-2: #b9c4d4; --muted: #7f8da3;
  --accent: #5b9dff; --accent-soft: #1e3355;
  --hot: #f0655c; --cold: #4d90fd; --ok: #3fce6b; --warn: #f2b93c;
  --radius: 12px; --radius-sm: 8px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px -12px rgba(0,0,0,.5);
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f5f9; --panel: #fff; --panel-2: #f0f3f8; --panel-3: #e6ebf3;
    --line: #dde3ec; --line-2: #c8d1de;
    --fg: #131a26; --fg-2: #3b4859; --muted: #66748a;
    --accent-soft: #dfeaff;
    --shadow: 0 1px 2px rgba(16,24,40,.05), 0 8px 24px -14px rgba(16,24,40,.25);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 14px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1,h2,h3,h4 { margin: 0; font-weight: 600; letter-spacing: -.011em; }
h1 { font-size: 15px; }
h2 { font-size: 14px; }
h3 { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- barre superieure ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40; background: var(--panel);
  border-bottom: 1px solid var(--line); box-shadow: var(--shadow);
}
.topbar .line1 { display: flex; align-items: center; gap: 12px; padding: 9px 20px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 9px; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.spacer { flex: 1; }
.badge {
  font: 500 11.5px/1 var(--mono); padding: 6px 10px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line); white-space: nowrap; color: var(--fg-2);
}
.badge b { color: var(--fg); }
.badge.live { border-color: var(--ok); color: var(--ok); }
.badge.live b { color: var(--ok); }
.badge.off { border-color: var(--line-2); }
.pulse { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); margin-right: 5px; animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .25 } }

/* ---------- onglets ---------- */
.tabs { display: flex; gap: 2px; padding: 0 14px; overflow-x: auto; }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted);
  padding: 9px 13px; font: 500 13px/1 inherit; cursor: pointer; white-space: nowrap; border-radius: 0;
}
.tabs button:hover { color: var(--fg); }
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- disposition ---------- */
main { padding: 18px 20px 40px; max-width: 1720px; margin: 0 auto; }
.tabpane { display: none; }
.tabpane.on { display: grid; gap: 16px; grid-template-columns: repeat(12, 1fr); align-content: start; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px; min-width: 0; box-shadow: var(--shadow);
}
.card > .head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.c12 { grid-column: span 12 } .c9 { grid-column: span 9 } .c8 { grid-column: span 8 }
.c7 { grid-column: span 7 } .c6 { grid-column: span 6 } .c5 { grid-column: span 5 }
.c4 { grid-column: span 4 } .c3 { grid-column: span 3 }
@media (max-width: 1240px) { .c9,.c8,.c7,.c6,.c5,.c4,.c3 { grid-column: span 12 } }

/* ---------- controles ---------- */
button, select, input {
  font: inherit; color: var(--fg); background: var(--panel-2);
  border: 1px solid var(--line-2); border-radius: var(--radius-sm); padding: 6px 10px;
}
button { cursor: pointer; transition: border-color .12s, background .12s; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(1.08); }
button.danger:hover { border-color: var(--hot); color: var(--hot); }
button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
select { padding-right: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { padding: 5px 11px; font-size: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); min-width: 0; }
.field.inline { flex-direction: row; align-items: center; gap: 7px; }
.field input, .field select { width: 100%; }
.grid-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: 9px; }

/* ---------- indicateurs ---------- */
.kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 10px; }
.kpi > div { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; }
.kpi b { display: block; font: 600 19px/1.25 var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi span { font-size: 11px; color: var(--muted); display: block; margin-top: 2px; }
.kpi .pos b { color: var(--ok) } .kpi .neg b { color: var(--hot) }

/* ---------- matrice 4 x 7 ---------- */
.bulletin { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.bulletin .cell {
  aspect-ratio: 1.3; border-radius: var(--radius-sm); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font: 600 15px/1 var(--mono); color: #f4f8ff; text-shadow: 0 1px 2px rgba(0,0,0,.35);
}
.bulletin .cell .sub { font: 500 10px/1 var(--mono); opacity: .8; margin-top: 3px; }
.bulletin .cell.picked { outline: 2px solid var(--fg); outline-offset: 1.5px; }
.bulletin.mini .cell { aspect-ratio: 1.5; font-size: 11px; border-radius: 6px }
.bulletin.mini .cell .sub { display: none }
.bulletin.tiny { gap: 3px }
.bulletin.tiny .cell { aspect-ratio: 1.35; font-size: 9px; border-radius: 4px }
.bulletin.tiny .cell .sub { display: none }
.scale { display: flex; align-items: center; gap: 9px; font-size: 11px; color: var(--muted); margin-top: 12px }
.scale .ramp { height: 8px; flex: 1; border-radius: 4px }
.multi { display: grid; grid-template-columns: repeat(auto-fit, minmax(184px, 1fr)); gap: 12px }
.multi .item { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px }
.multi .item h4 { font: 600 11px/1 var(--mono); color: var(--muted); margin-bottom: 8px }

/* ---------- barres ---------- */
.bars { display: grid; gap: 4px }
.bar { display: grid; grid-template-columns: var(--label, 86px) 1fr var(--val, 56px); gap: 9px; align-items: center; font: 500 11.5px/1 var(--mono) }
.bar .track { height: 13px; background: var(--panel-2); border-radius: 4px; position: relative; overflow: hidden }
.bar .track i { position: absolute; top: 0; bottom: 0; border-radius: 3px }
.bar .track .mid { position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: var(--line-2) }
.bar em { font-style: normal; text-align: right; color: var(--fg-2) }

/* ---------- tableaux ---------- */
table { width: 100%; border-collapse: collapse; font: 400 12.5px/1.5 var(--mono); font-variant-numeric: tabular-nums }
th, td { padding: 6px 9px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap }
th { color: var(--muted); font-weight: 500; position: sticky; top: 0; background: var(--panel); z-index: 1; font-size: 11px; text-transform: uppercase; letter-spacing: .05em }
th:first-child, td:first-child { text-align: left }
tbody tr:hover { background: var(--panel-2) }
tbody tr.strong td { font-weight: 600 }
tbody tr.dim td { color: var(--muted) }
td.pos { color: var(--ok) } td.neg { color: var(--hot) }
.tablewrap { overflow: auto; border-radius: var(--radius-sm) }

/* ---------- paliers ---------- */
.tierlist { display: grid; gap: 8px }
.tier {
  display: grid; grid-template-columns: 54px 1fr 96px 96px; gap: 12px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px;
}
.tier.paying { border-color: var(--accent); background: linear-gradient(90deg, var(--accent-soft), var(--panel-2) 60%) }
.tier .n { font: 700 21px/1 var(--mono); text-align: center }
.tier .n small { display: block; font: 500 9px/1.4 system-ui; color: var(--muted); text-transform: uppercase; letter-spacing: .06em }
.tier .meter { height: 9px; background: var(--panel-3); border-radius: 5px; overflow: hidden; margin-bottom: 5px }
.tier .meter i { display: block; height: 100%; background: var(--accent); border-radius: 5px }
.tier .meter i.grey { background: var(--muted) }
.tier .lbl { font-size: 11px; color: var(--muted) }
.tier .val { text-align: right; font: 500 12.5px/1.35 var(--mono) }
.tier .val small { display: block; font: 400 10px/1.4 system-ui; color: var(--muted) }
.tier .val b { color: var(--ok) }
@media (max-width: 760px) { .tier { grid-template-columns: 46px 1fr; } .tier .val { text-align: left } }

/* ---------- grilles proposees ---------- */
.gridcards { display: grid; grid-template-columns: repeat(auto-fit, minmax(198px, 1fr)); gap: 12px }
.gridcard { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px }
.gridcard h4 { font: 600 10.5px/1 var(--mono); color: var(--muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .06em }
.gridcard .nums { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 9px }
.gridcard .nums b {
  width: 31px; height: 31px; border-radius: 8px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font: 600 13px/1 var(--mono)
}
.gridcard button { width: 100%; margin-top: 8px; font-size: 11.5px; padding: 5px }

/* ---------- tirages ---------- */
.draws { display: grid; gap: 5px; overflow: auto }
.draw { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; font: 400 11px/1 var(--mono) }
.draw .when { color: var(--muted); width: 92px; flex: none }
.draw i {
  font-style: normal; width: 22px; height: 22px; border-radius: 5px; display: grid; place-items: center;
  font-size: 10.5px; font-weight: 600
}
.draw i.b { background: var(--cold); color: #fff }
.draw i.y { background: var(--warn); color: #1a1206 }

/* ---------- courbe ---------- */
.chart svg { width: 100%; height: 170px; display: block }
.chart .zero { stroke: var(--line-2); stroke-width: 1; stroke-dasharray: 2 3 }
.chart .agent { fill: none; stroke: var(--accent); stroke-width: 1.8 }
.chart .rand { fill: none; stroke: var(--muted); stroke-width: 1.2; stroke-dasharray: 4 3 }
.legend { display: flex; gap: 14px; font-size: 11px; color: var(--muted); margin-top: 8px }
.legend i { display: inline-block; width: 14px; height: 2px; vertical-align: middle; margin-right: 5px }

/* ---------- divers ---------- */
.note { font-size: 12px; color: var(--muted); border-left: 2px solid var(--line-2); padding-left: 11px; margin-top: 12px; line-height: 1.6 }
.note b { color: var(--fg-2) }
.sliders { display: grid; gap: 8px }
.slider { display: grid; grid-template-columns: 148px 1fr 46px; gap: 10px; align-items: center }
.slider label { font-size: 12px; cursor: help; color: var(--fg-2) }
.slider input[type=range] { width: 100%; accent-color: var(--accent) }
.slider output { font: 500 12px/1 var(--mono); text-align: right; color: var(--muted) }
.hist { display: flex; gap: 2px; align-items: flex-end; height: 40px }
.hist i { flex: 1; background: var(--accent); border-radius: 2px 2px 0 0; min-height: 1px; opacity: .85 }
.log { font: 400 11px/1.6 var(--mono); color: var(--muted); overflow: auto }
.log div { border-bottom: 1px solid var(--line); padding: 3px 0 }
.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--accent); color: var(--fg);
  padding: 9px 16px; border-radius: 999px; box-shadow: var(--shadow); font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 60
}
.toast.show { opacity: 1 }

/* --- journee de jeu ------------------------------------------------------- */
.daybar { height: 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; overflow: hidden }
.daybar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--ok)); transition: width .4s }
#dayChart svg { height: 130px }
#dayChart rect { rx: 1.5 }
.c4 { grid-column: span 4 }
@media (max-width: 1240px) { .c4 { grid-column: span 12 } }

/* --- mode simple / avance -------------------------------------------------- */
body.mode-simple [data-adv] { display: none !important }
body:not(.mode-simple) [data-simple] { display: none !important }
.modeswitch { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 999px; padding: 2px }
.modeswitch button {
  border: 0; background: none; border-radius: 999px; padding: 4px 13px;
  font: 500 12px/1 inherit; color: var(--muted)
}
.modeswitch button[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 600 }
.modeswitch button:hover { color: var(--fg) }
.modeswitch button[aria-pressed="true"]:hover { color: #fff }
/* En mode simple, la lecture prime : moins de colonnes, plus d'air. */
body.mode-simple .kpi { grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)) }
body.mode-simple .kpi b { font-size: 21px }
body.mode-simple main { max-width: 1180px }

/* --- grille du prochain tirage -------------------------------------------- */
.nextgrid {
  background: linear-gradient(135deg, var(--accent-soft), var(--panel-2) 70%);
  border: 1px solid var(--line-2); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px;
}
.nextgrid.placed { border-color: var(--accent) }
.ng-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 11px }
.ng-state { font: 600 12px/1 system-ui; text-transform: uppercase; letter-spacing: .07em; color: var(--muted) }
.nextgrid.placed .ng-state { color: var(--accent) }
.ng-when { font: 500 13px/1 var(--mono); color: var(--fg-2) }
.ng-when b { color: var(--fg); font-variant-numeric: tabular-nums }
.ng-nums { display: flex; flex-wrap: wrap; gap: 8px }
.ng-nums b {
  width: 46px; height: 46px; border-radius: 11px; display: grid; place-items: center;
  font: 700 19px/1 var(--mono); background: var(--panel); border: 1px solid var(--line-2); color: var(--fg);
}
.nextgrid.placed .ng-nums b { background: var(--accent); border-color: var(--accent); color: #fff }
.ng-foot { font-size: 12px; color: var(--muted); margin-top: 10px }

/* --- smartphone ------------------------------------------------------------ */
@media (max-width: 720px) {
  .topbar .line1 { padding: 8px 12px; gap: 8px; row-gap: 6px }
  .topbar h1 { font-size: 14px }
  .badge { font-size: 11px; padding: 5px 8px }
  .topbar .spacer { flex-basis: 100%; height: 0 }
  .tabs { padding: 0 8px; -webkit-overflow-scrolling: touch; scrollbar-width: none }
  .tabs::-webkit-scrollbar { display: none }
  .tabs button { padding: 9px 11px; font-size: 12.5px }
  main { padding: 12px 12px 32px }
  .tabpane.on { gap: 12px }
  .card { padding: 12px; border-radius: 10px }
  .card > .head { gap: 8px; margin-bottom: 10px }
  .kpi { grid-template-columns: repeat(2, 1fr); gap: 8px }
  body.mode-simple .kpi { grid-template-columns: repeat(2, 1fr) }
  .kpi b, body.mode-simple .kpi b { font-size: 17px }
  .kpi span { font-size: 10.5px }
  .bulletin { gap: 4px }
  .bulletin .cell { font-size: 13px; border-radius: 7px }
  .bulletin .cell .sub { font-size: 9px }
  .ng-nums { gap: 6px }
  .ng-nums b { width: 40px; height: 40px; font-size: 17px; border-radius: 9px }
  .slider { grid-template-columns: 1fr; gap: 3px }
  .slider output { text-align: left }
  .bar { grid-template-columns: var(--label, 64px) 1fr var(--val, 46px); gap: 6px; font-size: 11px }
  .tier { grid-template-columns: 46px 1fr; row-gap: 8px }
  .tier .val { text-align: left }
  .gridcards { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 9px }
  .gridcard .nums b { width: 27px; height: 27px; font-size: 12px }
  .multi { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) }
  table { font-size: 11.5px }
  th, td { padding: 5px 6px }
  .draw .when { width: 100%; margin-bottom: 2px }
  .draw i { width: 24px; height: 24px }
  .chart svg { height: 140px }
  .toast { left: 12px; right: 12px; transform: none; text-align: center }
  .grid-fields { grid-template-columns: repeat(2, 1fr) }
}
@media (max-width: 400px) {
  .bulletin .cell { font-size: 11px }
  .bulletin .cell .sub { display: none }
  .ng-nums b { width: 36px; height: 36px; font-size: 15px }
  .kpi b, body.mode-simple .kpi b { font-size: 15px }
}
