/* EloFlow mobile evaluation meters: slimmer bar, full board height.
   Desktop dimensions remain unchanged. */
@media(max-width:760px){
 body.elo-unified-chess .tool-page .analysis-board-column>.board-with-eval,
 body.elo-unified-chess .tool-page .prep-analysis-layout .prep-board-row{
  display:grid!important;
  grid-template-columns:18px minmax(0,1fr)!important;
  column-gap:6px!important;
  width:100%!important;
  max-width:100%!important;
  min-width:0!important;
 }
 body.elo-unified-chess .tool-page .analysis-board-column>.board-with-eval>.board-eval-wrap,
 body.elo-unified-chess .tool-page .prep-analysis-layout .prep-board-row>.prep-eval-bar{
  grid-column:1!important;
  grid-row:1!important;
  width:18px!important;
  min-width:18px!important;
  max-width:18px!important;
  flex:0 0 18px!important;
  height:100%!important;
  max-height:none!important;
  align-self:stretch!important;
  box-sizing:border-box!important;
 }
 body.elo-unified-chess .tool-page .analysis-board-column>.board-with-eval>#board,
 body.elo-unified-chess .tool-page .prep-analysis-layout .prep-board-row>#board{
  grid-column:2!important;
  grid-row:1!important;
  min-width:0!important;
  max-width:100%!important;
 }
 body.elo-unified-chess .tool-page .board-eval-track .board-eval-text,
 body.elo-unified-chess .tool-page .prep-eval-bar #prep-eval-label{
  font-size:9px!important;
  letter-spacing:-.4px!important;
  left:0!important;
  right:0!important;
  width:100%!important;
  max-width:100%!important;
 }
}

/* Repertoire Explorer: keep 0.00 horizontal, legible, and centered. */
@media(max-width:760px){
 body.elo-unified-chess .tool-page .prep-analysis-layout .prep-board-row{grid-template-columns:24px minmax(0,1fr)!important}
 body.elo-unified-chess .tool-page .prep-analysis-layout .prep-board-row>.prep-eval-bar{width:24px!important;min-width:24px!important;max-width:24px!important;flex-basis:24px!important}
 body.elo-unified-chess .tool-page .prep-analysis-layout .prep-board-row>.prep-eval-bar #prep-eval-label{
  display:block!important;position:absolute!important;left:0!important;right:0!important;
  top:auto!important;bottom:5px!important;transform:none!important;
  width:100%!important;max-width:100%!important;min-width:0!important;
  writing-mode:horizontal-tb!important;text-orientation:mixed!important;
  white-space:nowrap!important;overflow:visible!important;word-break:normal!important;
  font:600 8px/1 Arial,sans-serif!important;letter-spacing:-.45px!important;text-align:center!important;
 }
 /* Mobile repertoire controls: Back + Next, Reset, then Flip Board. */
 body.elo-unified-chess .tool-page .board-controls.elo-board-toolbar:has(#prep-flip){
  display:grid!important;grid-template-columns:minmax(0,1fr)!important;
  gap:8px!important;align-items:stretch!important;
 }
 body.elo-unified-chess .tool-page .board-controls.elo-board-toolbar:has(#prep-flip)>.elo-nav-pair{
  display:grid!important;grid-template-columns:repeat(2,minmax(0,1fr))!important;
  width:100%!important;min-width:0!important;gap:8px!important;
 }
 body.elo-unified-chess .tool-page .board-controls.elo-board-toolbar:has(#prep-flip) :is(#back,#forward,#reset,#prep-flip){
  width:100%!important;min-width:0!important;margin:0!important;box-sizing:border-box!important;
 }
 body.elo-unified-chess .tool-page .board-controls.elo-board-toolbar:has(#prep-flip)>#game-count{grid-column:1!important;text-align:center}
}

/* v3: Analysis uses .tool-card .board-with-eval (not .analysis-board-column).
   Use the measured board height instead of 100% of a grid row. */
@media(max-width:760px){
 body.elo-unified-chess .tool-page .tool-card:first-of-type .board-with-eval{
  display:grid!important;grid-template-columns:24px minmax(0,1fr)!important;
  gap:6px!important;width:100%!important;max-width:100%!important;
  min-width:0!important;align-items:start!important;overflow:visible!important;
 }
 body.elo-unified-chess .tool-page .tool-card:first-of-type .board-with-eval>.board-eval-wrap{
  display:block!important;visibility:visible!important;opacity:1!important;
  grid-column:1!important;grid-row:1!important;position:relative!important;
  width:24px!important;min-width:24px!important;max-width:24px!important;
  height:var(--chess-board-height,320px)!important;
  min-height:0!important;max-height:var(--chess-board-height,320px)!important;
  margin:0!important;top:0!important;align-self:start!important;overflow:hidden!important;
 }
 body.elo-unified-chess .tool-page .tool-card:first-of-type .board-with-eval>#board{
  grid-column:2!important;grid-row:1!important;min-width:0!important;
  width:100%!important;max-width:100%!important;margin:0!important;
 }
 body.elo-unified-chess .tool-page .tool-card:first-of-type .board-with-eval>.board-eval-wrap .board-eval-track{
  display:block!important;position:absolute!important;inset:0!important;
  width:100%!important;height:100%!important;
 }
 /* Repertoire meter must not inherit an inline vertical offset or stretch
    beyond the board. Its height is measured by the existing ResizeObserver. */
 body.elo-unified-chess .tool-page .prep-analysis-layout .prep-board-row>.prep-eval-bar{
  top:0!important;bottom:auto!important;
  height:var(--chess-board-height,320px)!important;
  max-height:var(--chess-board-height,320px)!important;
  min-height:0!important;align-self:start!important;overflow:hidden!important;
 }
 body.elo-unified-chess .tool-page .prep-analysis-layout .prep-board-row>.prep-eval-bar .board-eval-track{
  position:absolute!important;inset:0!important;height:100%!important;
 }
 body.elo-unified-chess .tool-page .prep-analysis-layout .prep-board-row>.prep-eval-bar #prep-eval-label{
  top:auto!important;bottom:5px!important;left:0!important;right:0!important;
  transform:none!important;writing-mode:horizontal-tb!important;
  width:100%!important;white-space:nowrap!important;font-size:8px!important;
 }
}

/* v4: align the meter to the board's actual top edge, not the grid row.
   The board can sit lower in its row due to legacy chessboard margins. */
@media(max-width:760px){
 body.elo-unified-chess .tool-page .tool-card:first-of-type .board-with-eval>.board-eval-wrap,
 body.elo-unified-chess .tool-page .prep-analysis-layout .prep-board-row>.prep-eval-bar{
  transform:translateY(var(--elo-meter-offset,0px))!important;
  transform-origin:top left!important;
  top:0!important;
  height:var(--chess-board-height,320px)!important;
  min-height:0!important;
  max-height:var(--chess-board-height,320px)!important;
 }
 body.elo-unified-chess .tool-page .tool-card:first-of-type .board-with-eval>.board-eval-wrap{
  width:18px!important;min-width:18px!important;max-width:18px!important;
 }
 body.elo-unified-chess .tool-page .tool-card:first-of-type .board-with-eval{
  grid-template-columns:18px minmax(0,1fr)!important;
 }
 body.elo-unified-chess .tool-page .prep-analysis-layout .prep-board-row>.prep-eval-bar{
  width:20px!important;min-width:20px!important;max-width:20px!important;
 }
 body.elo-unified-chess .tool-page .prep-analysis-layout .prep-board-row{
  grid-template-columns:20px minmax(0,1fr)!important;
 }
 body.elo-unified-chess .tool-page .prep-analysis-layout .prep-board-row>.prep-eval-bar #prep-eval-label{
  display:block!important;white-space:nowrap!important;word-break:normal!important;
  writing-mode:horizontal-tb!important;transform:none!important;
  font-size:7px!important;letter-spacing:-.5px!important;
 }
}

/* EloFlow v5: Analysis mobile layout. Keep review and controls out of the board cell. */
@media(max-width:760px){
 body.elo-unified-chess .tool-page .tool-card:first-of-type>.analysis-three-column{
  display:flex!important;flex-direction:column!important;align-items:stretch!important;
  gap:16px!important;width:100%!important;min-width:0!important;
  height:auto!important;overflow:visible!important;
 }
 body.elo-unified-chess .tool-page .tool-card:first-of-type>.analysis-three-column>.analysis-board-column{
  order:0!important;display:block!important;position:relative!important;
  width:100%!important;max-width:100%!important;min-width:0!important;
  margin:0!important;transform:none!important;overflow:visible!important;
 }
 body.elo-unified-chess .tool-page .tool-card:first-of-type>.analysis-three-column>.analysis-controls-panel{
  order:1!important;position:relative!important;grid-column:auto!important;grid-row:auto!important;
  width:100%!important;max-width:100%!important;min-width:0!important;
  margin:0!important;transform:none!important;z-index:auto!important;
 }
 body.elo-unified-chess .tool-page .tool-card:first-of-type>.analysis-three-column>.analysis-engine-column{
  order:2!important;position:relative!important;grid-column:auto!important;grid-row:auto!important;
  width:100%!important;max-width:100%!important;min-width:0!important;
  margin:0!important;transform:none!important;z-index:auto!important;
 }
 body.elo-unified-chess .tool-page .tool-card:first-of-type .analysis-board-column>.board-with-eval{
  display:grid!important;grid-template-columns:18px minmax(0,1fr)!important;
  gap:6px!important;position:relative!important;isolation:isolate!important;
  width:100%!important;max-width:100%!important;min-width:0!important;
  margin:0!important;overflow:visible!important;
 }
 body.elo-unified-chess .tool-page .tool-card:first-of-type .analysis-board-column>.board-with-eval>.board-eval-wrap{
  grid-column:1!important;grid-row:1!important;display:block!important;
  position:relative!important;z-index:1!important;box-sizing:border-box!important;
  width:18px!important;min-width:18px!important;max-width:18px!important;
  margin:0!important;overflow:hidden!important;
 }
 body.elo-unified-chess .tool-page .tool-card:first-of-type .analysis-board-column>.board-with-eval>#board{
  grid-column:2!important;grid-row:1!important;position:relative!important;
  z-index:1!important;width:100%!important;max-width:100%!important;
  min-width:0!important;margin:0!important;transform:none!important;
 }
 body.elo-unified-chess .tool-page .tool-card:first-of-type .analysis-controls-panel>.review-side-stats{
  position:static!important;transform:none!important;max-width:100%!important;
  min-width:0!important;overflow-wrap:anywhere!important;
 }
}

/* EloFlow v6: full-width mobile Repertoire Explorer controls and statistics. */
@media(max-width:760px){
 body.elo-unified-chess .tool-page .prep-analysis-layout{
  display:flex!important;flex-direction:column!important;align-items:stretch!important;
  width:100%!important;max-width:100%!important;min-width:0!important;gap:18px!important;
 }
 body.elo-unified-chess .tool-page .prep-analysis-layout>.prep-board-area{
  order:0!important;width:100%!important;max-width:100%!important;min-width:0!important;
  margin:0!important;grid-column:auto!important;grid-row:auto!important;
 }
 body.elo-unified-chess .tool-page .prep-analysis-layout>.prep-control-stack{
  order:1!important;display:flex!important;flex-direction:column!important;
  align-items:stretch!important;align-self:stretch!important;
  width:100%!important;max-width:100%!important;min-width:0!important;
  margin:0!important;grid-column:auto!important;grid-row:auto!important;gap:18px!important;
 }
 body.elo-unified-chess .tool-page .prep-analysis-layout>.prep-control-stack>.prep-controls-panel,
 body.elo-unified-chess .tool-page .prep-analysis-layout>.prep-control-stack>.prep-stats-side{
  width:100%!important;max-width:100%!important;min-width:0!important;
  box-sizing:border-box!important;margin:0!important;align-self:stretch!important;
 }
 body.elo-unified-chess .tool-page .prep-analysis-layout>.prep-control-stack>.prep-controls-panel .board-controls{
  width:100%!important;max-width:100%!important;box-sizing:border-box!important;
 }
 body.elo-unified-chess .tool-page .prep-analysis-layout>.prep-engine-side{
  order:2!important;width:100%!important;max-width:100%!important;
  min-width:0!important;margin:0!important;grid-column:auto!important;grid-row:auto!important;
 }
}

/* EloFlow v7: mobile Analysis uses normal document flow, not legacy grid rails.
   This prevents sidebar buttons and labels painting behind the board. */
@media(max-width:760px){
 body.elo-unified-chess main.tool-page .tool-card:first-of-type>.analysis-three-column{
  display:block!important;position:relative!important;grid-template-columns:none!important;
  grid-template-rows:none!important;overflow:visible!important;isolation:isolate!important;
  width:100%!important;min-width:0!important;height:auto!important;
 }
 body.elo-unified-chess main.tool-page .tool-card:first-of-type>.analysis-three-column>.analysis-board-column,
 body.elo-unified-chess main.tool-page .tool-card:first-of-type>.analysis-three-column>.analysis-controls-panel,
 body.elo-unified-chess main.tool-page .tool-card:first-of-type>.analysis-three-column>.analysis-engine-column{
  display:block!important;position:relative!important;float:none!important;clear:both!important;
  inset:auto!important;grid-column:auto!important;grid-row:auto!important;
  transform:none!important;min-width:0!important;max-width:100%!important;
  width:100%!important;box-sizing:border-box!important;justify-self:auto!important;
 }
 body.elo-unified-chess main.tool-page .tool-card:first-of-type>.analysis-three-column>.analysis-board-column{
  margin:0 0 18px!important;z-index:1!important;
 }
 body.elo-unified-chess main.tool-page .tool-card:first-of-type>.analysis-three-column>.analysis-controls-panel{
  margin:0 0 18px!important;z-index:0!important;
 }
 body.elo-unified-chess main.tool-page .tool-card:first-of-type>.analysis-three-column>.analysis-engine-column{
  margin:0!important;z-index:0!important;
 }
 body.elo-unified-chess main.tool-page .tool-card:first-of-type .analysis-board-column>.board-top-switch{
  display:none!important;
 }
 body.elo-unified-chess main.tool-page .tool-card:first-of-type .analysis-board-column>.board-with-eval{
  display:grid!important;position:relative!important;grid-template-columns:18px minmax(0,1fr)!important;
  grid-template-rows:auto!important;gap:6px!important;
  margin:0!important;width:100%!important;max-width:100%!important;
  height:auto!important;overflow:visible!important;
 }
 body.elo-unified-chess main.tool-page .tool-card:first-of-type .analysis-board-column>.board-with-eval>#board{
  grid-column:2!important;grid-row:1!important;width:100%!important;
  max-width:100%!important;min-width:0!important;height:auto!important;
  aspect-ratio:1/1!important;margin:0!important;
 }
 body.elo-unified-chess main.tool-page .tool-card:first-of-type .analysis-board-column>.board-with-eval>.board-eval-wrap{
  grid-column:1!important;grid-row:1!important;width:18px!important;
  min-width:18px!important;max-width:18px!important;overflow:hidden!important;
 }
}

/* EloFlow v8: explicit Analysis order and score containment on phones. */
@media(max-width:760px){
 body.elo-unified-chess main.tool-page .tool-card:first-of-type>.analysis-three-column{
  display:flex!important;flex-direction:column!important;align-items:stretch!important;
  gap:14px!important;
 }
 body.elo-unified-chess main.tool-page .tool-card:first-of-type>.analysis-three-column>.analysis-board-column{
  order:1!important;flex:0 0 auto!important;margin:0!important;
 }
 body.elo-unified-chess main.tool-page .tool-card:first-of-type>.analysis-three-column>.analysis-controls-panel{
  order:2!important;flex:0 0 auto!important;margin:0!important;
 }
 body.elo-unified-chess main.tool-page .tool-card:first-of-type>.analysis-three-column>.analysis-engine-column{
  order:3!important;flex:0 0 auto!important;margin:0!important;
 }
 body.elo-unified-chess main.tool-page .tool-card:first-of-type .analysis-controls-panel>.review-side-stats{
  display:block!important;position:relative!important;inset:auto!important;
  width:100%!important;max-width:100%!important;min-width:0!important;
  margin:18px 0 0!important;transform:none!important;box-sizing:border-box!important;
 }
 body.elo-unified-chess main.tool-page .tool-card:first-of-type .analysis-board-column>.board-with-eval>.board-eval-wrap{
  overflow:hidden!important;position:relative!important;box-sizing:border-box!important;
 }
 body.elo-unified-chess main.tool-page .tool-card:first-of-type .analysis-board-column>.board-with-eval>.board-eval-wrap .board-eval-track{
  position:absolute!important;inset:0!important;overflow:hidden!important;
 }
 body.elo-unified-chess main.tool-page .tool-card:first-of-type .analysis-board-column>.board-with-eval>.board-eval-wrap .board-eval-text{
  position:absolute!important;left:0!important;right:0!important;bottom:4px!important;top:auto!important;
  display:block!important;width:100%!important;max-width:100%!important;
  padding:0!important;margin:0!important;box-sizing:border-box!important;
  writing-mode:horizontal-tb!important;text-orientation:mixed!important;
  transform:none!important;white-space:nowrap!important;overflow:hidden!important;
  text-align:center!important;font:700 7px/1 Arial,sans-serif!important;
  letter-spacing:-.45px!important;z-index:2!important;
 }
}

/* EloFlow v9: move navigation and engine switches beside the board on phones. */
.elo-analysis-mobile-nav,.elo-analysis-mobile-toggles{display:none}
@media(max-width:760px){
 body.elo-unified-chess .analysis-board-column>.elo-analysis-mobile-nav{
  display:block!important;width:100%!important;margin:0 0 10px!important;
 }
 body.elo-unified-chess .analysis-board-column>.elo-analysis-mobile-nav>.elo-nav-pair{
  display:grid!important;grid-template-columns:repeat(2,minmax(0,1fr))!important;
  gap:10px!important;width:100%!important;
 }
 body.elo-unified-chess .analysis-board-column>.elo-analysis-mobile-nav button{
  width:100%!important;min-width:0!important;min-height:42px!important;
 }
 body.elo-unified-chess .analysis-board-column>.elo-analysis-mobile-toggles{
  display:grid!important;grid-template-columns:repeat(3,minmax(0,1fr))!important;
  align-items:start!important;gap:6px!important;
  width:100%!important;min-width:0!important;margin:12px 0 0!important;
 }
 body.elo-unified-chess .analysis-board-column>.elo-analysis-mobile-toggles>label{
  display:flex!important;flex-direction:column!important;align-items:center!important;
  justify-content:flex-start!important;text-align:center!important;
  gap:7px!important;min-width:0!important;width:100%!important;
  padding:6px 2px!important;margin:0!important;box-sizing:border-box!important;
  font-size:11px!important;line-height:1.25!important;white-space:normal!important;
 }
 body.elo-unified-chess .analysis-board-column>.elo-analysis-mobile-toggles>label>input[type=checkbox]{
  flex:0 0 auto!important;margin:0!important;
 }
 body.elo-unified-chess .analysis-board-column>.elo-analysis-mobile-toggles>label>.analysis-switch-caption{
  display:block!important;position:static!important;text-align:center!important;
  font-size:11px!important;white-space:normal!important;
 }
}

/* EloFlow v10: Stockfish results immediately after toggles, controls next, stats last. */
@media(max-width:760px){
 body.elo-unified-chess main.tool-page .tool-card:first-of-type>.analysis-three-column>.analysis-board-column{order:1!important}
 body.elo-unified-chess main.tool-page .tool-card:first-of-type>.analysis-three-column>.analysis-engine-column{order:2!important}
 body.elo-unified-chess main.tool-page .tool-card:first-of-type>.analysis-three-column>.analysis-controls-panel{order:3!important}
 body.elo-unified-chess main.tool-page .tool-card:first-of-type>.analysis-three-column>#review-side-stats{order:4!important}
 body.elo-unified-chess main.tool-page .tool-card:first-of-type>.analysis-three-column>.review-side-stats{
  width:100%!important;min-width:0!important;max-width:100%!important;
  margin:8px 0 0!important;box-sizing:border-box!important;
  position:relative!important;transform:none!important;
 }
 body.elo-unified-chess .analysis-board-column>.elo-analysis-mobile-toggles>label>input[type=checkbox]{
  appearance:none!important;-webkit-appearance:none!important;
  display:block!important;position:relative!important;
  flex:0 0 42px!important;width:42px!important;height:24px!important;
  min-width:42px!important;max-width:42px!important;
  min-height:24px!important;max-height:24px!important;
  border-radius:20px!important;border:1px solid #47758c!important;
  background:#244359!important;cursor:pointer!important;
  box-sizing:border-box!important;transform:none!important;
 }
 body.elo-unified-chess .analysis-board-column>.elo-analysis-mobile-toggles>label>input[type=checkbox]::before{
  content:""!important;position:absolute!important;top:3px!important;left:3px!important;
  width:16px!important;height:16px!important;border-radius:50%!important;
  background:#bdd2df!important;transition:left .15s ease!important;
 }
 body.elo-unified-chess .analysis-board-column>.elo-analysis-mobile-toggles>label>input[type=checkbox]:checked{
  background:#079ac1!important;border-color:#3bc5ec!important;
 }
 body.elo-unified-chess .analysis-board-column>.elo-analysis-mobile-toggles>label>input[type=checkbox]:checked::before{
  left:21px!important;background:#e5faff!important;
 }
 body.elo-unified-chess .analysis-board-column>.elo-analysis-mobile-toggles>label>input[type=checkbox]:focus-visible{
  outline:2px solid white!important;outline-offset:3px!important;
 }
}

/* EloFlow v11: best lines, engine details, opening, then switches. */
.elo-analysis-mobile-results,.elo-analysis-mobile-details{display:none}
@media(max-width:760px){
 body.elo-unified-chess .analysis-board-column>.elo-analysis-mobile-results,
 body.elo-unified-chess .analysis-board-column>.elo-analysis-mobile-details{
  display:block!important;width:100%!important;min-width:0!important;
  max-width:100%!important;box-sizing:border-box!important;
 }
 body.elo-unified-chess .analysis-board-column>.elo-analysis-mobile-results{margin:12px 0 4px!important}
 body.elo-unified-chess .analysis-board-column>.elo-analysis-mobile-details{margin:4px 0 10px!important}
 body.elo-unified-chess .analysis-board-column>.elo-analysis-mobile-results>.engine-lines-panel{
  display:flex!important;flex-direction:column!important;gap:6px!important;
  width:100%!important;min-width:0!important;
 }
 body.elo-unified-chess .analysis-board-column>.elo-analysis-mobile-results>.engine-lines-panel:empty{display:none!important}
 body.elo-unified-chess .analysis-board-column>.elo-analysis-mobile-details>:is(.engine-lines-settings,.engine-depth-control){
  margin:7px 0!important;max-width:100%!important;
 }
 body.elo-unified-chess .analysis-board-column>.elo-analysis-mobile-toggles>label>input[type=checkbox]{
  box-sizing:border-box!important;overflow:hidden!important;
  padding:0!important;margin:0!important;vertical-align:middle!important;
 }
 body.elo-unified-chess .analysis-board-column>.elo-analysis-mobile-toggles>label>input[type=checkbox]::before{
  box-sizing:border-box!important;top:3px!important;left:3px!important;
  width:16px!important;height:16px!important;max-width:16px!important;max-height:16px!important;
  transform:none!important;translate:none!important;inset-inline-start:3px!important;
 }
 body.elo-unified-chess .analysis-board-column>.elo-analysis-mobile-toggles>label>input[type=checkbox]:checked::before{
  left:21px!important;inset-inline-start:21px!important;transform:none!important;translate:none!important;
 }
}
