/* ============================================================
   VARIABLES & BASE
============================================================ */
:root{
  --bg:#0b1020; --fg:#e5e7eb; --muted:rgba(229,231,235,.75);
  --bd:rgba(255,255,255,.12);
  --accent:rgba(255,220,140,.95);
  --fz-base:14px;
  --fz-sm:12px;
  --gap:8px;
  --r:14px;
}
*{ box-sizing:border-box; }
html,body{
  height:100%; margin:0;
  background:var(--bg); color:var(--fg);
  font-family:system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
  font-size:var(--fz-base);
}

/* ============================================================
   LAYOUT
============================================================ */
#app{
  height:100%; display:flex; flex-direction:column;
  gap:var(--gap); padding:var(--gap);
}

/* ============================================================
   TOPBAR
============================================================ */
.topbar{
  background:linear-gradient(180deg,rgba(255,255,255,.07),rgba(255,255,255,.04));
  border:1px solid var(--bd); border-radius:var(--r);
  padding:8px 10px; display:flex; flex-direction:column; gap:6px;
}

/* Ligne toujours visible */
.topbar-main{
  display:flex; flex-wrap:wrap; gap:var(--gap); align-items:center;
}
/* Panneau options : toujours visible sur desktop */
.topbar-options{
  display:flex; flex-wrap:wrap; gap:var(--gap); align-items:center;
}
/* Bouton accordéon : caché sur desktop */
.btn-toggle-opts{ display:none; }

.group{ display:flex; flex-wrap:wrap; gap:var(--gap); align-items:center; }

/* ============================================================
   BOUTONS & PILLS
============================================================ */
button{
  appearance:none; border:1px solid var(--bd);
  background:rgba(255,255,255,.06); color:var(--fg);
  border-radius:999px; padding:6px 12px;
  cursor:pointer; font-weight:850; font-size:14px;
  min-height:34px; line-height:1.2;
  touch-action:manipulation;
  -webkit-tap-highlight-color:transparent;
  transition:background .12s;
}
button:disabled{ opacity:.5; cursor:not-allowed; }
button:active:not(:disabled){ background:rgba(255,255,255,.14); }

.pill{
  border:1px solid var(--bd); background:rgba(255,255,255,.04);
  border-radius:999px; padding:5px 12px;
  color:var(--muted); font-weight:780; font-size:13px;
  white-space:nowrap; min-height:30px;
  display:inline-flex; align-items:center; line-height:1.2;
}

/* Bouton accordéon */
.btn-toggle-opts{
  margin-left:auto; padding:5px 10px;
  font-size:15px; border-radius:10px;
  background:rgba(255,255,255,.08);
  transition:background .15s, transform .2s;
}
.btn-toggle-opts[aria-expanded="true"]{
  background:rgba(255,220,140,.18);
  border-color:rgba(255,220,140,.4);
  transform:rotate(90deg);
}

/* ============================================================
   MAIN
============================================================ */
.main{
  flex:1; display:grid;
  grid-template-columns:1fr 380px;
  gap:var(--gap); min-height:0;
}
.card{
  border:1px solid var(--bd); background:rgba(255,255,255,.05);
  border-radius:var(--r); padding:10px; min-height:0;
}

/* Zone canvas */
#wrapCanvas{
  position:relative; border:1px solid var(--bd);
  border-radius:var(--r); overflow:hidden;
  background:radial-gradient(1200px 600px at 30% 10%,
    rgba(255,255,255,.10),rgba(255,255,255,.02) 55%,rgba(0,0,0,.30) 100%);
  min-height:260px; touch-action:manipulation; user-select:none;
}
canvas{ display:block; width:100%; height:100%; }

#hint{
  margin-top:8px; color:var(--muted);
  line-height:1.4; font-size:12px;
}
#toast{
  position:absolute; left:10px; top:10px;
  padding:8px 12px; border-radius:12px;
  background:rgba(0,0,0,.65); border:1px solid rgba(255,255,255,.18);
  font-weight:900; font-size:14px; display:none;
  max-width:calc(100% - 20px); pointer-events:none;
}
#toast.show{ display:block; }

/* HUD droite */
#gridPills{
  display:flex; flex-wrap:wrap; gap:6px;
  justify-content:flex-end; padding-top:4px;
}
.chPill{
  border:1px solid rgba(255,255,255,.14);
  background:rgba(255,255,255,.05);
  border-radius:999px; padding:4px 9px;
  font-weight:900; color:rgba(255,255,255,.90);
  user-select:none; font-size:12px;
}
.chPill.active{
  border-color:rgba(255,235,180,.75);
  box-shadow:0 0 0 3px rgba(255,220,140,.18),0 0 18px rgba(255,220,140,.22);
  background:rgba(255,220,140,.10);
  color:rgba(255,245,220,.98);
}
.hudLine{
  display:flex; justify-content:space-between; gap:10px;
  padding:5px 0; border-bottom:1px solid rgba(255,255,255,.07);
  font-size:12px;
}
.hudLine:last-child{ border-bottom:0; }
.hudKey{ color:var(--muted); font-weight:850; }
.hudVal{ font-weight:900; text-align:right; }

/* ============================================================
   MODALES
============================================================ */
.modal{
  position:fixed; inset:0; display:none;
  align-items:center; justify-content:center;
  background:rgba(0,0,0,.60); z-index:9999; padding:14px;
}
.modal.show{ display:flex; }
.modal .cardModal{
  width:min(520px,96vw);
  background:rgba(10,14,26,.98);
  border:1px solid rgba(255,255,255,.16);
  border-radius:16px; padding:18px;
  display:grid; gap:12px;
  box-shadow:0 12px 40px rgba(0,0,0,.45);
}
.modal h2{ margin:0; font-size:18px; }
.modal p{ margin:0; color:var(--muted); line-height:1.45; font-size:14px; }
.modal label{ font-weight:850; color:rgba(255,255,255,.92); font-size:14px; }
.modal input{
  width:100%; padding:10px 14px;
  border-radius:12px; border:1px solid rgba(255,255,255,.18);
  background:rgba(255,255,255,.06); color:var(--fg);
  outline:none; font-size:15px; min-height:42px;
}
.modal .rowBtn{ display:flex; gap:10px; justify-content:flex-end; flex-wrap:wrap; }

/* ============================================================
   TABLETTE : HUD sous canvas
============================================================ */
@media (max-width:1100px){
  .main{ grid-template-columns:1fr; }
}

/* ============================================================
   SMARTPHONE ≤ 640px
============================================================ */
@media (max-width:640px){

  #app{ gap:5px; padding:5px; }

  /* Afficher le bouton accordéon, masquer les options par défaut */
  .btn-toggle-opts{
    display:inline-flex; align-items:center; justify-content:center;
    flex-shrink:0;
  }
  .topbar-options{
    display:none;                      /* masqué par défaut */
    flex-direction:column;
    align-items:stretch;
    padding-top:6px;
    border-top:1px solid rgba(255,255,255,.08);
    gap:5px;
  }
  .topbar-options.open{ display:flex; } /* ouvert par JS */

  /* Options en grille 2 colonnes */
  .topbar-options .group{
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:5px;
  }
  .topbar-options #btnSend{ grid-column:span 2; }

  /* Barre principale : Start/Stop + pills d'état en ligne */
  .topbar-main{
    flex-wrap:nowrap; gap:5px; align-items:center;
  }
  .group-actions{
    display:flex; flex-wrap:nowrap; gap:5px; flex-shrink:0;
  }
  .group-score{
    flex:1; display:flex; flex-wrap:nowrap; gap:5px;
    overflow-x:auto; -webkit-overflow-scrolling:touch;
    scrollbar-width:none;
  }
  .group-score::-webkit-scrollbar{ display:none; }
  .group-score .pill{ flex-shrink:0; }

  /* Tailles compactes mobile */
  button{ font-size:13px; min-height:38px; padding:7px 11px; border-radius:12px; }
  .pill{ font-size:12px; min-height:32px; padding:4px 9px; }

  /* Canvas */
  .main{ gap:5px; }
  #wrapCanvas{ min-height:48dvh; border-radius:12px; }
  #hint{ font-size:11px; margin-top:4px; line-height:1.3; }
  #toast{ font-size:14px; padding:7px 11px; }

  /* HUD */
  .card:not(#wrapCanvas){ padding:7px; border-radius:12px; }
  .hudLine{ font-size:11px; padding:3px 0; }
  .chPill{ font-size:11px; padding:3px 7px; }

  /* Modales en sheet depuis le bas */
  .modal{ padding:8px; align-items:flex-end; }
  .modal .cardModal{
    width:100%; border-radius:18px 18px 14px 14px;
    padding:18px 16px 24px; gap:12px;
  }
  .modal h2{ font-size:17px; }
  .modal p, .modal label{ font-size:13px; }
  .modal input{ font-size:16px; padding:12px 14px; min-height:46px; border-radius:12px; }
  .modal .rowBtn button{ flex:1; min-height:46px; border-radius:12px; }
}

/* ============================================================
   TRÈS PETIT ÉCRAN ≤ 360px
============================================================ */
@media (max-width:360px){
  button{ font-size:12px; padding:6px 9px; }
  .pill{ font-size:11px; }
  #wrapCanvas{ min-height:44dvh; }
}

/* ============================================================
   isMobile sur tablette (pointer coarse, écran > 640px)
============================================================ */
@media (min-width:641px){
  html.isMobile button{ min-height:42px; font-size:14px; }
  html.isMobile .pill{ min-height:36px; font-size:13px; }
}
