/* Billiards. The table is one canvas, drawn and sized by app.js to the room .table-section is given: it keeps its
   proportions and stands upright on an upright screen. The cloth, the balls and the cues are the canvas's own colours;
   the marks drawn over the cloth take the site's tokens.
   Wide screens: the players and whose shot it is in a slim bar above; the table between its controls, the power bar on
   the left and the spin, the cue, the potted balls and fine aim on the right. The table side is never mirrored.
   Upright screens: the players above, the upright table, then the potted balls and the controls in a row under it. */
:root { --ball-ivory: #fbf6ea; --ball-shade: #b9ae98; --notch: color-mix(in srgb, var(--gk-white) 14%, transparent); --plate: color-mix(in srgb, var(--gk-night) 80%, transparent); }
.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 10px max(12px, var(--gk-safe-end)) max(12px, var(--gk-safe-bottom)) max(12px, var(--gk-safe-start)); }

/* The players, each with the balls of their group, and whose shot it is between them. */
.bar { flex: none; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr) minmax(0, 1fr); gap: 10px; align-items: stretch; }
#seat-0 { --seat: var(--gk-seat-1); }
#seat-1 { --seat: var(--gk-seat-2); flex-direction: row-reverse; }
#seat-1 .gk-seat-text { text-align: end; }
/* The name keeps some room; on a narrow plate the balls give way first. */
.bar .gk-seat-text { min-width: 3em; }
.ball-strip { --ball: 24px; flex: 0 1 auto; display: flex; align-items: center; gap: 3px; min-width: 0; padding-block: 2px; overflow: hidden; }
.talk { min-width: 0; display: flex; flex-direction: column; justify-content: center; text-align: center; }
/* The turn line is one line; the event line has room for two, kept reserved, so a long message never moves the table.
   A foul is also said in the middle of the screen. */
.talk .gk-turn { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.talk .gk-event { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; min-height: 2.8em; line-height: 1.4; }

/* A small ball, in a player's plate and in the rail of potted balls. Its colour comes from the script (--ball-color). */
.mini-ball { flex: none; width: var(--ball, 24px); height: var(--ball, 24px); border-radius: 50%; display: grid; place-items: center; direction: ltr;
  font: var(--gk-number) var(--gk-text-xs)/1 var(--gk-font); color: var(--gk-night);
  background: radial-gradient(circle at 34% 28%, var(--gk-shine), transparent 34%), radial-gradient(circle, var(--ball-ivory) 0 40%, var(--ball-color) 42%);
  box-shadow: inset 0 -2px 3px var(--gk-dark), var(--gk-shadow-1); }
.mini-ball.stripe { background: radial-gradient(circle at 34% 28%, var(--gk-shine), transparent 34%), radial-gradient(circle, var(--ball-ivory) 0 40%, transparent 42%), linear-gradient(var(--ball-ivory) 0 22%, var(--ball-color) 22% 78%, var(--ball-ivory) 78%); }
.mini-ball.potted { opacity: .25; filter: grayscale(.6); }
.mini-ball.empty { background: var(--gk-well); box-shadow: var(--gk-sunk); }

/* The table between its controls. */
.play { flex: 1; min-height: 0; display: flex; align-items: stretch; gap: 12px; direction: ltr; }
.table-section { flex: 1; min-width: 0; min-height: 0; display: grid; place-items: center; }
#table { display: block; touch-action: none; cursor: crosshair; border-radius: 3.4% / 6%; box-shadow: 0 14px 0 var(--gk-night), 0 26px 44px var(--gk-dark); }
.side { flex: none; width: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
/* While it is not your shot the shot controls rest; the cue chooser and the potted balls stay as they are. */
.play.idle :is(.power, .fine) { opacity: .4; }
:is(.power, .fine, .spin-pad):focus-visible { outline: var(--gk-focus); outline-offset: var(--gk-focus-gap); }

/* The tools beside the table: spin (gold, it changes the shot) and the cue chooser. */
.gk-btn.tool { flex: none; width: 56px; height: 56px; padding: 7px; }
.tool svg { width: 34px; height: 34px; fill: none; }
.spin-ball { position: relative; display: block; width: 100%; height: 100%; border-radius: 50%; background: radial-gradient(circle at 36% 30%, var(--gk-white), var(--ball-ivory) 60%, var(--ball-shade)); box-shadow: inset 0 -3px 5px var(--gk-dark); }
.spin-ball i { position: absolute; left: 37%; top: 37%; width: 26%; height: 26%; border-radius: 50%; background: var(--gk-leave); box-shadow: 0 0 0 1px var(--gk-leave-shade); }

/* Power: press the bar, pull it back and let go. The cue in it is a picture of the chosen cue (drawn by the script).
   Beside the table it stands upright and is pulled down. */
.power { position: relative; flex: 1 1 0; width: 56px; min-height: 110px; max-height: 520px; overflow: hidden; border-radius: var(--gk-r-lg); border: 1px solid var(--gk-line);
  background: linear-gradient(90deg, var(--gk-tile), var(--gk-rim)); box-shadow: var(--gk-sunk); cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; transition: opacity var(--gk-move); }
.power.pulling { cursor: grabbing; border-color: var(--gk-gold); }
.power-fill { position: absolute; inset: 0 0 auto 0; height: var(--pull, 0%); background: linear-gradient(180deg, var(--gk-go), var(--gk-gold) 55%, var(--gk-leave)); opacity: .85; }
.power-cue { position: absolute; top: 5%; bottom: 8%; left: 50%; width: 11px; translate: -50% 0; pointer-events: none; background: var(--cue-tall) center / 100% 100% no-repeat; filter: drop-shadow(2px 0 2px var(--gk-dark)); }
.power-value, .fine span { padding: 8px 3px; border-radius: var(--gk-r-pill); background: var(--plate); color: var(--gk-ink); font-size: var(--gk-text-xs); line-height: 1.2; white-space: nowrap; writing-mode: vertical-rl; pointer-events: none; }
.power-value { position: absolute; left: 50%; bottom: 8px; translate: -50% 0; }
/* Fine aim: a wheel that turns the cue a little for a long drag. Beside the table it is dragged up or down. */
.fine { flex: 0 1 150px; width: 56px; min-height: 80px; display: grid; place-items: center; border-radius: var(--gk-r-lg); border: 1px solid var(--gk-line); box-shadow: var(--gk-sunk);
  cursor: ns-resize; touch-action: none; user-select: none; -webkit-user-select: none; transition: opacity var(--gk-move);
  background: repeating-linear-gradient(0deg, var(--notch) 0 2px, transparent 2px 14px) 0 var(--turn, 0px), linear-gradient(90deg, var(--gk-tile), var(--gk-rim)); }

/* Balls that are down roll into this rail, in the order they went down. */
.rack { --ball: 24px; flex: 1 1 0; width: 34px; min-height: 60px; padding: 5px 0; display: flex; flex-direction: column-reverse; align-items: center; gap: 2px; overflow: hidden;
  border-radius: var(--gk-r-pill); border: 1px solid var(--gk-line); background: linear-gradient(90deg, var(--gk-night), var(--gk-rim) 45%, var(--gk-night)); box-shadow: var(--gk-sunk); }
.rack .mini-ball.arriving { animation: rack-in .6s cubic-bezier(.3, 0, .55, 1.2) both; }
@keyframes rack-in { from { translate: 0 calc(-1 * var(--fall, 320px)); } }
@keyframes rack-in-flat { from { translate: var(--fall, 320px) 0; } }

/* The spin pop-up: a large cue ball; the red mark is where the cue tip strikes. */
.spin-pad { position: relative; width: min(220px, 60vw, 38dvh); aspect-ratio: 1; margin: 4px auto 14px; border-radius: 50%; cursor: crosshair; touch-action: none;
  background: radial-gradient(circle at 36% 30%, var(--gk-white), var(--ball-ivory) 58%, var(--ball-shade)); box-shadow: inset 0 -10px 18px var(--gk-dark), var(--gk-shadow-2); }
.spin-pad::before { content: ""; position: absolute; inset: 11%; border-radius: 50%; border: 1px dashed color-mix(in srgb, var(--gk-night) 22%, transparent); }
.spin-pad::after { content: ""; position: absolute; left: 50%; top: 8%; bottom: 8%; border-left: 1px solid color-mix(in srgb, var(--gk-night) 12%, transparent); }
.spin-pad i { position: absolute; left: 43%; top: 43%; width: 14%; height: 14%; border-radius: 50%; background: var(--gk-leave); box-shadow: 0 0 0 2px var(--gk-leave-shade), var(--gk-shadow-1); pointer-events: none; }
/* The cue pop-up: every cue as it looks on the table. The chosen one wears a gold ring; one still in the shop has a dashed edge. */
.cue-list { display: grid; gap: 8px; margin: 4px 0 2px; }
.gk-btn.cue-option { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; width: 100%; padding: 11px 12px; font-size: var(--gk-text-sm); white-space: normal; direction: ltr; }
.cue-option canvas { display: block; width: 100%; height: auto; }
.gk-btn.cue-option[aria-checked=true] { border-color: var(--gk-gold-edge); background: linear-gradient(var(--gk-raise), var(--gk-raise-deep)); box-shadow: 0 0 0 2px var(--gk-gold), var(--gk-shadow-2); }
.gk-btn.cue-option.locked { opacity: .72; border-style: dashed; }

/* Upright screens: the players above, the upright table, then the potted balls in a strip and, under it, spin, the cue
   chooser, fine aim and the power bar in a row. Fine aim is dragged sideways and the power bar is pulled to the left. */
@media (orientation: portrait) {
  .stage { gap: 8px; padding-top: 8px; }
  .bar { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px 8px; }
  .talk { grid-column: 1 / -1; grid-row: 2; }
  #seat-0, #seat-1 { flex-direction: column; align-items: stretch; gap: 4px; }
  #seat-1 .gk-seat-text { text-align: start; }
  #table { border-radius: 6% / 3.4%; box-shadow: 0 9px 0 var(--gk-night), 0 18px 30px var(--gk-dark); }
  .play { display: grid; grid-template-columns: auto auto auto minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto auto; grid-template-areas: "table table table table" "rack rack rack rack" "spin cue fine power"; gap: 8px; }
  .table-section { grid-area: table; }
  .side { display: contents; }
  #spin-open { grid-area: spin; } #cue-open { grid-area: cue; } #fine { grid-area: fine; } #power { grid-area: power; }
  .gk-btn.tool { width: 48px; height: 48px; padding: 6px; }
  .tool svg { width: 30px; height: 30px; }
  .rack { grid-area: rack; flex-direction: row; width: auto; height: 32px; min-height: 0; padding: 0 6px; background: linear-gradient(var(--gk-night), var(--gk-rim) 45%, var(--gk-night)); }
  .rack .mini-ball.arriving { animation-name: rack-in-flat; }
  .fine { width: clamp(84px, 26vw, 140px); height: 48px; min-height: 0; cursor: ew-resize;
    background: repeating-linear-gradient(90deg, var(--notch) 0 2px, transparent 2px 14px) var(--turn, 0px) 0, linear-gradient(var(--gk-tile), var(--gk-rim)); }
  .fine span { padding: 3px 9px; writing-mode: horizontal-tb; }
  .power { width: auto; height: 48px; min-height: 0; max-height: none; background: linear-gradient(var(--gk-tile), var(--gk-rim)); }
  .power-fill { inset: 0 0 0 auto; height: auto; width: var(--pull, 0%); background: linear-gradient(270deg, var(--gk-go), var(--gk-gold) 55%, var(--gk-leave)); }
  .power-cue { top: 50%; bottom: auto; left: 10%; right: 6%; width: auto; height: 11px; translate: 0 -50%; background-image: var(--cue-flat); filter: drop-shadow(0 2px 2px var(--gk-dark)); }
  .power-value { left: 0; right: 0; bottom: 2px; translate: none; padding: 0; background: none; text-align: center; writing-mode: horizontal-tb; text-shadow: 0 1px 2px var(--gk-night); }
}
/* An upright phone: smaller plates and balls, so a whole group fits under each name. */
@media (max-width: 599px) and (orientation: portrait) {
  .bar .gk-seat { padding: 6px 9px; }
  .gk-seat-name { font-size: var(--gk-text-sm); }
  .ball-strip { --ball: clamp(16px, 5vw, 22px); gap: 2px; }
  .rack { --ball: 20px; height: 28px; }
}
/* An upright tablet: larger controls under the table. */
@media (min-width: 600px) and (max-width: 1023px) and (orientation: portrait) {
  .stage { gap: 12px; padding-top: 14px; }
  .bar { width: 100%; max-width: 760px; margin-inline: auto; }
  .gk-turn { font-size: var(--gk-text-lg); }
  .gk-btn.tool { width: 56px; height: 56px; padding: 7px; }
  .tool svg { width: 34px; height: 34px; }
  .fine, .power { height: 56px; }
  .fine { width: 180px; }
  .rack { height: 36px; }
}
/* A sideways phone: one line per player and slimmer controls beside the table. */
@media (orientation: landscape) and (max-height: 560px) {
  .stage { gap: 6px; padding-top: 6px; padding-bottom: max(6px, var(--gk-safe-bottom)); }
  .bar { gap: 8px; }
  .bar .gk-seat { padding: 4px 10px; gap: 8px; }
  .gk-seat-note { display: none; }
  .gk-seat-name { font-size: var(--gk-text-sm); }
  .ball-strip { --ball: 18px; gap: 2px; }
  .gk-turn { min-height: 0; font-size: var(--gk-text-sm); line-height: 1.3; }
  .talk .gk-event { margin: 0; min-height: 1.3em; font-size: var(--gk-text-xs); line-height: 1.3; -webkit-line-clamp: 1; }
  .play { gap: 8px; }
  .side { width: 44px; gap: 8px; }
  .gk-btn.tool { width: 44px; height: 44px; padding: 4px; }
  .tool svg { width: 26px; height: 26px; }
  .fine, .power { width: 44px; min-height: 60px; }
  .rack { --ball: 20px; width: 28px; min-height: 40px; }
  #table { box-shadow: 0 6px 0 var(--gk-night), 0 12px 20px var(--gk-dark); }
}
