/* Shared game UI kit. Pair with /js/ui.js (usage notes are at the top of that file).
   Every class starts with "ui-" so it never clashes with a game's own CSS. Colors only from tokens.css. */

.ui-num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }

/* ---------- frame: controls beside the stage (desktop), stage on top (phone) ---------- */
.ui-frame { container-type: inline-size; width: 100%; }
.ui-frame-in {
  display: grid; gap: 0;
  grid-template-columns: minmax(270px, 320px) minmax(0, 1fr);
  grid-template-areas: "controls stage";
  align-items: stretch;
  border: 1px solid var(--line); border-radius: 8px;   /* desktop: controls + stage are ONE block */
}
.ui-controls {
  grid-area: controls; display: flex; flex-direction: column; gap: 12px;
  background: var(--surface); border-right: 1px solid var(--line); border-radius: 7px 0 0 7px; padding: 14px;
}
.ui-stage {
  grid-area: stage; position: relative; min-height: 420px; min-width: 0;
  background: var(--stage); border-radius: 0 7px 7px 0;
  padding: 16px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  overflow: hidden;
}
.ui-controls-end { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
@container (max-width: 680px) {
  /* phone: stage, then the controls as a second card; the kit puts the main button high in the DOM itself */
  .ui-frame-in { grid-template-columns: minmax(0, 1fr); grid-template-areas: "stage" "controls"; gap: 10px; border: 0; border-radius: 0; }
  .ui-stage { min-height: 300px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; }
  .ui-controls { padding: 14px; gap: 10px; border: 1px solid var(--line); border-radius: 8px; }
  .ui-controls-end { margin-top: 0; }
}

/* ---------- fields ---------- */
.ui-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ui-label { display: flex; justify-content: space-between; gap: 8px; font: 600 14px var(--font); color: var(--muted); }
.ui-label b { font-weight: 500; color: var(--text); font-variant-numeric: tabular-nums; }
.ui-box {
  display: flex; align-items: stretch; min-height: 44px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  transition: border-color .15s;
}
.ui-box:focus-within { border-color: var(--focus); }
.ui-box.is-bad { border-color: var(--lose); }
.ui-box input {
  flex: 1; min-width: 0; border: 0; background: transparent; color: var(--text);
  font: 500 16px var(--font-num); font-variant-numeric: tabular-nums; padding: 0 12px; outline: none;
}
.ui-box input:disabled { color: var(--muted); }
.ui-affix { display: flex; align-items: center; padding: 0 0 0 12px; color: var(--muted); font-size: 14px; }
.ui-affix.is-end { padding: 0 12px 0 0; }
.ui-box-btn {
  border: 0; border-left: 1px solid var(--line); background: transparent; color: var(--muted);
  font: 700 13px var(--font); width: 44px; flex: none; padding: 0; cursor: pointer;
}
.ui-box-btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.ui-box-btn:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.ui-box-btn:disabled { cursor: default; opacity: .4; }
.ui-coin {
  display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font: 700 10px var(--font); flex: none;
}

/* ---------- buttons ---------- */
.ui-btn {
  appearance: none; border: 1px solid transparent; border-radius: var(--radius-sm);
  min-height: 44px; padding: 0 18px; font: 600 15px var(--font); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: background .15s, border-color .15s, opacity .15s, transform .15s;
  color: var(--text); background: var(--surface-2); border-color: var(--line);
}
.ui-btn:hover:not(:disabled) { background: var(--surface-3); }
.ui-btn:active:not(:disabled) { transform: scale(.96); }
.ui-btn:disabled { cursor: default; opacity: .5; }
.ui-btn.is-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); min-height: 46px; font: 700 14px var(--font); }
.ui-btn.is-primary:disabled { opacity: .4; }   /* Stake: keeps its colour, fades to .4 */
.ui-btn.is-primary.is-busy:disabled { background: var(--accent); }
.ui-btn.is-primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.07); }
.ui-btn.is-quiet { background: transparent; border-color: transparent; color: var(--muted); }
.ui-btn.is-quiet:hover:not(:disabled) { color: var(--text); background: var(--surface-2); }
.ui-btn.is-wide { width: 100%; }
/* busy (.is-spin, set by button() with the lock): the label hides and OUR die icon wobbles. Stake's motion (desk/keno/dice
   probes): 1000 ms loop, none → scale 1.3 → scale 1.3 rotate(-10deg) → none, cubic-bezier(.87,-.41,.19,1.44) per step */
.ui-btn.is-busy { position: relative; }
.ui-btn.is-spin { color: transparent !important; }
.ui-btn.is-spin::after {
  content: ""; position: absolute; width: 18px; height: 18px; background: var(--text);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Crect x='2.5' y='2.5' width='15' height='15' rx='4' fill='none' stroke='black' stroke-width='2'/%3E%3Ccircle cx='7' cy='7' r='1.6'/%3E%3Ccircle cx='10' cy='10' r='1.6'/%3E%3Ccircle cx='13' cy='13' r='1.6'/%3E%3C/svg%3E") center / contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Crect x='2.5' y='2.5' width='15' height='15' rx='4' fill='none' stroke='black' stroke-width='2'/%3E%3Ccircle cx='7' cy='7' r='1.6'/%3E%3Ccircle cx='10' cy='10' r='1.6'/%3E%3Ccircle cx='13' cy='13' r='1.6'/%3E%3C/svg%3E") center / contain no-repeat;
  animation: ui-wobble 1s cubic-bezier(.87, -.41, .19, 1.44) infinite;
}
.ui-btn.is-primary.is-spin::after { background: var(--accent-ink); }
@keyframes ui-wobble { 0% { transform: none; } 25% { transform: scale(1.3); } 50% { transform: scale(1.3) rotate(-10deg); } 100% { transform: none; } }
@keyframes ui-spin { to { transform: rotate(360deg); } }
.ui-row { display: flex; gap: 8px; }
.ui-row > * { flex: 1; }

/* ---------- segmented choice ---------- */
.ui-seg {
  display: flex; padding: 3px; gap: 3px; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.ui-seg button {
  flex: 1; min-height: 38px; border: 0; border-radius: 6px; background: transparent; color: var(--muted);
  font: 500 14px var(--font); cursor: pointer; padding: 0 8px; white-space: nowrap;
}
.ui-seg button:hover:not(:disabled):not([aria-pressed="true"]) { color: var(--text); }
.ui-seg button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); }
.ui-seg button:disabled { cursor: default; opacity: .4; }

/* ---------- slider ---------- */
.ui-slider { --p: 50%; padding: 2px 0; }
.ui-slider input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 24px; background: transparent; margin: 0; cursor: pointer;
}
.ui-slider input[type=range]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px; background: linear-gradient(to right, var(--accent) var(--p), var(--surface-3) var(--p));
}
.ui-slider input[type=range]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--surface-3); }
.ui-slider input[type=range]::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--accent); }
.ui-slider input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; margin-top: -8px; border-radius: 50%;
  background: var(--text); border: 4px solid var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.ui-slider input[type=range]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; background: var(--text); border: 4px solid var(--accent);
}
.ui-slider input[type=range]:disabled { cursor: default; opacity: .5; }
.ui-slider input[type=range]:focus-visible { outline: none; }
.ui-slider input[type=range]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- stats ---------- */
.ui-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 8px; width: 100%; }
.ui-stat {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 8px 12px; min-width: 0;
}
.ui-stat-label { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ui-stat-value { font: 600 16px var(--font-num); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- result line + error line ---------- */
.ui-result { min-height: 24px; font: 600 16px var(--font); text-align: center; font-variant-numeric: tabular-nums; }
.ui-result.is-win { color: var(--win); }
.ui-result.is-lose { color: var(--lose); }
.ui-result.is-info { color: var(--muted); font-weight: 500; }
.ui-result.is-pop { animation: ui-pop .25s ease-out; }
@keyframes ui-pop { from { transform: scale(.94); opacity: .3; } to { transform: none; opacity: 1; } }
.ui-error { min-height: 0; font-size: 14px; color: var(--lose); }
.ui-error:empty { display: none; }
.ui-error a { color: var(--text); }

/* ---------- tiles (grid games: mines, keno ...) ---------- */
.ui-tiles { display: grid; gap: 8px; width: 100%; max-width: 520px; grid-template-columns: repeat(var(--cols, 5), minmax(0, 1fr)); }
.ui-tile {
  aspect-ratio: 1; border: 0; border-radius: var(--radius-sm); background: var(--surface-3); color: var(--text);
  font: 600 15px var(--font-num); font-variant-numeric: tabular-nums; cursor: pointer; padding: 0;
  display: grid; place-items: center; box-shadow: 0 3px 0 rgba(0,0,0,.35); transition: background .15s, transform .08s, opacity .2s;
}
.ui-tile > * { width: 64%; height: 64%; }
.ui-tile:hover:not(:disabled) { background: color-mix(in srgb, var(--surface-3) 80%, var(--text)); }
.ui-tile:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.35); }
.ui-tile:disabled { cursor: default; }
.ui-tile[data-state="picked"] { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent), 0 3px 0 rgba(0,0,0,.35); color: var(--text); }   /* number in --text: blue-on-dark was 3.65:1 */
.ui-tile[data-state="win"] { background: color-mix(in srgb, var(--win) 22%, var(--surface-2)); box-shadow: inset 0 0 0 2px var(--win); color: var(--win); }
.ui-tile[data-state="lose"] { background: color-mix(in srgb, var(--lose) 22%, var(--surface-2)); box-shadow: inset 0 0 0 2px var(--lose); color: var(--lose); }
.ui-tile[data-state="open"] { background: var(--surface-2); box-shadow: none; }
.ui-tile[data-state="dim"] { background: var(--surface-2); box-shadow: none; opacity: .45; }

/* ---------- big number on the stage ---------- */
.ui-big { font: 700 clamp(40px, 9cqi, 72px) var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; line-height: 1; }
.ui-big.is-win { color: var(--win); }
.ui-big.is-lose { color: var(--lose); }
.ui-hint { font-size: 13px; color: var(--muted); text-align: center; }

@media (prefers-reduced-motion: reduce) {
  .ui-result.is-pop { animation: none; }
  .ui-btn, .ui-tile { transition: none; }
}

/* The hidden attribute always wins over a kit piece's own display (buttons, boxes, tiles ...). */
[class^="ui-"][hidden], [class*=" ui-"][hidden], .ui-frame [hidden] { display: none !important; }

/* ---------- Manual / Auto ---------- */
.ui-modes { margin-bottom: 2px; }
.ui-auto { display: flex; flex-direction: column; gap: 14px; }
.ui-auto-rule { display: grid; grid-template-columns: minmax(0, 1fr) 84px; gap: 8px; }
.ui-auto-rule .ui-seg button { min-height: 36px; }
.ui-auto-rule .ui-box { min-height: 44px; }
.ui-label-note { color: var(--muted); opacity: .8; }
.ui-auto-note:empty { display: none; }
@container (max-width: 680px) { .ui-auto { gap: 12px; } }
/* phone: stage, then the Manual | Auto tabs, then the main button, then the fields */
/* mode tabs (Manual | Auto): 44px tall in all */
.ui-modes .ui-seg button { min-height: 36px; font-weight: 600; }
@container (max-width: 680px) { .ui-modes { margin-bottom: 0; } }

/* ---------- feel: controls dim over 150 ms while a bet is in flight ---------- */
.ui-box, .ui-seg button, .ui-slider input, .ui-box-btn, .ui-tile { transition: opacity .15s cubic-bezier(.4,0,.2,1), background .15s, border-color .15s; }
.ui-box:has(input:disabled) { opacity: .4; }   /* Stake (page probe): locked controls all fade to .4 */
.ui-seg button:disabled, .ui-box-btn:disabled, .ui-slider input:disabled { opacity: .4; }
.ui-btn.is-spin::after { width: 18px; height: 18px; }

/* ---------- toasts (ui.toast): top left under the header, newest on top ---------- */
.ui-toasts { position: fixed; top: 80px; left: 16px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; width: min(340px, calc(100vw - 32px)); pointer-events: none; }
.ui-toast { position: relative; overflow: hidden; pointer-events: auto; display: grid; gap: 2px; padding: 12px 40px 14px 14px; border-radius: 8px;
  background: var(--surface-3); color: var(--text); border-left: 3px solid var(--accent); box-shadow: 0 8px 20px rgba(0,0,0,.35), 0 2px 4px rgba(0,0,0,.2); font: 400 13px/1.4 var(--font); }
.ui-toast b { font: 700 14px var(--font); }
.ui-toast span { color: var(--muted); }
.ui-toast-x { position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font: 400 18px/1 var(--font); cursor: pointer; }
.ui-toast-x:hover { color: var(--text); background: rgb(255 255 255 / .06); }
.ui-toast-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--accent); transform-origin: left; opacity: .7; }

/* ---------- recent results row ---------- */
.ui-recent { position: absolute; top: var(--ui-recent-top, 12px); right: 12px;   /* a game can push the row down: .its-stage { --ui-recent-top: 56px } */
  display: flex; gap: 6px; justify-content: flex-end; max-width: 60%; overflow: hidden; z-index: 2; pointer-events: auto; }
.ui-chip {
  flex: none; min-width: 58px; height: 28px; padding: 0 9px; border: 0; border-radius: 6px; cursor: pointer;
  background: var(--surface-3); color: var(--text); font: 600 12px var(--font-num); font-variant-numeric: tabular-nums;
}
.ui-chip.is-win { background: var(--win); color: var(--bg); }
/* a practice result (0.00 amount) is a <span>, a real bet a <button>: a button centres its own text, a span does not, so
   the number sat at the top of the pill (Limbo) or left of centre (Dice). Same look for both (Zach 2026-11-23). */
.ui-chip[data-practice] { display: inline-flex; align-items: center; justify-content: center; }
.ui-chip:hover { filter: brightness(1.12); }
/* phones show the strip too (5b, 2026-11-20 night: "exactly like Stake" overrides the old no-chips-on-phones rule; Stake's phone shows it) */

/* ---------- Advanced switch (auto) + net gain box ---------- */
.ui-switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 36px; font-size: 14px; color: var(--muted); cursor: pointer; }
.ui-switch-input { appearance: none; -webkit-appearance: none; width: 38px; height: 22px; border-radius: 11px; background: var(--surface-3); position: relative; cursor: pointer; margin: 0; flex: none; transition: background .15s; }
.ui-switch-input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--muted); transition: transform .15s, background .15s; }
.ui-switch-input:checked { background: var(--accent); }
.ui-switch-input:checked::after { transform: translateX(16px); background: var(--accent-ink); }
.ui-switch-input:disabled { opacity: .5; cursor: default; }
.ui-gain { align-items: center; }
.ui-gain-value { padding: 0 12px; font-weight: 500; font-size: 16px; color: var(--text); }

/* ---------- select ---------- */
.ui-select-box { position: relative; }
.ui-select { flex: 1; min-width: 0; appearance: none; -webkit-appearance: none; border: 0; background: transparent; color: var(--text); font: 500 15px var(--font); padding: 0 34px 0 12px; outline: none; cursor: pointer; }
.ui-select option { background: var(--surface-2); color: var(--text); }
.ui-select:disabled { color: var(--muted); cursor: default; }
.ui-select-box:has(.ui-select:disabled) { opacity: .55; }
.ui-select-arrow { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; font-size: 12px; }
.ui-hint:empty { display: none; }   /* an empty note never adds a gap (Dice Strategy note, Auto note) */
/* keyboard focus inside a box: a clear 2px ring, not only a border colour change */
.ui-box:has(:focus-visible) { box-shadow: 0 0 0 2px var(--focus); }
