/* What every card table has, as JSBridge's table has it: the felt, the bar
   across the top - the game's name, then its buttons on the left, raised off
   the bar with a glyph each, and the gear at the right - and under the bar
   the panel that says how the game stands. Each game's own stylesheet adds
   its table. */
:root {
  --felt-top: rgb(30 104 66); --felt-bottom: rgb(16 57 36); --page: #11161a; --chrome: #1b2227;
  --chrome-2: #242d33; --ink: #e8ece9; --ink-soft: #9fb0a8; --rule: #33403a; --accent: #f2c14e; --red: #ff6b6b;
  --label: rgb(183 207 195); --zone-hot: rgb(61 125 92); --zone-edge: rgb(165 195 179);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  display: flex; flex-direction: column; min-height: 100vh;
  background: radial-gradient(ellipse at top, var(--felt-top), var(--felt-bottom)) fixed, var(--felt-bottom);
  color: var(--ink); font: 15px/1.4 system-ui, "Segoe UI", sans-serif;
}
a { color: var(--accent); }
button, select, a.button {
  font: inherit; color: var(--ink); background: var(--chrome-2); border: 1px solid var(--rule); border-radius: 6px;
  padding: 5px 12px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center;
}
select { padding: 4px 6px; }
button:hover:not(:disabled), a.button:hover { border-color: var(--zone-edge); }
button:focus-visible, select:focus-visible, a.button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button:disabled { opacity: .35; cursor: default; }
button.primary { background: var(--felt-top); border-color: var(--zone-hot); }

/* --- The bar ------------------------------------------------------------ */

.bar {
  position: sticky; top: 0; z-index: 25;
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "title controls gear";
  align-items: center; gap: 8px 20px; padding: 10px 16px;
  background: var(--chrome); border-bottom: 1px solid var(--rule);
}
.bar h1 { grid-area: title; margin: 0; font-size: 17px; font-weight: 600; letter-spacing: .02em; white-space: nowrap; }
.bar .pip { color: var(--accent); }
.bar .pip.red { color: var(--red); }
.controls { grid-area: controls; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.controls label { display: inline-flex; align-items: center; gap: 6px; color: var(--label); }
.bar .gear { grid-area: gear; }

/* Buttons that do something stand up off the bar, and go down when pressed. */
.controls button, .controls a.button, .pl-actions button, .pl-actions .button, #set-done, dialog form button {
  background-image: linear-gradient(rgb(255 255 255 / .14), rgb(0 0 0 / .14));
  border-color: rgb(255 255 255 / .2) rgb(0 0 0 / .4) rgb(0 0 0 / .55);
  box-shadow: 0 3px 0 rgb(0 0 0 / .45), 0 4px 8px rgb(0 0 0 / .28);
  transition: transform .08s ease, box-shadow .08s ease, filter .15s ease;
}
:is(.controls button, .controls a.button, .pl-actions button, .pl-actions .button, #set-done, dialog form button):hover:not(:disabled) { filter: brightness(1.12); }
:is(.controls button, .controls a.button, .pl-actions button, .pl-actions .button, #set-done, dialog form button):active:not(:disabled) {
  transform: translateY(3px);
  background-image: linear-gradient(rgb(0 0 0 / .18), rgb(255 255 255 / .04));
  box-shadow: 0 0 0 rgb(0 0 0 / .45), inset 0 2px 5px rgb(0 0 0 / .5);
}
:is(.controls button, .controls a.button, .pl-actions button, .pl-actions .button, #set-done, dialog form button):disabled { box-shadow: none; background-image: none; }
.controls [hidden] { display: none !important; }

/* A button's glyph: an Assets/Icons/btn-*.svg drawn as a mask in the colour
   of the button's text. */
.ico {
  display: inline-block; width: 16px; height: 16px; margin: 0 6px 0 -2px; flex: none;
  background-color: currentColor;
  -webkit-mask: var(--ico) center / contain no-repeat; mask: var(--ico) center / contain no-repeat;
}
.ico-table { --ico: url(../Assets/Icons/btn-table.svg); }
.ico-deal { --ico: url(../Assets/Icons/btn-deal.svg); }
.ico-undo { --ico: url(../Assets/Icons/btn-undo.svg); }
.ico-pass { --ico: url(../Assets/Icons/btn-pass.svg); }
.ico-step { --ico: url(../Assets/Icons/btn-step.svg); }
.ico-close { --ico: url(../Assets/Icons/btn-close.svg); }
.ico-meld { --ico: url(../Assets/Icons/btn-meld.svg); }
.ico-layoff { --ico: url(../Assets/Icons/btn-layoff.svg); }
.ico-discard { --ico: url(../Assets/Icons/btn-discard.svg); }
.ico-hint { --ico: url(../Assets/Icons/btn-hint.svg); }

/* --- How the game stands, under the bar ---------------------------------- */

/* Always three rows high, however much there is to say, so the table starts
   the same distance under the bar: the panel sits in a slot of that height
   (js/table-tools.js makes it), and what does not fit is behind More, which
   opens the panel down over the table rather than pushing the table down. */
.info-slot {
  --info-rows: 3;
  position: relative; flex: none; margin: 10px 14px 0;
  font-size: 13px; line-height: 1.5; height: calc(var(--info-rows) * 1.5em + 16px);
}
.info {
  position: absolute; top: 0; left: 0; max-width: 100%; height: 100%; overflow: hidden;
  /* The space under the third row is a border the panel's colour, not
     padding: what is hidden is cut off at the padding, so none of a fourth
     row shows there. */
  padding: 8px 12px 0; border-bottom: 8px solid rgb(0 0 0 / .22); background-clip: padding-box;
  display: flex; flex-wrap: wrap; align-items: baseline; align-content: flex-start; gap: 0 16px;
  border-radius: 10px; background: rgb(0 0 0 / .22); color: var(--label); font-size: 13px; line-height: 1.5;
}
.info.overflows { padding-right: 76px; }
.info.open {
  height: auto; min-height: 100%; max-height: min(60vh, 480px); overflow-y: auto; z-index: 20;
  background: #0e2e20; border-bottom-color: #0e2e20; box-shadow: 0 10px 28px rgb(0 0 0 / .5);
}
.info-more {
  position: absolute; right: 8px; bottom: 0;      /* inside: past the edge it would count as more to show */ z-index: 1;
  padding: 1px 10px; font-size: 12px; line-height: 1.5; border-radius: 11px;
  border-color: var(--accent); background: #173f2c;
}
.info.open .info-more { position: sticky; bottom: 0; margin-left: auto; align-self: flex-end; }
.info-more[hidden] { display: none; }
.info b { color: #fff; font-weight: 600; font-variant-numeric: tabular-nums; }
.info .k { color: var(--label); opacity: .85; }
.info .status { flex-basis: 100%; color: var(--accent); font-weight: 600; }
.info .status.refused { color: var(--red); }
.info .status:empty, .info > span:empty { display: none; }
.info .down { color: var(--red); }

/* --- The bar over a hand or a pile -------------------------------------- */

/* Its name, what there is to know about it, and its gear at the right end -
   the same over a player's hand, the stock, the discard pile, a player's
   melds, the trick. */
.who, .pile-bar {
  display: inline-flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 2px 8px;
  padding: 3px 10px; border-radius: 8px; background: rgb(0 0 0 / .28); font-size: 13px; line-height: 1.4;
}
.who b, .pile-bar b { font-weight: 600; }
.who .seat-name, .who .k, .pile-bar .k { color: var(--ink-soft); font-size: 12px; font-variant-numeric: tabular-nums; }

/* --- Beside a hand: its gear, and the hint (js/table-tools.js) ----------- */

.hand-gear {
  display: inline-grid; place-items: center; width: 22px; height: 22px; margin: -2px -4px -2px 4px; padding: 0;
  vertical-align: middle; background: transparent; border: 0; border-radius: 50%; opacity: .75;
}
.hand-gear img { width: 14px; height: 14px; display: block; }
.hand-gear:hover { opacity: 1; background: rgb(255 255 255 / .14); }
.hand-hint {
  margin-left: 6px; padding: 0 7px; height: 22px; line-height: 1; font-size: 13px; font-weight: 700;
  border-radius: 11px; border: 1px solid var(--accent); background: rgb(242 193 78 / .16); color: inherit;
}
.hand-hint:hover { background: rgb(242 193 78 / .3); }

/* Their flyout. */
.sort-pop {
  position: fixed; z-index: 40; min-width: 200px; padding: 8px 10px; border-radius: 8px;
  background: #083D28; border: 1px solid rgb(255 255 255 / .14); box-shadow: 0 8px 24px rgb(0 0 0 / .45); color: var(--ink);
}
.sort-pop:focus { outline: none; }
.sort-title { margin: 2px 2px 8px; font-size: 13px; font-weight: 600; color: var(--label); }
.pile-size label { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--label); }
.pile-size output { color: var(--ink); font-variant-numeric: tabular-nums; }
.pile-size input { width: 100%; margin: 6px 0 0; accent-color: var(--accent); }
.pile-size .reset { margin-top: 6px; font-size: 12px; padding: 3px 8px; }
.help-pop { width: min(340px, calc(100vw - 16px)); padding: 10px 12px; }
.help-title { margin: 0 0 6px; font-weight: 600; }
.help-text { margin: 0 0 8px; font-size: 14px; line-height: 1.45; }
.help-where { margin: 0 0 8px; padding: 5px 8px; border-radius: 6px; background: rgb(255 255 255 / .07); font-size: 14px; }
.help-where span { color: var(--ink-soft); font-size: 12px; }
/* While the hint from the bar is open: where the move starts, and where it goes. */
.hint-from { outline: 2px dashed var(--accent); outline-offset: 3px; border-radius: 6px; }
.hint-to { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; box-shadow: 0 0 14px rgb(242 193 78 / .45); }
.help-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.help-pop .help-use { border: 2px solid var(--accent); background: rgb(242 193 78 / .19); padding: 5px 10px; text-align: left; }
.help-pop .help-no { padding: 5px 10px; border: 1px solid rgb(255 255 255 / .35); background: rgb(255 255 255 / .06); }

/* --- Dialogs ------------------------------------------------------------- */

dialog { background: var(--chrome); color: var(--ink); border: 1px solid var(--rule); border-radius: 12px; max-width: 460px; }
dialog::backdrop { background: rgb(0 0 0 / .5); }
dialog h2 { margin-top: 0; }
dialog form { display: flex; flex-wrap: wrap; gap: 8px; }
dialog.notice { max-width: 480px; border-color: var(--accent); }
/* "Are you sure?" (TableTools.ask), as the club's pages ask it. */
dialog.ask { width: min(380px, calc(100vw - 32px)); padding: 18px 20px 16px; }
dialog.ask form { display: block; }
dialog.ask p { margin: 0 0 16px; font-size: 15px; line-height: 1.45; }
dialog.ask .ask-buttons { display: flex; justify-content: flex-end; gap: 10px; }
dialog.ask button { padding: 6px 14px; }
dialog.ask button.danger { background: #8f2a2a; border-color: #c25050; color: #fff; }
dialog.notice .notice-from { margin: 0 0 4px; color: var(--ink-soft); font-size: 13px; }
dialog.notice .notice-text { white-space: pre-wrap; overflow-wrap: anywhere; }

/* Scores, in a dialog and in the panel's Scores tab. */
table.scores { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; margin-bottom: 12px; }
.scores th, .scores td { padding: 4px 6px; text-align: right; }
.scores th { color: var(--ink-soft); font-weight: 600; border-bottom: 1px solid var(--rule); }
.scores th:first-child, .scores td:first-child { text-align: left; }
.scores tfoot td { border-top: 1px solid var(--rule); font-weight: 700; }
.scores td.moon, .scores td.lead { color: var(--accent); }

/* The Players tab: a row a seat, as JSBridge's. */
.pl-seat { display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 6px 8px; padding: 8px 0; border-bottom: 1px solid var(--rule); }
.pl-seat .pl-name { color: var(--ink-soft); font-size: 13px; }
.pl-seat .pl-controls { display: flex; gap: 6px; }
.pl-seat .pl-controls button { padding: 4px 10px; font-size: 13px; }
.pl-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.link-status.network { color: var(--ink-soft); }
.link-status.reconnecting, .link-status.failed { color: var(--red); }

@media (max-width: 600px) {
  .bar { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "title gear" "controls controls"; padding: 8px 10px; }
  .controls { gap: 6px 8px; }
  .controls button, .controls a.button { padding: 4px 9px; }
}

/* A visitor's game of the day (js/visitor.js): a word over the top of the
   table - the midnight warning, the invitation after a game - put away with
   a tap. */
.visit-note {
  position: fixed; left: 50%; top: 64px; transform: translateX(-50%); z-index: 30;
  width: max-content; max-width: min(560px, calc(100% - 28px)); padding: 10px 16px; cursor: pointer;
  background: var(--chrome); color: var(--ink); border: 1px solid var(--accent); border-radius: 10px;
  box-shadow: 0 6px 18px rgb(0 0 0 / .45); font-size: 14px; line-height: 1.45;
}
.visit-note a { color: var(--accent); font-weight: 600; }
.visit-note::after { content: " \00d7"; color: var(--ink-soft); }
.visit-note[hidden] { display: none; }
@media (max-width: 600px) { .visit-note { font-size: 12px; padding: 6px 10px; } }
