/* Origines v0.9.0 — Phase 3 board-first composition contract.
   This file is loaded after each family stylesheet and is authoritative for
   composition only. Game geometry remains in the family renderers/styles. */

:root{
  --ag-board-gap:.6rem;
  --ag-board-rail-wide:320px;
  --ag-board-rail-compact:280px;
  --ag-board-tablet-secondary:28dvh;
  --ag-game-dock-reserve:3.75rem;
  --ag-stage-pad:.72rem;
}

.ag-board-first-main{
  min-width:0;
  min-height:0;
  grid-template-rows:auto auto minmax(0,1fr)!important;
  gap:.42rem!important;
}
.ag-game-intro{min-width:0;margin:0!important}
.ag-variant-strip{
  min-width:0;
  min-height:0;
  margin:0!important;
  overflow-x:auto;
  overflow-y:hidden;
  scroll-snap-type:x proximity;
  scrollbar-width:thin;
  overscroll-behavior-x:contain;
}
.ag-variant-strip>*{scroll-snap-align:start}
.ag-board-first-layout{
  min-width:0;
  min-height:0;
  height:100%;
  display:grid!important;
  grid-template-columns:minmax(0,1fr) minmax(300px,var(--ag-board-rail-wide))!important;
  grid-template-rows:minmax(0,1fr) auto!important;
  gap:var(--ag-board-gap)!important;
  align-items:stretch;
}
.ag-board-stage{
  grid-column:1;
  grid-row:1;
  min-width:0;
  min-height:0;
  height:100%;
  overflow:hidden!important;
  display:flex!important;
  flex-direction:column;
  padding:var(--ag-stage-pad)!important;
  contain:layout paint;
}
.ag-board-stage :is(.board-heading,.board-top){flex:0 0 auto}
.ag-board-stage :is(.carre-board,.heritage-board,.nim-rows){min-width:0;min-height:0}
.ag-game-rail{
  grid-column:2;
  grid-row:1 / span 2;
  min-width:0;
  min-height:0;
  height:100%;
  overflow-y:auto!important;
  overflow-x:hidden!important;
  overscroll-behavior:contain;
  scrollbar-gutter:stable;
  container-type:inline-size;
  container-name:game-rail;
  align-content:start;
  gap:.5rem!important;
}
.ag-game-rail>.ag-panel,.ag-game-rail>ag-historical-guide{min-width:0}
.ag-resource-layer{min-width:0;min-height:0}
.ag-game-dock{display:none}

/* The board, not the side rail, owns the visual weight on large desktops. */
@media (min-width:1200px) and (min-height:521px){
  .ag-board-first-main{--ag-board-rail-wide:320px;--ag-stage-pad:.78rem}
  .ag-board-stage :is(.carre-board,.heritage-board){max-width:min(100%,820px)}
}

/* Compact desktop / tablet landscape. */
@media (min-width:900px) and (max-width:1199px) and (min-height:521px){
  .ag-board-first-main{--ag-board-rail-wide:var(--ag-board-rail-compact);--ag-stage-pad:.62rem}
  .ag-board-first-layout{grid-template-columns:minmax(0,1fr) minmax(250px,var(--ag-board-rail-compact))!important}
  .ag-game-intro :is(#collectionHero,.traditional-head>div>p:not(.eyebrow)){display:none}
  .ag-variant-strip :is(.variant-card,.heritage-variant){min-width:148px}
}

/* Tablet portrait is deliberately NOT the phone UI. The physical board gets a
   full-width row; Partie remains available beneath it while resources become a
   temporary layer when opened. */
@media (min-width:700px) and (max-width:899px) and (orientation:portrait) and (min-height:700px){
  .ag-board-first-main{
    --ag-stage-pad:.55rem;
    grid-template-rows:auto auto minmax(0,1fr)!important;
  }
  .ag-board-first-layout{
    grid-template-columns:1fr!important;
    grid-template-rows:minmax(0,1fr) auto auto!important;
    gap:.38rem!important;
  }
  .ag-board-stage{min-height:0!important;height:100%!important}
  .ag-game-rail{
    grid-column:1!important;
    grid-row:3!important;
    height:auto!important;
    max-height:var(--ag-board-tablet-secondary)!important;
    display:grid!important;
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    grid-template-rows:none!important;
    grid-auto-rows:min-content;
    overflow:auto!important;
  }
  .ag-game-rail>#onlineLobbyRoot,
  .ag-game-rail>.online-lobby,
  .ag-game-rail>.ag-resource-layer,
  .ag-game-rail>.ag-tutorial-panel:not([hidden]){grid-column:1/-1}
  .ag-game-dock{display:none!important}
  .mobile-panel-backdrop{display:none!important}
  .ag-variant-strip{display:flex!important;gap:.35rem!important;padding-bottom:.08rem!important}
  .ag-variant-strip :is(.variant-card,.heritage-variant){flex:0 0 154px!important;width:auto!important;min-height:54px!important}

  body[data-resource-open="true"] .ag-game-rail{
    position:fixed!important;
    z-index:82;
    left:max(1rem,env(safe-area-inset-left))!important;
    right:max(1rem,env(safe-area-inset-right))!important;
    top:max(4rem,calc(env(safe-area-inset-top) + 3.2rem))!important;
    bottom:max(1rem,env(safe-area-inset-bottom))!important;
    height:auto!important;
    max-height:none!important;
    display:block!important;
    padding:.65rem!important;
    border:1px solid rgba(209,173,104,.24);
    border-radius:16px;
    background:rgba(9,13,18,.985);
    box-shadow:0 24px 72px rgba(0,0,0,.68);
    overflow:auto!important;
  }
  body[data-resource-open="true"]::after{
    content:"";
    position:fixed;
    z-index:76;
    inset:0;
    background:rgba(0,0,0,.56);
    pointer-events:none;
  }
}

/* Phone portrait: board fills the playable viewport; everything secondary is
   reached from the bottom dock and rendered as an accessible temporary sheet. */
@media (max-width:699px) and (orientation:portrait){
  .ag-board-first-main{
    grid-template-rows:minmax(0,1fr)!important;
    padding-bottom:var(--ag-game-dock-reserve)!important;
    gap:0!important;
  }
  .ag-game-intro{display:none!important}
  .ag-board-first-layout{
    grid-template-columns:1fr!important;
    grid-template-rows:minmax(0,1fr) auto!important;
    gap:.18rem!important;
  }
  .ag-board-stage{
    height:100%!important;
    padding:.36rem!important;
    border-radius:12px!important;
  }
  .ag-board-stage :is(.board-heading,.board-top){min-height:36px!important}
  .ag-board-stage :is(.carre-board,.heritage-board){flex:1 1 auto;max-width:100%;max-height:100%;margin:.08rem auto!important}
  .ag-game-dock{display:grid!important}
  .ag-variant-strip,.ag-game-rail{
    position:fixed!important;
    z-index:82;
    left:max(.3rem,env(safe-area-inset-left))!important;
    right:max(.3rem,env(safe-area-inset-right))!important;
    bottom:calc(var(--ag-game-dock-reserve) + env(safe-area-inset-bottom))!important;
    width:auto!important;
    height:auto!important;
    max-height:min(72dvh,640px)!important;
    padding:.55rem!important;
    border:1px solid rgba(209,173,104,.24);
    border-radius:15px;
    background:rgba(9,13,18,.985);
    box-shadow:0 20px 62px rgba(0,0,0,.72);
    overflow:auto!important;
    visibility:hidden!important;
    opacity:0;
    pointer-events:none;
    transform:translateY(12px);
  }
  body[data-mobile-drawer="variants"] .ag-variant-strip,
  body[data-mobile-drawer="game"] .ag-game-rail,
  body[data-mobile-drawer="resources"] .ag-game-rail,
  body[data-mobile-drawer="tutorial"] .ag-game-rail{
    visibility:visible!important;
    opacity:1;
    pointer-events:auto;
    transform:none;
  }
  body[data-mobile-drawer="variants"] .ag-variant-strip{
    display:grid!important;
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    gap:.35rem!important;
  }
  body[data-mobile-drawer="variants"] .ag-variant-strip>*{width:auto!important;min-width:0!important;min-height:52px!important}
  body[data-mobile-drawer="game"] .ag-game-rail{display:grid!important;grid-template-columns:1fr!important;grid-auto-rows:auto!important}
  .ag-game-rail>.historical-summary, .ag-game-rail>ag-historical-guide{display:none!important}
}

/* Low-height landscape phone: keep the physical board wide and move the dock to
   the safe right edge. The shell owns the dock geometry; this contract owns the
   content sheets and board allocation. */
@media (max-height:520px) and (orientation:landscape){
  .ag-board-first-main{
    grid-template-rows:minmax(0,1fr)!important;
    padding-right:3.55rem!important;
    padding-bottom:.08rem!important;
    gap:0!important;
  }
  .ag-game-intro{display:none!important}
  .ag-board-first-layout{grid-template-columns:1fr!important;grid-template-rows:minmax(0,1fr) auto!important;gap:0!important}
  .ag-board-stage{height:100%!important;padding:.2rem!important;border-radius:10px!important}
  .ag-board-stage :is(.board-heading,.board-top){min-height:30px!important}
  .ag-board-stage :is(.carre-board,.heritage-board){margin:0 auto!important;max-height:100%}
  .ag-game-dock{display:grid!important}
  .ag-variant-strip,.ag-game-rail{
    position:fixed!important;
    z-index:82;
    left:max(.25rem,env(safe-area-inset-left))!important;
    right:3.55rem!important;
    top:max(.25rem,env(safe-area-inset-top))!important;
    bottom:max(.25rem,env(safe-area-inset-bottom))!important;
    width:auto!important;
    height:auto!important;
    max-height:none!important;
    padding:.45rem!important;
    border:1px solid rgba(209,173,104,.24);
    border-radius:14px;
    background:rgba(9,13,18,.985);
    box-shadow:0 18px 54px rgba(0,0,0,.72);
    overflow:auto!important;
    visibility:hidden!important;
    opacity:0;
    pointer-events:none;
  }
  body[data-mobile-drawer="variants"] .ag-variant-strip,
  body[data-mobile-drawer="game"] .ag-game-rail,
  body[data-mobile-drawer="resources"] .ag-game-rail,
  body[data-mobile-drawer="tutorial"] .ag-game-rail{
    visibility:visible!important;
    opacity:1;
    pointer-events:auto;
  }
}

/* Shape guidance shared explicitly by renderers. */
.heritage-board[data-board-shape="square"]{width:min(70dvh,760px,100%)}
.heritage-board[data-board-shape="wide"],
.heritage-board[data-board-shape="track"],
.heritage-board[data-board-shape="congkak"]{width:100%;max-width:100%}

@media (min-width:700px) and (max-width:899px) and (orientation:portrait){
  .heritage-board[data-board-shape="square"]{width:min(62dvh,100%);min-height:250px}
  .heritage-board[data-board-shape="wide"],.heritage-board[data-board-shape="track"]{width:100%;min-height:210px}
}

@media (max-width:699px) and (orientation:portrait){
  .heritage-board[data-board-shape="square"]{width:min(100%,calc(100dvh - 120px));height:auto}
  .heritage-board[data-board-shape="wide"],.heritage-board[data-board-shape="track"],.heritage-board[data-board-shape="congkak"]{width:100%;height:auto;max-height:100%;overflow:hidden}
}

/* Keep all controls comfortably tappable unless the board geometry itself makes
   44px impossible (e.g. Dhamet 9×9 intersections). */
@media (max-width:899px){
  .ag-game-rail .ag-button,.ag-game-dock .ag-button{min-height:44px}
  .ag-game-rail select,.ag-game-rail input{min-height:42px}
}

/* Dhamet 9×9: 44px nodes cannot fit at phone widths, so preserve a documented
   26px physical target while keeping spacing and the whole 9×9 graph visible. */
.carre-board[data-size="9"] .node{width:clamp(26px,6.6%,38px)}

@media(prefers-reduced-motion:reduce){
  .ag-variant-strip,.ag-game-rail{scroll-behavior:auto!important;transition:none!important}
}

/* Shared rail normalization: old families used different grid definitions. */
.ag-game-rail{display:grid!important;grid-template-columns:1fr!important;grid-auto-rows:auto}
.ag-game-intro{min-height:44px!important;align-items:center!important}
.ag-game-intro h1{margin:0!important;font-size:clamp(1.45rem,2.65vw,2.35rem)!important}
.ag-game-intro :is(#collectionTagline,.traditional-head p:not(.eyebrow)){margin:.08rem 0!important}

/* Mid-size landscape tablets use the compact rail rather than falling back to
   either the large desktop rail or the phone drawer model. */
@media (min-width:700px) and (max-width:899px) and (orientation:landscape) and (min-height:521px){
  .ag-board-first-main{--ag-board-rail-wide:250px;--ag-stage-pad:.5rem}
  .ag-board-first-layout{grid-template-columns:minmax(0,1fr) 250px!important}
  .ag-game-intro #collectionHero{display:none!important}
  .ag-game-rail{grid-template-columns:1fr!important}
  .ag-variant-strip{max-height:76px}
}

@media (min-width:700px) and (max-width:899px) and (orientation:portrait) and (min-height:700px){
  .ag-variant-strip.variant-sections>.variant-family{flex:0 0 min(320px,78vw)!important}
}

@media (max-width:699px) and (orientation:portrait){
  body[data-mobile-drawer="variants"] .ag-variant-strip.variant-sections{grid-template-columns:1fr!important}
  body[data-mobile-drawer="variants"] .ag-variant-strip.variant-sections>.variant-family{width:100%!important;min-width:0!important}
  .ag-board-stage .move-controls{
    flex:0 0 auto;
    display:grid!important;
    grid-template-columns:repeat(3,minmax(0,1fr));
    gap:.24rem!important;
    padding:.3rem!important;
  }
  .ag-board-stage .move-controls label{font-size:.68rem}
  .ag-board-stage .move-controls :is(input,select){width:100%;min-width:0;min-height:36px}
  .ag-board-stage .move-controls .ag-button{min-height:40px}
  .ag-board-stage .nim-rows{flex:1 1 auto;overflow:auto;margin:.15rem 0!important}
  .rules-sheet{
    left:max(.3rem,env(safe-area-inset-left))!important;
    right:max(.3rem,env(safe-area-inset-right))!important;
    top:auto!important;
    bottom:calc(var(--ag-game-dock-reserve) + env(safe-area-inset-bottom))!important;
    width:auto!important;
    max-height:78dvh!important;
    border-radius:16px!important;
    padding:.75rem!important;
  }
  .rules-head{top:-.75rem!important}
}

@media (max-width:430px) and (orientation:portrait){
  .ag-board-stage .move-controls{grid-template-columns:repeat(2,minmax(0,1fr))}
  .ag-board-stage .move-controls #moveButton{grid-column:1/-1}
  .ag-board-stage .nim-rows{padding:.25rem!important;border-width:4px!important}
  .ag-board-stage .nim-row{min-height:32px!important}
  .ag-board-stage .match{height:clamp(21px,3.7dvh,31px)!important;width:7px!important}
}

@media (max-height:520px) and (orientation:landscape){
  .ag-board-stage .move-controls{display:grid!important;grid-template-columns:repeat(3,minmax(0,1fr));gap:.18rem!important;padding:.2rem!important}
  .ag-board-stage .move-controls label{font-size:.62rem}
  .ag-board-stage .move-controls :is(input,select){min-height:30px}
  .ag-board-stage .move-controls .ag-button{min-height:32px}
  .ag-board-stage .nim-rows{flex:1 1 auto;overflow:auto;margin:.08rem 0!important;padding:.2rem!important;border-width:4px!important}
  .rules-sheet{
    left:max(.25rem,env(safe-area-inset-left))!important;
    right:3.55rem!important;
    top:max(.25rem,env(safe-area-inset-top))!important;
    bottom:max(.25rem,env(safe-area-inset-bottom))!important;
    width:auto!important;
    max-height:none!important;
    border-radius:14px!important;
  }
}

/* v1.2.0 Phase 13 — canonical game-zone architecture.
   Composition only: collection header -> variant selector -> play stage ->
   action console -> Partie rail. Geometry, rules and object placement stay owned
   by the existing family renderers/calibrations. */
[data-game-architecture="v1"] [data-game-zone]{min-width:0}
[data-game-architecture="v1"] [data-game-zone="collection-header"]{flex:0 0 auto}
[data-game-architecture="v1"] [data-game-zone="variant-selector"]{flex:0 0 auto}
[data-game-architecture="v1"] [data-game-zone="play-layout"]{min-height:0}
[data-game-architecture="v1"] [data-game-zone="play-stage"]{min-height:0}
[data-game-architecture="v1"] [data-game-zone="variant-context"]{flex:0 0 auto;min-height:36px}
[data-game-architecture="v1"] [data-game-zone="board"]{flex:1 1 auto;min-height:0}
[data-game-architecture="v1"] [data-game-zone="action-console"]{flex:0 0 auto}
[data-game-architecture="v1"] [data-game-zone="game-rail"]{min-height:0}
[data-game-architecture="v1"] [data-game-zone="game-panel"]{min-width:0}

.ag-variant-context{display:flex;align-items:flex-start;justify-content:space-between;gap:.6rem;padding-bottom:.32rem;border-bottom:1px solid rgba(237,224,199,.055)}
.ag-variant-context .board-title-block{min-width:0;flex:1}
.ag-variant-context h2{margin:.08rem 0 0;font-size:1.08rem;line-height:1.15}

.ag-action-console{
  grid-column:1;
  grid-row:2;
  flex:0 0 auto;
  min-width:0;
  display:grid;
  grid-template-columns:minmax(0,1fr) auto;
  align-items:center;
  gap:.45rem .65rem;
  margin-top:.38rem;
  padding:.46rem .55rem .06rem;
  border-top:1px solid rgba(209,173,104,.16);
}
.ag-action-console>.game-state-line{min-width:0;display:flex;align-items:center;gap:.42rem;flex-wrap:wrap;margin:0}
.ag-action-console>.game-state-line .game-state-message{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ag-action-console-actions{display:flex;align-items:center;justify-content:flex-end;gap:.35rem;min-width:0}
.ag-action-console-actions:empty{display:none}
.ag-action-console-actions .ag-button{min-height:34px;padding:.35rem .62rem}
.ag-action-console--forms{grid-template-columns:1fr;align-items:stretch;gap:.34rem;padding-top:.38rem}
.ag-action-console--forms .move-controls{margin:0;min-width:0}
.ag-action-console--forms #limitGauge{margin:0;min-height:0}
.alquerque-console-actions .draw-actions{display:flex;align-items:center;gap:.35rem;margin:0}
.alquerque-console-actions #drawResponse:not([hidden]){display:inline-flex;gap:.3rem}

/* The Partie panel owns session/mode controls; contextual move controls stay in
   the action console. This keeps the visual hierarchy stable without restyling
   button semantics, which remains Phase 14. */
[data-game-zone="game-panel"]>.eyebrow:first-child{margin-top:0}

@media (max-width:899px){
  .ag-action-console{padding:.34rem .4rem .04rem;gap:.3rem .4rem}
  .ag-action-console>.game-state-line{font-size:.82rem}
  .ag-action-console-actions .ag-button{min-height:36px;padding-inline:.5rem}
}

@media (max-width:699px) and (orientation:portrait){
  .ag-variant-context{min-height:32px!important;padding-bottom:.2rem}
  .ag-variant-context h2{font-size:.92rem}
  .ag-action-console{margin-top:.18rem;padding:.25rem .28rem 0;grid-template-columns:minmax(0,1fr) auto}
  .ag-action-console--forms{grid-template-columns:1fr}
  .ag-action-console>.game-state-line .game-state-message{max-width:52vw}
}

@media (max-height:520px) and (orientation:landscape){
  .ag-variant-context{min-height:28px!important;padding-bottom:.12rem}
  .ag-variant-context h2{font-size:.88rem}
  .ag-action-console{margin-top:.12rem;padding:.18rem .22rem 0;gap:.22rem}
  .ag-action-console>.game-state-line{font-size:.76rem}
  .ag-action-console-actions .ag-button{min-height:30px;padding:.22rem .42rem;font-size:.74rem}
}

@media (max-width:699px) and (orientation:portrait){
  [data-game-architecture="v1"] [data-game-zone="play-stage"]{grid-column:1;grid-row:1}
  [data-game-architecture="v1"] [data-game-zone="action-console"]{grid-column:1;grid-row:2}
  [data-game-architecture="v1"] [data-game-zone="game-rail"]{grid-column:1;grid-row:auto}
}

@media (max-height:520px) and (orientation:landscape){
  [data-game-architecture="v1"] [data-game-zone="play-stage"]{grid-column:1;grid-row:1}
  [data-game-architecture="v1"] [data-game-zone="action-console"]{grid-column:1;grid-row:2}
  [data-game-architecture="v1"] [data-game-zone="game-rail"]{grid-column:1;grid-row:auto}
}


/* v1.2.0 Phase 14 — semantic game-control language
   v1.3.5 Pass 2 consolidates its visuals on shared semantic tokens only.
   Visual/control semantics only. No board geometry, rules, handlers or navigation ordering. */
[data-game-architecture="v1"] .ag-button[data-control-role]{
  min-height:var(--ag-control-min-height);border-radius:var(--ag-control-radius);
  font-weight:var(--ag-font-weight-control);letter-spacing:var(--ag-letter-control);
  border-color:var(--ag-border-control);background:var(--ag-surface-control);color:var(--ag-text-primary);
  box-shadow:none;
  transition:background-color var(--ag-motion-fast) var(--ag-ease-standard),border-color var(--ag-motion-fast) var(--ag-ease-standard),color var(--ag-motion-fast) var(--ag-ease-standard),box-shadow var(--ag-motion-fast) var(--ag-ease-standard),transform var(--ag-motion-fast) var(--ag-ease-standard),opacity var(--ag-motion-fast) var(--ag-ease-standard);
}
[data-game-architecture="v1"] .ag-button[data-control-role="primary"]{
  border-color:var(--ag-border-accent);background:var(--ag-accent-gradient);color:var(--ag-text-on-accent);
  font-weight:var(--ag-font-weight-control-strong);box-shadow:var(--ag-elevation-control);
}
[data-game-architecture="v1"] .ag-button[data-control-role="secondary"]{
  border-color:var(--ag-border-control);background:var(--ag-surface-control);color:var(--ag-text-primary);
}
[data-game-architecture="v1"] .ag-button[data-control-role="contextual"]{
  border-color:var(--ag-border-contextual);background:var(--ag-surface-accent-soft);color:var(--ag-text-contextual);
}
[data-game-architecture="v1"] .ag-button[data-control-role="danger"]{
  border-color:var(--ag-border-danger);background:var(--ag-surface-danger-soft);color:var(--ag-text-danger);
}
[data-game-architecture="v1"] .ag-button[data-control-role="toggle"]{
  border-color:var(--ag-border-control);background:var(--ag-surface-control-pressed);color:var(--ag-text-secondary);font-weight:700;
}
[data-game-architecture="v1"] .ag-button[data-control-role="toggle"][aria-pressed="true"]{
  border-color:var(--ag-border-accent-strong);background:var(--ag-surface-accent-active);color:var(--ag-text-primary);box-shadow:var(--ag-toggle-ring);
}
@media(hover:hover){
  [data-game-architecture="v1"] .ag-button[data-control-role]:not(:disabled):not([aria-disabled="true"]):hover{transform:translateY(-1px);border-color:var(--ag-border-control-hover);}
  [data-game-architecture="v1"] .ag-button[data-control-role="primary"]:not(:disabled):hover{background:var(--ag-accent-gradient-hover);box-shadow:var(--ag-elevation-control-hover);}
  [data-game-architecture="v1"] .ag-button[data-control-role="secondary"]:not(:disabled):hover{background:var(--ag-surface-control-hover);}
  [data-game-architecture="v1"] .ag-button[data-control-role="contextual"]:not(:disabled):hover{background:var(--ag-surface-accent-active);}
  [data-game-architecture="v1"] .ag-button[data-control-role="danger"]:not(:disabled):hover{border-color:var(--ag-border-danger-strong);filter:brightness(1.06);}
  [data-game-architecture="v1"] .ag-button[data-control-role="toggle"]:not(:disabled):hover{background:var(--ag-surface-control-hover);}
  [data-game-architecture="v1"] :is(select,input)[data-control-field]:not(:disabled):not([readonly]):hover{border-color:var(--ag-border-contextual);}
}
[data-game-architecture="v1"] .ag-button[data-control-role]:not(:disabled):active{transform:translateY(0);box-shadow:var(--ag-elevation-pressed)}
[data-game-architecture="v1"] .ag-button[data-control-role]:focus-visible,
[data-game-architecture="v1"] :is(select,input)[data-control-field]:focus-visible{
  outline:2px solid var(--ag-focus);outline-offset:2px;box-shadow:var(--ag-focus-ring);
}
[data-game-architecture="v1"] .ag-button[data-control-role]:disabled,
[data-game-architecture="v1"] .ag-button[data-control-role][aria-disabled="true"]{
  opacity:.42;cursor:not-allowed;transform:none;box-shadow:none;filter:saturate(.55);
}
[data-game-architecture="v1"] .ag-button[data-control-state="pending"],
[data-game-architecture="v1"] .ag-button[aria-busy="true"]{
  opacity:1;cursor:progress;border-color:var(--ag-border-control-hover);box-shadow:var(--ag-toggle-ring);
}
[data-game-architecture="v1"] .ag-button[data-control-state="pending"]::after,
[data-game-architecture="v1"] .ag-button[aria-busy="true"]::after{
  content:"";width:.42rem;aspect-ratio:1;border-radius:50%;background:currentColor;opacity:.72;box-shadow:0 0 0 .2rem var(--ag-surface-accent-soft);
}
[data-game-architecture="v1"] :is(select,input)[data-control-field]{
  min-height:var(--ag-control-min-height);width:100%;min-width:0;border:1px solid var(--ag-border-control);border-radius:var(--ag-control-radius);
  background:var(--ag-field-surface);color:var(--ag-text-primary);padding:.42rem .68rem;font:inherit;line-height:1.2;
  box-shadow:inset 0 1px 0 var(--ag-surface-control);
  transition:border-color var(--ag-motion-fast) var(--ag-ease-standard),background-color var(--ag-motion-fast) var(--ag-ease-standard),box-shadow var(--ag-motion-fast) var(--ag-ease-standard),opacity var(--ag-motion-fast) var(--ag-ease-standard);
}
[data-game-architecture="v1"] select[data-control-field]{color-scheme:dark}
[data-game-architecture="v1"] :is(select,input)[data-control-field]:disabled,
[data-game-architecture="v1"] :is(select,input)[data-control-field][readonly]{opacity:.5;cursor:not-allowed;background:var(--ag-surface-disabled)}
[data-game-architecture="v1"] :is(select,input)[data-control-field]:invalid:not(:focus){border-color:var(--ag-border-danger-strong)}
[data-game-architecture="v1"] [data-game-zone="game-panel"] label,
[data-game-architecture="v1"] [data-game-zone="action-console"] label{color:var(--ag-text-secondary);font-size:.76rem;font-weight:var(--ag-font-weight-label);letter-spacing:var(--ag-letter-control)}
[data-game-architecture="v1"] [data-game-zone="action-console"] .ag-button[data-control-role="primary"]{min-width:7.5rem}
@media(max-width:700px){
  [data-game-architecture="v1"] .ag-button[data-control-role]{min-height:var(--ag-control-min-height-touch)}
  [data-game-architecture="v1"] :is(select,input)[data-control-field]{min-height:var(--ag-control-min-height-touch);font-size:16px}
}
@media(prefers-reduced-motion:reduce){
  [data-game-architecture="v1"] .ag-button[data-control-role],
  [data-game-architecture="v1"] :is(select,input)[data-control-field]{transition:none!important}
}


/* v1.2.0 Phase 15 — stable resource navigation slots */
[data-navigation-slot]{position:relative}
[data-navigation-slot][data-navigation-state="selected"]{box-shadow:inset 0 0 0 1px rgba(231,196,120,.46)}
[data-navigation-slot][data-navigation-state="coming"],
[data-navigation-slot][data-navigation-state="to-document"]{opacity:.68}
[data-navigation-slot][data-navigation-state="coming"]{border-style:dashed}
[data-navigation-slot][data-navigation-state="to-document"]{border-color:rgba(125,173,196,.4)}

/* v1.2.0 Phase 16 — viewport-safe mobile/PWA composition.
   The board-first contract consumes the visual viewport variables emitted by
   pwa.js; gameplay geometry and calibrated anchors are intentionally untouched. */
@media (max-width:699px) and (orientation:portrait){
  .ag-board-first-main{height:100%;max-height:100%;min-height:0}
  .ag-board-first-layout{height:100%;max-height:100%;min-height:0}
  .ag-board-stage{min-height:0;max-height:100%}
  .ag-board-stage [data-game-zone="board"]{min-height:0;max-height:100%}
  .ag-variant-strip,.ag-game-rail{
    left:max(.3rem,var(--ag-safe-left,0px))!important;
    right:max(.3rem,var(--ag-safe-right,0px))!important;
    bottom:calc(var(--ag-game-dock-reserve) + var(--ag-safe-bottom,0px))!important;
    max-height:min(72dvh,calc(var(--ag-viewport-height,100dvh) - 5rem))!important;
  }
  .rules-sheet{
    left:max(.3rem,var(--ag-safe-left,0px))!important;
    right:max(.3rem,var(--ag-safe-right,0px))!important;
    bottom:calc(var(--ag-game-dock-reserve) + var(--ag-safe-bottom,0px))!important;
    max-height:min(78dvh,calc(var(--ag-viewport-height,100dvh) - 4.6rem))!important;
  }
}
@media (max-height:520px) and (orientation:landscape){
  .ag-board-first-main{
    height:100%;max-height:100%;min-height:0;
    padding-left:var(--ag-safe-left,0px)!important;
    padding-right:calc(3.55rem + var(--ag-safe-right,0px))!important;
  }
  .ag-board-first-layout,.ag-board-stage{height:100%;max-height:100%;min-height:0}
  .ag-variant-strip,.ag-game-rail{
    left:max(.25rem,var(--ag-safe-left,0px))!important;
    right:calc(3.55rem + var(--ag-safe-right,0px))!important;
    top:max(.25rem,var(--ag-safe-top,0px))!important;
    bottom:max(.25rem,var(--ag-safe-bottom,0px))!important;
  }
  .rules-sheet{
    left:max(.25rem,var(--ag-safe-left,0px))!important;
    right:calc(3.55rem + var(--ag-safe-right,0px))!important;
    top:max(.25rem,var(--ag-safe-top,0px))!important;
    bottom:max(.25rem,var(--ag-safe-bottom,0px))!important;
  }
}
html[data-pwa-display-mode="fullscreen"] .ag-board-first-main,
html[data-pwa-display-mode="standalone"] .ag-board-first-main{min-height:0;max-height:100%}

/* v1.3.1 — collapsible variant navigation and contextual rule explanations */
.ag-variant-collapse-toggle{display:inline-flex!important;align-items:center;justify-content:center;gap:.35rem;white-space:nowrap}
.ag-variant-collapse-glyph{font-size:.72em;opacity:.72}
.ag-rule-notice{margin:.35rem 0 0;padding:.48rem .62rem;border:1px solid rgba(209,173,104,.22);border-radius:.7rem;background:rgba(181,138,77,.065);max-width:min(100%,720px)}
.ag-rule-notice[data-kind="blocked"]{border-color:rgba(209,173,104,.42);background:rgba(181,138,77,.09)}
.ag-rule-notice-title{display:block;color:var(--ag-brass);font-size:.76rem;letter-spacing:.025em;margin-bottom:.18rem}
.ag-rule-notice-list{margin:0;padding-left:1.08rem;display:grid;gap:.12rem;color:var(--ag-text);font-size:.74rem;line-height:1.3}
.ag-rule-notice-list li::marker{color:var(--ag-brass)}
@media(min-width:700px){
  .ag-variant-strip[data-desktop-collapsed="true"]{display:none!important}
  .ag-board-first-main[data-variants-collapsed="true"]{grid-template-rows:auto minmax(0,1fr)!important}
  .ag-board-first-main[data-variants-collapsed="true"]>.ag-board-first-layout{grid-row:2}
}
@media(max-width:699px){
  .ag-variant-collapse-toggle{display:none!important}
  .ag-rule-notice{margin:.2rem 0 0;padding:.4rem .5rem;max-height:5.5rem;overflow:auto}
  .ag-rule-notice-title{font-size:.7rem}
  .ag-rule-notice-list{font-size:.68rem;line-height:1.22}
}
@media(max-height:520px) and (orientation:landscape){
  .ag-rule-notice{max-height:4.6rem;padding:.32rem .45rem}
}

/* v1.3.1 refinement — explanation boxes stay attached to the full action context. */
.ag-rule-notice{grid-column:1/-1;min-width:0}
[data-rule-inspect="true"]:not(:disabled){cursor:help}
@media(min-width:700px){
  .ag-game-rail [data-game-zone="game-panel"]{align-self:start;padding:.62rem .68rem!important}
  .ag-game-rail [data-game-zone="game-panel"] :is(.mode-row,.mode-actions,.session-action-row){gap:.3rem!important}
}


/* v1.3.3 — full-window responsive composition and mono-variant contract */
.ag-board-first-main[data-single-variant="true"]{grid-template-rows:auto minmax(0,1fr)!important}
.ag-board-first-main[data-single-variant="true"]>.ag-variant-strip{display:none!important}
.ag-board-first-main[data-single-variant="true"] .ag-variant-collapse-toggle{display:none!important}
.ag-board-first-main[data-single-variant="true"]>.ag-board-first-layout{grid-row:2!important}
.ag-action-console-actions{flex-wrap:wrap}
@media(min-width:1200px) and (min-height:521px){
  .ag-board-first-layout{grid-template-columns:minmax(0,1fr) minmax(260px,300px)!important}
  .ag-board-stage{padding:.62rem!important}
  .ag-board-stage :is(.carre-board,.heritage-board){max-width:min(100%,980px)}
}
@media(max-width:699px) and (orientation:portrait){
  .ag-action-console{position:relative;z-index:5;background:linear-gradient(180deg,rgba(8,11,15,.94),rgba(8,11,15,.985));padding-bottom:.15rem!important}
  .ag-action-console-actions{justify-content:flex-start;min-width:0;width:100%}
}


/* v1.3.3 Pass 2 — visualViewport/zoom hardening and critical-action guarantee.
   Composition only: no gameplay geometry, rules, calibration or hit targets. */
.ag-action-console{min-height:42px;max-width:100%;overflow:visible;align-self:end}
.ag-action-console-actions{max-width:100%}
.ag-action-console-actions>[data-control-role="primary"]{flex:0 0 auto}
html[data-viewport-class="medium"] .ag-game-intro :is(#collectionHero,.traditional-head>div>p:not(.eyebrow)){display:none}
@media(min-width:700px) and (orientation:landscape) and (min-height:521px) and (max-width:1100px){
  .ag-board-first-main{--ag-board-rail-wide:250px;--ag-stage-pad:.5rem}
  .ag-board-first-layout{grid-template-columns:minmax(0,1fr) minmax(220px,250px)!important;gap:.38rem!important}
  .ag-game-rail{min-width:0!important}
  .ag-action-console{grid-template-columns:1fr!important;gap:.28rem!important;margin-top:.18rem!important;padding:.28rem .35rem .06rem!important}
  .ag-action-console-actions{justify-content:flex-start!important;width:100%}
  .ag-variant-strip{max-height:74px}
}
@media(min-width:700px) and (max-height:700px) and (min-height:521px){
  .ag-game-intro{min-height:38px!important}
  .ag-game-intro :is(#collectionHero,.traditional-head>div>p:not(.eyebrow)){display:none!important}
  .ag-variant-strip{max-height:68px!important}
  .ag-board-stage{padding:.42rem!important}
  .ag-action-console{min-height:38px!important;max-height:132px;overflow:auto;overscroll-behavior:contain}
  .ag-action-console>.game-state-line{font-size:.78rem}
  .ag-action-console-actions .ag-button{min-height:34px}
}
@media(max-width:699px) and (orientation:portrait){
  .ag-action-console{min-height:44px;max-height:calc(34dvh - .25rem);overflow:auto;overscroll-behavior:contain;padding-bottom:max(.12rem,var(--ag-safe-bottom,0px))!important}
  .ag-action-console-actions>[data-control-role="primary"]{min-height:40px}
}
@media(max-height:520px) and (orientation:landscape){
  .ag-action-console{min-height:34px;max-height:34dvh;overflow:auto;overscroll-behavior:contain;background:rgba(8,11,15,.985)}
  .ag-action-console-actions{justify-content:flex-start!important;flex-wrap:wrap!important}
}


/* v1.3.5 Pass 3 — shared panel/menu/text hierarchy.
   Presentation only: no board geometry, rules, engine or calibration changes. */
:where(.collection-head,.traditional-head) .eyebrow,
:where(.control-panel,.coach-panel,.historical-summary,.play-controls,.online-lobby) .eyebrow,
.session-actions-label,
.local-resume-kicker{
  color:var(--ag-text-contextual);
  font-size:var(--ag-font-size-eyebrow);
  font-weight:var(--ag-font-weight-eyebrow);
  letter-spacing:var(--ag-letter-eyebrow);
  line-height:1.2;
  text-transform:uppercase;
}

:where(.collection-head,.traditional-head) h1{
  color:var(--ag-text-primary);
  font-family:var(--ag-font-serif);
  font-weight:400;
  letter-spacing:.025em;
  text-wrap:balance;
}

:where(.ag-variant-context,.board-top,.resource-heading,.online-lobby-head,.historical-summary,.coach-panel) h2,
:where(.historical-summary,.lobby-block,.rules-sheet) h3{
  color:var(--ag-text-primary);
  font-family:var(--ag-font-serif);
  font-weight:400;
  letter-spacing:.012em;
}

:where(.control-panel,.coach-panel,.historical-summary,.play-controls,.online-lobby,.resource-panel,.rules-sheet) :is(p,li,label),
.game-state-message,
.guide-relation{
  line-height:var(--ag-line-body);
}

/* Variant navigation is a quiet chrome layer; family artwork remains owned by Pass 4. */
.ag-variant-strip{
  border:1px solid var(--ag-border-panel);
  border-radius:var(--ag-r2);
  background:var(--ag-surface-rail);
  box-shadow:inset 0 1px 0 var(--ag-highlight-hairline);
}
.ag-variant-strip.variant-sections>.variant-family>h2{
  margin:.1rem 0 .32rem;
  color:var(--ag-text-secondary);
  font-size:var(--ag-font-size-eyebrow);
  font-weight:var(--ag-font-weight-eyebrow);
  letter-spacing:var(--ag-letter-eyebrow);
  line-height:1.2;
  text-transform:uppercase;
}
.ag-variant-collapse-toggle{
  color:var(--ag-text-subtle);
  font-size:var(--ag-font-size-meta);
  letter-spacing:var(--ag-letter-meta);
}

/* Partie rail: shared depth and typography, without family-specific restyling. */
.ag-game-rail>:is(.ag-panel,.online-lobby,ag-historical-guide),
.traditional-side>:is(.ag-panel,.online-lobby,ag-historical-guide){
  border-color:var(--ag-border-panel);
  background:var(--ag-surface-panel-soft);
  box-shadow:var(--ag-elevation-panel-soft);
}
[data-game-zone="game-panel"]>.eyebrow:first-child,
.play-controls>.eyebrow:first-child,
.historical-summary>.eyebrow:first-child{
  margin:0 0 .22rem;
}
:where(.control-panel,.play-controls) label{
  color:var(--ag-text-subtle);
  font-size:var(--ag-font-size-body);
  font-weight:var(--ag-font-weight-label);
}
:where(.control-panel,.play-controls) label>:is(select,input){
  margin-top:.2rem;
}
:where(.coach-panel,.historical-summary) :is(#coachText,p){
  color:var(--ag-text-secondary);
  font-size:var(--ag-font-size-body);
}

/* Resource panels and drawers share the same editorial ladder. */
.resource-panel,
.rules-sheet{
  border-color:var(--ag-border-panel-strong);
  background:var(--ag-surface-panel);
}
.resource-heading{
  border-bottom-color:var(--ag-border-divider);
  background:var(--ag-surface-panel);
}
.resource-heading h2,
.rules-head h2{
  font-size:var(--ag-font-size-panel-title);
}
.resource-panel #variantContent>section,
.rules-section{
  border-bottom-color:var(--ag-border-divider);
}
.resource-panel #variantContent h3,
.rules-section>h3{
  color:var(--ag-text-contextual);
  font-size:var(--ag-font-size-eyebrow);
  font-weight:var(--ag-font-weight-eyebrow);
  letter-spacing:var(--ag-letter-eyebrow);
  text-transform:uppercase;
}

/* The action console reads as a distinct interaction shelf, not another card. */
.ag-action-console{
  border:1px solid var(--ag-border-panel);
  border-top-color:var(--ag-border-panel-strong);
  border-radius:var(--ag-r2);
  background:var(--ag-surface-panel-inset);
  box-shadow:inset 0 1px 0 var(--ag-highlight-hairline);
}
.ag-action-console .game-turn-pill{
  border-color:var(--ag-border-contextual);
  background:var(--ag-surface-accent-soft);
  color:var(--ag-text-primary);
  font-size:var(--ag-font-size-body);
}
.ag-action-console .game-state-message{
  border-left-color:var(--ag-accent-metal-bright);
  color:var(--ag-text-secondary);
  font-size:var(--ag-font-size-meta);
}

/* Persistent rule explanations use the same semantic notice language. */
.ag-rule-notice{
  border-color:var(--ag-border-panel-strong);
  background:var(--ag-surface-notice);
  box-shadow:inset 0 1px 0 var(--ag-highlight-hairline);
}
.ag-rule-notice[data-kind="blocked"]{
  border-color:var(--ag-border-accent);
  background:var(--ag-surface-accent-soft);
}
.ag-rule-notice-title{
  color:var(--ag-text-contextual);
  font-size:var(--ag-font-size-eyebrow);
  font-weight:var(--ag-font-weight-eyebrow);
  letter-spacing:var(--ag-letter-meta);
}
.ag-rule-notice-list{
  color:var(--ag-text-primary);
  font-size:var(--ag-font-size-meta);
  line-height:var(--ag-line-compact);
}
.ag-rule-notice-list li::marker{color:var(--ag-accent-metal-bright)}

/* Mobile dock is chrome: flatter surface, stronger active state, same 44px targets. */
.mobile-game-toolbar{
  border-color:var(--ag-border-panel-strong);
  background:var(--ag-surface-dock);
  box-shadow:var(--ag-elevation-dock);
}
.mobile-game-toolbar .ag-button{
  color:var(--ag-text-subtle);
}
.mobile-game-toolbar .ag-button[aria-pressed="true"],
.mobile-game-toolbar .ag-button[data-navigation-state="active"]{
  border-color:var(--ag-border-accent);
  background:var(--ag-surface-accent-active);
  color:var(--ag-text-primary);
}

@media(max-width:760px), (max-height:520px) and (orientation:landscape){
  .ag-variant-strip{border-radius:.65rem}
  .ag-game-rail>:is(.ag-panel,.online-lobby,ag-historical-guide),
  .traditional-side>:is(.ag-panel,.online-lobby,ag-historical-guide){box-shadow:none}
  .ag-action-console{border-radius:.65rem}
}


/* v1.3.6 — rail/menu resilience across browser zoom and narrow containers.
   The rail adapts to its actual inline size instead of assuming that a viewport
   breakpoint guarantees enough room for long French labels. */
.ag-game-rail>*{min-width:0;max-width:100%}
.play-controls,.play-controls .mode-row,.traditional-session-actions,.traditional-session-actions .session-action-row{min-width:0;max-width:100%}
.play-controls .mode-row{grid-template-columns:repeat(3,minmax(0,1fr))}
.play-controls .mode-row .ag-button,
.traditional-session-actions .session-action-row .ag-button{
  min-width:0!important;max-width:100%;width:100%;white-space:normal!important;overflow-wrap:anywhere;text-wrap:balance;line-height:1.14;
}
.play-controls #modeHint{min-width:0;max-width:100%;overflow-wrap:anywhere}
@container game-rail (max-width:319px){
  .traditional-session-actions .session-action-row{grid-template-columns:1fr!important}
  .traditional-session-actions .session-action-row .ag-button{min-height:38px}
}
@container game-rail (max-width:239px){
  .play-controls .mode-row{grid-template-columns:1fr!important}
}
@media(max-width:699px) and (orientation:portrait), (max-height:520px) and (orientation:landscape){
  .ag-game-rail{overflow-x:hidden!important}
  body[data-mobile-drawer="game"] .ag-game-rail [data-game-zone="game-panel"]{width:100%;max-width:100%}
}


/* v1.7.6 — BOARD MAX mobile/tablet/PWA.
   Goal: maximise the physical board. Secondary navigation is temporary chrome;
   gameplay rules, engines, calibrated anchors and hit semantics are untouched. */
:root{
  --ag-board-max-dock:3.05rem;
  --ag-board-max-sheet-gap:.28rem;
  --ag-board-max-console:56px;
  --ag-action-shelf-band-height:56px;
  --ag-action-shelf-side-height:184px;
  --ag-board-aspect:1;
  --ag-board-max-w:100%;
  --ag-board-max-h:100%;
  /* v1.7.8 Phase 7 — shared capture/control collision contract. */
  --ag-controls-safe-right:0px;
  --ag-capture-gutter:6px;
}

@media (max-width:1199px), (max-height:700px) and (orientation:landscape){
  .ag-board-first-main{
    width:100%!important;max-width:none!important;height:100%!important;max-height:100%!important;
    margin:0!important;padding:0!important;gap:0!important;
    grid-template-rows:minmax(0,1fr)!important;
  }
  .ag-game-intro{display:none!important}
  .ag-board-first-layout{
    position:relative;display:grid!important;height:100%!important;max-height:100%!important;min-height:0!important;
    grid-template-columns:minmax(0,1fr)!important;grid-template-rows:minmax(0,1fr) auto!important;
    gap:0!important;padding:0!important;
  }
  .ag-board-stage{
    position:relative;grid-column:1!important;grid-row:1!important;height:100%!important;max-height:100%!important;
    min-height:0!important;padding:.16rem calc(var(--ag-board-max-dock) + .18rem) .12rem .16rem!important;
    border-radius:8px!important;container-type:size;container-name:board-stage;
    --ag-controls-safe-right:var(--ag-board-max-dock);--ag-capture-gutter:4px;
  }
  .ag-variant-context{
    position:absolute!important;z-index:9;left:.3rem;top:.3rem;right:calc(var(--ag-board-max-dock) + .45rem);
    width:auto;min-height:0!important;padding:0!important;border:0!important;pointer-events:none;
  }
  .ag-variant-context .board-title-block{display:flex;align-items:center;gap:.34rem;min-width:0}
  .ag-variant-context :is(.eyebrow,.board-phase){display:none!important}
  .ag-variant-context h2{
    max-width:min(62vw,26rem);margin:0!important;padding:.2rem .45rem;border:1px solid rgba(209,173,104,.2);
    border-radius:999px;background:rgba(8,11,15,.72);backdrop-filter:blur(8px);font-size:.72rem!important;
    line-height:1.08!important;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color:var(--ag-text-secondary);
  }
  .ag-board-stage [data-game-zone="board"]{min-width:0!important;min-height:0!important;max-width:100%!important;max-height:100%!important;margin:auto!important}
  .ag-board-stage>.learning-banner{position:absolute;z-index:10;left:.35rem;right:calc(var(--ag-board-max-dock) + .4rem);top:2.15rem;max-height:4rem;overflow:auto;margin:0!important;padding:.35rem .45rem!important;font-size:.7rem}

  /* One compact, safe action row replaces tall consoles. */
  .ag-action-console{
    grid-column:1!important;grid-row:2!important;height:var(--ag-board-max-console)!important;min-height:var(--ag-board-max-console)!important;max-height:var(--ag-board-max-console)!important;box-sizing:border-box!important;
    margin:0!important;padding:.22rem calc(var(--ag-board-max-dock) + .25rem) max(.12rem,var(--ag-safe-bottom,0px)) .28rem!important;
    display:flex!important;align-items:center!important;gap:.28rem!important;overflow:auto!important;
    border-top:1px solid rgba(209,173,104,.14)!important;background:rgba(8,11,15,.96)!important;
    scrollbar-width:none;overscroll-behavior:contain;
  }
  .ag-action-console::-webkit-scrollbar{display:none}
  .ag-action-console>.game-state-line{flex:1 1 auto!important;min-width:8rem;flex-wrap:nowrap!important;gap:.25rem!important}
  .ag-action-console>.game-state-line .game-state-message{max-width:38vw;white-space:normal!important;font-size:.65rem!important;line-height:1.15!important;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;line-clamp:2;overflow:hidden!important}
  .ag-action-console .game-turn-pill{min-height:28px!important;padding:.2rem .42rem!important;font-size:.66rem!important;white-space:nowrap}
  .ag-action-console-actions{flex:0 0 auto!important;flex-wrap:nowrap!important;gap:.22rem!important;width:auto!important}
  .ag-action-console-actions .ag-button,.ag-action-console .direct-confirm-button{min-height:42px!important;height:42px;padding:.2rem .48rem!important;font-size:.7rem!important;white-space:nowrap}
  .ag-action-console--forms{max-height:92px!important;display:grid!important;grid-template-columns:minmax(0,1fr)!important;align-items:stretch!important}
  .ag-action-console--forms .move-controls{max-height:62px;overflow:auto}

  /* All secondary surfaces are sheets, including tablet portrait/landscape. */
  .ag-game-dock{display:grid!important}
  .ag-variant-strip,.ag-game-rail{
    position:fixed!important;z-index:102!important;
    left:max(var(--ag-board-max-sheet-gap),var(--ag-safe-left,0px))!important;
    right:calc(var(--ag-board-max-dock) + max(var(--ag-board-max-sheet-gap),var(--ag-safe-right,0px)))!important;
    top:max(2.55rem,calc(var(--ag-safe-top,0px) + 2.2rem))!important;
    bottom:max(var(--ag-board-max-sheet-gap),var(--ag-safe-bottom,0px))!important;
    width:auto!important;height:auto!important;max-height:none!important;
    padding:.55rem!important;border:1px solid rgba(209,173,104,.24);border-radius:14px;
    background:rgba(9,13,18,.985);box-shadow:0 20px 62px rgba(0,0,0,.72);
    overflow:auto!important;visibility:hidden!important;opacity:0;pointer-events:none;transform:translateY(8px);
  }
  body[data-mobile-drawer="variants"] .ag-variant-strip,
  body[data-mobile-drawer="game"] .ag-game-rail,
  body[data-mobile-drawer="resources"] .ag-game-rail,
  body[data-mobile-drawer="tutorial"] .ag-game-rail,
  body[data-mobile-drawer="strategy"] .ag-game-rail,
  body[data-mobile-drawer="info"] .ag-game-rail{
    visibility:visible!important;opacity:1!important;pointer-events:auto!important;transform:none!important;
  }
  body[data-mobile-drawer="variants"] .ag-variant-strip{display:grid!important;grid-template-columns:repeat(auto-fit,minmax(150px,1fr))!important;gap:.35rem!important}
  body[data-mobile-drawer="game"] .ag-game-rail{display:grid!important;grid-template-columns:1fr!important;grid-auto-rows:auto!important}
  .ag-game-rail>.historical-summary,.ag-game-rail>ag-historical-guide{display:none!important}
  .mobile-panel-backdrop{position:fixed!important;z-index:96!important;inset:0 var(--ag-board-max-dock) 0 0!important;background:rgba(0,0,0,.58)!important}
  .mobile-panel-backdrop:not([hidden]){display:block!important}

  /* Icon dock: tiny visual chrome, full 44px touch targets. */
  .mobile-game-toolbar{
    position:fixed!important;z-index:106!important;left:auto!important;
    right:max(.18rem,var(--ag-safe-right,0px))!important;top:50%!important;bottom:auto!important;
    width:2.72rem!important;max-height:calc(var(--ag-visual-viewport-height,100dvh) - 5rem);
    transform:translateY(-50%);display:grid!important;grid-auto-flow:row!important;grid-template-columns:1fr!important;
    grid-auto-rows:44px!important;gap:.14rem!important;padding:.16rem!important;overflow:auto!important;
    border-radius:999px!important;background:rgba(8,11,15,.84)!important;backdrop-filter:blur(12px);
  }
  .mobile-game-toolbar .ag-button{
    width:44px!important;min-width:44px!important;max-width:44px!important;height:44px!important;min-height:44px!important;
    padding:0!important;border-radius:50%!important;font-size:0!important;line-height:1!important;display:grid!important;place-items:center!important;
  }
  .mobile-game-toolbar .ag-button[data-control-icon]::before{width:1rem;height:1rem;margin:0}

  /* v1.7.8 Phase 5 — strict board-ratio contract.
     Every calibrated board derives its visible geometry from the canonical board
     master aspect. Only one physical dimension is imposed; the other remains auto. */
  .ag-board-stage{--ag-board-max-w:100cqw;--ag-board-max-h:100cqh}
  .ag-board-stage :is(.carre-board,.mancala-board,.tafl-board,.ur-board,.senet-board,.fanorona-board,.nim-rows)[data-board-master="true"]{
    width:min(var(--ag-board-max-w),calc(var(--ag-board-max-h) * var(--ag-board-aspect)))!important;
    height:auto!important;max-width:var(--ag-board-max-w)!important;max-height:var(--ag-board-max-h)!important;
    aspect-ratio:var(--ag-board-aspect)!important;margin:auto!important;
  }
  .ag-board-stage :is(.carre-board,.tafl-board)[data-board-master="true"]{--ag-board-aspect:1;width:min(100cqw,100cqh)!important}
  .ag-board-stage .nim-rows[data-board-master="true"]{overflow:hidden!important}
}

/* Portrait phones rotate long archaeological/race boards so their long axis
   consumes the screen height rather than being squeezed into a short strip. */
@media (max-width:699px) and (orientation:portrait){
  .ag-board-stage :is(.ur-board,.senet-board,.fanorona-board[data-mobile-shape="wide"])[data-board-master="true"]{
    width:min(var(--ag-board-max-h),calc(var(--ag-board-max-w) * var(--ag-board-aspect)))!important;
    height:auto!important;max-width:var(--ag-board-max-h)!important;max-height:var(--ag-board-max-w)!important;
    position:absolute!important;left:50%;top:50%;transform:translate(-50%,-50%) rotate(90deg)!important;
  }
  .ag-board-stage .congkak-board[data-board-master="true"]{height:auto!important;max-height:var(--ag-board-max-h)!important}
}

/* v1.7.8 Phase 2 — one collapsible command pod on phone/tablet.
   Keep the existing BOARD MAX safe gutter; only the persistent chrome changes. */
@media (max-width:1199px), (max-height:700px) and (orientation:landscape){
  .mobile-game-toolbar.ag-control-pod{
    width:var(--ag-board-max-dock)!important;
    max-height:calc(var(--ag-visual-viewport-height,100dvh) - 1rem)!important;
    display:flex!important;
    flex-direction:column!important;
    align-items:center!important;
    grid-template-columns:none!important;
    grid-auto-flow:row!important;
    grid-auto-rows:auto!important;
    gap:.14rem!important;
    padding:.16rem!important;
    overflow:visible!important;
    border-radius:999px!important;
  }
  .ag-control-pod-toggle{
    flex:0 0 44px!important;
    order:0;
  }
  .ag-control-pod-toggle[data-control-icon]::before{width:1rem;height:1rem;margin:0}
  .ag-control-pod-replay-slot{order:1;flex:0 0 auto;width:44px}
  .ag-control-pod-replay-slot:not([hidden]){display:grid!important;place-items:center}
  .ag-control-pod-replay-slot>.ag-control-pod-replay{width:44px!important;min-width:44px!important;max-width:44px!important;height:44px!important;min-height:44px!important;padding:0!important;border-radius:50%!important;font-size:0!important;display:grid!important;place-items:center!important}
  .ag-control-pod-replay-slot>.ag-control-pod-replay[data-control-icon]::before{width:1.05rem;height:1.05rem;margin:0}
  .ag-control-pod-items{
    order:2;
    min-height:0;
    max-height:calc(var(--ag-visual-viewport-height,100dvh) - 4rem);
    display:grid;
    grid-template-columns:44px;
    grid-auto-rows:44px;
    gap:.14rem;
    overflow-y:auto;
    overflow-x:hidden;
    overscroll-behavior:contain;
    scrollbar-width:none;
  }
  .ag-control-pod-items::-webkit-scrollbar{display:none}
  .ag-control-pod-items[hidden]{display:none!important}
  .ag-control-pod-items>.ag-button{margin:0!important}
  .ag-control-pod[data-control-pod-state="collapsed"]{
    background:rgba(8,11,15,.9)!important;
    box-shadow:0 8px 24px rgba(0,0,0,.42)!important;
  }
  .ag-control-pod[data-control-pod-state="expanded"]{
    background:rgba(8,11,15,.96)!important;
    box-shadow:0 14px 36px rgba(0,0,0,.58)!important;
  }
}

/* v1.7.8 Phase 3 — explicit sheet dismissal and stable focus semantics. */
@media (max-width:1199px), (max-height:700px) and (orientation:landscape){
  [data-mobile-modal="true"]>.ag-panel-explicit-close{
    position:sticky;top:-.2rem;z-index:8;justify-self:end;grid-column:1/-1;
    min-width:44px;min-height:44px;margin:0 0 .35rem auto;padding:.35rem .7rem;
    border-radius:999px;background:rgba(18,24,32,.96);box-shadow:0 6px 18px rgba(0,0,0,.32);
  }
}

/* v1.7.8 Phase 6 — portrait fit by board family.
   Phase 5 owns canonical aspect ratios. Phase 6 only chooses the portrait fit:
   square families maximise the inscribed square; Mancala/Congkak and Nim keep
   their native horizontal master; Ur, Senet and Fanoron-Tsivy rotate only when
   the actual board-stage content box is portrait, where rotation strictly
   increases the usable area of a horizontal master. */
@media (max-width:899px) and (orientation:portrait){
  /* Alquerque/Morris, Tafl and compact Fanorona are canonical squares. */
  .ag-board-stage :is(
    .carre-board,
    .tafl-board,
    .fanorona-board[data-board-master-variant="fanoron-telo"],
    .fanorona-board[data-board-master-variant="fanoron-dimy"]
  )[data-board-master="true"]{
    --ag-board-aspect:1;
    width:min(100cqw,100cqh)!important;
    height:auto!important;
    max-width:100cqw!important;
    max-height:100cqh!important;
    position:relative!important;
    left:auto!important;top:auto!important;
    transform:none!important;
  }

  /* Mancala/Congkak and Nim always preserve the native horizontal master. */
  .ag-board-stage :is(.mancala-board,.nim-rows)[data-board-master="true"]{
    width:min(var(--ag-board-max-w),calc(var(--ag-board-max-h) * var(--ag-board-aspect)))!important;
    height:auto!important;
    max-width:var(--ag-board-max-w)!important;
    max-height:var(--ag-board-max-h)!important;
    position:relative!important;
    left:auto!important;top:auto!important;
    transform:none!important;
  }
  .ag-board-stage .mancala-board[data-board-master-variant="congkak"]{
    display:block!important;
    aspect-ratio:var(--ag-board-aspect)!important;
  }

  /* Default long-board state is native. This deliberately overrides the older
     phone-only unconditional rotations unless the stage geometry proves that
     rotation is beneficial in the container query below. */
  .ag-board-stage :is(
    .ur-board[data-board-master-variant="royal-ur"],
    .senet-board[data-board-master-variant="senet"],
    .fanorona-board[data-board-master-variant="fanoron-tsivy"]
  )[data-board-master="true"]{
    width:min(var(--ag-board-max-w),calc(var(--ag-board-max-h) * var(--ag-board-aspect)))!important;
    height:auto!important;
    max-width:var(--ag-board-max-w)!important;
    max-height:var(--ag-board-max-h)!important;
    position:relative!important;
    left:auto!important;top:auto!important;
    transform:none!important;
  }
  .ag-board-stage .ur-board[data-board-master-variant="royal-ur"] :is(.ur-roll,.ur-tray){transform:none!important}
  .ag-board-stage .ur-board[data-board-master-variant="royal-ur"] .ur-finish-counter{transform:translate(-50%,-50%)!important;transform-origin:50% 50%!important}
  .ag-board-stage .ur-board[data-board-master-variant="royal-ur"] .ur-reserve-count{transform:translateY(-50%)!important;transform-origin:50% 50%!important}
  .ag-board-stage .senet-board[data-board-master-variant="senet"] :is([class~="senet-cell-label"],.senet-finish){transform:none!important}

  /* For a horizontal master (aspect > 1), rotation has a larger fitted area iff
     stage height > stage width. Container orientation expresses exactly that
     geometry and avoids rotating a portrait viewport whose remaining stage is
     actually landscape after chrome/action allocation. */
  @container board-stage (orientation:portrait){
    .ag-board-stage :is(
      .ur-board[data-board-master-variant="royal-ur"],
      .senet-board[data-board-master-variant="senet"],
      .fanorona-board[data-board-master-variant="fanoron-tsivy"]
    )[data-board-master="true"]{
      width:min(var(--ag-board-max-h),calc(var(--ag-board-max-w) * var(--ag-board-aspect)))!important;
      height:auto!important;
      max-width:var(--ag-board-max-h)!important;
      max-height:var(--ag-board-max-w)!important;
      position:absolute!important;
      left:50%!important;top:50%!important;
      transform:translate(-50%,-50%) rotate(90deg)!important;
    }
    .ag-board-stage .ur-board[data-board-master-variant="royal-ur"] .ur-roll{transform:rotate(-90deg)!important}
    .ag-board-stage .ur-board[data-board-master-variant="royal-ur"] .ur-tray{transform:none!important}
    .ag-board-stage .ur-board[data-board-master-variant="royal-ur"] .ur-finish-counter{transform:translate(-50%,-50%) rotate(-90deg)!important;transform-origin:50% 50%!important}
    .ag-board-stage .ur-board[data-board-master-variant="royal-ur"] .ur-reserve-count{transform:translateY(-50%) rotate(-90deg)!important;transform-origin:50% 50%!important}
    .ag-board-stage .senet-board[data-board-master-variant="senet"] :is([class~="senet-cell-label"],.senet-finish){transform:rotate(-90deg)!important}
    .ag-board-stage .fanorona-board[data-board-master-variant="fanoron-tsivy"] .capture-choice{transform:rotate(-90deg) translateX(110%)!important}
  }
}

/* v1.7.8 Phase 10 — Replay is a persistent primary command, never buried in Partie. */
.ag-global-replay-host{display:flex;align-items:center;justify-content:flex-end;min-height:44px}
.ag-global-replay-host[hidden]{display:none!important}
.ag-global-replay-host>.move-replay{min-height:44px;white-space:normal}
@media (max-width:1199px), (max-height:700px) and (orientation:landscape){.ag-global-replay-host{display:none!important}}

/* Phase 13 compatibility aliases for the historical Board Max icon selectors.
   They now inherit the shared SVG mask from data-control-icon. */
#mobileVariantsButton::before,
#mobileGameButton::before,
#mobileTutorialButton::before,
#mobileContentButton::before,
#mobileRulesButton::before,
#mobileChallengesButton::before,
#mobileStrategyButton::before{content:""!important;width:1rem;height:1rem;margin:0}

/* v1.7.8 Phase 14 — compact header + one command hierarchy.
   Compact/PWA surfaces keep only navigation identity in the shell capsule;
   secondary application controls are re-homed into the existing game control pod. */
@media (max-width:1199px), (max-height:700px) and (orientation:landscape){
  body.ag-fixed-app .ag-shell-header[data-compact-controls="reduced"]{
    right:auto!important;
    width:max-content!important;
    max-width:calc(100vw - var(--ag-board-max-dock) - max(.55rem,var(--ag-safe-right,0px)))!important;
    grid-template-columns:auto minmax(0,auto) auto!important;
  }
  body.ag-fixed-app .ag-shell-header[data-compact-controls="reduced"] .ag-game-name strong{max-width:min(42vw,18rem)!important}
  body.ag-fixed-app .ag-shell-header[data-compact-controls="reduced"] .ag-user{gap:0!important;min-width:0!important}
  .ag-control-pod-system-items{
    display:grid;
    grid-template-columns:44px;
    grid-auto-rows:44px;
    gap:.14rem;
    padding-top:.18rem;
    margin-top:.04rem;
    border-top:1px solid rgba(209,173,104,.16);
  }
  .ag-control-pod-system-items[hidden]{display:none!important}
  body.ag-fixed-app .ag-control-pod-system-items :is(.ag-language,.ag-effects-button,.ag-fullscreen-button,.ag-account-button){
    display:grid!important;
    place-items:center!important;
    width:44px!important;min-width:44px!important;max-width:44px!important;
    height:44px!important;min-height:44px!important;max-height:44px!important;
    margin:0!important;padding:0!important;border-radius:50%!important;
  }
  body.ag-fixed-app .ag-control-pod-system-items :is(.ag-effects-button,.ag-fullscreen-button,.ag-account-button){font-size:0!important}
  body.ag-fixed-app .ag-control-pod-system-items .ag-language{font-size:.68rem!important;text-align:center;text-align-last:center}
  body.ag-fixed-app .ag-control-pod-system-items [data-control-icon]::before{width:1rem!important;height:1rem!important;margin:0!important}
}
@media (max-width:1199px), (max-height:700px) and (orientation:landscape){
  .ag-control-pod-items>.ag-control-pod-system-items{grid-row:span 4}
  body.ag-fixed-app .ag-control-pod-system-items .ag-fullscreen-button[hidden]{display:none!important}
}

/* v1.7.9 Phase 1 — rendered board ratio lock.
   A calibrated physical master must never be stretched by the flex column.
   The stage is a size container at every viewport, so both available axes are
   measurable even outside the historical BOARD MAX breakpoint. The master owns
   its canonical aspect; exactly one physical dimension is derived from the two
   stage dimensions. This block is intentionally last so legacy family flex
   rules cannot win. */
.ag-board-stage{
  container-type:size;
  container-name:board-stage;
}
.ag-board-stage [data-game-zone="board"][data-board-master="true"],
.ag-board-stage :is(.carre-board,.mancala-board,.tafl-board,.ur-board,.senet-board,.fanorona-board,.nim-rows)[data-board-master="true"]{
  flex-grow:0!important;
  flex-shrink:0!important;
  flex-basis:auto!important;
  min-width:0!important;
  min-height:0!important;
  width:min(100cqw,calc(100cqh * var(--ag-board-aspect,var(--board-master-aspect))))!important;
  height:auto!important;
  max-width:100cqw!important;
  max-height:100cqh!important;
  aspect-ratio:var(--ag-board-aspect,var(--board-master-aspect))!important;
  align-self:center;
  box-sizing:border-box;
}

/* Compact BOARD MAX owns measurable stage dimensions through size containment.
   Compute exactly one physical dimension; never stretch both axes. */
@media (max-width:1199px), (max-height:700px) and (orientation:landscape){
  .ag-board-stage :is(.carre-board,.mancala-board,.tafl-board,.ur-board,.senet-board,.fanorona-board,.nim-rows)[data-board-master="true"]{
    width:min(100cqw,calc(100cqh * var(--ag-board-aspect,var(--board-master-aspect))))!important;
    height:auto!important;
    max-width:100cqw!important;
    max-height:100cqh!important;
  }
  .ag-board-stage :is(
    .carre-board,
    .tafl-board,
    .fanorona-board[data-board-master-variant="fanoron-telo"],
    .fanorona-board[data-board-master-variant="fanoron-dimy"]
  )[data-board-master="true"]{
    --ag-board-aspect:1;
    width:min(100cqw,100cqh)!important;
    height:auto!important;
  }
  /* The floating variant chip must never sit under the global Back control. */
  .ag-variant-context{left:3.45rem!important}
}


/* Preserve the already validated Phase 6 adaptive rotations after the Phase 1
   final ratio lock. The rotated box swaps stage axes but keeps canonical aspect. */
@media (max-width:899px) and (orientation:portrait){
  @container board-stage (orientation:portrait){
    .ag-board-stage :is(
      .ur-board[data-board-master-variant="royal-ur"],
      .senet-board[data-board-master-variant="senet"],
      .fanorona-board[data-board-master-variant="fanoron-tsivy"]
    )[data-board-master="true"]{
      width:min(100cqh,calc(100cqw * var(--ag-board-aspect,var(--board-master-aspect))))!important;
      height:auto!important;
      max-width:100cqh!important;
      max-height:100cqw!important;
      position:absolute!important;
      left:50%!important;
      top:50%!important;
      transform:translate(-50%,-50%) rotate(90deg)!important;
    }
  }
}

/* v1.7.9 Phase 2 — adaptive rotation for every rectangular Nim and Mancala master.
   Native landscape remains horizontal. On compact surfaces, a portrait board-stage
   swaps the available stage axes and rotates the entire calibrated master, so its
   artwork, live objects and hit targets stay in one transform tree. Canonical
   ratios remain owned by board-masters.js: Nim 1.5988, Oware/Kalah 2.0,
   Congkak 2.3496. */
@media (max-width:1199px){
  .ag-board-stage :is(.nim-rows,.mancala-board)[data-board-master="true"]{
    position:relative!important;
    left:auto!important;
    top:auto!important;
    transform:none!important;
    transform-origin:50% 50%!important;
  }

  @container board-stage (orientation:portrait){
    /* Traditional Mancala renders the physical master inside a generic heritage
       host. Make that host consume the real stage before centring the rotated
       master; this avoids the old portrait reflow path and keeps labels/UI upright. */
    .ag-board-stage .heritage-board:is(
      [data-board-variant="oware"],
      [data-board-variant="kalah"],
      [data-board-variant="congkak"]
    ){
      width:100cqw!important;
      max-width:100cqw!important;
      height:100cqh!important;
      min-height:0!important;
      margin:0!important;
      position:relative!important;
      display:grid!important;
      place-items:center!important;
      overflow:visible!important;
    }
    .ag-board-stage .heritage-board[data-board-variant="congkak"] .congkak-shell{
      display:contents!important;
    }
    .ag-board-stage .heritage-board[data-board-variant="congkak"] .congkak-meta{
      position:absolute!important;
      left:50%!important;
      bottom:.18rem!important;
      transform:translateX(-50%)!important;
      z-index:8;
      max-width:calc(100% - .5rem);
      justify-content:center;
      pointer-events:none;
    }

    .ag-board-stage :is(.nim-rows,.mancala-board)[data-board-master="true"]{
      width:min(100cqh,calc(100cqw * var(--ag-board-aspect,var(--board-master-aspect))))!important;
      height:auto!important;
      max-width:100cqh!important;
      max-height:100cqw!important;
      position:absolute!important;
      left:50%!important;
      top:50%!important;
      transform:translate(-50%,-50%) rotate(90deg)!important;
      transform-origin:50% 50%!important;
    }
  }
}



/* v1.7.9 Phase 3 — compact chrome without a permanent right-side layout lane.
   Menu + Replay float over a small safe corner; the board, action console,
   secondary sheets and capture trays reclaim the full compact viewport width.
   Expanding the menu creates an overlay popover instead of growing a rail that
   participates in gameplay geometry. */
@media (max-width:1199px), (max-height:700px) and (orientation:landscape){
  :root{
    --ag-board-max-dock:0px;
    --ag-compact-pod-edge:.22rem;
    --ag-compact-pod-gap:.14rem;
    --ag-compact-pod-span:5.85rem;
  }

  .ag-board-stage{
    padding:.16rem .18rem .12rem .16rem!important;
    --ag-controls-safe-right:0px!important;
  }
  .ag-action-console{
    padding-right:.28rem!important;
  }
  .ag-variant-strip,.ag-game-rail{
    right:max(var(--ag-board-max-sheet-gap),var(--ag-safe-right,0px))!important;
  }
  .mobile-panel-backdrop{
    inset:0!important;
  }

  /* Only the title/banner avoid the tiny floating control corner; the physical
     board itself does not reserve this space. */
  .ag-variant-context{
    right:calc(var(--ag-compact-pod-span) + max(.35rem,var(--ag-safe-right,0px)))!important;
  }
  .ag-board-stage>.learning-banner{
    right:.35rem!important;
    top:3.2rem!important;
  }

  .mobile-game-toolbar.ag-control-pod{
    position:fixed!important;
    z-index:106!important;
    left:auto!important;
    right:max(var(--ag-compact-pod-edge),var(--ag-safe-right,0px))!important;
    top:max(var(--ag-compact-pod-edge),var(--ag-safe-top,0px))!important;
    bottom:auto!important;
    width:auto!important;
    max-width:none!important;
    max-height:none!important;
    transform:none!important;
    display:grid!important;
    grid-template-columns:44px 44px!important;
    grid-template-rows:44px!important;
    grid-auto-flow:column!important;
    grid-auto-rows:none!important;
    gap:var(--ag-compact-pod-gap)!important;
    padding:.16rem!important;
    overflow:visible!important;
    border-radius:999px!important;
    background:rgba(8,11,15,.9)!important;
    box-shadow:0 8px 24px rgba(0,0,0,.42)!important;
  }
  .ag-control-pod-toggle{
    grid-column:1!important;
    grid-row:1!important;
    order:0!important;
  }
  .ag-control-pod-replay-slot{
    grid-column:2!important;
    grid-row:1!important;
    order:0!important;
    width:44px!important;
  }
  .ag-control-pod-items{
    position:absolute!important;
    z-index:1!important;
    top:calc(100% + .22rem)!important;
    right:0!important;
    order:0!important;
    width:calc(88px + var(--ag-compact-pod-gap) + .36rem)!important;
    max-width:calc(100vw - .44rem - var(--ag-safe-left,0px) - var(--ag-safe-right,0px))!important;
    max-height:calc(var(--ag-visual-viewport-height,100dvh) - 4rem - var(--ag-safe-top,0px) - var(--ag-safe-bottom,0px))!important;
    display:grid!important;
    grid-template-columns:repeat(2,44px)!important;
    grid-auto-rows:44px!important;
    align-content:start!important;
    gap:var(--ag-compact-pod-gap)!important;
    padding:.18rem!important;
    overflow-y:auto!important;
    overflow-x:hidden!important;
    overscroll-behavior:contain;
    scrollbar-width:none;
    border:1px solid rgba(209,173,104,.22)!important;
    border-radius:20px!important;
    background:rgba(8,11,15,.965)!important;
    box-shadow:0 14px 36px rgba(0,0,0,.58)!important;
    backdrop-filter:blur(12px);
  }
  .ag-control-pod-items[hidden]{display:none!important}
  .ag-control-pod[data-control-pod-state="expanded"]{
    background:rgba(8,11,15,.94)!important;
    box-shadow:0 8px 24px rgba(0,0,0,.48)!important;
  }
  .ag-control-pod-system-items{
    grid-column:1/-1!important;
    grid-row:auto!important;
    grid-template-columns:repeat(2,44px)!important;
    grid-auto-rows:44px!important;
    padding-top:.18rem!important;
  }
  .ag-control-pod-items>.ag-control-pod-system-items{
    grid-row:auto!important;
  }

  /* The shell identity avoids the small top-right pod, but this reservation is
     chrome-only and never shrinks the gameplay stage. */
  body.ag-fixed-app .ag-shell-header[data-compact-controls="reduced"]{
    max-width:calc(100vw - var(--ag-compact-pod-span) - max(.55rem,var(--ag-safe-right,0px)))!important;
  }
}

/* v1.7.9 Phase 4 — compact action shelf lives in empty frame space, never over
   the rendered board master. JS measures the real master rectangle and places
   the existing action-console node into the best free gutter of the stage. */
@media (max-width:1199px), (max-height:700px) and (orientation:landscape){
  .ag-board-first-layout{position:relative!important;grid-template-rows:minmax(0,1fr)!important}
  .ag-action-console.ag-action-console--frame-shelf[data-action-shelf="frame"]{
    z-index:31!important;
    box-sizing:border-box!important;
    margin:0!important;
    height:var(--ag-action-shelf-band-height)!important;
    min-height:var(--ag-action-shelf-band-height)!important;
    max-height:var(--ag-action-shelf-band-height)!important;
    padding:.38rem .48rem!important;
    display:grid!important;
    grid-template-columns:minmax(0,1fr) auto!important;
    align-items:center!important;
    gap:.28rem .45rem!important;
    overflow:auto!important;
    border:1px solid rgba(209,173,104,.32)!important;
    border-radius:14px!important;
    background:linear-gradient(180deg,rgba(18,23,31,.93),rgba(8,11,15,.96))!important;
    box-shadow:0 10px 28px rgba(0,0,0,.42),inset 0 1px 0 rgba(255,255,255,.035)!important;
    backdrop-filter:blur(11px);
    scrollbar-width:none;
  }
  .ag-action-console.ag-action-console--frame-shelf::-webkit-scrollbar{display:none}
  .ag-action-console.ag-action-console--frame-shelf>.game-state-line{
    min-width:0!important;flex-wrap:wrap!important;gap:.18rem .3rem!important;font-size:.74rem!important;line-height:1.15!important;
  }
  .ag-action-console.ag-action-console--frame-shelf>.game-state-line .game-state-message{
    max-width:none!important;white-space:normal!important;overflow:visible!important;text-overflow:clip!important;
    display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;line-clamp:2;
  }
  .ag-action-console.ag-action-console--frame-shelf .game-turn-pill{
    min-height:30px!important;padding:.22rem .5rem!important;font-size:.72rem!important;font-weight:700;white-space:nowrap;
  }
  .ag-action-console.ag-action-console--frame-shelf .ag-action-console-actions{
    width:auto!important;max-width:100%!important;justify-content:flex-end!important;flex-wrap:wrap!important;gap:.24rem!important;
  }
  .ag-action-console.ag-action-console--frame-shelf .ag-action-console-actions .ag-button,
  .ag-action-console.ag-action-console--frame-shelf .direct-confirm-button{
    min-height:44px!important;height:44px!important;padding:.28rem .58rem!important;font-size:.74rem!important;white-space:nowrap;
  }
  .ag-action-console.ag-action-console--frame-shelf .draw-actions{flex-wrap:wrap!important;justify-content:flex-end!important}

  /* Nim keeps a stable confirm target while its explanatory text can use the
     frame shelf naturally instead of overflowing/clipping below the board. */
  .ag-action-console--direct.ag-action-console--frame-shelf{
    grid-template-columns:minmax(0,1fr) auto!important;
    grid-template-areas:"state confirm" "summary confirm" "hint hint"!important;
    align-items:center!important;
  }
  .ag-action-console--direct.ag-action-console--frame-shelf>.game-state-line{grid-area:state!important}
  .ag-action-console--direct.ag-action-console--frame-shelf>.direct-selection-console{display:contents!important}
  .ag-action-console--direct.ag-action-console--frame-shelf .direct-selection-summary{
    grid-area:summary!important;min-width:0!important;margin:0!important;font-size:.72rem!important;line-height:1.18!important;
    white-space:normal!important;overflow:visible!important;text-overflow:clip!important;
  }
  .ag-action-console--direct.ag-action-console--frame-shelf .direct-confirm-button{
    grid-area:confirm!important;align-self:stretch!important;min-width:96px!important;width:auto!important;font-weight:750;
    border-color:rgba(209,173,104,.48)!important;background:rgba(181,138,77,.18)!important;
  }
  .ag-action-console--direct.ag-action-console--frame-shelf .direct-selection-hint{
    grid-area:hint!important;margin:0!important;min-height:0!important;font-size:.66rem!important;line-height:1.15!important;
    white-space:normal!important;overflow:visible!important;
  }
}

/* Phase 4 fallback: when the rendered master naturally leaves no safe gutter,
   create a bottom frame gutter by slightly reducing the master's available
   height. The shelf still never overlays the playable rectangle. */
@media (max-width:1199px), (max-height:700px) and (orientation:landscape){
  .ag-board-stage[data-action-shelf-reserve="bottom"] [data-board-master="true"][data-board-master-variant]{
    width:min(100cqw,calc((100cqh - var(--ag-action-shelf-reserve,0px)) * var(--ag-board-aspect,var(--board-master-aspect))))!important;
    max-height:calc(100cqh - var(--ag-action-shelf-reserve,0px))!important;
    transform:translateY(calc(var(--ag-action-shelf-reserve,0px) * -.5))!important;
  }
  @container board-stage (orientation:portrait){
    .ag-board-stage[data-action-shelf-reserve="bottom"] :is(.nim-rows,.mancala-board)[data-board-master="true"]{
      width:min(calc(100cqh - var(--ag-action-shelf-reserve,0px)),calc(100cqw * var(--ag-board-aspect,var(--board-master-aspect))))!important;
      max-width:calc(100cqh - var(--ag-action-shelf-reserve,0px))!important;
      max-height:100cqw!important;
      top:calc(50% - (var(--ag-action-shelf-reserve,0px) / 2))!important;
      transform:translate(-50%,-50%) rotate(90deg)!important;
    }
  }
}
@media (max-width:899px) and (orientation:portrait){
  @container board-stage (orientation:portrait){
    .ag-board-stage[data-action-shelf-reserve="bottom"] :is(
      .ur-board[data-board-master-variant="royal-ur"],
      .senet-board[data-board-master-variant="senet"],
      .fanorona-board[data-board-master-variant="fanoron-tsivy"]
    )[data-board-master="true"]{
      width:min(calc(100cqh - var(--ag-action-shelf-reserve,0px)),calc(100cqw * var(--ag-board-aspect,var(--board-master-aspect))))!important;
      max-width:calc(100cqh - var(--ag-action-shelf-reserve,0px))!important;
      max-height:100cqw!important;
      top:calc(50% - (var(--ag-action-shelf-reserve,0px) / 2))!important;
      transform:translate(-50%,-50%) rotate(90deg)!important;
    }
  }
}

/* Side gutters may be tall and narrow. In that case the same shelf becomes a
   vertical capsule rather than forcing the board smaller merely to keep a
   horizontal row. */
@media (max-width:1199px), (max-height:700px) and (orientation:landscape){
  .ag-action-console.ag-action-console--frame-shelf:is([data-action-shelf-position="left"],[data-action-shelf-position="right"]){
    height:var(--ag-action-shelf-side-height)!important;
    min-height:var(--ag-action-shelf-side-height)!important;
    max-height:var(--ag-action-shelf-side-height)!important;
    grid-template-columns:minmax(0,1fr)!important;
    align-content:start!important;
  }
  .ag-action-console.ag-action-console--frame-shelf:is([data-action-shelf-position="left"],[data-action-shelf-position="right"]) .ag-action-console-actions{
    justify-content:flex-start!important;
  }
  .ag-action-console--direct.ag-action-console--frame-shelf:is([data-action-shelf-position="left"],[data-action-shelf-position="right"]){
    grid-template-columns:minmax(0,1fr)!important;
    grid-template-areas:"state" "summary" "confirm" "hint"!important;
  }
  .ag-action-console--direct.ag-action-console--frame-shelf:is([data-action-shelf-position="left"],[data-action-shelf-position="right"]) .direct-confirm-button{
    width:100%!important;
  }
}

/* v1.7.9 Phase 5 — compact icon scale and optical centring.
   44px touch targets stay unchanged; only the symbol grows inside them. */
@media (max-width:1199px), (max-height:700px) and (orientation:landscape){
  .mobile-game-toolbar .ag-button[data-control-icon]::before,
  .ag-control-pod-toggle[data-control-icon]::before,
  .ag-control-pod-replay-slot>.ag-control-pod-replay[data-control-icon]::before,
  body.ag-fixed-app .ag-control-pod-system-items [data-control-icon]::before{
    width:1.28rem!important;
    height:1.28rem!important;
    margin:0!important;
    align-self:center!important;
    justify-self:center!important;
  }
  .ag-control-pod-toggle[data-control-icon="menu"]::before,
  .ag-control-pod-toggle[data-control-icon="close"]::before{width:1.32rem!important;height:1.32rem!important}
  .ag-control-pod-replay-slot>.ag-control-pod-replay[data-control-icon="replay"]::before{width:1.3rem!important;height:1.3rem!important}
}

/* v1.7.9 Phase 11 — rendered-geometry correction. Tablet-portrait square
   traditional masters live inside a deliberately narrower heritage host that
   preserves capture-tray gutters; size the physical master to that host rather
   than the wider stage container. */
@media (min-width:700px) and (max-width:899px) and (orientation:portrait) and (min-height:700px){
  .ag-board-stage .heritage-board[data-board-shape="square"] > :is(.tafl-board,.fanorona-board)[data-board-master="true"]{
    width:100%!important;
    max-width:100%!important;
    height:auto!important;
  }
}

/* v1.8.1 — one stable viewport owns traditional board geometry.
   The generic heritage host fills the play stage; the physical board receives
   one measured, ratio-preserving rectangle from board-viewport.js. This shared
   contract supersedes historical family/breakpoint sizing without altering any
   board master, calibration, hit target or engine state. */
.ag-board-stage>.ag-stable-board-viewport{
  /* A zero flex basis makes the stage allocation, rather than the board or the
     side rail's intrinsic content, authoritative. `height:0` is intentional:
     flex-grow assigns the remaining stage block-size after the heading. */
  flex:1 1 0!important;
  width:100%!important;
  height:0!important;
  block-size:0!important;
  min-width:0!important;
  min-height:0!important;
  max-width:none!important;
  max-height:none!important;
  margin:0!important;
  padding:0!important;
  display:grid!important;
  place-items:center!important;
  position:relative!important;
  overflow:visible!important;
  contain:size layout paint;
}
/* Phase 7B.2 — the Congkak decorative shell must not keep its historical
   940px cap around a stable master. Otherwise the correctly fitted board is
   centred against an undersized parent and its outer frame is clipped. */
.ag-board-stage>.ag-stable-board-viewport>.congkak-shell{
  width:100%!important;
  max-width:none!important;
  margin:0!important;
  justify-self:stretch!important;
}

.ag-board-stage .ag-stable-board-viewport [data-board-master="true"][data-board-fit="stable"]{
  width:var(--ag-stable-board-width)!important;
  height:var(--ag-stable-board-height)!important;
  min-width:0!important;
  min-height:0!important;
  max-width:var(--ag-stable-board-width)!important;
  max-height:var(--ag-stable-board-height)!important;
  flex:0 0 auto!important;
  margin:auto!important;
}

/* Refined shared hierarchy: board first, compact navigation, quiet controls. */
.ag-board-stage{
  border-color:color-mix(in srgb,var(--ag-brass) 18%,transparent);
  background:
    radial-gradient(circle at 50% 42%,rgba(209,173,104,.055),transparent 48%),
    linear-gradient(150deg,rgba(16,21,28,.98),rgba(7,10,14,.995));
  box-shadow:inset 0 1px 0 rgba(255,255,255,.025),0 16px 42px rgba(0,0,0,.22);
}
.ag-game-rail>[data-game-zone="game-panel"]{
  border-radius:14px;
  background:linear-gradient(180deg,rgba(18,24,32,.9),rgba(10,14,19,.94));
}
.ag-action-console{
  border-color:rgba(209,173,104,.2);
  background:linear-gradient(180deg,rgba(15,20,27,.96),rgba(8,11,15,.985));
}
.ag-variant-collapse-toggle[aria-expanded="false"]{
  border-color:rgba(209,173,104,.34);
  background:rgba(181,138,77,.1);
}

/* v1.8.5 Phase 4 — compact circular controls use exact geometric centring.
   44px touch targets stay unchanged; every icon occupies a 20px centred box. */
@media (max-width:1199px), (max-height:700px) and (orientation:landscape){
  .mobile-game-toolbar .ag-button[data-control-icon]::before,
  .ag-control-pod-toggle[data-control-icon]::before,
  .ag-control-pod-replay-slot>.ag-control-pod-replay[data-control-icon]::before,
  body.ag-fixed-app .ag-control-pod-system-items [data-control-icon]::before{
    width:20px!important;height:20px!important;
    margin:0!important;align-self:center!important;justify-self:center!important;
    transform:none!important;
  }
  .ag-control-pod-toggle[data-control-icon="menu"]::before,
  .ag-control-pod-toggle[data-control-icon="close"]::before,
  .ag-control-pod-replay-slot>.ag-control-pod-replay[data-control-icon="replay"]::before{
    width:20px!important;height:20px!important;transform:none!important;
  }
}
