:root {
  --bg: #1a1a20;
  --panel: #24242c;
  --text: #d4d0c4;
  --muted: #78746a;
  --accent: #c9a227;
  --btn: #2e2e38;
  --btn-hi: #4a4a56;
  --btn-lo: #16161c;
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

/* Self-hosted (OFL), latin subset only: CJK falls through to the stack below,
   and the canvas keeps its hand-drawn pixel font — it never uses a CSS font. */
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/jetbrains-mono-latin.woff2") format("woff2");
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "JetBrains Mono", "Courier New", ui-monospace, Menlo, monospace;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 16px;
  -webkit-tap-highlight-color: transparent;
}

.game {
  width: min(100%, 1600px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

.topbar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 4px;
  color: var(--accent);
  text-shadow: 2px 2px 0 #000;
}

.top-actions {
  display: flex;
  gap: 8px;
}

canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border: 3px solid #000;
  box-shadow: 0 0 0 2px #3a3a44;
  background: #000;
  max-width: 100%;
}

.single-view {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 1000px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  justify-content: center;
}

.group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

button,
a.button {
  font-family: inherit;
  font-size: 15px;
  font-weight: bold;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text);
  background: var(--btn);
  border: none;
  border-radius: 0;
  padding: 12px 18px;
  min-height: 46px;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  box-shadow:
    -3px 0 0 0 #000,
    3px 0 0 0 #000,
    0 -3px 0 0 #000,
    0 3px 0 0 #000;
  -webkit-font-smoothing: none;
  font-smooth: never;
}

button:hover:not(:disabled),
a.button:hover {
  background: #3a3a46;
}

button:active:not(:disabled),
a.button:active {
  transform: translateY(2px);
  background: #22222a;
}

button:disabled,
a.button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

button.primary,
a.button.primary {
  background: #8a7020;
  color: #e8e0c8;
}

button.primary:hover:not(:disabled),
a.button.primary:hover {
  background: #9a7e24;
}

button.primary:active:not(:disabled),
a.button.primary:active {
  background: #6e5a1a;
}

button.mini,
a.button.mini {
  font-size: 12px;
  padding: 8px 12px;
  min-height: 36px;
}

.chip-btn::before {
  content: "";
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-right: 7px;
  vertical-align: -4px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100% 100%;
  image-rendering: pixelated;
}

.chip-btn[data-bet="5"]::before {
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%208%208'%20shape-rendering='crispEdges'%3E%3Cpath%20fill='%23a84040'%20d='M2%200h4v1H2zM1%201h6v1H1zM0%202h8v4H0zM1%206h6v1H1zM2%207h4v1H2z'/%3E%3Crect%20x='2'%20y='2'%20width='4'%20height='4'%20fill='%23e0dcd0'/%3E%3Crect%20x='3'%20y='3'%20width='2'%20height='2'%20fill='%23a84040'/%3E%3C/svg%3E");
}

.chip-btn[data-bet="25"]::before {
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%208%208'%20shape-rendering='crispEdges'%3E%3Cpath%20fill='%234a8a4a'%20d='M2%200h4v1H2zM1%201h6v1H1zM0%202h8v4H0zM1%206h6v1H1zM2%207h4v1H2z'/%3E%3Crect%20x='2'%20y='2'%20width='4'%20height='4'%20fill='%23e0dcd0'/%3E%3Crect%20x='3'%20y='3'%20width='2'%20height='2'%20fill='%234a8a4a'/%3E%3C/svg%3E");
}

.chip-btn[data-bet="100"]::before {
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%208%208'%20shape-rendering='crispEdges'%3E%3Cpath%20fill='%234a4a52'%20d='M2%200h4v1H2zM1%201h6v1H1zM0%202h8v4H0zM1%206h6v1H1zM2%207h4v1H2z'/%3E%3Crect%20x='2'%20y='2'%20width='4'%20height='4'%20fill='%23e0dcd0'/%3E%3Crect%20x='3'%20y='3'%20width='2'%20height='2'%20fill='%234a4a52'/%3E%3C/svg%3E");
}

.chip-btn[data-bet="500"]::before {
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%208%208'%20shape-rendering='crispEdges'%3E%3Cpath%20fill='%236a4a8a'%20d='M2%200h4v1H2zM1%201h6v1H1zM0%202h8v4H0zM1%206h6v1H1zM2%207h4v1H2z'/%3E%3Crect%20x='2'%20y='2'%20width='4'%20height='4'%20fill='%23e0dcd0'/%3E%3Crect%20x='3'%20y='3'%20width='2'%20height='2'%20fill='%236a4a8a'/%3E%3C/svg%3E");
}

.stats {
  width: 100%;
  max-width: 720px;
  background: var(--panel);
  border: 2px solid #000;
  padding: 14px 16px;
}

.stats.hidden {
  display: none;
}

.stats h2 {
  margin: 0 0 10px;
  font-size: 13px;
  letter-spacing: 3px;
  color: var(--accent);
}

.stats dl {
  margin: 0 0 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 2px 20px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 13px;
  border-bottom: 1px dashed #3a3a44;
}

.stat-row dt {
  color: var(--muted);
  letter-spacing: 1px;
}

.stat-row dd {
  margin: 0;
  font-weight: bold;
}

.hint {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 1px;
  text-align: center;
}

@media (pointer: coarse) {
  button {
    min-height: 54px;
    font-size: 16px;
    padding: 14px 18px;
  }

  button.mini,
  a.button.mini {
    min-height: 42px;
    font-size: 13px;
  }

  .row {
    gap: 12px;
  }
}

@media (max-width: 480px) {
  h1 {
    font-size: 15px;
  }

  button {
    padding: 12px 12px;
    font-size: 14px;
  }
}
.wallet {
  font-size: 13px;
  letter-spacing: 1px;
  color: var(--muted);
  padding: 6px 4px;
}

.wallet b {
  color: var(--accent);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 8, 14, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}

.overlay.hidden {
  display: none;
}

.dialog {
  width: min(100%, 420px);
  background: var(--panel);
  border: 2px solid #000;
  box-shadow: -3px 0 0 0 #000, 3px 0 0 0 #000, 0 -3px 0 0 #000, 0 3px 0 0 #000;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dialog h2 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 3px;
  color: var(--accent);
}

.dialog p {
  margin: 0;
  font-size: 14px;
}

.dialog .muted {
  color: var(--muted);
}

.dialog label {
  font-size: 12px;
  letter-spacing: 2px;
  color: var(--muted);
}

.dialog input {
  font-family: inherit;
  font-size: 18px;
  font-weight: bold;
  color: var(--text);
  background: #14141a;
  border: 2px solid #000;
  border-radius: 0;
  padding: 10px 12px;
  width: 100%;
}

.dialog input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

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

.actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.actions .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.error {
  color: #a84a4a;
  font-size: 13px;
}

.error.hidden {
  display: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #241a1a;
  border: 2px solid #000;
  box-shadow: -3px 0 0 0 #000, 3px 0 0 0 #000, 0 -3px 0 0 #000, 0 3px 0 0 #000;
  color: #c8a09a;
  font-size: 13px;
  padding: 10px 16px;
  z-index: 20;
  max-width: min(90vw, 480px);
}

.toast.hidden {
  display: none;
}

/* ---------- BANKRUPT burst-in alert ---------- */
.bankrupt {
  z-index: 60;
  animation: bankrupt-shake 0.5s 0.02s both;
}
.bankrupt__card {
  position: relative;
  z-index: 2;
  border-color: #000;
  animation: bankrupt-in 0.55s cubic-bezier(0.16, 1.2, 0.3, 1) both;
}
.bankrupt__card h2 {
  font-size: 34px;
  letter-spacing: 8px;
  color: #e0b23a;
  text-shadow: 3px 3px 0 #000;
}
.bankrupt__flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 50%, rgba(255, 228, 140, 0.9), rgba(232, 120, 52, 0.35) 38%, rgba(0, 0, 0, 0) 68%);
  animation: bankrupt-flash 0.6s ease-out both;
}
.bankrupt__ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 120px;
  height: 120px;
  margin: -60px 0 0 -60px;
  border: 4px solid #e0b23a;
  border-radius: 50%;
  pointer-events: none;
  animation: bankrupt-ring 0.65s ease-out both;
}
.bankrupt__shards {
  position: absolute;
  left: 50%;
  top: 50%;
  pointer-events: none;
}
.bankrupt__shards i {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  background: #e0b23a;
  box-shadow: 3px 3px 0 #000;
  animation: bankrupt-shard 0.75s ease-out both;
}
.bankrupt__shards i:nth-child(2) { background: #a84040; }
.bankrupt__shards i:nth-child(3) { background: #e8e4d0; }
.bankrupt__shards i:nth-child(4) { background: #a84040; }
.bankrupt__shards i:nth-child(5) { background: #e8e4d0; }
.bankrupt__shards i:nth-child(6) { background: #a84040; }
.bankrupt__shards i:nth-child(7) { background: #e8e4d0; }
.bankrupt__shards i:nth-child(8) { background: #a84040; }
.bankrupt__shards i:nth-child(1) { --dx: 240px; --dy: -150px; }
.bankrupt__shards i:nth-child(2) { --dx: -250px; --dy: -120px; }
.bankrupt__shards i:nth-child(3) { --dx: 260px; --dy: 60px; }
.bankrupt__shards i:nth-child(4) { --dx: -230px; --dy: 110px; }
.bankrupt__shards i:nth-child(5) { --dx: 90px; --dy: -220px; }
.bankrupt__shards i:nth-child(6) { --dx: -110px; --dy: -230px; }
.bankrupt__shards i:nth-child(7) { --dx: 140px; --dy: 210px; }
.bankrupt__shards i:nth-child(8) { --dx: -160px; --dy: 200px; }
@keyframes bankrupt-in {
  0% { transform: scale(0.05) rotate(-6deg); opacity: 0; }
  55% { transform: scale(1.14) rotate(2deg); opacity: 1; }
  76% { transform: scale(0.95) rotate(-1deg); }
  100% { transform: scale(1) rotate(0); }
}
@keyframes bankrupt-flash {
  0% { opacity: 0; transform: scale(0.35); }
  22% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.7); }
}
@keyframes bankrupt-ring {
  0% { transform: scale(0.15); opacity: 0.95; }
  100% { transform: scale(6); opacity: 0; }
}
@keyframes bankrupt-shard {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0.25); opacity: 0; }
}
@keyframes bankrupt-shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-9px, 5px); }
  40% { transform: translate(8px, -5px); }
  60% { transform: translate(-6px, 3px); }
  80% { transform: translate(4px, -2px); }
}
@media (prefers-reduced-motion: reduce) {
  .bankrupt, .bankrupt__card, .bankrupt__flash, .bankrupt__ring, .bankrupt__shards i { animation: none; }
}

/* --- mode switch + online tables (multiplayer) --- */
.modes {
  display: flex;
  gap: 4px;
  margin-left: 16px;
}
.modes .mode {
  font: inherit;
  font-size: 12px;
  letter-spacing: 1px;
  padding: 4px 10px;
  background: #17150f;
  color: #8a8674;
  border: 2px solid #2a271d;
  cursor: pointer;
}
.modes .mode.is-active {
  background: #2a271d;
  color: #e8e2cf;
}
.online-view {
  width: 100%;
  max-width: min(94vw, 1160px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.tables {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.table-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font: inherit;
  text-align: left;
  padding: 12px 14px;
  background: #14120d;
  color: #d4d0c4;
  border: 2px solid #2a271d;
  cursor: pointer;
}
.table-row:hover:not(:disabled) {
  border-color: #c9a227;
}
.table-row:disabled {
  opacity: 0.6;
  cursor: default;
}
.table-row.is-mine {
  border-color: #c9a227;
}
.table-row__name {
  min-width: 72px;
  color: #c9a227;
}
.table-row__meta {
  flex: 1;
  color: #8a8674;
  font-size: 12px;
}
.online-table {
  border: 2px solid #2a271d;
  background: #100e0a;
  padding: 10px;
}
.online-table__head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.online-table__head b {
  color: #c9a227;
}
.online-table__head .mini {
  margin-left: auto;
}
.online-seats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 6px;
}
.online-seat {
  padding: 8px 10px;
  background: #17150f;
  border: 2px solid #241f16;
  font-size: 13px;
}
#table-screen {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  margin: 0 auto 8px;
  image-rendering: pixelated;
  background: #0d1a12;
}
.online-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}
.online-controls .group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.online-controls .group button {
  font: inherit;
  font-size: 13px;
  padding: 8px 12px;
  background: #17150f;
  color: #d4d0c4;
  border: 2px solid #2a271d;
  cursor: pointer;
}
.online-controls .group button.primary {
  background: #c9a227;
  color: #17150f;
  border-color: #c9a227;
}
.online-controls .group button:disabled {
  opacity: 0.35;
  cursor: default;
}
.online-controls .online-hint {
  font-size: 12px;
}
.room-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.room-bar input {
  font: inherit;
  font-size: 16px;
  letter-spacing: 4px;
  text-transform: uppercase;
  width: 108px;
  padding: 8px 10px;
  text-align: center;
  background: #100e0a;
  color: var(--accent);
  border: 2px solid #2a271d;
}
.room-bar button,
.room-lobby__start {
  font: inherit;
  font-size: 13px;
  padding: 9px 14px;
  background: #17150f;
  color: #d4d0c4;
  border: 2px solid #2a271d;
  cursor: pointer;
}
.room-bar button.primary,
.room-lobby__start {
  background: var(--accent);
  color: #17150f;
  border-color: var(--accent);
  font-weight: 700;
}
.room-bar__error {
  color: #a84a4a;
  font-size: 12px;
}
.room-lobby {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.room-lobby__code {
  font-size: 13px;
  color: #8a8674;
  letter-spacing: 2px;
}
.room-lobby__code b {
  font-size: 22px;
  letter-spacing: 6px;
  color: var(--accent);
}
.room-lobby__start {
  font-size: 16px;
  padding: 12px 42px;
}
.room-lobby__wait {
  font-size: 13px;
  color: #8a8674;
  letter-spacing: 2px;
}
.dots i {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 4px;
  background: var(--accent);
  animation: dot-blink 1.2s steps(1) infinite;
}
.dots i:nth-child(2) { animation-delay: 0.4s; }
.dots i:nth-child(3) { animation-delay: 0.8s; }
@keyframes dot-blink {
  0%, 60% { opacity: 1; }
  61%, 100% { opacity: 0.15; }
}
.room-seats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}
.room-seat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 84px;
  padding: 10px 6px;
  background: #17150f;
  border: 2px solid #2a271d;
}
.room-seat__name {
  font-size: 13px;
  color: #e8e2cf;
  max-width: 76px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.room-seat__tag {
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--accent);
}
.room-seat--empty {
  border-style: dashed;
}
.room-seat--empty .room-seat__name,
.room-seat--empty .room-seat__tag {
  color: #3d4038;
}
