:root {
  color-scheme: light;
  --ink: #2b201a;
  --muted: #7e6b60;
  --canvas: #f4ede2;
  --surface: #fffaf3;
  --surface-strong: #ffffff;
  --border: #e1d4c2;
  --wine: #6f1d32;
  --wine-deep: #4d1022;
  --gold: #e7ad55;
  --green: #2d7559;
  --danger: #a43b42;
  --radius: 20px;
  --shadow: 0 24px 65px rgba(72, 45, 25, 0.16);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
  background: #eae0d2;
  color: var(--ink);
  margin: 0;
  min-width: 320px;
}

button,
input { font: inherit; }

button { cursor: pointer; }
button:disabled { cursor: not-allowed; }

button:focus-visible,
input:focus-visible {
  outline: 3px solid #d89a40;
  outline-offset: 3px;
}

.app-shell {
  background: var(--canvas);
  box-shadow: var(--shadow);
  min-height: 100vh;
  overflow: hidden;
}

.auth-button,
.soft-button,
.light-button,
.outline-button,
.primary-button {
  align-items: center;
  border-radius: 11px;
  display: inline-flex;
  font-weight: 700;
  gap: 7px;
  justify-content: center;
  min-height: 40px;
  padding: 9px 14px;
}

.auth-button {
  background: rgba(255, 247, 237, 0.08);
  border: 1px solid rgba(255, 247, 237, 0.22);
  color: #fff7ed;
  font-size: 11px;
  min-height: 36px;
  padding: 7px 11px;
}

.auth-button.is-authenticated { background: #fff7ed; color: var(--wine); }

.game-night {
  background: #332019;
  color: #fff7ed;
  padding: 26px clamp(18px, 4vw, 44px) 30px;
}

.game-heading {
  align-items: flex-end;
  display: flex;
  gap: 28px;
  justify-content: space-between;
  margin: 0 auto 20px;
  max-width: 1180px;
}

.kicker {
  color: #8b7467;
  display: block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.game-heading .kicker { color: #d9b8ac; }

.game-heading h1,
.ledger-heading h2,
.card-top h3,
.dialog-heading h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
  letter-spacing: -0.025em;
}

.game-heading h1 { font-size: clamp(30px, 4vw, 42px); margin: 4px 0 0; }
.game-heading p { color: #cdbbb2; font-size: 13px; margin: 7px 0 0; }
.game-actions { align-items: center; display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }
.session-actions { align-items: center; display: flex; gap: 9px; }
.sync-status { color: #cbb7ad; font-size: 10px; }

.last-settled {
  align-items: center;
  background: rgba(255, 247, 237, 0.08);
  border: 1px solid rgba(255, 247, 237, 0.15);
  border-radius: 12px;
  display: flex;
  gap: 9px;
  min-height: 48px;
  padding: 9px 12px;
}

.context-icon { color: var(--gold); font-size: 18px; }
.last-settled > span:last-child { color: #c2afa5; display: flex; flex-direction: column; font-size: 11px; }
.last-settled strong { color: #fff7ed; font-size: 12px; margin-top: 2px; }

.soft-button {
  background: rgba(255, 247, 237, 0.08);
  border: 1px solid rgba(255, 247, 237, 0.2);
  color: #fff7ed;
  font-size: 12px;
}

.light-button { background: #fff7ed; border: 0; color: #5e182d; font-size: 12px; }
.light-button:hover { background: #ffffff; }

.table-shell { margin: 0 auto; max-width: 1040px; padding: 7px 12px; }

.game-table {
  background: radial-gradient(circle at 50% 44%, #76223a 0%, #4f1327 68%, #3b0e1d 100%);
  border: 12px solid #41251b;
  border-radius: 190px;
  box-shadow: inset 0 0 0 2px rgba(255, 226, 190, 0.22), inset 0 24px 54px rgba(0, 0, 0, 0.27), 0 18px 38px rgba(0, 0, 0, 0.32);
  height: 470px;
  position: relative;
}

.game-table::before {
  border: 1px dashed rgba(255, 243, 224, 0.16);
  border-radius: inherit;
  content: "";
  inset: 23px;
  pointer-events: none;
  position: absolute;
}

.game-table::after {
  background: radial-gradient(circle, rgba(255, 255, 255, 0.05) 0 1px, transparent 1.5px);
  background-size: 11px 11px;
  border-radius: inherit;
  content: "";
  inset: 10px;
  opacity: 0.45;
  pointer-events: none;
  position: absolute;
}

.player-seat {
  left: var(--seat-x);
  position: absolute;
  top: var(--seat-y);
  transform: translate(-50%, -50%);
  z-index: 3;
}

.player-seat button {
  align-items: center;
  background: rgba(31, 18, 15, 0.92);
  border: 1px solid rgba(255, 231, 203, 0.22);
  border-radius: 15px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.24);
  color: #fff5e9;
  display: flex;
  gap: 10px;
  max-width: 170px;
  min-height: 52px;
  min-width: 138px;
  padding: 8px 11px;
  text-align: left;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.player-seat button:hover { border-color: rgba(255, 231, 203, 0.5); transform: translateY(-2px); }

.player-seat button.is-selected {
  background: #4a2f18;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(231, 173, 85, 0.22), 0 12px 26px rgba(0, 0, 0, 0.3);
  transform: translateY(-4px);
}

.avatar {
  align-items: center;
  background: var(--avatar-bg, #e8ddff);
  border-radius: 50%;
  color: var(--avatar-ink, #5b31a8);
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 800;
  height: 34px;
  justify-content: center;
  letter-spacing: 0.03em;
  width: 34px;
}

.avatar-0 { --avatar-bg: #e8ddff; --avatar-ink: #5b31a8; }
.avatar-1 { --avatar-bg: #ffe4cf; --avatar-ink: #9a4918; }
.avatar-2 { --avatar-bg: #d9f0e5; --avatar-ink: #156348; }
.avatar-3 { --avatar-bg: #fde1e6; --avatar-ink: #a13b50; }
.avatar-4 { --avatar-bg: #dcecff; --avatar-ink: #245c9d; }
.avatar-5 { --avatar-bg: #eee5d5; --avatar-ink: #705e3c; }

.seat-copy { display: flex; min-width: 0; flex-direction: column; }
.seat-copy strong { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-copy small { color: #bca9a0; font-size: 10px; margin-top: 2px; white-space: nowrap; }
.seat-copy small b { color: #f8eadd; font-weight: 700; }

.pot-center {
  align-items: center;
  display: flex;
  flex-direction: column;
  left: 50%;
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(270px, 34%);
  z-index: 4;
}

.pot-center > span { color: #dfc5bc; font-size: 11px; font-weight: 800; letter-spacing: 0.13em; text-transform: uppercase; }
.pot-center > strong { color: #fff9f1; font-family: Georgia, "Times New Roman", serif; font-size: clamp(50px, 7vw, 68px); font-weight: 500; letter-spacing: -0.055em; line-height: 1; margin-top: 4px; }
.pot-center > small { color: #d0b8ae; font-size: 11px; margin-top: 7px; text-align: center; }

.pot-center > button {
  background: var(--gold);
  border: 0;
  border-radius: 999px;
  color: #3c2213;
  font-size: 12px;
  font-weight: 800;
  margin-top: 14px;
  min-height: 42px;
  padding: 10px 17px;
}

.pot-center > button:hover:not(:disabled) { background: #f0bd70; }
.pot-center > button:disabled { opacity: 0.58; }
.entry-status { color: #c4aaa0; font-size: 10px; margin-top: 8px; min-height: 15px; text-align: center; }

.ledger { margin: 0 auto; max-width: 1280px; padding: 28px clamp(18px, 4vw, 44px) 34px; }
.ledger-heading { align-items: flex-end; display: flex; justify-content: space-between; margin-bottom: 16px; }
.ledger-heading h2 { font-size: 30px; margin: 3px 0 0; }
.ledger-heading p { color: var(--muted); font-size: 12px; margin: 5px 0 0; }

.outline-button { background: transparent; border: 1px solid #d6c7b4; color: var(--ink); font-size: 12px; }
.outline-button:hover { background: #fff8ee; }

.tally-card,
.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.tally-card { padding: 16px 18px; }
.tally-labels { color: #917b6f; display: grid; font-size: 11px; grid-template-columns: minmax(190px, 0.8fr) minmax(160px, 1fr) 70px 65px; padding: 0 8px 9px 32px; }
.tally-labels span:nth-child(3), .tally-labels span:nth-child(4) { text-align: right; }
.tally-list { display: flex; flex-direction: column; gap: 4px; }

.tally-row {
  align-items: center;
  border-radius: 12px;
  display: grid;
  font-size: 12px;
  gap: 8px;
  grid-template-columns: 18px 32px minmax(70px, 110px) 48px minmax(120px, 1fr) 50px 55px;
  min-height: 48px;
  padding: 6px 8px;
}

.tally-row:first-child { background: #f5eadb; }
.tally-row .avatar { height: 30px; width: 30px; }
.rank { color: #9b8376; text-align: center; }
.tally-row > strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leader-badge { background: #f5dca9; border-radius: 999px; color: #855207; font-size: 9px; font-style: normal; padding: 4px 6px; text-align: center; }
.contribution-track { background: #eaded0; border-radius: 999px; height: 7px; overflow: hidden; }
.contribution-track i { background: #b46f43; border-radius: inherit; display: block; height: 100%; transition: width 0.22s ease; }
.loss-count { color: #716057; text-align: right; }
.loss-amount { text-align: right; }

.empty-row { color: var(--muted); font-size: 13px; padding: 28px 12px; text-align: center; }

.ledger-cards { display: grid; gap: 12px; grid-template-columns: 0.8fr 1.2fr 1fr; margin-top: 12px; }
.info-card { padding: 17px 18px; }
.card-top { align-items: flex-start; display: flex; justify-content: space-between; }
.card-top h3 { font-size: 20px; margin: 3px 0 0; }
.amount-pill { background: #f0e4d4; border-radius: 999px; color: #705c50; font-size: 10px; padding: 6px 8px; }
.info-card > p { color: #76645a; font-size: 12px; margin: 11px 0; }
.info-card > button:not(.icon-button) { background: transparent; border: 0; color: var(--wine); font-size: 11px; padding: 0; }

.lifetime-grid { display: grid; grid-template-columns: repeat(2, 1fr); margin-top: 12px; }
.lifetime-grid > div { border-left: 1px solid #e7dbcc; border-top: 1px solid #e7dbcc; display: flex; flex-direction: column; padding: 11px; }
.lifetime-grid > div:nth-child(odd) { border-left: 0; padding-left: 0; }
.lifetime-grid > div:nth-child(-n + 2) { border-top: 0; padding-top: 0; }
.lifetime-grid span { color: #846f63; font-size: 11px; }
.lifetime-grid strong { font-family: Georgia, "Times New Roman", serif; font-size: 17px; margin-top: 4px; }

.icon-button,
.close-button { align-items: center; background: transparent; border: 0; color: inherit; display: inline-flex; justify-content: center; }
.icon-button { min-height: 36px; min-width: 36px; }
.activity-list { display: flex; flex-direction: column; margin-top: 8px; }
.activity-item { align-items: center; border-top: 1px solid #eadfd2; display: grid; gap: 8px; grid-template-columns: 30px 1fr auto auto; min-height: 50px; padding: 8px 0; }
.activity-item:first-child { border-top: 0; }
.activity-item .avatar { height: 29px; width: 29px; }
.activity-item p { display: flex; flex-direction: column; margin: 0; min-width: 0; }
.activity-item p strong { font-size: 11px; }
.activity-item p span { color: #88756a; font-size: 9px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-item > b { color: var(--green); font-size: 11px; }
.remove-loss { background: transparent; border: 0; color: var(--danger); font-size: 10px; padding: 6px; }
.activity-empty { color: var(--muted); font-size: 12px; padding: 18px 0 6px; }

dialog {
  background: transparent;
  border: 0;
  color: var(--ink);
  max-height: calc(100vh - 32px);
  max-width: min(520px, calc(100vw - 28px));
  padding: 0;
  width: 100%;
}

dialog::backdrop { background: rgba(29, 17, 13, 0.68); backdrop-filter: blur(4px); }
.dialog-card { background: #fffaf3; border: 1px solid #e1d4c2; border-radius: 22px; box-shadow: 0 24px 70px rgba(20, 10, 6, 0.36); display: flex; flex-direction: column; margin: 0; max-height: calc(100vh - 32px); padding: 22px; }
.dialog-heading { align-items: flex-start; display: flex; justify-content: space-between; }
.dialog-heading h2 { font-size: 25px; margin: 3px 0 0; }
.close-button { background: #f1e7db; border-radius: 50%; font-size: 22px; height: 36px; width: 36px; }
.dialog-copy { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 12px 0 18px; }
.dialog-card label { color: #5d4d44; display: flex; flex-direction: column; font-size: 12px; font-weight: 700; gap: 7px; margin-bottom: 14px; }
.dialog-card input { background: #fff; border: 1px solid #d8cab8; border-radius: 11px; color: var(--ink); font-size: 16px; min-height: 46px; padding: 10px 12px; width: 100%; }
.money-input { align-items: center; background: #fff; border: 1px solid #d8cab8; border-radius: 11px; display: flex; }
.money-input > span { color: #806c61; padding-left: 12px; }
.money-input input { border: 0; }
.form-error { color: var(--danger); font-size: 12px; margin: -3px 0 11px; min-height: 18px; }
.primary-button { background: var(--wine); border: 0; color: #fff9f0; font-size: 13px; width: 100%; }
.primary-button:hover { background: #81283f; }
.primary-button:disabled { opacity: 0.6; }

.history-dialog { max-width: min(720px, calc(100vw - 28px)); }
.history-list { display: flex; flex-direction: column; min-height: 100px; overflow: auto; }
.history-item { align-items: center; border-top: 1px solid #eadfd2; display: grid; gap: 10px; grid-template-columns: 36px 1fr auto auto; padding: 11px 0; }
.history-item:first-child { border-top: 0; }
.history-item p { display: flex; flex-direction: column; margin: 0; }
.history-item p strong { font-size: 13px; }
.history-item p span { color: var(--muted); font-size: 11px; margin-top: 3px; }
.history-item > b { color: var(--green); font-size: 12px; }
.history-empty { color: var(--muted); padding: 26px 0; text-align: center; }

.toast {
  background: #2d211b;
  border-radius: 12px;
  bottom: 22px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.26);
  color: #fff8ef;
  font-size: 13px;
  left: 50%;
  max-width: calc(100vw - 32px);
  opacity: 0;
  padding: 12px 16px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 14px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
}

.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: #7c2630; }

@media (max-width: 900px) {
  .game-heading { align-items: flex-start; flex-direction: column; }
  .game-actions { justify-content: flex-start; width: 100%; }
  .ledger-cards { grid-template-columns: 1fr 1fr; }
  .activity-card { grid-column: 1 / -1; }
}

@media (max-width: 680px) {
  .game-night { padding: 22px 14px 24px; }
  .game-heading { gap: 17px; }
  .game-actions { align-items: stretch; display: grid; grid-template-columns: 1fr 1fr; }
  .last-settled { grid-column: 1 / -1; }
  .session-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .soft-button, .light-button { width: 100%; }
  .table-shell { padding: 0; }
  .game-table { border-radius: 58px; display: grid; gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); height: auto; min-height: 440px; padding: 24px 18px; }
  .game-table::before { border-radius: 40px; inset: 12px; }
  .player-seats { display: contents; }
  .player-seat { left: auto !important; position: static; top: auto !important; transform: none; z-index: 3; }
  .player-seat button { max-width: none; min-height: 52px; min-width: 0; width: 100%; }
  .pot-center { grid-column: 1 / -1; grid-row: 1; left: auto; padding: 12px 0 20px; position: relative; top: auto; transform: none; width: auto; }
  .pot-center > strong { font-size: 56px; }
  .ledger { padding: 24px 14px 28px; }
  .ledger-heading { align-items: flex-start; gap: 12px; }
  .outline-button { align-self: flex-end; }
  .tally-labels { display: none; }
  .tally-card { padding: 12px; }
  .tally-row { grid-template-columns: 16px 31px minmax(60px, 90px) minmax(55px, 1fr) 36px 46px; }
  .tally-row .leader-badge, .tally-row > span:nth-child(4) { display: none; }
  .ledger-cards { grid-template-columns: 1fr; }
  .activity-card { grid-column: auto; }
}

@media (max-width: 430px) {
  .game-actions { grid-template-columns: 1fr; }
  .last-settled { grid-column: auto; }
  .game-table { padding: 22px 12px; }
  .player-seat button { gap: 6px; padding: 7px; }
  .player-seat .avatar { height: 30px; width: 30px; }
  .seat-copy small { font-size: 9px; }
  .ledger-heading { flex-direction: column; }
  .outline-button { align-self: flex-start; }
  .tally-row { grid-template-columns: 14px 30px minmax(60px, 1fr) 34px 42px; }
  .tally-row .contribution-track { display: none; }
  .activity-item { grid-template-columns: 30px 1fr auto; }
  .activity-item .remove-loss { grid-column: 2 / -1; justify-self: start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
