/* Shared table UI: the responsive grid (docs/ux/table-v2-spec.md §4). Only the
   regions; what goes in them belongs to the components and the tables.
   Block owners (one builder per block; anyone else asks the UX lead):
     [A] base + phone portrait  C06 (C07 asks C06 for changes, through the lead)
     [B] phone landscape        C11 (C12 asks C11)
     [C] desktop / tablet       C08
     [D] board internals        C01 (.tui-board, .tui-board-head, .tui-grid; C02/C03 use them)
   The action dock is one element in every mode (the main button never has two copies):
   the bottom band on phones, the bottom of the right column on a phone on its side and
   on desktop, next to the hand.                                                 */

/* [A] base + phone portrait ------------------------------------------------ */
.tui {
  height: 100dvh;
  display: grid;
  overflow: hidden;
  background: var(--tui-bg);
  color: var(--tui-text);
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: var(--tui-top-h) minmax(0, 1fr) auto auto auto; /* the dock row grows with a selection bar or a decision above it */
  grid-template-areas: "top" "boards" "me" "hand" "dock";
}
.tui-top { grid-area: top; position: relative; min-width: 0; display: flex; align-items: center; gap: var(--tui-gap); padding: 0 8px; background: var(--tui-panel); border-bottom: 1px solid var(--tui-line); }
.tui-rail { grid-area: rail; display: none; min-height: 0; }
.tui-boards { grid-area: boards; min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto minmax(0, 1.15fr); }
.tui-opps { min-height: 0; display: grid; }
.tui-opps > .tui-board:not(.tui-focus) { display: none; } /* phones: one opponent at a time */
.tui-split { height: 0; position: relative; z-index: 2; display: flex; justify-content: center; }
.tui-me { grid-area: me; min-width: 0; display: flex; align-items: center; gap: var(--tui-gap); padding: 0 8px; min-height: var(--tui-me-h); background: var(--tui-panel); border-top: 1px solid var(--tui-line); overflow-x: auto; }
.tui-hand { grid-area: hand; min-width: 0; }
.tui-side { grid-area: side; display: none; min-height: 0; }
.tui-dock { grid-area: dock; min-width: 0; min-height: var(--tui-dock-h); } /* no overflow here: vs-computer floats its selection bar above the dock (a scroll box would clip it); online caps its own dock in client-v2.css */
.tui-top .tui-bar { display: none; } /* phones: the step pill and ⋯ are the top bar; a table shows the bar in landscape and on desktop (its own v2 CSS) */

/* [B] phone on its side ----------------------------------------------------- */
@media (orientation: landscape) and (max-height: 500px) {
  .tui {
    grid-template-columns: var(--tui-rail-w-land) minmax(0, 1fr) var(--tui-side-w-land);
    grid-template-rows: minmax(0, 1fr) auto var(--tui-hand-h-land);
    grid-template-areas: "rail boards side" "rail me side" "rail hand dock";
  }
  .tui-top { display: none; }
  .tui-rail, .tui-side { display: flex; flex-direction: column; gap: var(--tui-gap); padding: 6px; background: var(--tui-panel); overflow-y: auto; }
  .tui-rail { border-right: 1px solid var(--tui-line); }
  .tui-side { border-left: 1px solid var(--tui-line); }
  .tui-boards { grid-template-rows: minmax(0, 1fr) 0 minmax(0, 1fr); }
  .tui-dock { background: var(--tui-panel); border-left: 1px solid var(--tui-line); }
}

/* [C] desktop / tablet ------------------------------------------------------ */
.tui-bar, .tui-inspector { display: none; } /* shown by the desktop block below */
@media (min-width: 900px) and (min-height: 501px) {
  .tui {
    grid-template-columns: var(--tui-rail-w) minmax(0, 1fr) var(--tui-side-w);
    grid-template-rows: var(--tui-top-h-desk) minmax(0, 1fr) auto;
    grid-template-areas: "top top top" "rail boards side" "rail hand dock";
  }
  .tui-me { display: none; }
  .tui-bar { display: flex; }
  .tui-rail, .tui-side { display: flex; flex-direction: column; gap: 8px; padding: 10px; background: var(--tui-panel); }
  .tui-rail { border-right: 1px solid var(--tui-line); }
  .tui-side { border-left: 1px solid var(--tui-line); }
  .tui-boards { padding: 8px; gap: 8px; grid-template-rows: minmax(0, 1.2fr) minmax(0, 1fr); }
  .tui-opps { gap: 8px; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); }
  .tui-opps > .tui-board:not(.tui-focus) { display: flex; }
  .tui[data-seats="5"] .tui-opps, .tui[data-seats="6"] .tui-opps { grid-auto-flow: row; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tui-opps .tui-board { --tui-card-w: var(--tui-opp-card-w, clamp(76px, 5.6vw, 118px)); }
  .tui-split { display: none; }
  .tui-players { display: flex; flex-direction: column; gap: var(--tui-gap); }
  .tui-rail > .tui-inspector { margin-top: auto; }
  .tui-hand { min-height: 0; }
  .tui-dock { background: var(--tui-panel); border-left: 1px solid var(--tui-line); border-top: 1px solid var(--tui-line); align-self: stretch; }
  /* top bar: steps, prompt and tools in one row; controls 40px (36-44px) */
  .tui-seatstrip, .tui-top > .tui-chip, .tui-top > .tui-step, .tui-top > .tui-more { display: none; }
  .tui-bar { flex: 1; min-width: 0; align-items: center; gap: var(--tui-gap); overflow: hidden; }
  .tui-bar button, .tui-bar select { min-height: calc(var(--tui-top-h-desk) - 12px); }
  .tui-bar .tui-prompt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
/* [C-bar] a table's v2 CSS used to be the only thing that showed the bar on desktop: [A] hides it with a 0,2,0 rule that the 0,1,0 rule above could not beat. Same specificity, later in the file. */
@media (min-width: 900px) and (min-height: 501px) {
  .tui-top .tui-bar { display: flex; }
}
/* [C-quad] Quadrants (docs/ux/desktop-proposal.md, concept B): a table asks for it with data-layout="quad" (TableUI.rootAttrs({ layout: 'quad' }); 2-4 seats only).
   Every board gets an equal cell: you bottom left, the others clockwise from you (1 top left, 2 top right, 3 bottom right). With 3 seats the fourth cell
   (.tui-cell-spare) holds the inspector. The left rail is gone: its players are a strip over the boards, and the inspector is the top of the right column
   (the side: inspector, stack, zones, log; --tui-side-w is its width), with the dock under it, next to the hand. The players strip goes when
   the boards carry their own heads.                                                                                                      */
@media (min-width: 900px) and (min-height: 501px) {
  .tui[data-layout="quad"] {
    grid-template-columns: minmax(0, 1fr) var(--tui-side-w);
    grid-template-rows: var(--tui-top-h-desk) auto minmax(0, 1fr) auto;
    grid-template-areas: "top top" "players side" "boards side" "hand dock";
  }
  .tui[data-layout="quad"] .tui-rail { grid-area: players; flex-direction: row; align-items: stretch; padding: 8px 8px 0; background: none; border: 0; }
  .tui[data-layout="quad"] .tui-rail > .tui-players { flex: 1; min-width: 0; flex-direction: row; }
  .tui[data-layout="quad"] .tui-rail > .tui-players > * { flex: 1 1 0; min-width: 0; }
  .tui[data-layout="quad"] .tui-rail > .tui-tools, .tui[data-layout="quad"] .tui-rail > .tui-inspector { display: none; }
  .tui[data-layout="quad"] .tui-side { min-height: 0; overflow-y: auto; }
  /* the inspector takes a fixed share of the column (the hint and a card are the same size), so what is under it never jumps when the pointer moves over a card */
  .tui[data-layout="quad"] .tui-side > .tui-inspector { flex: 0 0 clamp(128px, 19vh, 400px); min-height: 0; overflow: hidden; }
  /* the card on the left, its name and type line beside it (desktop Q6): a short window used to squash the card to a strip with the type line cut off under the Stack panel;
     here the card takes the inspector's whole height and the words sit next to it, in the side column and in the spare cell alike */
  .tui[data-layout="quad"] .tui-inspector { container-type: size; }
  .tui[data-layout="quad"] .tui-inspector .tui-insp:not(.tui-insp-empty) { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-auto-rows: min-content; column-gap: 10px; row-gap: 2px; align-content: start; height: 100%; }
  .tui[data-layout="quad"] .tui-inspector .tui-insp-face { grid-column: 1; grid-row: 1 / span 12; height: 100cqh; max-height: none; width: auto; aspect-ratio: 5 / 7; margin: 0; align-self: start; min-height: 0; }
  .tui[data-layout="quad"] .tui-inspector .tui-insp-face > * { width: 100%; height: 100%; }
  .tui[data-layout="quad"] .tui-inspector .tui-insp-title, .tui[data-layout="quad"] .tui-inspector .tui-insp-line { grid-column: 2; min-width: 0; overflow-wrap: anywhere; }
  /* nothing hovered yet (desktop Q6): the same shape as a card in the box (an outline of one, 5:7, and the hint beside it), not an empty dark panel that looks unfinished */
  .tui[data-layout="quad"] .tui-insp-empty { aspect-ratio: auto; flex: 1; height: 100%; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; column-gap: 10px; padding: 0; border: 0; text-align: left; }
  .tui[data-layout="quad"] .tui-insp-empty::before { content: ''; height: 100cqh; aspect-ratio: 5 / 7; box-sizing: border-box; border: 1px dashed var(--tui-line); border-radius: var(--tui-radius); background: var(--tui-panel-2); }
  .tui[data-layout="quad"] .tui-boards { display: grid; padding: 8px; gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); }
  .tui[data-layout="quad"][data-seats="2"] .tui-boards { grid-template-columns: minmax(0, 1fr); }
  .tui[data-layout="quad"] .tui-grid { display: flex; flex-wrap: wrap; align-items: flex-start; align-content: flex-start; } /* (a grid of columns one card wide put a tapped card, 1.4 times as wide, over the next one) */
  .tui[data-layout="quad"] .tui-grid > * { max-width: none; } /* (the 120px cap above squeezed a tapped slot, wider than a card, and let its card spill over the next one; the fit rule sizes the cards now) */
  .tui[data-layout="quad"] .tui-opps { display: contents; }
  .tui[data-layout="quad"] .tui-opps > :nth-child(1) { grid-area: 1 / 1; }
  .tui[data-layout="quad"] .tui-opps > :nth-child(2) { grid-area: 1 / 2; }
  .tui[data-layout="quad"] .tui-opps > :nth-child(3) { grid-area: 2 / 2; }
  .tui[data-layout="quad"] .tui-mine { grid-area: 2 / 1; }
  .tui[data-layout="quad"] .tui-cell-spare { grid-area: 2 / 2; min-height: 0; min-width: 0; display: flex; flex-direction: column; padding: 8px 10px; box-sizing: border-box; border: 1px dashed var(--tui-line); border-radius: var(--tui-radius); overflow: hidden; }
  .tui[data-layout="quad"] .tui-cell-spare > .tui-inspector { flex: 1; min-height: 0; }
  /* the dock is one row next to the hand; a selection bar or a decision (anything above the row) floats over the foot of the side column instead of growing the row */
  .tui[data-layout="quad"] .tui-dock { position: relative; }
  .tui[data-layout="quad"] .tui-dock > :not(.tui-dock-in):not(.act-bar) { position: absolute; left: 0; right: 0; bottom: 100%; z-index: 30; box-sizing: border-box; max-height: calc(100dvh - var(--tui-top-h-desk) - 200px); overflow: auto; margin: 0; background: var(--tui-panel); border-top: 1px solid var(--tui-line); }
}
/* [C-dock] desktop Q7, the hand and the main button as one group in the middle (owner: "I don't like how far to the right it is"). The bottom row is four tracks: a spacer,
   the hand (as wide as its cards, never wider than the boards' column), a spacer, and the side column's width. The hand sits in the middle of the boards' column as before; the dock
   spans the second spacer and the side column's width, so the main button is the first thing right of the hand and the status text fills the rest. A selection bar or a decision
   still floats over the foot of the side column (it is as wide as the side column and flush right). Under 1101px the older arrangement stays (the hand needs the width). */
@media (min-width: 1101px) and (min-height: 501px) {
  .tui[data-layout="quad"] {
    grid-template-columns: minmax(0, 1fr) fit-content(calc(100% - var(--tui-side-w))) minmax(0, 1fr) var(--tui-side-w);
    grid-template-areas: "top top top top" "players players players side" "boards boards boards side" "gl hand dock dock";
  }
  .tui[data-layout="quad"] .tui-dock > :not(.tui-dock-in):not(.act-bar) { left: auto; right: 0; width: var(--tui-side-w); }
  .tui[data-layout="quad"] .tui-dock { justify-content: center; }
  .tui[data-layout="quad"] .tui-dock-in { flex-wrap: nowrap; justify-content: flex-start; align-items: center; height: auto; min-height: var(--tui-dock-h); }
  /* The button must not slide as cards leave the hand (client.e2e: "the main button stays in one place"): the hand's track is never narrower than an 8-card hand (7 and the one just drawn), so the
     button stays right of where that ends, however few cards are left; a longer hand pushes it, as before. Never wider than the boards' column. */
  .tui[data-layout="quad"] .tui-hand { min-width: min(calc(8 * var(--tui-hand-card-w) + 7 * var(--tui-gap) + 24px), calc(100vw - var(--tui-side-w) - 32px)); }
  .tui[data-layout="quad"] .tui-dock-in .tui-dock-main { order: -2; flex: none; margin: 0 var(--tui-gap) 0 12px; }
  .tui[data-layout="quad"] .tui-dock-in .tui-dock-btn { order: -1; }
  .tui[data-layout="quad"] .tui-dock-in .tui-dock-status { order: 0; flex: 1 1 0; min-width: 0; }
}
/* tablet landscape (1024x768): narrower rails so the boards keep their width */
@media (min-width: 900px) and (max-width: 1100px) and (min-height: 501px) {
  .tui { --tui-rail-w: 220px; --tui-side-w: 260px; }
}

/* [D] board internals ------------------------------------------------------- */
.tui-board { min-height: 0; display: flex; flex-direction: column; gap: var(--tui-gap); padding: 6px 8px; overflow: hidden; border-left: 3px solid var(--tui-seat, var(--tui-line)); }
.tui-grid { flex: 1; min-height: 0; overflow-y: auto; display: grid; gap: var(--tui-gap); align-content: start; grid-template-columns: repeat(auto-fill, minmax(var(--tui-card-w), 1fr)); }
@media (orientation: landscape) and (max-height: 500px) {
  .tui-grid { grid-template-columns: repeat(auto-fill, minmax(var(--tui-card-w-land), 1fr)); }
}
@media (min-width: 900px) and (min-height: 501px) {
  .tui-board { border: 1px solid var(--tui-line); border-left: 3px solid var(--tui-seat, var(--tui-line)); border-radius: var(--tui-radius); padding: 8px 10px; }
  .tui-grid > * { max-width: var(--tui-card-max); }
}

/* [state] desktop Q9: the seat whose turn it is carries a ring in its colour and a TURN tag; the seat holding priority a PRIORITY tag. */
@media (min-width: 900px) and (min-height: 501px) {
  .tui[data-layout="quad"] .tui-players .tui-chip { position: relative; }
  .tui[data-layout="quad"] .tui-players .tui-chip.tui-active { box-shadow: 0 0 0 2px var(--tui-seat, var(--tui-accent)), 0 0 14px var(--tui-seat, var(--tui-accent)); }
  .tui[data-layout="quad"] .tui-players .tui-chip.tui-active.tui-prio { box-shadow: 0 0 0 2px var(--tui-seat, var(--tui-accent)), 0 0 14px var(--tui-seat, var(--tui-accent)), inset 0 0 0 2px var(--tui-gold); }
  .tui[data-layout="quad"] .tui-players .tui-chip.tui-active::before { content: 'TURN'; position: absolute; top: -9px; left: 8px; font: 800 10px/14px system-ui, sans-serif; letter-spacing: .08em; padding: 0 6px; border-radius: 4px; background: var(--tui-seat, var(--tui-accent)); color: #000; }
  .tui[data-layout="quad"] .tui-players .tui-chip.tui-prio::after { content: 'PRIORITY'; position: absolute; width: auto; height: auto; right: 8px; top: -9px; right: 8px; font: 800 10px/14px system-ui, sans-serif; letter-spacing: .08em; padding: 0 6px; border-radius: 4px; background: #fff; color: #111; }
}
