/*
 * What every game on the page looks like: the gate, the game shell (topbar, timer, stage, controls),
 * buttons, chips, player plates and the toast. Each game's own stylesheet adds only what is
 * particular to it, and themes the shell by overriding the variables below on its root.
 *
 * Sized for the Discord activity frame, which is short and wide on desktop and narrow and tall on
 * mobile, so the stage scrolls and the control panel is pinned to the bottom where a thumb can reach.
 */

:root {
  /* Theme: blackjack's felt is the default, and what the gate is drawn on. A game overrides these
   * on its root to recolour the whole shell. */
  --bg-top: #0b4f34;
  --bg-mid: #073423;
  --bg-edge: #062a1c;
  --panel: rgba(4, 26, 18, 0.92);
  --accent: #e8c15a;
  --accent-hover: #f0cd72;
  --accent-ink: #1b1403;

  --ink: #f4f1e8;
  --ink-dim: rgba(244, 241, 232, 0.6);
  --gold: #e8c15a;
  --win: #57d98b;
  --lose: #e5646c;
  --push: #d9c15a;
  --danger: #c0392b;
  --danger-hover: #d4483a;
  --radius: 10px;

  /*
   * How much of the frame Discord's own UI covers. On mobile the activity runs full screen with
   * Discord's header and home bar drawn on top, and these are the only way to find out by how much.
   * Outside Discord they are unset and fall back to the device's own insets.
   */
  --sait: var(--discord-safe-area-inset-top, env(safe-area-inset-top, 0px));
  --saib: var(--discord-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  --sail: var(--discord-safe-area-inset-left, env(safe-area-inset-left, 0px));
  --sair: var(--discord-safe-area-inset-right, env(safe-area-inset-right, 0px));
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: radial-gradient(ellipse at 50% 0%, var(--bg-top) 0%, var(--bg-mid) 55%, var(--bg-edge) 100%);
  color: var(--ink);
  font: 14px/1.45 "gg sans", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

[hidden] { display: none !important; }

/* ------------------------------------------------------------------ gate */

.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  padding-top: calc(24px + var(--sait));
  z-index: 20;
  background: radial-gradient(ellipse at 50% 30%, var(--bg-top) 0%, var(--bg-edge) 100%);
}

.gate-card {
  max-width: 340px;
  text-align: center;
}

.gate-suit {
  font-size: 44px;
  color: var(--gold);
  line-height: 1;
}

.gate-card h1 {
  margin: 10px 0 6px;
  font-size: 26px;
  letter-spacing: 0.02em;
}

.gate-card p {
  color: var(--ink-dim);
  margin: 0 0 18px;
  min-height: 2.9em;
}

/* ------------------------------------------------------------------ shell */

/* Every game: topbar, timer, a scrolling stage, and the controls pinned under it. */
.game {
  height: 100%;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  /* An auto column grows to fit its widest content, which pushed the whole table off the side of a
   * phone. Pinning it to the frame makes the stage wrap or scroll inside it instead. */
  grid-template-columns: minmax(0, 1fr);
  padding-left: var(--sail);
  padding-right: var(--sair);
  background: radial-gradient(ellipse at 50% 0%, var(--bg-top) 0%, var(--bg-mid) 55%, var(--bg-edge) 100%);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px 8px;
  padding-top: calc(10px + var(--sait));
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.phase {
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The back button keeps its size; the title and the status beside it give way instead - the
 * status first, since the title says which game this is. */
.topbar .nav-back { flex: none; }

.topbar-left > .muted {
  flex-shrink: 20;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.muted { color: var(--ink-dim); }

.small { font-size: 12px; margin: 2px 0 0; text-align: center; }

.label {
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--ink-dim);
}

/* Never squeezed: every game has to show the player's chips. */
.wallet {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.28);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.chip-icon {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.35);
  flex: none;
}

/* Deadline countdown for whatever the game is currently waiting on. */
.timer {
  height: 3px;
  background: rgba(0, 0, 0, 0.25);
}

.timer-fill {
  height: 100%;
  width: 0;
  background: var(--timer, var(--accent));
  /* Driven every frame from the deadline, so no CSS transition - it would fight the JS. */
}

/* ------------------------------------------------------------------ players */

/* A player's box: a blackjack seat, a duellist, someone in a Wordle round. */
.plate {
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius);
  min-width: 0;
  transition: box-shadow 0.2s ease, opacity 0.2s ease;
}

/* Whoever the game is waiting on. */
.plate.turn {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 18px color-mix(in srgb, var(--accent) 20%, transparent);
}

.plate.me { background: rgba(255, 255, 255, 0.08); }
.plate.away { opacity: 0.55; }

.avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex: none;
  background: rgba(0, 0, 0, 0.3);
  object-fit: cover;
}

/* Stands in for a picture that isn't there. */
.avatar.initial {
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-dim);
}

.tag {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--ink-dim);
  flex: none;
}

.result { font-weight: 600; }
.result.win { color: var(--win); }
.result.lose { color: var(--lose); }
.result.push { color: var(--push); }

/* ------------------------------------------------------------------ controls */

.controls {
  background: var(--panel);
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  padding: 10px 14px;
  padding-bottom: max(10px, var(--saib));
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel > p { margin: 0; }

.panel-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.panel-label {
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--ink-dim);
}

.bet-amount {
  font-size: 19px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
}

.chip-row {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.chip {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 3px dashed rgba(255, 255, 255, 0.55);
  background: #17624a;
  color: var(--ink);
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  flex: none;
  transition: transform 0.12s ease;
}

.chip:hover:not(:disabled) { transform: translateY(-2px); }
.chip:disabled { opacity: 0.35; cursor: default; }

.button {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  padding: 9px 15px;
  border-radius: 7px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: background 0.12s ease;
}

.button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.15); }

.button:disabled {
  opacity: 0.35;
  cursor: default;
}

.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.button.primary:hover:not(:disabled) { background: var(--accent-hover); }

.button.ghost { background: transparent; }

.button.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.button.danger:hover:not(:disabled) { background: var(--danger-hover); }

.button.big {
  width: 100%;
  padding: 16px;
  font-size: 18px;
  letter-spacing: 0.02em;
}

.button.compact {
  padding: 5px 10px;
  font-size: 12px;
}

/* A text box, dressed like the buttons beside it. */
.input {
  appearance: none;
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(0, 0, 0, 0.28);
  color: var(--ink);
  font: inherit;
  padding: 9px 12px;
  border-radius: 7px;
}

.input::placeholder { color: var(--ink-dim); }

.input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Every game's way back to the lobby, first thing in its topbar. */
.nav-back {
  flex: none;
  white-space: nowrap;
  margin-left: -6px;
}

/* A pill of mutually exclusive choices, such as a game's modes. */
.segmented {
  display: flex;
  padding: 2px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.28);
  flex: none;
}

.segment {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-dim);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 11px;
  border-radius: 999px;
  cursor: pointer;
}

.segment:hover:not(.active) { color: var(--ink); }

.segment.active {
  background: var(--accent);
  color: var(--accent-ink);
}

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.86);
  color: var(--ink);
  padding: 9px 15px;
  border-radius: 7px;
  font-size: 13px;
  max-width: 82vw;
  text-align: center;
  z-index: 30;
  animation: rise 0.18s ease-out;
}

@keyframes rise {
  from { transform: translate(-50%, 8px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* Narrow activity frames and phone screens. */
@media (max-width: 460px) {
  .chip { width: 42px; height: 42px; }
}

/* A game with a mode toggle has too much for one row on a phone or a narrow frame: the toggle drops
 * to a row of its own, full width, and the wallet stays up top beside the title. The title is sized
 * from zero, so it gives way to the wallet rather than pushing it onto a row of its own too. */
@media (max-width: 600px) {
  .topbar:has(.segmented) {
    flex-wrap: wrap;
    row-gap: 8px;
  }

  .topbar:has(.segmented) .topbar-left { flex: 1 1 0; }
  .topbar:has(.segmented) .topbar-right { display: contents; }

  .topbar .segmented {
    order: 1;
    flex: 1 0 100%;
  }

  .topbar .segmented .segment { flex: 1; }
}

/* A phone: the title alone. The status beside it is shown on the board or the result card too. */
@media (max-width: 420px) {
  .topbar:has(.segmented) .topbar-left > .muted { display: none; }
}
