/* 0.25: shared, viewport-aware geometry. Themes continue to own materials.
   ID scope intentionally outranks theme geometry, including fixed fantasy plates. */
html[data-theme] {
  --fit-side:clamp(166px,17vw,240px);
  --fit-board:min(700px,max(260px,calc(100svh - 264px)),calc(96vw - var(--fit-side)*2 - 88px));
}
html[data-theme] #appHeader{position:relative;top:auto;margin:8px auto 0;width:96%;max-width:1460px;clip-path:none}
html[data-theme] #appHeader .app-header__inner{min-height:60px;padding:0 16px;width:100%}
html[data-theme] #appHeader .brand-title{font-size:28px}
html[data-theme] .page-shell{width:96%;max-width:1460px;margin:12px auto 18px}
html[data-theme] #gameWrap{gap:12px}
html[data-theme] #gameWrap .game-stage{
  display:grid;grid-template-columns:var(--fit-side) minmax(0,calc(var(--fit-board) + 40px)) var(--fit-side);
  justify-content:center;align-items:start;gap:14px;
}
html[data-theme] #gameWrap .center-stage{
  order:0;min-width:0;padding:0;background:transparent;border:0;box-shadow:none;
  clip-path:none;overflow:visible;
}
html[data-theme] #gameWrap .board-region{flex:none;width:100%;min-width:0}
html[data-theme] #gameWrap .board-shell{
  width:100%;max-width:none;padding:3px;
  grid-template-columns:16px minmax(0,1fr) 16px;
  grid-template-rows:16px auto 16px;clip-path:none;
}
html[data-theme] #gameWrap .board-shell::before{clip-path:none;pointer-events:none}
html[data-theme] #gameWrap .board{width:100%;max-width:none;aspect-ratio:1;height:auto;border-width:1px}
html[data-theme] #gameWrap .board-files,
html[data-theme] #gameWrap .board-ranks{font-size:10px;line-height:1}
html[data-theme] #gameWrap .board .glyph{width:88%;height:88%;font-size:clamp(22px,4vw,54px)}
html[data-theme] #gameWrap .player-panel{
  min-height:0;height:auto;min-width:0;padding:16px 12px 12px;
  clip-path:none;overflow:visible;
}
html[data-theme] #gameWrap .player-panel::before{clip-path:none;pointer-events:none}
html[data-theme] #gameWrap .panel-gem,
html[data-theme] #gameWrap .panel-point-gem{display:none}
html[data-theme] #gameWrap .player-panel__heading{margin:0;padding:0;min-height:0}
html[data-theme] #gameWrap .player-panel__heading h2{font-size:clamp(12px,1.15vw,16px);letter-spacing:.08em}
html[data-theme] #gameWrap .heading-rule{height:8px;margin:6px auto 9px}
html[data-theme] #gameWrap .bank-help{font-size:10px;margin:4px 0 8px}
html[data-theme] #gameWrap .bank{
  flex:none;grid-template-columns:repeat(2,minmax(0,1fr));grid-template-rows:repeat(3,minmax(0,1fr));gap:7px;
}
html[data-theme] #gameWrap .bank .piece{
  height:clamp(72px,calc((var(--fit-board) - 110px)/3),172px);
  min-height:0;min-width:0;grid-template-rows:minmax(0,1fr) auto;padding:6px;
  touch-action:manipulation;
}
html[data-theme] #gameWrap .bank .glyph{width:100%;height:100%;min-height:0;margin:0;font-size:clamp(30px,5svh,60px)}
html[data-theme] #gameWrap .piece-name{font-size:9px;line-height:1.2;letter-spacing:.04em;padding:3px 0;margin:0}
html[data-theme] #gameWrap .count{position:absolute;margin:0;font-size:11px;top:5px;right:5px;bottom:auto;left:auto;transform:none}
html[data-theme] #gameWrap .player-footer{
  display:flex;justify-content:space-around;gap:8px;
  margin:10px 0 0;padding:10px 0 0;clip-path:none;background:none;
}
html[data-theme] #gameWrap .player-footer::before,
html[data-theme] #gameWrap .player-footer::after{display:none}
/* A shared small dial preserves both clock hands without huge fixed offsets. */
html[data-theme] #gameWrap .clock-block{
  display:grid;grid-template-columns:32px auto;grid-template-rows:auto auto;
  align-items:center;justify-content:center;gap:2px 7px;padding:0;min-height:0;
}
html[data-theme] #gameWrap .clock-block::before{
  content:"";position:relative;grid-area:1/1/3/2;inset:auto;margin:0;
  width:32px;height:32px;box-sizing:border-box;border:1px solid currentColor;border-radius:50%;
  background:radial-gradient(circle,currentColor 0 1px,transparent 2px);box-shadow:none;
  align-self:center;justify-self:center;transform:none;
}
html[data-theme] #gameWrap .clock-block::after,
html[data-theme] #gameWrap .clock-minute{
  content:"";display:block;position:relative;grid-area:1/1/3/2;
  inset:auto;margin:0;width:32px;height:32px;border:0;box-shadow:none;border-radius:0;
  background:linear-gradient(currentColor,currentColor) center 6px/2px 10px no-repeat;
  align-self:center;justify-self:center;transform-origin:center;
  transform:rotate(var(--clock-hand-angle,0deg));pointer-events:none;
}
html[data-theme] #gameWrap .clock-minute{
  background-size:1px 13px;background-position:center 3px;
  transform:rotate(var(--clock-second-angle,0deg));
}
html[data-theme] #gameWrap .clock-value{grid-area:1/2;font-size:24px;line-height:1.05;margin:0;letter-spacing:0}
html[data-theme] #gameWrap .clock-label{grid-area:2/2;font-size:8px;line-height:1.2;margin:0;letter-spacing:.07em}
html[data-theme] #gameWrap .clock-caption{display:none}
html[data-theme] #gameWrap .material-value{font-size:22px}
html[data-theme] #gameWrap .turn-console{
  width:100%;max-width:none;margin-top:8px;padding:8px 10px;min-height:0;
  clip-path:none;flex-wrap:wrap;gap:5px 12px;
}
html[data-theme] #gameWrap .turn-console::before{clip-path:none;pointer-events:none}
html[data-theme] #gameWrap .status-line{gap:7px;flex-wrap:wrap;justify-content:center}
html[data-theme] #gameWrap .status-line strong{font-size:14px;letter-spacing:.06em}
html[data-theme] #gameWrap .status-line span{font-size:11px}
html[data-theme] #gameWrap .status-chips{margin:3px 0 0;gap:5px 9px;justify-content:center}
html[data-theme] #gameWrap .status-chip{font-size:9px;letter-spacing:.04em;padding:1px 4px}
html[data-theme] #gameWrap .center-actions{width:100%;max-width:none;display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px;margin-top:8px}
html[data-theme] #gameWrap .center-actions button{height:40px;min-width:0;padding:4px;font-size:10px;letter-spacing:.04em;gap:5px}
html[data-theme] #gameWrap .btn-ico{width:15px;height:15px}
html[data-theme] #gameWrap .history-panel{width:100%;margin:0;padding:12px;min-width:0;clip-path:none}
html[data-theme] #gameWrap .history-panel::before{clip-path:none;pointer-events:none}
html[data-theme] #gameWrap .history-heading{margin-bottom:6px}
html[data-theme] #gameWrap .history-heading h2{font-size:13px}
html[data-theme] #gameWrap .move-history-scroll{max-height:110px;overflow:auto}
html[data-theme] #gameWrap .page-finial{display:none}
@media(max-width:800px){
  html[data-theme] #appHeader .app-header__inner{min-height:48px;padding:0 8px;display:flex;justify-content:space-between}
  html[data-theme] #appHeader .brand-title{font-size:22px}
  html[data-theme] #appHeader .brand-block::before,
  html[data-theme] #appHeader .brand-block::after{display:none}
  html[data-theme] #appHeader .icon-button{height:38px;width:38px;padding:0;justify-content:center}
  html[data-theme] #appHeader .icon-button__label{display:none}
  html[data-theme] .page-shell{margin-top:8px}
  html[data-theme] #gameWrap .game-stage{
    display:flex;flex-direction:column;align-items:stretch;gap:7px;
    width:min(100%,540px);margin:auto;
  }
  /* Reuse the same live regions; do not clone either bank or the board. */
  html[data-theme] #gameWrap .center-stage{display:contents}
  html[data-theme] #gameWrap #panelBlack{order:0}
  html[data-theme] #gameWrap .board-region{order:1}
  html[data-theme] #gameWrap .turn-console{order:2}
  html[data-theme] #gameWrap #panelWhite{order:3}
  html[data-theme] #gameWrap .center-actions{order:4}
  html[data-theme] #gameWrap .player-panel{
    display:grid;grid-template-columns:1fr auto;grid-template-rows:auto auto;
    gap:5px 8px;padding:8px;min-height:0;
  }
  html[data-theme] #gameWrap .player-panel__heading{grid-area:1/1;display:flex;align-items:center}
  html[data-theme] #gameWrap .player-panel__heading h2{font-size:11px;letter-spacing:.06em}
  html[data-theme] #gameWrap .player-panel .eyebrow,
  html[data-theme] #gameWrap .heading-rule,
  html[data-theme] #gameWrap .bank-help,
  html[data-theme] #gameWrap .active-indicator{display:none}
  html[data-theme] #gameWrap .bank{grid-area:2/1/3/3;grid-template-columns:repeat(6,minmax(0,1fr));grid-template-rows:1fr;gap:4px}
  html[data-theme] #gameWrap .bank .piece{height:68px;min-height:44px;padding:4px 2px}
  html[data-theme] #gameWrap #panelBlack .bank .piece{height:48px;grid-template-rows:minmax(0,1fr)}
  html[data-theme] #gameWrap #panelBlack .piece-name{display:none}
  html[data-theme] #gameWrap .bank .glyph{font-size:32px}
  html[data-theme] #gameWrap #panelBlack .bank .glyph{font-size:28px}
  html[data-theme] #gameWrap .piece-name{font-size:7px;letter-spacing:0;padding:2px 0;clip-path:none}
  html[data-theme] #gameWrap .count{font-size:10px;top:2px;right:3px;padding:0 2px}
  html[data-theme] #gameWrap .count-gem{display:none}
  html[data-theme] #gameWrap .player-footer{grid-area:1/2;display:block;padding:0;margin:0;border:0}
  html[data-theme] #gameWrap .clock-block{display:flex;gap:0}
  html[data-theme] #gameWrap .clock-value{font-size:18px;line-height:1.1}
  html[data-theme] #gameWrap .clock-label,
  html[data-theme] #gameWrap .clock-minute,
  html[data-theme] #gameWrap .clock-block::before,
  html[data-theme] #gameWrap .clock-block::after,
  html[data-theme] #gameWrap .material-block{display:none}
  html[data-theme] #gameWrap .board-shell{padding:2px;grid-template-columns:12px minmax(0,1fr) 12px;grid-template-rows:12px auto 12px}
  html[data-theme] #gameWrap .board .glyph{font-size:clamp(22px,7vw,40px)}
  html[data-theme] #gameWrap .turn-console{margin:0;padding:6px 8px}
  html[data-theme] #gameWrap .status-line strong{font-size:12px}
  html[data-theme] #gameWrap .status-line::after,
  html[data-theme] #gameWrap #statusDetail,
  html[data-theme] #gameWrap .status-divider{display:none}
  html[data-theme] #gameWrap .status-chips{margin:0}
  html[data-theme] #gameWrap .center-actions{margin:0}
  html[data-theme] #gameWrap .center-actions button{height:44px;clip-path:none}
  html[data-theme] #gameWrap .center-actions button::before{clip-path:none}
  html[data-theme] #gameWrap .history-panel{width:min(100%,540px);margin:auto}
  html[data-theme] #gameWrap .move-history-table{min-width:0}
  html[data-theme] #gameWrap .history-nav{min-width:36px;min-height:44px}
}

@media(max-width:800px){
  html[data-theme] #gameWrap .board-region{width:min(100%,max(220px,calc(100svh - 400px)));align-self:center}
}
