/* 8-Ball Pool — game skin over the shared tabletop layer. */

:root {
  --room: #16202a;
  --room-2: #0a1117;
  --felt: #1a5c40;
  --wood: #5e3717;
  --gold: #e8c368;
  --panel: rgba(9, 18, 25, 0.93);
  --panel-line: rgba(232, 195, 104, 0.22);
  --text: #eef3f7;
  --dim: rgba(238, 243, 247, 0.62);
  --warn: #ff9f5a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--room-2);
  color: var(--text);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-text-size-adjust: 100%;
}

#table {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: radial-gradient(130% 100% at 50% 40%, #1d2b38 0%, var(--room) 45%, var(--room-2) 100%);
  touch-action: none;
  cursor: crosshair;
}

/* ---------- HUD ---------- */

#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: max(8px, env(safe-area-inset-top)) 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  z-index: 5;
}

#hud > * { pointer-events: auto; }

.hud-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}

.seats { display: flex; gap: 8px; flex-wrap: wrap; }

.seat-chip {
  min-width: 204px;
  padding: 6px 11px 7px;
  border-radius: 11px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-left: 3px solid var(--seat);
  opacity: 0.66;
  transition: opacity 0.15s, border-color 0.15s;
}

.seat-chip.on-turn { opacity: 1; border-color: var(--gold); border-left-color: var(--seat); }

.seat-head { display: flex; align-items: baseline; gap: 8px; }
.seat-name { font-weight: 600; font-size: 13.5px; }
.seat-racks {
  margin-left: auto;
  font-size: 16px;
  font-weight: 700;
  color: var(--seat);
  font-variant-numeric: tabular-nums;
}

.seat-balls { display: flex; align-items: center; gap: 3px; margin-top: 4px; flex-wrap: wrap; }

/* The swatch canvas is rendered oversized and scaled down here, so the ball
   numbers stay crisp instead of being rasterised at icon size. */
.swatch { display: block; width: 22px; height: 22px; }
.swatch.down { opacity: 0.2; filter: grayscale(1); }
.seat-open { font-size: 11.5px; color: var(--dim); font-style: italic; }
.seat-left { font-size: 11px; color: var(--dim); margin-left: 5px; }

.hud-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  color: var(--dim);
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tag {
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--panel-line);
  font-size: 12px;
  color: var(--gold);
}

.tag.warn { color: var(--warn); border-color: rgba(255, 159, 90, 0.45); background: rgba(255, 159, 90, 0.12); }

/* ---------- control bar ---------- */

#bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 12px max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(10, 17, 23, 0) 0%, rgba(10, 17, 23, 0.9) 42%);
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  z-index: 5;
}

.status { display: flex; flex-direction: column; line-height: 1.25; min-width: 180px; }
.status-sub { font-size: 12.5px; color: var(--dim); }

.controls {
  margin-left: auto;
  display: flex;
  align-items: flex-end;
  gap: 14px;
}

.ctl-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--dim);
  margin-bottom: 4px;
}

.spin-box { text-align: center; }

canvas.spin {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  cursor: pointer;
  touch-action: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.power-box { flex: 1; min-width: 150px; max-width: 360px; }

.power-track {
  height: 26px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid var(--panel-line);
  overflow: hidden;
  cursor: ew-resize;
  touch-action: none;
}

.power-fill {
  height: 100%;
  width: 55%;
  background: linear-gradient(90deg, #4aa564 0%, #e8c368 55%, #e05a3c 100%);
  transition: width 0.06s linear;
}

.btn {
  font: inherit;
  padding: 7px 16px;
  border-radius: 9px;
  border: 1px solid var(--panel-line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.btn:hover:not(:disabled) { border-color: var(--gold); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.primary { background: var(--gold); color: #1b1710; border-color: var(--gold); font-weight: 700; }
.btn.ghost { background: rgba(9, 18, 25, 0.7); }
.btn.shoot { padding: 13px 30px; font-size: 16px; letter-spacing: 0.5px; }

/* ---------- menu ---------- */

#menu {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(5, 11, 16, 0.86);
  backdrop-filter: blur(3px);
  z-index: 20;
  padding: 20px;
  overflow: auto;
}

#menu.open { display: grid; }

.menu-card {
  width: min(470px, 100%);
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
}

.menu-card h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: 0.04em; color: var(--gold); }
.menu-card .sub { margin: 0 0 16px; color: var(--dim); font-size: 14px; }

.menu-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  font: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  padding: 11px 14px;
  margin-bottom: 8px;
  cursor: pointer;
}

.menu-item:hover { border-color: var(--gold); background: rgba(232, 195, 104, 0.1); }
.menu-item.primary { background: var(--gold); color: #1b1710; border-color: var(--gold); }
.menu-item.primary .mi-sub { color: rgba(27, 23, 16, 0.75); }
.mi-label { font-weight: 600; }
.mi-sub { font-size: 12.5px; color: var(--dim); }

.form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.seg-row { display: flex; flex-direction: column; gap: 5px; }
.seg-label { font-size: 12.5px; color: var(--dim); }
.seg { display: flex; gap: 5px; flex-wrap: wrap; }

.seg-btn {
  font: inherit;
  font-size: 13px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--panel-line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  cursor: pointer;
}

.seg-btn.on { background: var(--gold); color: #1b1710; border-color: var(--gold); font-weight: 600; }

.howto { margin: 0 0 12px; padding-left: 20px; font-size: 14px; line-height: 1.5; }
.howto li { margin-bottom: 7px; }

/* ---------- modals and toast ---------- */

.lede { font-size: 18px; margin: 0 0 8px; }
.dim { color: var(--dim); }

.score-table { margin-top: 12px; display: flex; flex-direction: column; gap: 4px; }

.score-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 5px 10px;
  border-left: 3px solid var(--seat);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  font-size: 13.5px;
}

.score-row strong { font-size: 17px; color: var(--seat); font-variant-numeric: tabular-nums; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 118px;
  transform: translate(-50%, 12px);
  background: var(--panel);
  border: 1px solid var(--panel-line);
  color: var(--text);
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 30;
  max-width: min(92vw, 440px);
  text-align: center;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- phones ---------- */

@media (max-width: 820px), (max-height: 560px) {
  .seat-chip { min-width: 0; padding: 5px 9px 6px; }
  .seat-balls .swatch { width: 18px; height: 18px; }
  .hud-meta { width: 100%; margin-left: 0; justify-content: flex-start; }
  #bar { gap: 10px; padding-top: 6px; }
  .status { min-width: 100%; }
  .controls { margin-left: 0; width: 100%; gap: 10px; }
  .btn.shoot { padding: 12px 20px; }
  canvas.spin { width: 50px; height: 50px; }
  .toast { bottom: 150px; }
  .menu-card { padding: 18px; }
  .menu-card h1 { font-size: 22px; }
}

/* ----------------------------------------------------------
   Modal dialogs. openModal() in src/core/modal.js is shared
   with the rest of the family and writes .tt-* class names, so
   this project carries just those rules rather than the whole
   tabletop stylesheet it has no other use for.
   ---------------------------------------------------------- */

.tt-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(5, 11, 16, 0.6);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.tt-modal {
  min-width: min(420px, 92vw);
  max-width: min(560px, 92vw);
  padding: 18px 20px 16px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
}

.tt-modal-title {
  margin-bottom: 12px;
  font-size: 17px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.02em;
}

.tt-modal-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 14px;
}

.tt-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.tt-modal-btn {
  padding: 8px 16px;
  border: 1px solid var(--panel-line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.tt-modal-btn:hover { background: rgba(255, 255, 255, 0.12); }

.tt-modal-btn.tt-primary {
  background: var(--gold);
  border-color: var(--gold);
  color: #1b1710;
  font-weight: 700;
}

.tt-modal-btn.tt-primary:hover { filter: brightness(1.08); }

/* Small key hints on the controls — desktop only, added by keyHint(). */
.key-hint {
  font-family: inherit;
  font-size: 10px;
  letter-spacing: 0.6px;
  text-transform: none;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--dim);
  vertical-align: middle;
}

.btn.shoot .key-hint {
  background: rgba(27, 23, 16, 0.18);
  border-color: rgba(27, 23, 16, 0.25);
  color: rgba(27, 23, 16, 0.72);
}

/* A ball crossed off the tray the instant it drops, rather than after the
   shot finishes settling. It flashes, then settles into the potted look. */
@keyframes potted {
  0%   { transform: scale(1);    filter: none;         opacity: 1; }
  22%  { transform: scale(1.55); filter: none;         opacity: 1; }
  55%  { transform: scale(1.12); filter: grayscale(0.4); opacity: 0.85; }
  100% { transform: scale(1);    filter: grayscale(1); opacity: 0.2; }
}

.swatch.just-potted {
  animation: potted 0.85s cubic-bezier(0.2, 0.9, 0.3, 1);
  position: relative;
  z-index: 2;
}
