/* ThePit · Copyright (C) 2026 abel0x
   SPDX-License-Identifier: AGPL-3.0-or-later
   Free software with ABSOLUTELY NO WARRANTY; see LICENSE for the terms. */

/* =========================================================
   Drop 16: offline peg board
   The board of pegs and slots, the balls on their way down, the rows,
   the risk and the last drops. The frame and the chips come from
   shared/css.
   ========================================================= */
:root {
  --print: rgba(240, 222, 168, .78);
  --print-soft: rgba(240, 222, 168, .3);
  --rail: clamp(8px, 1.3vh, 13px);
  /* The slots, from what pays back less than the bet to the top pays. */
  --tier-low: #2f5d73;
  --tier-even: #2d7a55;
  --tier-mid: #b08a2e;
  --tier-big: #c8641e;
  --tier-top: #b3243a;
}

/* ----------------------- Top bar on phones ----------------------- */
/* The language stays one tap away in the settings, and the way back to the
   lobby stands in for the machine's mark. */
@media (max-width: 600px) {
  .topbar { gap: 8px; padding-inline: 10px; }
  .subtitle,
  .topbar .lang-switch,
  .brand-mark { display: none; }
  .topbar-actions { gap: 6px; }
  .brand { gap: 8px; }
  .brand-text h1 { font-size: 14px; letter-spacing: 2.2px; gap: 6px; }
  .brand-number { min-width: 28px; padding: 2px 5px; }
  .balance-pill { min-width: 0; padding: 4px 10px; }
  .balance-value { font-size: 17px; }
  .icon-btn { width: 36px; height: 36px; }
  .toast { top: 64px; }
}

/* ----------------------- The machine ----------------------- */
.table-wrap {
  position: relative;
  z-index: 2;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(6px, 1.3vh, 14px);
  padding: clamp(6px, 1.4vh, 20px) clamp(8px, 2vw, 26px);
  padding-bottom: max(clamp(6px, 1.4vh, 16px), env(safe-area-inset-bottom));
  overflow: hidden;
}

.table {
  position: relative;
  width: min(1180px, 100%);
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}

/* One felt with a walnut rail, as at the tables of the pit. */
.table-felt {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(6px, 1.4vh, 16px);
  padding: clamp(10px, 1.8vh, 22px) clamp(10px, 2vw, 30px);
  border: var(--rail) solid transparent;
  border-radius: clamp(22px, 4vh, 44px);
  background:
    radial-gradient(ellipse 70% 60% at 30% -10%, rgba(255, 247, 218, .1), transparent 66%) padding-box,
    repeating-linear-gradient(4deg, rgba(255,255,255,.016) 0 1px, transparent 1px 4px) padding-box,
    repeating-linear-gradient(94deg, rgba(0,0,0,.024) 0 1px, transparent 1px 5px) padding-box,
    radial-gradient(130% 110% at 50% 10%, var(--felt-highlight) 0%, var(--felt-1) 26%, var(--felt-2) 64%, var(--felt-edge) 100%) padding-box,
    linear-gradient(142deg, rgba(255,232,164,.3), transparent 24%, rgba(0,0,0,.42) 72%, rgba(255,214,117,.2)) border-box,
    repeating-linear-gradient(102deg, #25160b 0 10px, #52371a 10px 18px, #30200f 18px 29px, #694821 29px 34px) border-box;
  box-shadow:
    inset 0 0 0 1px rgba(241, 211, 130, .18),
    inset 0 0 110px rgba(0, 0, 0, .55),
    inset 0 9px 34px rgba(255, 255, 255, .05),
    0 0 0 1px #0b0704,
    0 0 0 4px rgba(105, 72, 31, .58),
    0 30px 60px rgba(0, 0, 0, .6);
}
.table-rim {
  position: absolute;
  inset: 1px;
  border-radius: inherit;
  pointer-events: none;
  border: 2px solid rgba(225, 190, 99, .5);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.5), 0 1px 0 rgba(255,244,205,.16);
  z-index: 0;
}

/* ----------------------- Meter, banner and plaque ----------------------- */
.felt-head {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}

.drop-meter {
  justify-self: start;
  display: flex;
  overflow: hidden;
  border: 1px solid rgba(205,169,82,.46);
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(18,24,20,.78), rgba(5,10,8,.78));
}
.meter-item { min-width: 64px; padding: 5px 10px 6px; }
.meter-item + .meter-item { border-left: 1px solid rgba(205,169,82,.25); }
.meter-item small {
  display: block;
  font-size: 7.5px;
  font-weight: 700;
  letter-spacing: 1.4px;
  color: rgba(232, 202, 125, .62);
}
.meter-item strong {
  font-family: var(--font-display);
  font-size: clamp(13px, 2vh, 17px);
  color: var(--cream);
  font-variant-numeric: tabular-nums;
}

.banner {
  min-width: 0;
  max-width: min(480px, 52vw);
  pointer-events: none;
  padding: 7px 18px;
  border-radius: 4px;
  background: rgba(0, 0, 0, .42);
  border: 1px solid rgba(217, 182, 95, .35);
  font-weight: 600;
  letter-spacing: 1px;
  font-size: clamp(10.5px, 1.6vh, 14px);
  text-transform: uppercase;
  text-align: center;
  color: var(--gold-bright);
  line-height: 1.3;
  text-wrap: balance;
  transition: background .25s, border-color .25s, color .25s;
}
.banner small {
  display: block;
  margin-top: 1px;
  font-size: .8em;
  letter-spacing: .9px;
  opacity: .78;
}
.banner small:empty { display: none; }
.banner.flash-lose { background: rgba(0, 0, 0, .5); border-color: rgba(226, 104, 95, .55); color: #ffd9d6; }

.table-specs {
  justify-self: end;
  display: flex;
  align-items: stretch;
  overflow: hidden;
  border: 1px solid rgba(205,169,82,.46);
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(18,24,20,.78), rgba(5,10,8,.78));
  box-shadow: 0 5px 12px rgba(0,0,0,.3), inset 0 1px rgba(255,255,255,.05);
}
.table-spec { min-width: 50px; padding: 5px 10px 6px; text-align: left; }
.table-spec small {
  display: block;
  font-size: 7.5px;
  font-weight: 700;
  letter-spacing: 1.4px;
  color: rgba(232, 202, 125, .62);
}
.table-spec strong {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .3px;
  color: var(--cream);
}

/* ----------------------- The board ----------------------- */
.peg-body {
  position: relative;
  z-index: 2;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(170px, 220px);
  gap: clamp(8px, 1.4vw, 18px);
}
/* The board fills the space the felt leaves it and keeps its own shape
   inside: the SVG scales its drawing to fit and centres it. */
.board-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
}
.board {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.peg { fill: var(--print); }
.peg.hit { animation: pegHit .32s ease-out; }
@keyframes pegHit {
  0% { fill: #fffbe8; filter: drop-shadow(0 0 4px rgba(255, 244, 205, .95)); }
  100% { fill: var(--print); filter: none; }
}
.slot rect { stroke: rgba(0, 0, 0, .35); stroke-width: 1; }
.slot text {
  font-family: var(--font-display);
  font-size: 13.5px;
  font-weight: 800;
  text-anchor: middle;
  dominant-baseline: central;
  fill: #fff8e6;
  paint-order: stroke;
  stroke: rgba(0, 0, 0, .35);
  stroke-width: 2px;
}
.slot.tier-low rect { fill: var(--tier-low); }
.slot.tier-even rect { fill: var(--tier-even); }
.slot.tier-mid rect { fill: var(--tier-mid); }
.slot.tier-big rect { fill: var(--tier-big); }
.slot.tier-top rect { fill: var(--tier-top); }
.slot.landed rect { animation: slotLand .5s cubic-bezier(.2, .8, .3, 1); }
@keyframes slotLand {
  0% { transform: translateY(5px); filter: brightness(1.7) drop-shadow(0 0 8px rgba(255, 244, 205, .9)); }
  100% { transform: none; filter: none; }
}
.slot rect { transform-box: fill-box; }
.ball {
  fill: #fbf8ef;
  stroke: #c9a24b;
  stroke-width: 1.6;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .5));
}
.ball.resting { opacity: 0; transition: opacity .25s ease; }

/* ----------------------- Rows, risk and the last drops ----------------------- */
.peg-side {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.6vh, 16px);
}
.side-group { display: grid; gap: 5px; }
.side-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: rgba(232, 202, 125, .7);
}
.peg-side .seg { width: 100%; }
.peg-side .seg-btn { flex: 1 1 0; min-width: 0; padding-inline: 6px; }
.history-group { min-height: 0; flex: 1 1 auto; grid-template-rows: auto minmax(0, 1fr); }
.history {
  min-height: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 5px;
  overflow: hidden;
}
.history li {
  min-width: 52px;
  padding: 3px 8px;
  border-radius: 999px;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  color: #fff8e6;
  font-variant-numeric: tabular-nums;
}
.history .tier-low { background: var(--tier-low); }
.history .tier-even { background: var(--tier-even); }
.history .tier-mid { background: var(--tier-mid); }
.history .tier-big { background: var(--tier-big); }
.history .tier-top { background: var(--tier-top); }
.history .history-empty {
  min-width: 0;
  padding: 0;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  color: rgba(244, 239, 226, .55);
}

/* ----------------------- Controls ----------------------- */
.controls {
  position: relative;
  z-index: 3;
  width: min(1180px, 100%);
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: clamp(8px, 1.2vh, 14px) clamp(8px, 1.6vw, 22px);
}
.chips-tray {
  flex: 0 0 auto;
  display: flex;
  gap: clamp(6px, 1.1vw, 14px);
  justify-content: center;
  padding: clamp(8px, 1.3vh, 13px) clamp(10px, 1.6vw, 18px);
  padding-top: clamp(12px, 1.8vh, 18px);
  background:
    linear-gradient(180deg, rgba(255,255,255,.045), transparent 36%),
    linear-gradient(180deg, var(--tray-top), var(--tray-bottom));
  border: 1px solid rgba(217,182,95,.25);
  border-radius: 16px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.055), inset 0 -8px 16px rgba(0,0,0,.24), 0 12px 25px rgba(0,0,0,.24);
}
.action-row {
  flex: 1 0 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: clamp(8px, 1.4vw, 18px);
}
/* How many balls one drop sends down, beside the bet. */
.balls-picker { flex: 0 0 auto; }
.balls-picker .seg-btn { min-width: 0; padding-inline: 8px; }
.bet-total {
  display: grid;
  justify-items: end;
  gap: 1px;
  min-width: 92px;
  text-align: right;
}
.bet-total small {
  color: rgba(244, 239, 226, .55);
  font-size: 9px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  white-space: nowrap;
}
.bet-total strong {
  font-family: var(--font-display);
  font-size: clamp(17px, 2.3vh, 22px);
  color: var(--gold-bright);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.bet-total .balls-line { letter-spacing: .4px; text-transform: none; font-size: 10px; }
.bet-total .balls-line:empty { display: none; }
.bet-total .last-win { letter-spacing: .6px; text-transform: none; font-size: 10px; }
.bet-total .last-win b { color: rgba(214, 255, 233, .85); font-variant-numeric: tabular-nums; }

/* Drop: a brass plaque beside the tray. */
.deal-btn {
  flex: 0 0 auto;
  min-width: clamp(96px, 13vh, 132px);
  height: clamp(48px, 7.4vh, 64px);
  padding: 0 22px;
  border-radius: 14px;
  border: 1px solid rgba(80, 56, 12, .9);
  background:
    radial-gradient(120% 90% at 40% 20%, rgba(255,255,255,.45), transparent 45%),
    linear-gradient(180deg, #f3d985, #c9a24b 62%, #8c6a1c);
  box-shadow:
    0 0 0 3px rgba(20, 13, 4, .55),
    0 0 0 4px rgba(240, 215, 143, .45),
    0 10px 22px rgba(0,0,0,.45),
    inset 0 -5px 8px rgba(110, 76, 14, .5);
  color: #2a1d05;
  font-family: var(--font-display);
  font-size: clamp(14px, 2.2vh, 19px);
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform .14s ease, filter .2s ease;
}
.deal-btn:not(:disabled):hover { transform: translateY(-2px); filter: brightness(1.05); }
.deal-btn:not(:disabled):active { transform: translateY(1px) scale(.98); }
.deal-btn:disabled { cursor: not-allowed; filter: grayscale(.55) brightness(.62); }
.deal-btn.ready { animation: dealReady 2.4s ease-in-out infinite; }
@keyframes dealReady {
  0%, 100% { box-shadow: 0 0 0 3px rgba(20,13,4,.55), 0 0 0 4px rgba(240,215,143,.45), 0 10px 22px rgba(0,0,0,.45), inset 0 -5px 8px rgba(110,76,14,.5); }
  50% { box-shadow: 0 0 0 3px rgba(20,13,4,.55), 0 0 0 4px rgba(244,226,166,.9), 0 0 24px rgba(244,226,166,.4), inset 0 -5px 8px rgba(110,76,14,.5); }
}

/* ----------------------- Dialogs ----------------------- */
/* A miniature of the machine on each cloth: a triangle of pegs and a ball. */
.theme-preview::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 22%;
  width: 34px;
  height: 22px;
  transform: translateX(-50%);
  background:
    radial-gradient(circle, rgba(240, 222, 168, .9) 1.6px, transparent 2px) 50% 0 / 8px 7px,
    none;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
.theme-preview::after {
  content: "";
  position: absolute;
  left: calc(50% + 5px);
  top: 30%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #fbf8ef;
  box-shadow: 0 2px 3px rgba(0,0,0,.45);
}
.theme-option[data-set-theme="midnight"] { --preview-felt-top: #2b6288; --preview-felt-bottom: #0b2b47; }
.theme-option[data-set-theme="bordeaux"] { --preview-felt-top: #8e3a49; --preview-felt-bottom: #3e111c; }
.theme-option[data-set-theme="onyx"] { --preview-felt-top: #5d6268; --preview-felt-bottom: #2a2d31; }
.theme-option[data-set-theme="amethyst"] { --preview-felt-top: #7a54a8; --preview-felt-bottom: #36215a; }
.payout-table .settings-hint + .settings-hint { margin-top: 0; }
.returns-table { width: 100%; margin-top: 6px; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.returns-table caption { padding-bottom: 4px; text-align: left; font-size: 12px; font-weight: 700; color: var(--gold-bright); }
.returns-table th,
.returns-table td { padding: 3px 6px; text-align: right; border-bottom: 1px solid rgba(217, 182, 95, .14); }
.returns-table th:first-child { text-align: left; }
.returns-table thead th { font-size: 9px; letter-spacing: 1.2px; text-transform: uppercase; color: rgba(244, 239, 226, .55); font-weight: 600; }
.stat-wide { grid-column: 1 / -1; }

/* ----------------------- Phones and short screens ----------------------- */
@media (max-width: 760px) {
  .felt-head { grid-template-columns: auto 1fr; }
  .table-specs { display: none; }
  .banner { justify-self: center; max-width: 100%; }
}

/* Phones held upright: the rows and the risk side by side above the board,
   the last drops in a strip under them, and the tray on a row of its own. */
@media (max-width: 760px) and (orientation: portrait) {
  .peg-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .peg-side { order: -1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
  .history-group { grid-column: 1 / -1; grid-template-rows: none; }
  .history { flex-wrap: nowrap; }
  .history li { flex: 0 0 auto; min-width: 46px; padding-inline: 6px; font-size: 11px; }
  .controls { justify-content: center; }
  .chips-tray { width: 100%; gap: 4px; padding-inline: 6px; }
  .chips-tray .chip { --size: clamp(34px, 12vw, 50px); }
  .action-row { width: 100%; justify-content: space-between; }
}

/* Narrow phones: the rows and the risk one above the other, so that every
   word fits; the board is held by the width here and loses nothing. */
@media (max-width: 400px) and (orientation: portrait) {
  .peg-side { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 420px) {
  .bet-total { min-width: 0; }
  .bet-total .last-win { display: none; }
  .deal-btn { min-width: 84px; padding: 0 14px; }
  .meter-item { min-width: 48px; padding-inline: 7px; }
}

/* Phones on their side: the board beside a narrow column of choices. */
@media (max-height: 560px) {
  .topbar { padding-block: 4px; }
  .table-wrap { padding-block: 4px; gap: 4px; }
  .table-felt { padding: 6px 12px; gap: 4px; border-radius: 20px; }
  .felt-head { grid-template-columns: auto 1fr auto; }
  .banner { padding: 3px 12px; font-size: 10px; }
  .banner small { display: inline; margin-left: 6px; }
  .table-specs { display: flex; }
  .peg-body { grid-template-columns: minmax(0, 1fr) minmax(140px, 180px); }
  .peg-side { gap: 6px; }
  .peg-side .seg-btn { padding-block: 4px; font-size: 11px; }
  .history li { min-width: 42px; padding: 2px 5px; font-size: 10px; }
  .controls { flex-wrap: nowrap; gap: 8px; }
  .chips-tray { width: auto; gap: 4px; padding: 6px 8px; }
  .chips-tray .chip { --size: 30px; }
  .action-row { width: auto; gap: 8px; }
  .bet-total { min-width: 0; }
  .bet-total small { display: none; }
  .deal-btn { height: 42px; min-width: 76px; padding-inline: 12px; }
}

/* The narrowest phones: a slimmer picker and button, and the line of the
   drop's whole stake may wrap, so that a large bet still fits beside them. */
@media (max-width: 360px) {
  .balls-picker .seg-btn { padding-inline: 6px; }
  .deal-btn { min-width: 72px; padding: 0 10px; }
  .bet-total strong { font-size: 16px; }
  .bet-total .balls-line { white-space: normal; max-width: 9em; }
}

/* No transitions at all for reduced motion: each step appears in place. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0s !important;
    transition-delay: 0s !important;
  }
}
