:root {
  color-scheme: dark;
  --bg: #101416;
  --panel: #182023;
  --panel-strong: #202b2e;
  --felt: #126047;
  --felt-dark: #0c3d32;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f5f1e8;
  --muted: #aeb8b3;
  --accent: #f1c453;
  --spade: #2f3438;
  --heart: #d94343;
  --diamond: #2778d9;
  --club: #229b5a;
  --black: #202326;
  --green: #42d19d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% 18%, rgba(18, 96, 71, 0.52), transparent 34rem),
    linear-gradient(135deg, #0d1214, #151a1d 46%, #11191a);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 18px 0;
}

.topbar,
.board-heading,
.history-heading,
.player-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 14px;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.help-button {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(241, 196, 83, 0.42);
  border-radius: 999px;
  background: rgba(241, 196, 83, 0.12);
  color: var(--accent);
  font-size: 1rem;
  font-weight: 950;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hand-settings {
  display: grid;
  grid-template-columns: minmax(120px, 180px) minmax(180px, 1fr);
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 20, 22, 0.58);
}

.hand-settings label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.hand-settings select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font: inherit;
  text-transform: none;
}

.hand-settings:not(.is-specified) .hand-input-message {
  display: none;
}

.hand-input-message {
  min-height: 1.2em;
  margin: 0;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 800;
}

.card-picker {
  display: grid;
  grid-template-columns: repeat(13, minmax(34px, 1fr));
  gap: 5px;
  margin: -4px 0 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 20, 22, 0.58);
}

.card-picker.is-hidden {
  display: none;
}

.picker-card {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--black);
  font-size: 0.82rem;
  font-weight: 900;
}

.picker-card.is-selected {
  background: #fffaf0;
  outline: 3px solid var(--accent);
  outline-offset: 1px;
}

.picker-card.is-unavailable,
.picker-card:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.picker-card.is-selected {
  opacity: 1;
}

.hand-banner {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: grid;
  place-items: center;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.34);
  color: var(--text);
  font-size: clamp(3rem, 10vw, 8rem);
  font-weight: 950;
  text-transform: uppercase;
  text-shadow: 0 14px 40px rgba(0, 0, 0, 0.7);
}

.hand-banner.is-hidden {
  display: none;
}

.delay-control {
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.delay-control select {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font: inherit;
  text-transform: none;
}

.eyebrow,
.panel-label,
.stat-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.8rem, 3.4vw, 3.4rem);
  line-height: 1;
}

h2 {
  font-size: 1.3rem;
}

.mode-switch {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(46px, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  opacity: 0.82;
}

.mode-button,
.ghost-button,
.reset-button,
.deal-button {
  min-height: 42px;
  border-radius: 8px;
  color: var(--text);
}

.mode-button {
  min-height: 34px;
  padding: 0 10px;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
}

.mode-button.is-active {
  background: var(--accent);
  color: #211b0a;
  font-weight: 800;
}

.table-area {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(241, 196, 83, 0.22);
  border-radius: 16px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.06), transparent),
    radial-gradient(ellipse at center, var(--felt), var(--felt-dark));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
}

.player-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.player-panel,
.board-panel,
.history-panel,
.stat-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 20, 22, 0.72);
  backdrop-filter: blur(10px);
}

.player-panel {
  min-width: 0;
  padding: 14px;
  transition:
    border-color 160ms ease,
    transform 160ms ease,
    box-shadow 160ms ease;
}

.player-panel.is-winner {
  border-color: rgba(66, 209, 157, 0.96);
  background:
    linear-gradient(135deg, rgba(66, 209, 157, 0.42), rgba(241, 196, 83, 0.14)),
    rgba(16, 20, 22, 0.9);
  box-shadow: 0 0 0 2px rgba(66, 209, 157, 0.28), 0 18px 44px rgba(0, 0, 0, 0.3);
}

.player-panel.is-leading {
  border-color: rgba(241, 196, 83, 0.44);
  background:
    linear-gradient(135deg, rgba(241, 196, 83, 0.09), transparent),
    rgba(16, 20, 22, 0.78);
  box-shadow: 0 0 0 1px rgba(241, 196, 83, 0.08), 0 10px 22px rgba(0, 0, 0, 0.12);
}

.player-panel.is-leading .equity-line {
  color: var(--accent);
}

.player-panel.is-locked {
  border-color: rgba(66, 209, 157, 0.96);
  background:
    linear-gradient(135deg, rgba(66, 209, 157, 0.38), rgba(241, 196, 83, 0.12)),
    rgba(16, 20, 22, 0.9);
  box-shadow: 0 0 0 2px rgba(66, 209, 157, 0.26), 0 18px 44px rgba(0, 0, 0, 0.28);
}

.player-panel.is-locked .equity-line,
.player-panel.is-winner .equity-line {
  color: var(--green);
}

.cards {
  display: flex;
  gap: 10px;
  min-height: 108px;
  margin-top: 12px;
}

.board-cards {
  flex-wrap: wrap;
  gap: 8px;
}

.board-cards .card:nth-child(3),
.board-cards .card:nth-child(4) {
  margin-right: clamp(16px, 3vw, 34px);
}

.card {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: clamp(52px, 7vw, 76px);
  aspect-ratio: 0.68;
  padding: 9px;
  border: 1px solid rgba(0, 0, 0, 0.22);
  border-radius: 8px;
  background: #fffaf0;
  color: var(--black);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.24);
}

.card.suit-s {
  color: var(--spade);
}

.card.suit-h {
  color: var(--heart);
}

.card.suit-d {
  color: var(--diamond);
}

.card.suit-c {
  color: var(--club);
}

.picker-card.suit-s {
  color: #d7dcde;
}

.picker-card.suit-s.is-selected {
  color: var(--spade);
}

.picker-card.suit-h {
  color: var(--heart);
}

.picker-card.suit-d {
  color: var(--diamond);
}

.picker-card.suit-c {
  color: var(--club);
}

.card-rank {
  font-size: clamp(1.1rem, 2vw, 1.6rem);
  font-weight: 900;
  line-height: 1;
}

.card-suit {
  align-self: center;
  justify-self: center;
  font-size: clamp(1.7rem, 3vw, 2.5rem);
  line-height: 1;
}

.card-corner {
  align-self: end;
  justify-self: end;
  font-size: 0.95rem;
  font-weight: 900;
  line-height: 1;
  transform: rotate(180deg);
}

.hand-name,
.equity-line {
  min-height: 1.5em;
  margin: 10px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.result-detail {
  display: none;
}

.equity-line {
  margin-top: 4px;
  color: var(--accent);
  font-size: clamp(1.5rem, 3vw, 2.45rem);
  font-weight: 950;
  line-height: 1;
}

.equity-line.is-final-win,
.equity-line.is-final-lose,
.equity-line.is-final-chop {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 54px;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: clamp(2rem, 4.5vw, 3.6rem);
  line-height: 1;
}

.equity-line.is-final-win {
  background: rgba(66, 209, 157, 0.18);
  color: var(--green);
  box-shadow: inset 0 0 0 1px rgba(66, 209, 157, 0.55);
}

.equity-line.is-final-lose {
  background: rgba(255, 255, 255, 0.07);
  color: rgba(245, 241, 232, 0.56);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.equity-line.is-final-chop {
  background: rgba(241, 196, 83, 0.16);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(241, 196, 83, 0.48);
}

.board-panel {
  padding: 14px;
}

.deal-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 248px;
  min-height: 66px;
  padding: 0 32px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.28), transparent 42%),
    var(--accent);
  color: #211b0a;
  font-weight: 900;
  text-transform: uppercase;
  box-shadow:
    0 14px 28px rgba(0, 0, 0, 0.28),
    0 0 0 3px rgba(241, 196, 83, 0.16);
}

.deal-button::after {
  content: "";
  position: absolute;
  inset: -7px;
  z-index: -1;
  border-radius: 12px;
  background: rgba(241, 196, 83, 0.18);
}

.deal-button-label {
  font-size: clamp(1.25rem, 2.1vw, 1.75rem);
  line-height: 1;
}

.deal-button.is-opening {
  background: rgba(241, 196, 83, 0.58);
  cursor: wait;
}

.deal-button.is-next {
  min-width: 276px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.26), transparent 40%),
    var(--green);
  color: #061d14;
  box-shadow:
    0 18px 38px rgba(0, 0, 0, 0.34),
    0 0 0 4px rgba(66, 209, 157, 0.22);
}

.deal-button.is-next::after {
  background: rgba(66, 209, 157, 0.22);
}

.deal-button.is-disabled-action {
  background: rgba(255, 255, 255, 0.12);
  color: rgba(245, 241, 232, 0.58);
  box-shadow: none;
  cursor: not-allowed;
}

.deal-button.is-disabled-action::after {
  display: none;
}

.reset-button {
  padding: 0 14px;
  border: 1px solid rgba(241, 196, 83, 0.34);
  background: rgba(255, 255, 255, 0.08);
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 900;
}

.street-meter {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.street-step {
  min-width: 0;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-align: center;
}

.street-step.is-active {
  border-color: rgba(241, 196, 83, 0.88);
  background: rgba(241, 196, 83, 0.14);
  color: var(--accent);
}

.card.is-hidden-card {
  border-color: rgba(255, 255, 255, 0.14);
  background:
    linear-gradient(135deg, rgba(241, 196, 83, 0.18), transparent),
    repeating-linear-gradient(45deg, #202b2e, #202b2e 6px, #182023 6px, #182023 12px);
  color: transparent;
}

.card-button {
  text-align: left;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.card-button:hover {
  transform: translateY(-1px);
}

.card.is-hole-placeholder {
  cursor: pointer;
}

.card.is-active-slot {
  border-color: rgba(241, 196, 83, 0.96);
  box-shadow:
    0 0 0 3px rgba(241, 196, 83, 0.28),
    0 10px 18px rgba(0, 0, 0, 0.24);
}

.stats-area {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 12px 0;
}

.stat-card {
  padding: 12px;
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  line-height: 1;
}

.stat-card span {
  color: var(--muted);
  font-weight: 700;
}

.history-panel {
  padding: 18px;
  background: rgba(24, 32, 35, 0.82);
}

.history-heading h2 {
  font-size: 1rem;
}

.ghost-button {
  padding: 0 14px;
  border: 1px solid var(--line);
  background: transparent;
}

.history-list {
  display: grid;
  gap: 8px;
  min-height: 44px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.history-item {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-weight: 700;
}

.history-item strong {
  color: var(--text);
}

.history-cards {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.mini-card-group {
  display: inline-flex;
  gap: 3px;
}

.mini-card {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 34px;
  padding: 0 4px;
  border-radius: 5px;
  background: #fffaf0;
  color: var(--black);
  font-size: 0.76rem;
  font-weight: 900;
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.18);
}

.mini-card.suit-s {
  color: var(--spade);
}

.mini-card.suit-h {
  color: var(--heart);
}

.mini-card.suit-d {
  color: var(--diamond);
}

.mini-card.suit-c {
  color: var(--club);
}

.history-divider {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 900;
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.62);
}

.dialog-backdrop.is-hidden {
  display: none;
}

.dialog-panel {
  width: min(420px, 100%);
  padding: 20px;
  border: 1px solid rgba(241, 196, 83, 0.34);
  border-radius: 8px;
  background: #182023;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.dialog-panel p {
  color: var(--muted);
  font-weight: 700;
}

.help-dialog-panel {
  width: min(520px, 100%);
}

.help-copy {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.help-copy p {
  margin: 0;
  line-height: 1.65;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.dialog-primary-button {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 8px;
  background: var(--accent);
  color: #211b0a;
  font-weight: 900;
}

@media (max-width: 780px) {
  .app-shell {
    width: min(100vw - 12px, 680px);
    padding: 8px 0;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 8px;
  }

  .title-row {
    justify-content: space-between;
  }

  h1 {
    font-size: clamp(1.65rem, 8vw, 2.5rem);
  }

  .top-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
  }

  .top-actions .deal-button {
    grid-column: 1 / -1;
  }

  .delay-control {
    min-width: 0;
  }

  .mode-switch {
    justify-self: end;
    width: auto;
  }

  .player-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hand-settings {
    grid-template-columns: 1fr;
    margin-bottom: 8px;
    padding: 8px;
  }

  .card-picker {
    grid-template-columns: repeat(13, minmax(0, 1fr));
    gap: 3px;
    margin: -2px 0 8px;
    padding: 6px;
  }

  .picker-card {
    min-height: 28px;
    padding: 0;
    border-radius: 5px;
    font-size: 0.58rem;
  }

  .table-area {
    gap: 8px;
    padding: 8px;
  }

  .player-panel,
  .board-panel {
    padding: 8px;
  }

  .board-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .deal-button {
    width: 100%;
    min-width: 0;
    min-height: 58px;
    padding-inline: 18px;
  }

  .deal-button.is-next {
    min-width: 0;
  }

  .cards {
    gap: 5px;
    min-height: 70px;
    margin-top: 8px;
  }

  .card {
    width: clamp(32px, 10.4vw, 54px);
    padding: 5px;
    border-radius: 6px;
  }

  .card-rank {
    font-size: clamp(0.78rem, 3vw, 1.05rem);
  }

  .card-suit {
    font-size: clamp(1.1rem, 4.6vw, 1.65rem);
  }

  .card-corner {
    font-size: 0.66rem;
  }

  .board-cards .card:nth-child(3),
  .board-cards .card:nth-child(4) {
    margin-right: clamp(7px, 3vw, 14px);
  }

  .hand-name {
    min-height: 2.35em;
    margin-top: 6px;
    font-size: 0.72rem;
    line-height: 1.18;
  }

  .equity-line {
    min-height: 1.15em;
    margin-top: 3px;
    font-size: clamp(0.98rem, 5.2vw, 1.55rem);
  }

  .equity-line.is-final-win,
  .equity-line.is-final-lose,
  .equity-line.is-final-chop {
    min-height: 38px;
    padding: 6px 8px;
    font-size: clamp(1.35rem, 7vw, 2.1rem);
  }

  .street-meter {
    gap: 5px;
  }

  .stats-area {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .stat-card {
    padding: 10px;
  }

  .stat-card strong {
    font-size: clamp(1.45rem, 8vw, 2.2rem);
  }

  .history-panel {
    padding: 12px;
  }

  .mini-card {
    min-width: 24px;
    height: 30px;
    font-size: 0.68rem;
  }
}

@media (max-width: 430px) {
  .app-shell {
    width: min(100vw - 12px, 420px);
  }

  .top-actions {
    grid-template-columns: 1fr;
  }

  .mode-switch {
    justify-self: stretch;
  }

  .reset-button,
  .delay-control select {
    width: 100%;
  }

  .board-cards {
    gap: 6px;
  }

  .board-cards .card {
    width: clamp(32px, 12vw, 48px);
  }
}
