/* World Clocks tile layout shared by the themed UI templates (hud, neocom, upwell, abyssal,
   cockpit, b5, freighter, holo, probe, hive, tribal). Loaded by partials/_ui_skin_head.html only when the template is
   not Classic, before the template's own stylesheet, which adds the look (colours, type, EVE time
   emphasis) and sets --clk-max. Scoped away from Classic too, for the profile page's live preview. CSS only: the
   markup and the clock script in dashboard.html are Classic's.

   The Bootstrap row becomes a wrapping flex row whose tiles grow to fill every row. Where CSS
   round() and :has() exist, the rows are balanced: n clocks go in the fewest rows of at most --m
   tiles (5 on a wide card, 4 narrow, 3 tiny), k = ceil(n / rows) tiles per row. Rows are then
   full except possibly the last, which is shorter and whose tiles stretch: 7 -> 4 + 3 (3 + 3 + 1
   tiny), 10 -> 5 + 5 wide but 4 + 4 + 2 narrow. The counters stop at nth-child(10) because a
   site has at most 10 clocks (SLOTS = range(1, 11) in vikings/settings_views.py). */
html[data-ui]:not([data-ui="classic"]) #dash-clocks{--clk-fs:var(--clk-max, 21px)}
html[data-ui]:not([data-ui="classic"]) #dash-clocks > .row{display:flex;flex-wrap:wrap;gap:8px;margin:0}
html[data-ui]:not([data-ui="classic"]) #dash-clocks > .row > .col{flex:1 1 140px;width:auto;max-width:100%;min-width:0;margin:0;padding:0}
html[data-ui]:not([data-ui="classic"]) #dash-clocks .clock-display{font-variant-numeric:tabular-nums;white-space:nowrap;overflow:hidden;text-overflow:clip}

@supports (width: round(up, 1px, 1px)) and selector(:has(a)){
  html[data-ui]:not([data-ui="classic"]) #dash-clocks{container-type:inline-size}
  html[data-ui]:not([data-ui="classic"]) #dash-clocks > .row{--n:1;--m:4;--g:8px;gap:var(--g)}
  html[data-ui]:not([data-ui="classic"]) #dash-clocks > .row:has(> .col:nth-child(2)){--n:2}
  html[data-ui]:not([data-ui="classic"]) #dash-clocks > .row:has(> .col:nth-child(3)){--n:3}
  html[data-ui]:not([data-ui="classic"]) #dash-clocks > .row:has(> .col:nth-child(4)){--n:4}
  html[data-ui]:not([data-ui="classic"]) #dash-clocks > .row:has(> .col:nth-child(5)){--n:5}
  html[data-ui]:not([data-ui="classic"]) #dash-clocks > .row:has(> .col:nth-child(6)){--n:6}
  html[data-ui]:not([data-ui="classic"]) #dash-clocks > .row:has(> .col:nth-child(7)){--n:7}
  html[data-ui]:not([data-ui="classic"]) #dash-clocks > .row:has(> .col:nth-child(8)){--n:8}
  html[data-ui]:not([data-ui="classic"]) #dash-clocks > .row:has(> .col:nth-child(9)){--n:9}
  html[data-ui]:not([data-ui="classic"]) #dash-clocks > .row:has(> .col:nth-child(10)){--n:10}
  @container (min-width: 520px){html[data-ui]:not([data-ui="classic"]) #dash-clocks > .row{--m:5}}
  @container (max-width: 299.98px){html[data-ui]:not([data-ui="classic"]) #dash-clocks > .row{--m:3}}
  /* --w: one tile's share of the row (1px slack so rounding never wraps the last tile); the clock
     size follows it between 15px and the template's --clk-max. */
  html[data-ui]:not([data-ui="classic"]) #dash-clocks > .row > .col{--r:round(up, var(--n) / var(--m), 1);--k:round(up, var(--n) / var(--r), 1);
    --w:calc((100cqi - (var(--k) - 1) * var(--g)) / var(--k) - 1px);--clk-fs:clamp(15px, calc(var(--w) * .26), var(--clk-max, 21px));flex:1 1 var(--w)}
}

/* Each tile also caps its own digits by the room the time really has: the card is a size container,
   so 100cqi is its width inside the template's padding and border. --clk-em is how many em "HH:MM"
   takes in the template's clock face incl. letter-spacing (measured 2.3-3.2; 3.3 keeps a margin;
   Freighter's narrow VT323 sets its own). Roomy tiles keep --clk-max; only narrow ones shrink, so
   the minutes are never clipped (992-1024 px beside the sidebar, 360 px phones). */
@supports (container-type: inline-size){
  html[data-ui]:not([data-ui="classic"]) #dash-clocks .col > .card{container-type:inline-size}
  html[data-ui]:not([data-ui="classic"]) #dash-clocks .clock-display{--clk-fs:clamp(12px, calc(100cqi / var(--clk-em, 3.3)), var(--clk-max, 21px))}
}
