* {
  box-sizing: border-box;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

:root {
  color-scheme: light;
  --forest-950: #102f28;
  --forest-800: #173f34;
  --forest-700: #1f624b;
  --ivory-100: #fff9e8;
  --ivory-200: #f4ead0;
  --ivory-300: #e8d9b5;
  --brass-500: #d5aa4f;
  --brass-700: #8f6a2e;
  --coral: #e85f55;
  --sky: #53a7d8;
  --sun: #f5c84c;
  --danger-600: #b9423c;
  --ink: #17332d;
  --muted: #786f5e;
  --shadow: 0 16px 42px rgb(16 47 40 / 18%);
  --green-900: var(--forest-800);
  --green-800: var(--forest-700);
  --cream-100: var(--ivory-100);
  --cream-200: var(--ivory-200);
  --gold-500: var(--brass-500);
  --gold-600: var(--brass-700);
  --ease-out: cubic-bezier(.23, 1, .32, 1);
  color: var(--ink);
  background: var(--ivory-200);
  font-family: ui-rounded, "SF Pro Rounded", "PingFang SC", "Microsoft YaHei", sans-serif;
}

body {
  min-height: 100dvh;
  margin: 0;
  touch-action: pan-x pan-y;
  background:
    linear-gradient(rgb(244 234 208 / 12%), rgb(244 234 208 / 12%)),
    var(--ivory-200) url("./assets/board-background.png") center / cover fixed;
}

body:has(dialog[open]) {
  overflow: hidden;
}

button,
input,
select {
  min-height: 44px;
  font: inherit;
}

button {
  padding: 0 14px;
  cursor: pointer;
  touch-action: manipulation;
  color: var(--forest-950);
  background: linear-gradient(180deg, #fffdf3, var(--ivory-200));
  border: 1px solid rgb(143 106 46 / 62%);
  border-radius: 14px;
  box-shadow: 0 3px 0 rgb(143 106 46 / 25%);
  transition: transform 90ms var(--ease-out);
}

button:active,
.account-card:active {
  transition-duration: 140ms;
  transform: scale(.97);
}

button:disabled {
  cursor: not-allowed;
  opacity: .5;
}

.primary {
  width: 100%;
  font-weight: 800;
  background: linear-gradient(180deg, #f1c865, var(--brass-500));
  border-color: var(--brass-700);
}

.danger {
  color: #fff;
  background: var(--danger-600);
  border-color: #8c2d28;
}

.topbar {
  position: relative;
  z-index: 3;
  min-height: 104px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 13px clamp(14px, 2.2vw, 26px);
  color: var(--ivory-100);
  background:
    radial-gradient(circle at 28% -80%, rgb(83 167 216 / 30%), transparent 48%),
    linear-gradient(145deg, var(--forest-700), var(--forest-950));
  border-bottom: 2px solid var(--brass-500);
  box-shadow: 0 10px 28px rgb(16 47 40 / 20%);
}

.topbar::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 90px;
  height: 90px;
  background: url("./assets/ui-stickers.png") center / contain no-repeat;
  opacity: .42;
  transform: translateX(-50%);
  pointer-events: none;
}

.topbar > * {
  position: relative;
  z-index: 1;
}

.topbar h1 {
  margin: 2px 0 0;
  font-size: clamp(1.45rem, 2.4vw, 2rem);
  font-weight: 850;
  letter-spacing: -.025em;
  text-shadow: 0 2px 0 rgb(0 0 0 / 14%);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-mark {
  width: 58px;
  height: 58px;
  border: 2px solid rgb(255 249 232 / 72%);
  border-radius: 16px;
  box-shadow: 0 7px 18px rgb(0 0 0 / 24%);
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

.topbar-actions button {
  color: var(--ivory-100);
  background: rgb(255 249 232 / 10%);
  border-color: rgb(213 170 79 / 68%);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 14%);
}

.eyebrow {
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .14em;
  opacity: .72;
}

.board {
  position: relative;
  min-height: calc(100dvh - 104px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, .72fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-areas:
    "p1 bank p2"
    "p3 bank p4";
  gap: clamp(10px, 1.4vw, 16px);
  padding: clamp(12px, 1.7vw, 20px);
}

.board.players-3 {
  grid-template-areas:
    "p1 bank p3"
    "p2 bank p3";
}

.board.players-2 {
  grid-template-areas:
    "p1 bank p2"
    "p1 bank p2";
}

.seat-p1 { grid-area: p1; }
.seat-p2 { grid-area: p2; }
.seat-p3 { grid-area: p3; }
.seat-p4 { grid-area: p4; }
.seat-bank { grid-area: bank; }

.account-card {
  position: relative;
  overflow: hidden;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
  background: rgb(255 249 232 / 94%);
  border: 1px solid rgb(143 106 46 / 45%);
  border-radius: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(5px);
  transition: transform 90ms var(--ease-out);
  touch-action: none;
  user-select: none;
}

.player-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 7px;
  background: var(--player-color);
  box-shadow: 0 2px 0 rgb(255 255 255 / 50%);
}

.account-card.is-drag-source {
  transform: scale(.98);
  outline: 4px solid var(--gold-500);
  outline-offset: 3px;
}

.account-card.is-tap-source {
  outline: 4px solid var(--gold-500);
  outline-offset: 3px;
}

.account-card.is-drag-target {
  transform: scale(1.015);
  outline: 5px solid #57c98f;
  outline-offset: 3px;
}

.account-card:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid #f1c75b;
  outline-offset: 3px;
  box-shadow: 0 0 0 6px var(--forest-950);
}

.account-card:focus-visible {
  box-shadow: 0 0 0 6px var(--forest-950), var(--shadow);
}

.bank-card {
  align-items: center;
  justify-content: center;
  padding-top: min(48%, 300px);
  text-align: center;
  color: var(--ivory-100);
  background:
    radial-gradient(circle at 50% 8%, rgb(83 167 216 / 18%), transparent 42%),
    linear-gradient(160deg, var(--forest-700), var(--forest-950));
  border-color: var(--brass-500);
}

.bank-card::before {
  content: "";
  position: absolute;
  inset: 12px 8px auto;
  height: min(46%, 300px);
  background: url("./assets/bank-building.png") center / contain no-repeat;
  filter: drop-shadow(0 11px 12px rgb(0 0 0 / 24%));
  pointer-events: none;
}

.bank-card > * {
  position: relative;
  z-index: 1;
}

.bank-card .account-name {
  font-size: 1.05rem;
}

.bank-card .balance {
  color: #ffe28b;
  text-shadow: 0 3px 0 rgb(0 0 0 / 16%);
}

.bank-card button {
  min-width: 116px;
  font-weight: 850;
  background: linear-gradient(180deg, #ffe28b, var(--brass-500));
  border-color: #f2d37b;
}

.bank-card .bank-account-select {
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 0;
  color: inherit;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.bank-card .bank-account-select:focus-visible {
  box-shadow: 0 0 0 6px var(--forest-950);
}

.account-name {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
}

.player-card .account-name {
  font-size: 1.08rem;
}

.player-card small {
  width: max-content;
  max-width: 100%;
  padding: 5px 9px;
  color: var(--muted);
  background: rgb(232 217 181 / 48%);
  border-radius: 999px;
}

.token {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  display: inline-block;
  background: var(--token);
  border-radius: 7px;
  border: 1px solid rgb(16 47 40 / 20%);
  box-shadow: inset 0 2px 2px rgb(255 255 255 / 55%), 0 2px 4px rgb(16 47 40 / 16%);
}

.balance {
  font-size: clamp(1.6rem, 3.5vw, 3rem);
  font-variant-numeric: tabular-nums;
  font-weight: 850;
  letter-spacing: -.035em;
}

.balance.is-counting {
  transform-origin: left center;
  animation: balance-count-pop 360ms var(--ease-out) both;
}

.balance-delta {
  position: absolute;
  inset: 50% auto auto 50%;
  z-index: 3;
  translate: -50% -50%;
  width: max-content;
  padding: 7px 11px;
  border: 1px solid currentcolor;
  border-radius: 999px;
  box-shadow: 0 5px 14px rgb(16 47 40 / 18%);
  font-size: .92rem;
  font-variant-numeric: tabular-nums;
  font-weight: 850;
  line-height: 1;
  pointer-events: none;
  animation: transfer-delta-pop 520ms var(--ease-out) both;
}

.balance-delta.is-incoming {
  color: #963c35;
  background: #ffe2dc;
}

.balance-delta.is-outgoing {
  color: #16633f;
  background: #dcf5df;
}

@keyframes balance-count-pop {
  0% { transform: translateY(2px) scale(.985); }
  55% { transform: translateY(-1px) scale(1.035); }
  100% { transform: none; }
}

@keyframes transfer-delta-pop {
  0% { opacity: 0; transform: translateY(8px) scale(.96); }
  18% { opacity: 1; transform: translateY(0) scale(1); }
  68% { opacity: 1; transform: translateY(-10px) scale(1); }
  100% { opacity: 0; transform: translateY(-22px) scale(.98); }
}

@keyframes transfer-delta-fade {
  0%, 100% { opacity: 0; }
  25%, 75% { opacity: 1; }
}

.transfer-arrow {
  position: fixed;
  inset: 0;
  z-index: 5;
  width: 100%;
  height: 100%;
  overflow: visible;
  color: var(--ivory-100);
  pointer-events: none;
}

.transfer-arrow[hidden] {
  display: none;
}

.chalk-dust,
.chalk-line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chalk-dust {
  stroke: rgb(16 47 40 / 48%);
  stroke-width: 9;
  stroke-dasharray: 3 5;
}

.chalk-line {
  stroke: var(--ivory-100);
  stroke-width: 4;
  stroke-dasharray: 15 2 3 3;
}

.tap-hint {
  z-index: 7;
  position: fixed;
  right: 16px;
  bottom: 16px;
  left: 16px;
  max-width: max-content;
  margin: auto;
  padding: 8px 12px;
  text-align: center;
  color: var(--cream-100);
  background: var(--forest-950);
  border-radius: 999px;
  border: 1px solid rgb(213 170 79 / 52%);
  box-shadow: 0 10px 28px rgb(0 0 0 / 25%);
}

.tap-hint.is-error {
  background: #8c2d28;
}

.install-tip {
  z-index: 6;
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  left: max(12px, env(safe-area-inset-left));
  width: min(720px, calc(100vw - 24px));
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 0 auto;
  padding: 8px 8px 8px 16px;
  color: var(--ivory-100);
  background: var(--forest-950);
  border: 1px solid var(--brass-500);
  border-radius: 18px;
  box-shadow: 0 16px 42px rgb(0 0 0 / 30%);
}

.install-tip[hidden] {
  display: none;
}

.install-tip p {
  margin: 0;
  line-height: 1.45;
}

.install-tip button {
  flex: 0 0 auto;
  min-width: 88px;
}

.modal {
  position: fixed;
  inset-inline: 0;
  top: max(18px, 6vh);
  width: min(620px, calc(100vw - 32px));
  max-height: min(88dvh, calc(100dvh - 36px));
  margin: 0 auto;
  padding: 22px;
  overflow: auto;
  color: var(--ivory-100);
  background:
    radial-gradient(circle at 8% 0%, rgb(83 167 216 / 18%), transparent 35%),
    linear-gradient(155deg, var(--forest-700), var(--forest-950));
  border: 1px solid var(--brass-500);
  border-radius: 24px;
  box-shadow: 0 30px 90px rgb(0 0 0 / 42%);
}

.cashier-modal[open].is-entering,
.equalize-modal[open].is-entering {
  animation: modal-enter 180ms var(--ease-out) both;
}

@keyframes modal-enter {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes modal-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal::backdrop {
  background: rgb(8 25 20 / 52%);
  backdrop-filter: blur(3px);
}

.modal h2 {
  margin: 4px 0 16px;
  font-weight: 850;
  letter-spacing: -.025em;
}

.modal label {
  display: grid;
  gap: 6px;
  margin: 10px 0 6px;
  font-weight: 700;
}

.modal input,
.modal select {
  width: 100%;
  padding: 0 12px;
  color: var(--ink);
  background: var(--ivory-100);
  border: 1px solid var(--gold-500);
  border-radius: 12px;
  box-shadow: inset 0 2px 4px rgb(16 47 40 / 8%);
}

.modal input[type="color"] {
  padding: 5px;
}

.player-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 84px;
  gap: 10px;
  margin: 12px 0;
  padding: 8px 12px 12px;
  background: rgb(255 249 232 / 7%);
  border: 1px solid rgb(255 255 255 / 25%);
  border-radius: 16px;
}

.player-field legend {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 5px;
  font-weight: 800;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 44px;
  padding: 0;
  font-size: 1.5rem;
}

.cashier-modal {
  width: min(560px, calc(100vw - 32px));
}

.route {
  margin: 6px 0 14px;
  padding: 10px 12px;
  text-align: center;
  font-weight: 850;
  color: #ffe28b;
  background: rgb(255 249 232 / 8%);
  border: 1px solid rgb(213 170 79 / 35%);
  border-radius: 14px;
}

#cashier-amount {
  min-height: 58px;
  text-align: center;
  font-size: 1.55rem;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.amount-field {
  margin-top: 0;
}

.balance-preview {
  min-height: 3.2em;
  line-height: 1.6;
  white-space: pre-line;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.keypad button {
  min-height: 52px;
  font-size: 1.1rem;
  font-weight: 800;
  background: rgb(255 249 232 / 94%);
}

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

#equalize-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.equalize-option {
  min-height: 56px;
  display: grid;
  grid-template-columns: 24px 20px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 8px 12px;
  color: var(--ink);
  background: var(--ivory-100);
  border: 2px solid transparent;
  border-radius: 14px;
  cursor: pointer;
}

.equalize-option:has(input:checked) {
  border-color: var(--gold-500);
  box-shadow: inset 0 0 0 2px rgb(213 170 79 / 24%);
}

.equalize-option input {
  width: 22px;
  height: 22px;
  min-height: 22px;
  margin: 0;
  padding: 0;
  accent-color: var(--green-800);
}

.equalize-preview {
  min-height: 3.2em;
  margin: 14px 0;
  line-height: 1.7;
  white-space: pre-line;
}

.error {
  padding: 9px 11px;
  color: #ffe5e2;
  background: rgb(185 66 60 / 28%);
  border: 1px solid rgb(255 210 206 / 28%);
  border-radius: 12px;
}

@media (hover: hover) and (pointer: fine) {
  button:not(:disabled):not(:active):hover {
    transform: translateY(-1px);
  }

  .player-card:not(.is-drag-source):not(.is-drag-target):hover {
    transform: translateY(-2px);
  }
}

@media (max-width: 700px) {
  .topbar {
    min-height: 104px;
    padding-inline: 12px;
  }

  .topbar-actions {
    justify-content: flex-end;
    gap: 7px;
  }

  .topbar-actions button {
    padding-inline: 9px;
    font-size: .86rem;
  }

  .app-mark {
    width: 48px;
    height: 48px;
    border-radius: 14px;
  }

  .board,
  .board.players-2,
  .board.players-3,
  .board.players-4 {
    min-height: calc(100dvh - 104px);
    max-height: calc(100dvh - 104px);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
  }

  .account-card {
    min-height: 150px;
    flex: 0 0 auto;
    touch-action: pan-y;
  }

  .bank-card {
    min-height: 360px;
    order: -1;
    justify-content: flex-end;
    padding-top: 220px;
  }

  .bank-card::before {
    height: 218px;
  }

  .player-field {
    grid-template-columns: 1fr;
  }

  #equalize-options {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .topbar::after {
    display: none;
  }
}

@media (max-width: 600px) {
  .eyebrow {
    display: none;
  }

  .topbar {
    gap: 8px;
  }

  .brand-lockup {
    min-width: 0;
    gap: 8px;
  }

  .app-mark {
    width: 44px;
    height: 44px;
    border-radius: 12px;
  }

  .topbar h1 {
    font-size: 1.24rem;
    white-space: nowrap;
  }

  .topbar-actions {
    flex: 0 0 auto;
  }

  .topbar-actions button {
    padding-inline: 7px;
    font-size: .8rem;
  }

  .install-tip {
    flex-wrap: wrap;
    padding: 12px;
  }

  .install-tip button {
    width: 100%;
  }
}

@media (max-width: 460px) {
  .modal {
    top: 10px;
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 20px);
    padding: 18px;
    border-radius: 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cashier-modal[open].is-entering,
  .equalize-modal[open].is-entering {
    animation: modal-fade 120ms var(--ease-out) both;
  }

  button,
  .account-card {
    transition: none;
  }

  .balance.is-counting {
    animation: none;
    transform: none;
  }

  .balance-delta {
    animation: transfer-delta-fade 120ms var(--ease-out) both;
    transform: none;
  }

  button:active,
  .account-card:active,
  .account-card.is-drag-source,
  .account-card.is-tap-source,
  .account-card.is-drag-target {
    transform: none;
  }
}
