/* poker.css — self-contained stylesheet for the Datastar poker UI.
 *
 * Hand-ported from the poker-web Tailwind build: the color palette and the
 * few component rules (cards, timer border, collapsibles) are lifted from
 * assets/input.css; the utility-class layout used by the Dioxus components
 * is rewritten as plain CSS. Theme color: #1A130D.
 */

:root {
  --color-accent: #FBDB93;
  --color-accent-light: #FCE5AA;
  --color-primary: #BE5B50;
  --color-primary-light: #CF6E63;
  --color-muted: #8A2D3B;
  --color-muted-light: #A03548;
  --color-surface: #641B2E;
  --color-surface-light: #7A2238;
  --color-foreground: #F9F7F5;
  --color-base: #1A130D;
  --color-elevated: #2D2018;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  background: var(--color-base);
  color: var(--color-foreground);
  font-family:
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    sans-serif;
  overflow: hidden;
}

button {
  font: inherit;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
}

input {
  font: inherit;
  color: inherit;
}

/* Hide number-input spinners */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.select-all {
  user-select: all;
}

/* ---------------------------------------------------------------------------
 * Buttons
 * ------------------------------------------------------------------------- */

.btn {
  border-radius: 0.5rem;
  padding: 0.5rem 1rem;
  font-weight: 600;
  transition:
    filter 120ms ease,
    background 120ms ease;
}
.btn:hover {
  filter: brightness(1.15);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
/* Transient "in flight" state for CQRS write buttons (action POSTs). Added
 * imperatively on click (el.classList.add('loading')) and removed when the
 * next state morph re-renders the element. pointer-events:none blocks repeat
 * taps in the gap before the per-element request cancellation catches up. */
.btn.loading {
  opacity: 0.5;
  pointer-events: none;
}
.btn-block {
  display: block;
  width: 100%;
}
.btn-sm {
  padding: 0.25rem 0.75rem;
  font-size: 0.875rem;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-foreground);
}
.btn-primary:hover {
  background: var(--color-primary-light);
}

.btn-muted {
  background: var(--color-muted);
  color: var(--color-foreground);
}
.btn-muted:hover {
  background: var(--color-muted-light);
}

.btn-elevated {
  background: var(--color-elevated);
  color: var(--color-foreground);
}
.btn-elevated:hover {
  background: var(--color-base);
}

.btn-accent {
  background: var(--color-accent);
  color: var(--color-base);
}
.btn-accent:hover {
  background: var(--color-accent-light);
}

.btn-accent-soft {
  background: color-mix(in srgb, var(--color-accent) 20%, transparent);
  color: var(--color-accent);
}
.btn-accent-soft:hover {
  background: color-mix(in srgb, var(--color-accent) 30%, transparent);
}

/* ---------------------------------------------------------------------------
 * Connect screen
 * ------------------------------------------------------------------------- */

.connect-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.conn-card {
  background: var(--color-surface);
  width: 100%;
  max-width: 24rem;
  border-radius: 1rem;
  box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.5);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.conn-header {
  display: flex;
  flex-direction: column;
}
.conn-header h1 {
  font-size: 1.875rem;
  font-weight: 700;
  text-align: center;
  color: var(--color-accent);
}
.conn-header p {
  font-size: 0.75rem;
  color: color-mix(in srgb, var(--color-foreground) 50%, transparent);
  text-align: right;
}

.conn-fields {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.field > span {
  font-size: 0.875rem;
  color: color-mix(in srgb, var(--color-foreground) 60%, transparent);
}
.field > small {
  font-size: 0.75rem;
  color: color-mix(in srgb, var(--color-foreground) 40%, transparent);
}
.field input {
  background: var(--color-muted);
  border-radius: 0.5rem;
  padding: 0.5rem 1rem;
  border: none;
  outline: none;
}
.field input:focus {
  box-shadow: inset 0 0 0 2px var(--color-accent);
}

.host-settings summary {
  font-size: 0.875rem;
  color: color-mix(in srgb, var(--color-foreground) 60%, transparent);
  cursor: pointer;
  list-style: none;
}
.host-settings summary::after {
  content: " ▾";
  font-size: 0.75rem;
}
.host-settings[open] summary::after {
  content: " ▴";
}
.host-inputs {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.conn-buttons {
  display: flex;
  gap: 0.75rem;
}
.conn-buttons .btn {
  flex: 1;
}

/* Connection screen – landscape phones: widen card & grid the fields */
@media (orientation: landscape) and (max-height: 500px) {
  .conn-card {
    max-width: 42rem;
    padding: 1.25rem 2rem;
    gap: 0.75rem;
  }
  .conn-header {
    flex-direction: row;
    align-items: baseline;
    justify-content: center;
    gap: 0.5rem;
  }
  .conn-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem 1.5rem;
  }
  .host-inputs {
    flex-direction: row;
    gap: 0.75rem;
  }
}

/* ---------------------------------------------------------------------------
 * Game layout
 * ------------------------------------------------------------------------- */

.game-layout {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 16rem;
  background: var(--color-surface);
  border-right: 1px solid color-mix(in srgb, var(--color-muted) 50%, transparent);
  display: flex;
  flex-direction: column;
}

.player-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

#controls {
  padding: 0.75rem;
  border-top: 1px solid color-mix(in srgb, var(--color-muted) 50%, transparent);
}

.lobby-panel,
.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.waiting-text {
  font-size: 0.875rem;
  color: color-mix(in srgb, var(--color-foreground) 60%, transparent);
  text-align: center;
}

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  min-width: 0;
}

/* ---------------------------------------------------------------------------
 * Player list
 * ------------------------------------------------------------------------- */

.player-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  margin-bottom: 0.25rem;
  background: var(--color-surface);
  position: relative;
}
.player-us {
  background: var(--color-muted);
}
.player-dim {
  opacity: 0.5;
}

.player-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}
.player-name {
  color: var(--color-foreground);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-name-us {
  font-weight: 600;
  color: var(--color-accent);
}
.player-tag {
  font-size: 0.75rem;
  font-style: italic;
  color: color-mix(in srgb, var(--color-foreground) 40%, transparent);
}

.player-right {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  cursor: pointer;
}
.player-stack {
  font-size: 0.875rem;
  color: color-mix(in srgb, var(--color-foreground) 60%, transparent);
}
.player-bet {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-accent);
}

.blind-chip {
  font-size: 0.75rem;
  font-weight: 700;
}
.blind-sb {
  color: var(--color-accent);
}
.blind-bb {
  color: var(--color-primary);
}

/* Timer border: clockwise-disappearing ring for the active-turn player */
@property --timer-angle {
  syntax: "<angle>";
  initial-value: 360deg;
  inherits: true;
}

.timer-border {
  position: relative;
}
.timer-border::before {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: calc(0.5rem + 2px);
  background: conic-gradient(
    transparent calc(360deg - var(--timer-angle)),
    var(--color-accent) calc(360deg - var(--timer-angle))
  );
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  mask-composite: exclude;
  padding: 2px;
  pointer-events: none;
}

/* ---------------------------------------------------------------------------
 * Table
 * ------------------------------------------------------------------------- */

.table {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  min-height: 0;
  overflow-y: auto;
}
@media (min-width: 1024px) {
  .table {
    justify-content: center;
    gap: 1.5rem;
    padding: 1rem;
  }
}

.table-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0 0.25rem;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--color-foreground) 60%, transparent);
}
@media (min-width: 1024px) {
  .table-meta {
    justify-content: center;
    gap: 1rem;
    font-size: 0.875rem;
    width: auto;
  }
}

.room-chip {
  background: var(--color-surface);
  border: 1px solid color-mix(in srgb, var(--color-muted) 50%, transparent);
  border-radius: 0.25rem;
  padding: 0.125rem 0.5rem;
  cursor: pointer;
}
@media (min-width: 1024px) {
  .room-chip {
    padding: 0.25rem 0.75rem;
  }
}

/* Live blinds-timer chip in the table header. The countdown text is driven by
 * pokerBlindsTick (a 250ms interval) off an absolute deadline baked into
 * data-blind-deadline — see poker.js. */
.blinds-timer {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  background: var(--color-surface);
  border: 1px solid color-mix(in srgb, var(--color-muted) 50%, transparent);
  border-radius: 0.25rem;
  padding: 0.125rem 0.5rem;
  font-variant-numeric: tabular-nums;
}
@media (min-width: 1024px) {
  .blinds-timer {
    padding: 0.25rem 0.75rem;
  }
}
.blinds-level {
  font-weight: 600;
  color: var(--color-accent);
}
.blinds-text {
  min-width: 3.5em;
  text-align: center;
  color: color-mix(in srgb, var(--color-foreground) 70%, transparent);
}
.blinds-next {
  font-size: 0.7rem;
  color: color-mix(in srgb, var(--color-foreground) 45%, transparent);
}
/* Final-seconds warning state (toggled from JS). */
.blinds-timer.blinds-soon {
  border-color: var(--color-accent);
  animation: blinds-pulse 1s ease-in-out infinite;
}
.blinds-timer.blinds-soon .blinds-text {
  color: var(--color-accent);
  font-weight: 700;
}
@keyframes blinds-pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--color-accent) 40%, transparent);
  }
  50% {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent) 10%, transparent);
  }
}

.community-cards {
  display: flex;
  gap: 0.5rem;
}
@media (min-width: 1024px) {
  .community-cards {
    gap: 0.75rem;
  }
}

.pot {
  background: var(--color-surface);
  border-radius: 9999px;
  padding: 0.25rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-accent);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.3);
  user-select: none;
  cursor: pointer;
}
@media (min-width: 1024px) {
  .pot {
    padding: 0.5rem 1.5rem;
    font-size: 1.125rem;
  }
}

/* ---------------------------------------------------------------------------
 * Cards
 * ------------------------------------------------------------------------- */

.card,
.card-back,
.card-empty {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.5rem;
  font-weight: 700;
  font-size: 1.125rem;
  white-space: nowrap;
  width: 3.5rem;
  height: 5rem;
  flex: none;
}

.card {
  border: 2px solid color-mix(in srgb, var(--color-accent) 30%, transparent);
  background: var(--color-foreground);
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.3);
}
.card-back {
  border: 2px solid var(--color-muted);
  background: var(--color-surface);
  color: var(--color-accent);
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.3);
}
.card-empty {
  border: 2px dashed color-mix(in srgb, var(--color-muted) 50%, transparent);
  background: var(--color-elevated);
  color: color-mix(in srgb, var(--color-foreground) 40%, transparent);
}

.card-sm {
  width: 2.25rem;
  height: 3.25rem;
  font-size: 0.875rem;
}

.suit-red {
  color: var(--color-primary);
}
.suit-black {
  color: var(--color-base);
}

@media (min-width: 1024px) {
  .card,
  .card-back,
  .card-empty {
    width: 5rem;
    height: 7rem;
    font-size: 1.375rem;
  }
  .card-sm {
    width: 3rem;
    height: 4.25rem;
    font-size: 1rem;
  }
}

/* ---------------------------------------------------------------------------
 * Hole cards
 * ------------------------------------------------------------------------- */

.hole-cards {
  display: flex;
  justify-content: center;
  padding-bottom: 0.5rem;
}
.hole-cards-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}
.hole-card-row {
  display: flex;
  gap: 0.5rem;
}
@media (min-width: 1024px) {
  .hole-card-row {
    gap: 0.75rem;
  }
}
.hand-rank {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-accent);
  letter-spacing: 0.025em;
}

/* ---------------------------------------------------------------------------
 * Showdown
 * ------------------------------------------------------------------------- */

.showdown {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: 0.75rem;
}
@media (min-width: 1024px) {
  .showdown {
    gap: 1.25rem;
  }
}

.showdown-hand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.125rem;
  background: color-mix(in srgb, var(--color-surface) 60%, transparent);
  border-radius: 0.5rem;
  padding: 0.375rem 0.5rem;
}
.showdown-us {
  box-shadow: 0 0 0 2px var(--color-accent);
}
.showdown-name {
  font-size: 0.75rem;
  max-width: 5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: color-mix(in srgb, var(--color-foreground) 70%, transparent);
}
.showdown-name-us {
  color: var(--color-accent);
  font-weight: 600;
}
.showdown-cards {
  display: flex;
  gap: 0.25rem;
}
.showdown-line {
  font-size: 0.65rem;
  line-height: 1.25;
  color: color-mix(in srgb, var(--color-foreground) 60%, transparent);
}
.showdown-won {
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.25;
  color: #4ade80;
}

/* ---------------------------------------------------------------------------
 * Action bar
 * ------------------------------------------------------------------------- */

.action-bar {
  background: var(--color-surface);
  border-top: 1px solid color-mix(in srgb, var(--color-muted) 50%, transparent);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.action-bar-inert {
  min-height: 4rem;
  align-items: center;
  justify-content: center;
}

.action-waiting {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 2.5rem;
  color: color-mix(in srgb, var(--color-foreground) 50%, transparent);
  font-size: 0.875rem;
}

.preset-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: center;
}

.action-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

.raise-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.raise-input {
  background: var(--color-muted);
  border: none;
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  width: 7rem;
  outline: none;
}
.raise-input:focus {
  box-shadow: 0 0 0 2px var(--color-accent);
}
.raise-unit {
  font-size: 0.75rem;
  color: color-mix(in srgb, var(--color-foreground) 50%, transparent);
  user-select: none;
  white-space: nowrap;
}
.min-raise {
  font-size: 0.75rem;
  color: color-mix(in srgb, var(--color-foreground) 40%, transparent);
  user-select: none;
  white-space: nowrap;
}

/* ---------------------------------------------------------------------------
 * Toast (transient in-table messages: "Not your turn", etc.)
 * ------------------------------------------------------------------------- */

.toast {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: var(--color-elevated);
  color: var(--color-foreground);
  border: 1px solid color-mix(in srgb, var(--color-muted) 60%, transparent);
  border-radius: 0.5rem;
  padding: 0.6rem 1.1rem;
  font-size: 0.9rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  animation: toast-fade 3.2s ease forwards;
}

@keyframes toast-fade {
  0%,
  72% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

/* Force landscape on small portrait screens during game */
@media (orientation: portrait) and (max-width: 600px) {
  .portrait-rotate {
    transform: rotate(90deg);
    transform-origin: top left;
    width: 100vh;
    height: 100vw;
    position: fixed;
    top: 0;
    left: 100vw;
    overflow: auto;
  }
}
