:root {
  color-scheme: light;
  --bg: #f4f6f3;
  --panel: #ffffff;
  --ink: #17201b;
  --muted: #637067;
  --line: #d8dfd8;
  --green: #0b6b49;
  --green-dark: #084631;
  --red: #b83232;
  --blue: #2458b8;
  --amber: #c77700;
  --chip: #f6f0df;
  --shadow: 0 16px 40px rgba(26, 38, 31, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 0%, rgba(11, 107, 73, 0.10), transparent 32rem),
    linear-gradient(180deg, #f9faf7 0%, var(--bg) 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(11, 107, 73, 0.14);
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0 18px;
}

.topbar h1,
.section-header h2 {
  margin: 0;
}

.topbar h1 {
  font-size: clamp(1.6rem, 6vw, 2.6rem);
  line-height: 1;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.status-cluster {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.connection-status,
.room-badge {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 0.82rem;
  font-weight: 800;
}

.connection-status {
  background: #e8ece8;
  color: var(--muted);
}

.connection-status.online {
  background: rgba(11, 107, 73, 0.12);
  color: var(--green-dark);
}

.room-badge {
  background: var(--ink);
  color: #fff;
}

.icon-button {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line);
  font-weight: 900;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 16px;
}

.auth-panel,
.lobby-panel,
.seat-order-panel {
  margin-bottom: 14px;
}

.form-grid,
.settings-grid {
  display: grid;
  gap: 12px;
}

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

.wide-field {
  grid-column: 1 / -1;
}

.button-row {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.preview-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  margin-top: 10px;
  color: var(--green-dark);
  font-weight: 850;
  text-decoration: none;
}

.preview-link:hover {
  text-decoration: underline;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  min-height: 46px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 850;
}

.primary-button {
  background: var(--green);
  color: #fff;
}

.secondary-button {
  background: #e9efe9;
  color: var(--green-dark);
}

.ghost-button {
  background: transparent;
  color: var(--muted);
  box-shadow: inset 0 0 0 1px var(--line);
}

.danger-button {
  background: rgba(184, 50, 50, 0.10);
  color: #8f2626;
  box-shadow: inset 0 0 0 1px rgba(184, 50, 50, 0.22);
}

.full-button {
  width: 100%;
  margin-top: 14px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.player-list,
.seat-order-list,
.history-list {
  display: grid;
  gap: 8px;
}

.player-row,
.history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 46px;
  border-radius: 8px;
  background: #f6f8f5;
  padding: 9px 11px;
}

.player-row strong,
.history-row strong {
  overflow-wrap: anywhere;
}

.muted {
  color: var(--muted);
  font-size: 0.88rem;
}

.seat-row {
  position: relative;
  display: grid;
  grid-template-columns: 38px 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  min-height: 50px;
  border-radius: 8px;
  background: #f6f8f5;
  padding: 8px 10px 8px 8px;
  box-shadow: inset 0 0 0 1px rgba(23, 32, 27, 0.06);
}

.seat-row.is-dragging {
  opacity: 0.82;
  box-shadow:
    inset 0 0 0 1px rgba(23, 32, 27, 0.08),
    0 12px 26px rgba(23, 32, 27, 0.18);
}

.seat-row.drop-before {
  box-shadow:
    inset 0 3px 0 var(--green),
    inset 0 0 0 1px rgba(23, 32, 27, 0.06);
}

.seat-row.drop-after {
  box-shadow:
    inset 0 -3px 0 var(--green),
    inset 0 0 0 1px rgba(23, 32, 27, 0.06);
}

.drag-handle {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #e9efe9;
  color: var(--muted);
  touch-action: none;
}

.drag-handle::before {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  top: 10px;
  height: 3px;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 0 6px 0 currentColor, 0 12px 0 currentColor;
}

.seat-index {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 900;
}

.seat-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.seat-tags {
  display: flex;
  justify-content: flex-end;
  gap: 5px;
  flex-wrap: wrap;
}

.seat-role {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  background: #e3ebe5;
  color: var(--green-dark);
  padding: 0 8px;
  font-size: 0.74rem;
  font-weight: 900;
}

.seat-role.sb {
  background: rgba(199, 119, 0, 0.16);
  color: #8a5200;
}

.seat-role.bb {
  background: rgba(184, 50, 50, 0.14);
  color: #8f2626;
}

body.seat-dragging {
  user-select: none;
}

.table-grid {
  display: grid;
  gap: 14px;
}

.play-viewport {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-content: stretch;
  gap: 10px;
  min-height: calc(100svh - 104px);
}

.felt-table {
  display: grid;
  grid-template-rows: auto minmax(112px, 1fr) auto;
  border-radius: 8px;
  background:
    radial-gradient(circle at center, rgba(255, 255, 255, 0.08), transparent 30%),
    linear-gradient(145deg, #0d7a52, #07412f);
  color: #fff;
  padding: 12px;
  box-shadow: var(--shadow);
}

.hand-strip {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.86rem;
  font-weight: 800;
}

.pot-display {
  display: grid;
  place-items: center;
  min-height: 112px;
  margin: 10px 0 12px;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.12);
}

.pot-display span {
  color: rgba(255, 255, 255, 0.75);
  font-weight: 800;
}

.pot-display strong {
  font-size: clamp(2.8rem, 16vw, 5.4rem);
  line-height: 0.95;
}

.pot-display.pot-pop {
  animation: pot-pop 360ms ease-out;
}

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

.table-player {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 8px;
  align-items: center;
  min-height: 58px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  padding: 8px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.table-player.me {
  background: rgba(255, 255, 255, 0.22);
}

.table-player.settled-winner {
  box-shadow:
    inset 0 0 0 2px rgba(255, 222, 128, 0.92),
    0 0 0 3px rgba(255, 222, 128, 0.15);
}

.player-name {
  min-width: 0;
  font-size: 0.92rem;
  font-weight: 900;
  overflow-wrap: anywhere;
}

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

.presence-dot {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.38);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.16);
}

.presence-dot.online {
  background: #5ee08f;
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.16),
    0 0 12px rgba(94, 224, 143, 0.54);
}

.presence-dot.offline {
  background: rgba(255, 255, 255, 0.36);
}

.balance-pill,
.contribution-pill,
.position-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 7px;
  font-size: 0.72rem;
  font-weight: 850;
}

.balance-pill {
  justify-self: end;
  background: #fff;
  color: var(--green-dark);
}

.contribution-pill {
  background: rgba(0, 0, 0, 0.24);
  color: #fff;
}

.position-tags {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.position-pill {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

.position-pill.sb {
  background: rgba(199, 119, 0, 0.78);
}

.position-pill.bb {
  background: rgba(184, 50, 50, 0.78);
}

.settlement-stack {
  display: grid;
  gap: 14px;
}

.action-panel {
  padding: 12px;
}

.action-panel .section-header {
  margin-bottom: 10px;
}

.action-panel strong {
  font-size: 1.2rem;
}

.action-panel .button-row {
  margin-top: 10px;
}

.chip-rack {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.chip-button {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-height: 0;
  min-width: 0;
  border-radius: 999px;
  background:
    radial-gradient(circle, var(--chip) 0 42%, transparent 43%),
    repeating-conic-gradient(from 0deg, #f8faf8 0deg 12deg, currentColor 12deg 22deg);
  color: var(--green);
  box-shadow:
    inset 0 0 0 5px currentColor,
    0 8px 16px rgba(0, 0, 0, 0.14);
  font-size: clamp(0.86rem, 3.8vw, 1.08rem);
  font-weight: 950;
}

.flying-chip {
  position: fixed;
  display: grid;
  place-items: center;
  z-index: 30;
  pointer-events: none;
  border-radius: 999px;
  background:
    radial-gradient(circle, var(--chip) 0 42%, transparent 43%),
    repeating-conic-gradient(from 0deg, #f8faf8 0deg 12deg, currentColor 12deg 22deg);
  box-shadow:
    inset 0 0 0 5px currentColor,
    0 14px 28px rgba(0, 0, 0, 0.18);
  font-size: 1rem;
  font-weight: 950;
  will-change: transform, opacity;
}

.chip-button:nth-child(2n) {
  color: var(--red);
}

.chip-button:nth-child(3n) {
  color: var(--blue);
}

.chip-button:nth-child(4n) {
  color: var(--amber);
}

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

.winner-button {
  min-height: 44px;
  border-radius: 8px;
  background: #f2f5f1;
  color: var(--ink);
  padding: 0 10px;
  font-weight: 850;
  overflow-wrap: anywhere;
}

.winner-button.selected {
  background: #ffe7a6;
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 10;
  min-height: 48px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  padding: 13px 14px;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

@media (min-width: 700px) {
  .app-shell {
    padding: 24px;
  }

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

  .auth-panel {
    max-width: 620px;
  }

  .table-grid {
    grid-template-columns: minmax(0, 1fr) minmax(300px, 0.48fr);
    align-items: start;
  }

  .play-viewport {
    min-height: calc(100svh - 122px);
  }

  .felt-table {
    grid-template-rows: auto minmax(150px, 1fr) auto;
    min-height: clamp(360px, 56svh, 560px);
    padding: 16px;
  }

  .pot-display {
    min-height: 150px;
    margin: 18px 0;
  }

  .pot-display strong {
    font-size: clamp(4rem, 10vw, 6.6rem);
  }

  .table-players {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .table-player {
    min-height: 74px;
    padding: 10px;
  }

  .player-name {
    font-size: 1rem;
  }

  .balance-pill,
  .contribution-pill,
  .position-pill {
    min-height: 26px;
    padding: 0 8px;
    font-size: 0.78rem;
  }

  .action-panel {
    padding: 16px;
  }

  .action-panel strong {
    font-size: 1.35rem;
  }

  .chip-button {
    box-shadow:
      inset 0 0 0 6px currentColor,
      0 8px 16px rgba(0, 0, 0, 0.14);
  }
}

@media (min-width: 980px) {
  .play-viewport {
    grid-template-columns: minmax(0, 1fr) minmax(260px, 0.42fr);
    grid-template-rows: none;
    align-items: stretch;
  }

  .action-panel {
    align-self: stretch;
    display: grid;
    grid-template-rows: auto 1fr auto;
  }

  .chip-rack {
    align-content: center;
  }
}

@keyframes pot-pop {
  0% {
    transform: scale(1);
    box-shadow: none;
  }

  45% {
    transform: scale(1.025);
    box-shadow: 0 0 0 8px rgba(255, 255, 255, 0.08);
  }

  100% {
    transform: scale(1);
    box-shadow: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pot-display.pot-pop {
    animation: none;
  }
}

@media (max-width: 420px) {
  .app-shell {
    padding: 12px;
  }

  .settings-grid,
  .winner-grid {
    grid-template-columns: 1fr;
  }

  .button-row {
    flex-direction: column;
  }

  .primary-button,
  .secondary-button,
  .ghost-button,
  .danger-button {
    width: 100%;
  }
}
