:root{
    /* ===== Theme ===== */
    --bg:#0b1224;
    --bg2:#070c18;
    --txt:rgba(255,255,255,.92);
    --shadow:0 12px 30px rgba(0,0,0,.28);

    --red:#f2a7b5;
    --teal: rgba(170, 221, 227, .92);

    /* ===== Real visible height (set in JS via visualViewport) ===== */
    --appH: 100vh;

    /* ===== Safe padding / spacing ===== */
    --pad: clamp(8px, 1.2vw, 12px);
    --gapX: clamp(8px, 1.2vw, 12px);     /* gap between creature cards in landscape */
    --gapY: clamp(12px, 1.6vw, 16px);    /* gap inside button grids */
    --blockGap: clamp(12px, 2.0vw, 18px);/* gap between buttons block and creatures block */

    --topbarH: 64px; /* measured in JS */
    --zoneTopOffset: clamp(6px, 1.2vh, 12px);
    --bottomComfort: calc(env(safe-area-inset-bottom, 0px) + 6px);

    /* ===== Top bar sizes ===== */
    --btnSize: clamp(38px, 7.5vmin, 56px);
    --btnRadius: clamp(12px, 2.4vmin, 16px);
    --iconSize: clamp(14px, 3vmin, 20px);
    --dotSize: clamp(12px, 3vmin, 20px);

    /* ===== Landscape sizing (default) ===== */
    --oppBtnW: clamp(72px, 10.5vw, 110px);
    --oppBtnH: clamp(32px, 5.5vh, 48px);
    --oppBtnR: clamp(12px, 1.8vmin, 16px);
    --oppBtnF: clamp(10px, 1.3vw, 14px);

    --meBtnW: clamp(86px, 12.5vw, 135px);
    --meBtnH: clamp(38px, 6.5vh, 58px);
    --meBtnR: clamp(14px, 2.1vmin, 18px);
    --meBtnF: clamp(11px, 1.55vw, 16px);

    /* Creature "cubes" */
    --cardSize: clamp(46px, 6.2vw, 70px);

    /* Square buttons (Banc / points de Passe) */
    --sqBtnSize: clamp(44px, 6.0vw, 66px);
  }

  *{ box-sizing:border-box; }
  html, body{ height:100%; }

  body{
    margin:0;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    background: radial-gradient(1200px 800px at 28% 12%, #3b6fb6 0%, #1b2f5a 28%, var(--bg) 60%, var(--bg2) 100%);
    color: var(--txt);
    overflow:hidden;               /* 1 écran */
    -webkit-tap-highlight-color: transparent;
    height: var(--appH);           /* follow real visible height */
  }

  /* ===== Top bar ===== */
  .topBar{
    position:fixed; top:0; left:0; right:0;
    z-index:50;
    padding: calc(env(safe-area-inset-top,0px) + 4px) 0 4px 0;
    backdrop-filter: blur(10px);
    background: rgba(12,18,40,.16);
  }
  .topBarInner{
    display:flex;
    align-items:center;
    justify-content:space-between;
    padding:6px 8px;
    background: rgba(12,18,40,.34);
    box-shadow: var(--shadow);
  }
  .menuBtn{
    width:var(--btnSize);
    height:var(--btnSize);
    border-radius:var(--btnRadius);
    background: rgba(255,255,255,.07);
    color:#fff;
    font-size:var(--iconSize);
    font-weight:900;
    border:none;
    cursor:pointer;
    user-select:none;
    touch-action: manipulation;
  }
  .menuBtn:active{ transform: translateY(1px); }
  .turnDot{
    width:var(--dotSize);
    height:var(--dotSize);
    border-radius:999px;
    background:#22c55e;
    box-shadow: 0 6px 16px rgba(0,0,0,.25), 0 0 12px rgba(34,197,94,.6);
    transition: all 250ms ease;
  }
  .turnDot.red{ 
    background:#ef4444; 
    box-shadow: 0 6px 16px rgba(0,0,0,.25), 0 0 12px rgba(239,68,68,.5);
  }

  /* ===== Phase banner + micro feedback ===== */
  .phaseBanner{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:10px;
    padding:10px 12px;
    border-radius:14px;
    background: rgba(255,255,255,.06);
    border: 1px solid rgba(255,255,255,.12);
    box-shadow: 0 10px 24px rgba(0,0,0,.22);
  }
  .phaseBanner .title{
    font-weight:900;
    letter-spacing:.2px;
  }
  .phaseBanner .sub{
    opacity:.85;
    font-size:.95em;
    white-space:nowrap;
  }
  .phaseBanner .chip{
    display:inline-flex;
    align-items:center;
    gap:8px;
    padding:6px 10px;
    border-radius:999px;
    background: rgba(0,0,0,.18);
    border: 1px solid rgba(255,255,255,.12);
  }

  .flash{
    animation: flashPop 220ms ease-out;
  }
  @keyframes flashPop{
    from{ transform: scale(1.02); filter: brightness(1.15); }
    to{ transform: scale(1.0); filter: brightness(1.0); }
  }

  .toastWrap{
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
    z-index: 9999;
    display:flex;
    justify-content:center;
    pointer-events:none;
  }
  .toast{
    pointer-events:none;
    max-width: 680px;
    width: 100%;
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(0,0,0,.55);
    border: 1px solid rgba(255,255,255,.18);
    backdrop-filter: blur(10px);
    box-shadow: 0 14px 34px rgba(0,0,0,.35);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 180ms ease, transform 180ms ease;
    font-weight: 650;
    text-align:center;
  }
  .toast.show{
    opacity: 1;
    transform: translateY(0);
  }

  /* ===== Focus mode (playtest) ===== */
  body.focusMode .debugOnly{ display:none !important; }
  body.focusMode #undoBtn{ display:none !important; }
  body.focusMode #rollBtn{ display:none !important; }
  body.focusMode #passStatusRow{ display:none !important; }
  body.focusMode #deckValidationErrors{ display:none !important; }

  /* ===== Main layout ===== */
  .main{
    height: var(--appH);
    padding-top: calc(var(--topbarH) + var(--pad) + var(--zoneTopOffset));
    padding-left: var(--pad);
    padding-right: var(--pad);
    padding-bottom: var(--bottomComfort);
    display:flex;
    flex-direction:column;
    gap: var(--pad);
  }

  .zone{
    display:flex;
    align-items:center;
    gap: var(--blockGap);
    width:100%;
    flex: 0 0 auto;
  }

  /* central separator kept in HTML, hidden on purpose */
  .field{ display:none; }

  /* ===== Blocks ===== */
  .buttons{
    display:grid;
    grid-template-columns: repeat(3, var(--w));
    grid-auto-rows: var(--h);
    gap: var(--gapY);
    flex: 0 0 auto;
  }

  .btn{
    border:0;
    border-radius: var(--r);
    background: var(--red);
    color: rgba(0,0,0,.92);
    font-weight: 850;
    font-size: var(--f);
    line-height: 1.05;
    display:flex;
    align-items:center;
    justify-content:center;
    text-align:center;
    padding: 6px 8px;
    user-select:none;
    touch-action: manipulation;
    box-shadow: 0 10px 18px rgba(0,0,0,.18);
    position: relative;
    transform-origin: center center;
    transition: transform 160ms ease, box-shadow 160ms ease;
  }

  .btn.square{
    width: var(--sqBtnSize);
    height: var(--sqBtnSize);
    min-height: unset;
    padding: 6px;
    border-radius: 16px;
  margin: 0 auto;
    margin-left:auto;
    margin-right:auto;
    justify-self:center;
    align-self:center;
  }

  .cards{
    display:flex;
    gap: var(--gapX);
    overflow:hidden;
    flex: 1 1 auto;
    min-width:0;
    align-items:center;
    justify-content:flex-start;
  }

  .card{
    width: var(--cardSize);
    height: var(--cardSize);
    border-radius: 14px;
    background: var(--teal);
    color: rgba(255,255,255,.96);
    display:flex;
    align-items:center;
    justify-content:center;
    font-size: clamp(10px, 1.15vw, 14px);
    font-weight: 650;
    white-space:nowrap;
    box-shadow: 0 10px 18px rgba(0,0,0,.14);
    position: relative;
    transform-origin: center center;
    transition: transform 160ms ease, box-shadow 160ms ease;
    cursor: pointer;
    touch-action: manipulation;
    text-align:center;
    line-height:1.05;
  }

  /* ===== Zone themes (sizes) ===== */
  .opp{
    --w: var(--oppBtnW);
    --h: var(--oppBtnH);
    --r: var(--oppBtnR);
    --f: var(--oppBtnF);
  }
  .me{
    --w: var(--meBtnW);
    --h: var(--meBtnH);
    --r: var(--meBtnR);
    --f: var(--meBtnF);
  }

  /* ===== Interaction: rotate creature cards ===== */
  .card.is-vertical{
    transform: rotate(90deg) scale(0.92);
    box-shadow: 0 14px 28px rgba(0,0,0,.22);
    z-index: 5;
  }

  

  /* Rotation des carrés (ex: points d'Action / points de Passe) */
  .btn.square{
    transition: transform .16s ease, box-shadow .16s ease;
    will-change: transform;
  }
  .btn.square.is-vertical{
    transform: rotate(90deg) scale(0.92);
    z-index: 5;
    box-shadow: 0 14px 28px rgba(0,0,0,.22);
  }
/* ===== PORTRAIT ===== */
  @media (orientation: portrait){
    :root{
      /* a little tighter so everything fits */
      --pad: clamp(8px, 1.0vw, 12px);
      --gapY: clamp(10px, 1.4vh, 14px);
      --blockGap: clamp(10px, 1.4vh, 14px);
      --cardSize: clamp(64px, 11.0vw, 84px);
      --sqBtnSize: clamp(58px, 10.0vw, 78px);
    }

    .main{ gap: clamp(6px, 0.9vh, 10px); }

    .zone{
      flex-direction:column;
      align-items:stretch;
      gap: clamp(6px, 0.9vh, 10px);
    }

    .buttons{
      width:100%;
      grid-template-columns: repeat(3, 1fr);
      gap: clamp(10px, 1.4vh, 14px);
      /* critical: ensure lines are at least as tall as square buttons */
      grid-auto-rows: max(var(--h), var(--sqBtnSize));
    }

    .btn{
      min-height: 40px;
      font-size: clamp(12px, 3.0vw, 15px);
    }
    .btn.square{
      font-size: clamp(12px, 2.8vw, 15px);
    }

    .cards{
      width:100%;
      display:grid;
      grid-template-columns: repeat(3, 1fr);
      gap: clamp(10px, 1.4vh, 14px);
      overflow: visible;
      justify-items:center;
    }
    .card{
      width:100%;
      max-width: var(--cardSize);
      height: var(--cardSize);
      font-size: clamp(12px, 3.2vw, 16px);
      white-space: normal;
      padding: 0 6px;
    }

    /* zone joueur: creatures above, buttons below */
    .me .cards{ order: 1; }
    .me .buttons{ order: 2; }
  }

  /* ===== LANDSCAPE: give more air (without touching portrait) ===== */
  @media (orientation: landscape){
    :root{
      --gapY: clamp(14px, 2.4vh, 24px);
      --blockGap: clamp(18px, 2.6vw, 32px);
      --pad: clamp(10px, 1.6vw, 16px);
    }

    .main{
      gap: clamp(18px, 3.2vh, 44px);
      padding-bottom: clamp(10px, 2vh, 24px);
    }

    /* slightly smaller red buttons in landscape */
    .opp{
      --w: clamp(70px, 10.2vw, 104px);
      --h: clamp(30px, 5.2vh, 44px);
      --f: clamp(10px, 1.25vw, 13px);
    }
    .me{
      --w: clamp(82px, 12.0vw, 124px);
      --h: clamp(34px, 5.9vh, 52px);
      --f: clamp(11px, 1.45vw, 15px);
    }
  }


  /* ===== Setup Drawer (menu droite / ≡) ===== */
  .setupOverlay{
    position: fixed;
    inset: 0;
    z-index: 180;
    display: none;
    background: rgba(0,0,0,.45);
    backdrop-filter: blur(6px);
  }
  .setupOverlay.open{ display:block; }

  .setupDrawer{
    position: fixed;
    top: 0;
    right: 0;
    height: var(--appH);
    width: min(520px, 92vw);
    z-index: 190;
    background: rgba(7, 16, 29, .94);
    border-left: 1px solid rgba(255,255,255,.12);
    box-shadow: -18px 0 60px rgba(0,0,0,.45);
    transform: translateX(102%);
    transition: transform .18s ease-out;
    display:flex;
    flex-direction:column;
    padding-top: env(safe-area-inset-top,0px);
  }
  .setupDrawer.open{ transform: translateX(0); }

  .setupHeader{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(255,255,255,.10);
    background: rgba(255,255,255,.04);
  }
  .setupHeader .title{
    font-weight: 900;
    letter-spacing: .3px;
  }
  .setupClose{
    width: 44px;
    height: 44px;
    border-radius: 16px;
  margin: 0 auto;
    border: 0;
    background: rgba(255,255,255,.10);
    color:#fff;
    font-weight: 900;
    cursor:pointer;
    touch-action: manipulation;
  }
  .setupClose:active{ transform: translateY(1px); }

  .setupBody{
    padding: 14px;
    overflow:auto;
    -webkit-overflow-scrolling: touch;
    display:flex;
    flex-direction:column;
    gap: 14px;
  }

  .setupNote{
    opacity: .92;
    font-weight: 650;
    line-height: 1.25;
  }

  .fieldRow{
    display:flex;
    flex-wrap:wrap;
    gap: 10px;
    align-items:center;
  }
  .fieldRow label{
    font-size: 13px;
    opacity: .85;
    font-weight: 750;
  }
  .inp, .sel, .txt{
    border: 1px solid rgba(255,255,255,.14);
    border-radius: 14px;
    padding: 11px 12px;
    background: rgba(255,255,255,.06);
    color: rgba(255,255,255,.95);
    font-size: 14px;
    outline: none;
  }
  .txt{ width:100%; min-height: 120px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

  .setupBtn{
    border: 0;
    border-radius: 14px;
    padding: 12px 14px;
    font-weight: 900;
    cursor:pointer;
    color: rgba(0,0,0,.92);
    background: #a9dfe3;
    box-shadow: 0 12px 22px rgba(0,0,0,.18);
    user-select:none;
    touch-action: manipulation;
  }
  .setupBtn[disabled]{ opacity:.55; filter: grayscale(.25); }
  .inp[disabled], textarea.inp[disabled]{ opacity:.55; }

  .setupBtn.secondary{
    background: rgba(255,255,255,.10);
    color: rgba(255,255,255,.95);
    border: 1px solid rgba(255,255,255,.14);
    box-shadow: none;
  }
  .setupBtn:active{ transform: translateY(1px); }

  .pillInfo{
    display:inline-flex;
    align-items:center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,.14);
    background: rgba(255,255,255,.06);
    font-size: 13px;
    font-weight: 850;
  }
  .pillInfo small{ opacity:.85; font-weight: 750; }

  /* ===== Action Modal (menu fenêtre) ===== */
  .actionModal{
    position: fixed;
    inset: 0;
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    padding: max(12px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px))
             max(12px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
  }
  .actionModal.open{ display:flex; }

  .modalBackdrop{
    position:absolute;
    inset:0;
    background: rgba(0,0,0,.45);
    backdrop-filter: blur(6px);
  }

  .modalPanel{
    position: relative;
    width: min(560px, 92vw);
    max-height: min(720px, 84vh);
    border-radius: 26px;
    background: rgba(7, 40, 102, .92);
    box-shadow: 0 24px 70px rgba(0,0,0,.45);
    overflow: hidden;
    display:flex;
    flex-direction:column;
  }

  .modalHeader{
    display:flex;
    align-items:center;
    justify-content:space-between;
    padding: 16px 16px 10px 16px;
    background: rgba(0,0,0,.10);
  }

  .modalTag{
    padding: 6px 12px;
    border-radius: 14px;
    background: rgba(0,0,0,.18);
    font-weight: 700;
    letter-spacing: .2px;
  }

  .modalClose{
    width: 44px;
    height: 44px;
    border-radius: 16px;
  margin: 0 auto;
    border: 0;
    background: rgba(0,0,0,.18);
    color: #fff;
    font-weight: 900;
    cursor:pointer;
    touch-action: manipulation;
  }
  .modalClose:active{ transform: translateY(1px); }

  .modalContext{
    padding: 0 16px 10px 16px;
    opacity: .9;
    font-weight: 700;
  }

  .modalList{
    padding: 12px 14px 16px 14px;
    overflow:auto;
    display:flex;
    flex-direction:column;
    gap: 12px;
  }

  .modalItem{
    width:100%;
    border:0;
    border-radius: 999px;
    padding: 16px 18px;
    background: rgba(0,0,0,.22);
    color: rgba(255,255,255,.95);
    font-size: clamp(14px, 2.2vw, 22px);
    font-weight: 800;
    display:flex;
    align-items:center;
    justify-content:space-between;
    cursor:pointer;
    touch-action: manipulation;
  }
  .modalItem small{
    font-size: .78em;
    opacity: .85;
    font-weight: 750;
  }
  .modalItem:active{ transform: translateY(1px); }




    /* Prevent text selection / callout on long-press (mobile) */
    body, .btn, .card, .topBtn, .tile, .slot {
      -webkit-user-select: none;
      user-select: none;
      -webkit-touch-callout: none;
    }
    /* Prevent selection highlight in some browsers */
    * { -webkit-tap-highlight-color: transparent; }

  /* ===== Floating Hand Button ===== */
  .handFloatingBtn{
    position: fixed;
    /* Positions gérées par JavaScript pour éviter les sursauts */
    /* right et top sont définis dynamiquement en JS */
    width: clamp(56px, 12vmin, 70px);
    height: clamp(56px, 12vmin, 70px);
    border-radius: 50%;
    background: linear-gradient(135deg, #4a9eff 0%, #2563eb 100%);
    border: 3px solid rgba(255,255,255,.3);
    box-shadow: 0 8px 24px rgba(0,0,0,.35), 0 0 0 4px rgba(74,158,255,.2);
    display: none;
    align-items: center;
    justify-content: center;
    cursor: move;
    z-index: 100;
    touch-action: none;
    transition: box-shadow 200ms ease;
    user-select: none;
  }
  
  /* Landscape mode: pas de override de position, tout géré en JS */
  @media (orientation: landscape) {
    .handFloatingBtn{
      /* Positions gérées en JS */
    }
  }
  
  .handFloatingBtn.visible{ display: flex; }
  .handFloatingBtn.dragging{
    transition: none;
    opacity: 0.9;
  }
  
  .handFloatingBtn:hover{
    box-shadow: 0 12px 32px rgba(0,0,0,.45), 0 0 0 6px rgba(74,158,255,.3);
  }
  .handFloatingBtn .count{
    font-size: clamp(22px, 5.5vmin, 32px);
    font-weight: 900;
    opacity: 1;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0,0,0,.3);
  }

  /* ===== Hand Modal ===== */
.handCards{
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  padding: 16px;
  padding-bottom: 16px;
  /* IMPORTANT: pas de scroll ici (nested scroll = buggy sur mobile).
     Le scroll se fait sur .panelBody */
  overflow: visible;
  max-height: none;
  -webkit-overflow-scrolling: auto;
}
.handCard{
    aspect-ratio: 2.5/3.5;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--teal) 0%, rgba(120,200,210,.85) 100%);
    border: 2px solid rgba(255,255,255,.2);
    box-shadow: 0 6px 18px rgba(0,0,0,.25);
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    flex-direction: column;
    padding: 12px;
    cursor: pointer;
    transition: transform 160ms ease, opacity 200ms ease;
    position: relative;
    overflow: hidden;
  }
  .handCard:hover{
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0,0,0,.35);
  }
  .handCard:active{
    transform: scale(0.97);
  }
  .handCard.unaffordable{
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(0.5);
  }
  .handCard.unaffordable:hover{
    transform: none;
  }
  .handCard .card-cost{
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(0,0,0,.7);
    border: 2px solid rgba(255,255,255,.3);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 14px;
    color: #ffd700;
  }
  .handCard .cardName{
    font-size: 13px;
    font-weight: 800;
    line-height: 1.2;
    color: rgba(0,0,0,.9);
    margin-top: 36px;
    margin-bottom: 6px;
    width: 100%;
  }
  .handCard .cardType{
    font-size: 10px;
    font-weight: 600;
    color: rgba(0,0,0,.75);
    margin-bottom: 4px;
  }
  .handCard .cardSubtypes{
    font-size: 9px;
    font-weight: 600;
    font-style: italic;
    color: rgba(0,0,0,.65);
    margin-bottom: 6px;
  }
  .handCard .cardText{
    font-size: 9px;
    line-height: 1.3;
    color: rgba(0,0,0,.8);
    overflow-y: auto;
    flex: 1;
    width: 100%;
  }


/* ===== Unified Panel (modal + drawer) ===== */
.panelOverlay{
  position: fixed;
  inset: 0;
  display: none;
  background: rgba(0,0,0,.45);
  z-index: 9990;
}
.panelOverlay.open{
  display:flex;
  /* IMPORTANT: on scrolle l'"écran" (l'overlay) sur desktop aussi */
  align-items:flex-start;
  justify-content:center;
  overflow-y:auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 0 calc(20px + env(safe-area-inset-bottom, 0px));
}

/* Panel principal : refonte complète pour scroll fiable */

.panel{
  /* IMPORTANT: éviter les bugs iOS de scroll dans un élément transformé */
  position: relative;
  left: auto;
  top: auto;
  transform: none;
  width: min(520px, 92vw);
  /* Hauteur: laisser auto; le scroll se fait sur l'overlay (desktop + mobile) */
  height: auto;
  max-height: none;
  background: rgba(11,18,36,.97);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 16px;
  margin: 0 auto;
  box-shadow: 0 18px 70px rgba(0,0,0,.55);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Variante modal: le contenu peut dépasser, on scrolle sur l'overlay */
.panel--modal .panelBody{
  overflow: visible;
  -webkit-overflow-scrolling: auto;
  flex: none;
  min-height: auto;
  max-height: none;
  padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
}

/* Sur mobile, prendre encore plus de place */
@media (max-width: 768px) {
  /* Sur mobile, on laisse le panneau grandir et on scrolle sur l'écran (overlay) */
  .panelOverlay.open{ padding: 10px 0 calc(20px + env(safe-area-inset-bottom, 0px)); }
  .panel {
    height: auto;
    max-height: none;
    width: 95vw;
  }
  .panelBody{
    overflow: visible; /* pas de scroll interne mobile */
    -webkit-overflow-scrolling: auto;
    flex: none;
    min-height: auto;
    padding-bottom: calc(140px + env(safe-area-inset-bottom, 0px));
  }
}

/* En orientation portrait sur mobile, maximiser l'espace */
@media (max-width: 768px) and (orientation: portrait) {
  .panelOverlay.open{ padding-top: 8px; }
}

.panel--drawer{
  left: auto;
  right: 0;
  top: 0;
  transform: none;
  height: var(--appH, 100vh);
  max-height: var(--appH, 100vh);
  width: min(520px, 92vw);
  border-radius: 0;
  border-left: 1px solid rgba(255,255,255,.12);
}

.panelHeader{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid rgba(255,255,255,.10);
  flex-shrink: 0; /* Ne jamais réduire le header */
}
.panelTitle{
  font-weight: 900;
  letter-spacing: .3px;
}
.panelClose{
  border: 1px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.92);
  border-radius: 12px;
  padding: 8px 10px;
  cursor: pointer;
  flex-shrink: 0;
}
.panelContext{
  padding: 0 12px 8px 12px;
  opacity: .86;
  font-size: 12px;
  flex-shrink: 0;
}

/* PanelBody : la clé du scroll qui fonctionne */
.panelBody{
  padding: 12px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); /* évite que la barre PA + safe-area cache le contenu */
  overflow-y: auto; /* Force le scroll visible */
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  flex: 1 1 0; /* Flex basis 0 pour forcer le calcul correct */
  min-height: 0; /* Critique pour que flex fonctionne */
  max-height: none; /* hauteur gérée par le conteneur */
  overscroll-behavior: contain;
  touch-action: pan-y;
  position: relative;
}

/* Style de scrollbar plus visible pour indiquer qu'on peut scroller */
.panelBody::-webkit-scrollbar {
  width: 8px;
}

.panelBody::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px;
}

.panelBody::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.panelBody::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Sticky action rows inside panels (keeps critical buttons reachable on small screens) */
.stickyRow{
  position: sticky;
  bottom: -1px;
  z-index: 5;
  padding: 10px 0 6px 0;
  margin-top: 10px;
  background: linear-gradient(to top, rgba(11,18,36,.96) 70%, rgba(11,18,36,0));
  backdrop-filter: blur(6px);
}

.setupDetails summary{
  cursor:pointer;
  user-select:none;
  margin: 6px 0 10px 0;
  font-weight: 700;
  opacity: .92;
}

.logBox{
  background: rgba(2,6,23,.55);
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 14px;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.35;
  white-space: pre-wrap;
  max-height: 52vh;
  overflow:auto;
}

/* Hide legacy modals if still present in CSS expectations (defensive) */

/* ===== Animations cartes ===== */
@keyframes card-tap {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(90deg); }
}

@keyframes card-untap {
  0% { transform: rotate(90deg); }
  100% { transform: rotate(0deg); }
}

.card-tapping {
  animation: card-tap 0.3s ease forwards;
}

.card-untapping {
  animation: card-untap 0.3s ease forwards;
}

@keyframes slide-from-deck {
  0% { 
    transform: translateY(50px) scale(0.8);
    opacity: 0;
  }
  100% { 
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.card-drawing {
  animation: slide-from-deck 0.5s ease;
}

/* ===== Preview cartes (hover zoom) ===== */
.card-preview-container {
  position: relative;
}

.card-preview-zoom {
  position: absolute;
  z-index: 10000;
  pointer-events: none;
  transition: opacity 0.2s ease;
  opacity: 0;
}

.card-preview-zoom.visible {
  opacity: 1;
}

.card-preview-zoom img {
  width: 280px;
  height: auto;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  border: 2px solid rgba(255, 255, 255, 0.3);
}

/* ===== Historique & Undo ===== */
.history-panel {
  position: fixed;
  right: 16px;
  top: 80px;
  width: 280px;
  max-height: 400px;
  background: rgba(11, 18, 36, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  padding: 12px;
  overflow-y: auto;
  z-index: 10050;
  display: none;
}

.history-panel.open {
  display: block;
}

.history-entry {
  padding: 8px;
  margin-bottom: 6px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.4;
  border-left: 3px solid rgba(170, 221, 227, 0.5);
}

.history-entry.undoable {
  cursor: pointer;
  transition: all 0.2s ease;
}

.history-entry.undoable:hover {
  background: rgba(255, 255, 255, 0.08);
  border-left-color: rgba(170, 221, 227, 1);
}

/* ===== Mode Spectateur ===== */
.spectator-mode {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  background: rgba(255, 165, 0, 0.9);
  color: #000;
  border-radius: 20px;
  font-weight: 700;
  font-size: 13px;
  z-index: 9500;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.spectator-hands {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 80px;
}

.spectator-hand {
  background: rgba(11, 18, 36, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 12px;
}

.spectator-hand-title {
  font-weight: 700;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

/* ===== Reconnexion automatique ===== */
.reconnecting-banner {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  background: rgba(255, 193, 7, 0.95);
  color: #000;
  border-radius: 12px;
  font-weight: 700;
  font-size: 14px;
  z-index: 9500;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  display: none;
}

.reconnecting-banner.visible {
  display: block;
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from {
    transform: translateX(-50%) translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
  }
}
#setupOverlay,#setupDrawer,#logModal,#actionModal{ display:none !important; }


button:disabled{opacity:0.5;filter:grayscale(0.2);}

/* ===== Game Zones Improvements ===== */

/* Compteurs de zones */
.zone-counter {
  display: inline-block;
  min-width: 22px;
  height: 18px;
  padding: 1px 6px;
  margin-top: 8px;
  background: linear-gradient(135deg, rgba(74, 158, 255, 0.9) 0%, rgba(37, 99, 235, 0.9) 100%);
  border-radius: 9px;
  border: 1.5px solid rgba(255,255,255,.4);
  font-size: 0.7em;
  font-weight: 900;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.3), inset 0 1px 0 rgba(255,255,255,.2);
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.4);
}

/* Boutons de zone cliquables */
.game-zone-btn {
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.game-zone-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 20px rgba(0,0,0,.22);
}

.game-zone-btn:active {
  transform: translateY(0);
}

/* Zone terrain (remplace les 6 cartes fixes) */
.terrain-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,.03);
  border: 2px dashed rgba(255,255,255,.12);
  border-radius: 14px;
  cursor: pointer;
  transition: all 200ms ease;
  min-height: var(--cardSize);
  position: relative;
}

.terrain-zone:hover {
  background: rgba(255,255,255,.06);
  border-color: rgba(255,255,255,.2);
  transform: scale(1.02);
}

.terrain-zone:active {
  transform: scale(0.98);
}

.terrain-placeholder {
  text-align: center;
  padding: 8px;
}

.terrain-counter {
  font-size: clamp(20px, 4vmin, 32px);
  font-weight: 900;
  line-height: 1;
  margin-bottom: 4px;
}

.terrain-label {
  font-size: clamp(10px, 1.5vmin, 14px);
  font-weight: 700;
  opacity: 0.8;
}

/* Actions rapides terrain (toujours visibles) */
.terrain-quick-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  z-index: 3;
}

.tqa-btn {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(0,0,0,.22);
  color: rgba(255,255,255,.95);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  box-shadow: 0 6px 14px rgba(0,0,0,.25);
  transition: transform 120ms ease, background 120ms ease;
}

.tqa-btn:hover { transform: translateY(-1px); background: rgba(0,0,0,.28); }
.tqa-btn:active { transform: translateY(0); }

/* ===== Zone Modals ===== */
.zone-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(8px);
  padding: max(16px, env(safe-area-inset-top, 0px)) 
           max(16px, env(safe-area-inset-right, 0px))
           max(16px, env(safe-area-inset-bottom, 0px)) 
           max(16px, env(safe-area-inset-left, 0px));
}

.zone-modal.open {
  display: flex;
}

.zone-modal-content {
  background: linear-gradient(135deg, #0f1b3a 0%, #08111f 100%);
  border: 2px solid rgba(255,255,255,.15);
  border-radius: 20px;
  width: min(480px, 90vw);
  max-height: min(680px, 80vh);
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.zone-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: rgba(0,0,0,.2);
  border-bottom: 1px solid rgba(255,255,255,.1);
}

.zone-modal-title {
  font-size: clamp(16px, 2.5vmin, 20px);
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 10px;
}

.zone-modal-count {
  background: rgba(255,255,255,.1);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.85em;
  font-weight: 700;
}

.zone-modal-close {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: none;
  background: rgba(255,255,255,.08);
  color: #fff;
  font-size: 20px;
  font-weight: 900;
  cursor: pointer;
  transition: all 150ms ease;
}

.zone-modal-close:hover {
  background: rgba(255,255,255,.15);
  transform: scale(1.05);
}

.zone-modal-close:active {
  transform: scale(0.95);
}

.zone-modal-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

.zone-empty {
  text-align: center;
  padding: 40px 20px;
  opacity: 0.6;
}

.zone-empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.zone-empty-text {
  font-size: 14px;
  font-weight: 600;
}

/* ===== Game Cards Display ===== */
.game-card-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.game-card {
  aspect-ratio: 2.5/3.5;
  border-radius: 10px;
  background: linear-gradient(135deg, #2a5a8a 0%, #1a3a5a 100%);
  border: 2px solid rgba(255,255,255,.2);
  padding: 10px;
  position: relative;
  cursor: pointer;
  transition: all 180ms ease;
  overflow: hidden;
}

.game-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  border-color: rgba(255,255,255,.4);
}

.game-card:active {
  transform: translateY(-2px);
}

.game-card.tapped {
  opacity: 0.6;
  filter: grayscale(0.3);
}

.game-card.tapped::after {
  content: '↷';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 48px;
  font-weight: 900;
  color: rgba(255,255,255,.3);
  pointer-events: none;
}

.card-cost {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0,0,0,.7);
  border: 2px solid rgba(255,255,255,.3);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 14px;
  color: #ffd700;
}

.terrain-tap-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(255,255,255,.15);
  border: 2px solid rgba(255,255,255,.3);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 20px;
  color: #fff;
  cursor: pointer;
  transition: all 150ms ease;
  z-index: 10;
}

.terrain-tap-btn:hover {
  background: rgba(255,255,255,.25);
  border-color: rgba(255,255,255,.5);
  transform: scale(1.1);
}

.terrain-tap-btn:active {
  transform: scale(0.95);
}

.card-name {
  font-weight: 800;
  font-size: 13px;
  line-height: 1.2;
  margin-top: 36px;
  margin-bottom: 6px;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0,0,0,.5);
}

.card-type {
  font-size: 10px;
  font-weight: 600;
  opacity: 0.8;
  margin-bottom: 8px;
  color: #aaddff;
}

.card-subtypes {
  font-size: 9px;
  opacity: 0.7;
  font-style: italic;
}

.card-text {
  font-size: 9px;
  line-height: 1.3;
  opacity: 0.9;
  margin-top: 8px;
  max-height: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Card actions (context menu) */
.card-actions {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 150ms ease;
}

.game-card:hover .card-actions {
  opacity: 1;
}

.card-action-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: rgba(0,0,0,.7);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 150ms ease;
}

.card-action-btn:hover {
  background: rgba(255,255,255,.2);
  transform: scale(1.1);
}

.card-action-btn:active {
  transform: scale(0.95);
}

/* Chief card special styling */
.chief-card {
  background: linear-gradient(135deg, #8b5a3c 0%, #5a3a2c 100%);
  border: 3px solid #ffd700;
}

/* Token card styling */
.token-card {
  background: linear-gradient(135deg, #4a4a6a 0%, #2a2a4a 100%);
  border-style: dashed;
}

/* ===== Action Dice Display ===== */
.action-die-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 20px;
  background: rgba(0,0,0,.2);
  border-radius: 12px;
  margin: 16px 0;
}

.die-value {
  font-size: 64px;
  font-weight: 900;
  color: #4a9eff;
  text-shadow: 0 4px 8px rgba(0,0,0,.5);
  line-height: 1;
}

.die-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.die-btn {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,.2);
  background: rgba(255,255,255,.1);
  color: #fff;
  font-size: 24px;
  font-weight: 900;
  cursor: pointer;
  transition: all 150ms ease;
}

.die-btn:hover {
  background: rgba(255,255,255,.2);
  transform: scale(1.05);
}

.die-btn:active {
  transform: scale(0.95);
}

.die-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ===== Card Modal (sous-modal) ===== */
.card-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(12px);
}

.card-modal.open {
  display: flex;
}

.card-modal-content {
  background: linear-gradient(135deg, #1a2a4a 0%, #0a141f 100%);
  border: 2px solid rgba(255,255,255,.2);
  border-radius: 16px;
  margin: 0 auto;
  width: min(420px, 88vw);
  max-height: min(720px, 85vh);
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.card-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: rgba(0,0,0,.3);
  border-bottom: 1px solid rgba(255,255,255,.15);
}

.card-modal-header span {
  font-size: 16px;
  font-weight: 800;
}

.card-modal-close {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: rgba(255,255,255,.1);
  color: #fff;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
  transition: all 150ms ease;
}

.card-modal-close:hover {
  background: rgba(255,255,255,.2);
  transform: scale(1.05);
}

.card-modal-close:active {
  transform: scale(0.95);
}

.card-modal-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

/* Fiche carte */
.card-sheet {
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 16px;
}

.card-sheet-name {
  font-size: 18px;
  font-weight: 900;
  margin-bottom: 8px;
  color: #4ac3ff;
}

.card-sheet-type {
  font-size: 13px;
  font-weight: 700;
  color: rgba(255,255,255,.7);
  margin-bottom: 6px;
}

.card-sheet-subtypes {
  font-size: 12px;
  font-weight: 600;
  font-style: italic;
  color: rgba(255,255,255,.6);
  margin-bottom: 10px;
}

.card-sheet-cost {
  display: inline-block;
  background: rgba(255,215,0,.2);
  border: 2px solid rgba(255,215,0,.5);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 900;
  color: #ffd700;
  margin-bottom: 10px;
}

.card-sheet-text {
  font-size: 12px;
  line-height: 1.5;
  color: rgba(255,255,255,.85);
  white-space: pre-wrap;
}

/* Boutons d'actions zone */
.zone-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}

.zone-action-btn {
  padding: 10px 16px;
  border-radius: 10px;
  border: 1.5px solid rgba(255,255,255,.2);
  background: rgba(255,255,255,.08);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 150ms ease;
  white-space: nowrap;
}

.zone-action-btn:hover {
  background: rgba(255,255,255,.15);
  border-color: rgba(255,255,255,.3);
  transform: translateY(-2px);
}

.zone-action-btn:active {
  transform: translateY(0);
}

/* Actions carte */
.card-actions-section {
  margin-bottom: 14px;
}

.card-actions-title {
  font-size: 13px;
  font-weight: 700;
  color: rgba(255,255,255,.7);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card-action-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card-action-item {
  padding: 10px 14px;
  border-radius: 8px;
  border: 1.5px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.05);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 150ms ease;
}

.card-action-item:hover {
  background: rgba(255,255,255,.1);
  border-color: rgba(255,255,255,.25);
  transform: translateX(4px);
}

.card-action-item:active {
  transform: translateX(0);
}

.card-action-item.disabled-action {
  opacity: 0.5;
  cursor: not-allowed;
  background: rgba(255,255,255,.03);
  border-color: rgba(255,255,255,.08);
}

.card-action-item.disabled-action:hover {
  background: rgba(255,255,255,.03);
  border-color: rgba(255,255,255,.08);
  transform: translateX(0);
}

/* Marqueurs (counters) */
.counters-section {
  margin-bottom: 14px;
}

.counter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 8px;
  margin-bottom: 6px;
}

.counter-label {
  font-size: 13px;
  font-weight: 700;
  color: rgba(255,255,255,.8);
}

.counter-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.counter-value {
  min-width: 30px;
  text-align: center;
  font-size: 16px;
  font-weight: 900;
  color: #4ac3ff;
}

.counter-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1.5px solid rgba(255,255,255,.2);
  background: rgba(255,255,255,.08);
  color: #fff;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
  transition: all 150ms ease;
}

.counter-btn:hover {
  background: rgba(255,255,255,.15);
  transform: scale(1.05);
}

.counter-btn:active {
  transform: scale(0.95);
}

/* Note section */
.note-section {
  margin-bottom: 14px;
}

.note-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1.5px solid rgba(255,255,255,.2);
  background: rgba(255,255,255,.08);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  resize: vertical;
  min-height: 60px;
}

.note-input:focus {
  outline: none;
  border-color: #4ac3ff;
  background: rgba(255,255,255,.12);
}

.note-input::placeholder {
  color: rgba(255,255,255,.4);
}


/* ===== FIX: UI overlays above the unified panel overlay ===== */
.history-panel{ z-index: 10050 !important; }
.toastWrap{ z-index: 10060 !important; }
.reconnecting-banner, .spectator-mode{ z-index: 10040 !important; }
