ansarzeinulla commited on
Commit
be7997c
·
1 Parent(s): d4042a3
Files changed (1) hide show
  1. app.py +25 -48
app.py CHANGED
@@ -114,18 +114,13 @@ INDEX_MARKUP = r"""
114
  #bb-wrap { max-width: 1700px; margin: 0 auto; padding: 0 8px;
115
  font-family: system-ui, sans-serif; color: #2a2118; --bs: 42px; }
116
  #bb-wrap * { box-sizing: border-box; }
117
- /* Desktop: the row is pinned to a JS-measured viewport height (see fitViewport()),
118
- so the board is a hard 100%-height box and everything else — the stone size,
119
- the sidebar, the AI card's max-height — is derived FROM that fixed box instead
120
- of the page growing to fit whatever content the sidebar happens to have. */
121
- #bb-cols { display: flex; gap: 16px; align-items: stretch; min-height: 0; }
122
- #bb-main { position: relative; flex: 1 1 auto; min-width: 0; height: 100%; display: flex; align-items: stretch; }
123
- #bb-side { flex: 0 0 250px; height: 100%; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
124
  @media (max-width: 860px) {
125
  #bb-wrap { padding: 0 6px; }
126
- #bb-cols { flex-direction: column; gap: 12px; height: auto !important; }
127
- #bb-main { height: auto; }
128
- #bb-side { flex: 1 1 auto; width: 100%; height: auto; }
129
  .bb-board { padding: 10px; border-radius: 18px; gap: 6px; }
130
  .bb-cellrow, .bb-numrow { gap: 5px; }
131
  .bb-cell { padding: 4px; border-radius: 9px; }
@@ -137,18 +132,19 @@ INDEX_MARKUP = r"""
137
 
138
  .bb-card { background: #fffdf5; border: 1px solid #ecdfb8; border-radius: 16px; padding: 14px;
139
  display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
140
- /* the AI panel is capacity-bound (a fixed number of pit rows), not stretchy like
141
- the move-history card below it — cap it and let it scroll instead of growing
142
- the whole sidebar (and page) taller than the board. */
143
- #bb-ai-card { flex: 0 1 auto; max-height: 42%; overflow-y: auto; }
 
 
144
 
145
  /* ---- board: a real Bestemshe board with kumalak stones ---- */
146
- .bb-board { flex: 1 1 auto; width: 100%; height: 100%; overflow: hidden;
147
  background: linear-gradient(160deg, #ddba86 0%, #c99f68 100%);
148
  border: 2px solid #a67c48; border-radius: 22px; padding: 16px;
149
  box-shadow: inset 0 2px 10px rgba(120,80,30,0.20), 0 6px 18px rgba(120,80,20,0.16);
150
  display: flex; flex-direction: column; gap: 8px; }
151
- @media (max-width: 860px) { .bb-board { height: auto; overflow: visible; } }
152
 
153
  .ball { position: relative; display: inline-block; width: var(--bs); height: var(--bs); border-radius: 50%;
154
  background: radial-gradient(circle at 34% 30%, #fffdf6 0%, #eed9a6 46%, #bd9051 100%);
@@ -581,22 +577,9 @@ INDEX_JS = r"""
581
  return '<div class="' + cls + '"' + data + ">" + cellStack(count, side) + "</div>";
582
  }
583
 
584
- // Desktop: pin #bb-cols to the exact vertical space left in the viewport, so
585
- // the board (and everything measured off it) is a hard 100%-height box rather
586
- // than something the page grows to fit. Mobile keeps natural page scrolling.
587
- function fitViewport() {
588
- const wrap = document.getElementById("bb-wrap");
589
- const cols = document.getElementById("bb-cols");
590
- if (!wrap || !cols) return;
591
- if (window.innerWidth <= 860) { cols.style.height = ""; return; }
592
- const top = cols.getBoundingClientRect().top;
593
- cols.style.height = Math.max(320, window.innerHeight - top - 10) + "px";
594
- }
595
-
596
  // Each cell is 2 stones wide; the five cells fill the board's width, so the
597
- // stone size is whatever makes 2 of them fit snugly inside one cell — bounded
598
- // by width AND (on desktop, where the board has a real fixed height) by
599
- // height too, found by binary search against the board's actual layout.
600
  function sizeBoard() {
601
  const board = document.getElementById("bb-board");
602
  const wrap = document.getElementById("bb-wrap");
@@ -605,24 +588,19 @@ INDEX_JS = r"""
605
  const inner = board.clientWidth - parseFloat(cs.paddingLeft) - parseFloat(cs.paddingRight);
606
  const cellGap = 8, cellPad = 6, colGap = 6; // must match the CSS
607
  const cellOuter = (inner - 4 * cellGap) / 5;
608
- let hi = Math.floor((cellOuter - 2 * cellPad - colGap) / 2); // largest that fits the width
609
- hi = Math.max(14, Math.min(120, hi));
610
- let bs = hi;
611
-
612
- if (window.innerWidth > 860) {
613
- // Board has an explicit CSS height (100% of the fixed-height #bb-main) —
614
- // binary-search the largest bs whose natural content height still fits it.
615
- let lo = 14;
616
- for (let i = 0; i < 22; i++) {
617
- const mid = (lo + hi) / 2;
618
- wrap.style.setProperty("--bs", mid + "px");
619
- if (board.scrollHeight <= board.clientHeight) lo = mid; else hi = mid;
620
- }
621
- bs = Math.max(14, Math.floor(lo));
622
- }
623
  wrap.style.setProperty("--bs", bs + "px");
 
 
 
 
 
 
 
 
624
  }
625
- window.addEventListener("resize", () => { fitViewport(); sizeBoard(); });
626
 
627
  function announceEnd(node) {
628
  const titleEl = document.getElementById("bb-end-title");
@@ -671,7 +649,6 @@ INDEX_JS = r"""
671
  '<div class="bb-kazan kazan-white' + whiteTurn + '">' +
672
  '<span class="bb-kcount">' + cv.wk + '</span>' +
673
  '<div class="bb-kballs">' + kazanStack(cv.wk) + "</div></div>";
674
- fitViewport();
675
  sizeBoard();
676
 
677
  let hist = "";
 
114
  #bb-wrap { max-width: 1700px; margin: 0 auto; padding: 0 8px;
115
  font-family: system-ui, sans-serif; color: #2a2118; --bs: 42px; }
116
  #bb-wrap * { box-sizing: border-box; }
117
+ #bb-cols { display: flex; gap: 16px; align-items: stretch; }
118
+ #bb-main { position: relative; flex: 1 1 auto; min-width: 0; display: flex; align-items: flex-start; }
119
+ #bb-side { flex: 0 0 250px; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
 
 
 
 
120
  @media (max-width: 860px) {
121
  #bb-wrap { padding: 0 6px; }
122
+ #bb-cols { flex-direction: column; gap: 12px; }
123
+ #bb-side { flex: 1 1 auto; width: 100%; }
 
124
  .bb-board { padding: 10px; border-radius: 18px; gap: 6px; }
125
  .bb-cellrow, .bb-numrow { gap: 5px; }
126
  .bb-cell { padding: 4px; border-radius: 9px; }
 
132
 
133
  .bb-card { background: #fffdf5; border: 1px solid #ecdfb8; border-radius: 16px; padding: 14px;
134
  display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
135
+ /* The row is sized by whichever column is naturally tallest (align-items: stretch),
136
+ and that must stay the BOARD. The history card contributes ~nothing (its list is
137
+ flex: 1 1 0 + min-height: 0), so the AI card must stay small too: its content is
138
+ bounded (one bar + at most 5 pit rows), so cap it in px and scroll any overflow.
139
+ Never size it with a % — that would resolve against the row it is meant to fit. */
140
+ #bb-ai-card { flex: 0 0 auto; max-height: 200px; overflow-y: auto; }
141
 
142
  /* ---- board: a real Bestemshe board with kumalak stones ---- */
143
+ .bb-board { flex: 1 1 auto; width: 100%;
144
  background: linear-gradient(160deg, #ddba86 0%, #c99f68 100%);
145
  border: 2px solid #a67c48; border-radius: 22px; padding: 16px;
146
  box-shadow: inset 0 2px 10px rgba(120,80,30,0.20), 0 6px 18px rgba(120,80,20,0.16);
147
  display: flex; flex-direction: column; gap: 8px; }
 
148
 
149
  .ball { position: relative; display: inline-block; width: var(--bs); height: var(--bs); border-radius: 50%;
150
  background: radial-gradient(circle at 34% 30%, #fffdf6 0%, #eed9a6 46%, #bd9051 100%);
 
577
  return '<div class="' + cls + '"' + data + ">" + cellStack(count, side) + "</div>";
578
  }
579
 
 
 
 
 
 
 
 
 
 
 
 
 
580
  // Each cell is 2 stones wide; the five cells fill the board's width, so the
581
+ // stone size is whatever makes 2 of them fit snugly inside one cell. Recomputed
582
+ // on every render and on resize (keeps stones as large as the space allows).
 
583
  function sizeBoard() {
584
  const board = document.getElementById("bb-board");
585
  const wrap = document.getElementById("bb-wrap");
 
588
  const inner = board.clientWidth - parseFloat(cs.paddingLeft) - parseFloat(cs.paddingRight);
589
  const cellGap = 8, cellPad = 6, colGap = 6; // must match the CSS
590
  const cellOuter = (inner - 4 * cellGap) / 5;
591
+ let bs = Math.floor((cellOuter - 2 * cellPad - colGap) / 2); // largest that fits the width
592
+ bs = Math.max(14, Math.min(120, bs));
 
 
 
 
 
 
 
 
 
 
 
 
 
593
  wrap.style.setProperty("--bs", bs + "px");
594
+ // Then measure the real board height and shrink until it fits the device viewport.
595
+ for (let i = 0; i < 5; i++) {
596
+ const avail = window.innerHeight - board.getBoundingClientRect().top - 12;
597
+ const h = board.offsetHeight;
598
+ if (h <= avail || bs <= 14) break;
599
+ bs = Math.max(14, Math.floor(bs * avail / h));
600
+ wrap.style.setProperty("--bs", bs + "px");
601
+ }
602
  }
603
+ window.addEventListener("resize", sizeBoard);
604
 
605
  function announceEnd(node) {
606
  const titleEl = document.getElementById("bb-end-title");
 
649
  '<div class="bb-kazan kazan-white' + whiteTurn + '">' +
650
  '<span class="bb-kcount">' + cv.wk + '</span>' +
651
  '<div class="bb-kballs">' + kazanStack(cv.wk) + "</div></div>";
 
652
  sizeBoard();
653
 
654
  let hist = "";