@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Playfair+Display:wght@700&display=swap');

:root {
  --ink: #17201d;
  --muted: #6f7975;
  --green: #173b33;
  --green-light: #265c4f;
  --cream: #f4f0e7;
  --paper: #fffcf5;
  --gold: #d8ad5c;
  --red: #a4423a;
  --line: rgba(23, 59, 51, .13);
  --shadow: 0 18px 50px rgba(31, 45, 40, .09);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 10%, rgba(216, 173, 92, .18), transparent 26rem),
    linear-gradient(145deg, #f8f4eb, #eee9df);
  font-family: "DM Sans", system-ui, sans-serif;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { width: min(1080px, calc(100% - 32px)); margin: 0 auto; padding: 32px 0 64px; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 42px; }
.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark { display: grid; place-items: center; width: 48px; height: 48px; color: var(--paper); background: var(--green); border-radius: 50%; font-size: 25px; }
h1, h2, h3, p { margin-top: 0; }
h1, h2 { font-family: "Playfair Display", Georgia, serif; }
h1 { margin-bottom: 0; font-size: 30px; line-height: 1; }
h2 { margin-bottom: 10px; font-size: clamp(28px, 4vw, 42px); line-height: 1.12; }
h3 { margin-bottom: 5px; font-size: 18px; }
.eyebrow { margin-bottom: 5px; color: var(--green-light); font-size: 11px; font-weight: 700; letter-spacing: .15em; text-transform: uppercase; }
.hidden { display: none !important; }
.card { background: rgba(255, 252, 245, .9); border: 1px solid rgba(255,255,255,.8); border-radius: 24px; box-shadow: var(--shadow); }

.setup-card { display: grid; grid-template-columns: .85fr 1.15fr; gap: 64px; padding: clamp(28px, 5vw, 58px); }
.setup-copy p:last-child { max-width: 400px; color: var(--muted); line-height: 1.65; }
.player-inputs { display: grid; gap: 12px; }
.player-row { display: flex; gap: 10px; }
.player-row input { flex: 1; min-width: 0; }
input[type="text"], input[type="number"], select { width: 100%; padding: 14px 16px; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 12px; outline: none; transition: .2s; }
input:focus, select:focus { border-color: var(--green-light); box-shadow: 0 0 0 3px rgba(38, 92, 79, .12); }
select:disabled { color: var(--muted); background: var(--cream); cursor: not-allowed; }
.remove-player { width: 47px; flex: 0 0 47px; color: var(--muted); background: transparent; border: 0; border-radius: 12px; font-size: 22px; }
.remove-player:hover { color: var(--red); background: rgba(164,66,58,.08); }
.setup-actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 22px; }
.button { padding: 12px 18px; border: 0; border-radius: 12px; font-weight: 700; transition: transform .15s, background .15s; }
.button:hover { transform: translateY(-1px); }
.button-primary { color: #fff; background: var(--green); }
.button-primary:hover { background: var(--green-light); }
.button-secondary { color: var(--green); background: rgba(23,59,51,.08); }
.button-ghost { color: var(--green); background: transparent; border: 1px solid var(--line); }
.button-danger { color: #fff; background: var(--red); }
.error { min-height: 20px; margin: 12px 0 0; color: var(--red); font-size: 13px; font-weight: 600; }

.game-heading, .section-heading, .round-instructions, .history-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.game-heading { margin-bottom: 18px; }
.game-heading > div:first-child { flex: 1; min-width: 0; }
.game-heading h2, .section-heading h2 { margin-bottom: 0; }
.round-schedule { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.round-meta { display: flex; width: 100%; align-items: center; gap: 10px; margin-top: 9px; }
.first-bidder { display: inline-block; margin: 0; padding: 6px 10px; color: var(--green); background: rgba(216,173,92,.22); border-radius: 8px; font-size: 12px; font-weight: 700; }
.quick-ranking-button { margin-left: auto; border: 0; white-space: nowrap; }
.quick-ranking-button:hover { background: rgba(216,173,92,.35); }
.round-card { padding: clamp(22px, 4vw, 38px); }
.round-instructions { padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.round-instructions p { margin-bottom: 0; color: var(--muted); }
.tricks-progress { flex: none; padding: 8px 12px; background: var(--cream); border-radius: 9px; font-weight: 700; }
.round-grid { display: grid; grid-template-columns: minmax(130px, 1fr) 110px 110px; gap: 14px; align-items: center; }
.round-grid-header { padding: 20px 0 8px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.round-player { padding: 8px 0; }
.player-info { min-width: 0; }
.player-info strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.streaks { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.streaks:empty { display: none; }
.streak { padding: 3px 6px; border-radius: 6px; font-size: 9px; font-weight: 700; white-space: nowrap; }
.streak-win { color: var(--green-light); background: rgba(38,92,79,.09); }
.streak-loss { color: var(--red); background: rgba(164,66,58,.08); }
.round-player input, .round-player select { padding: 11px; text-align: center; }
.bid-hint { margin: 12px 0 0; color: var(--muted); font-size: 12px; }
.save-round { display: block; min-width: 180px; margin: 10px 0 0 auto; }

.score-section { margin-top: 46px; }
.section-heading { margin-bottom: 18px; }
.saved-status { color: var(--muted); font-size: 13px; }
.leaderboard { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 12px; margin-bottom: 18px; }
.leader { position: relative; overflow: hidden; padding: 20px; background: var(--green); border-radius: 18px; color: #fff; }
.leader:first-child { background: linear-gradient(135deg, #254f43, var(--green)); }
.leader:first-child::after { content: "♛"; position: absolute; right: 13px; top: 7px; color: var(--gold); font-size: 28px; opacity: .85; }
.leader-rank { color: rgba(255,255,255,.55); font-size: 12px; font-weight: 700; }
.leader-name { display: block; margin: 9px 0 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leader-score { color: var(--gold); font-family: "Playfair Display", serif; font-size: 28px; }
.history-card { padding: 26px; }
.history-heading { margin-bottom: 16px; }
.history-heading h3 { margin: 0; }
.text-button { padding: 5px; color: var(--red); background: transparent; border: 0; font-size: 13px; font-weight: 700; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { min-width: 105px; padding: 13px 12px; border-bottom: 1px solid var(--line); text-align: center; }
th:first-child, td:first-child { min-width: 75px; text-align: left; }
th { color: var(--muted); font-size: 12px; }
td { font-weight: 600; }
.score-positive { color: var(--green-light); }
.score-negative { color: var(--red); }
.bonus { display: block; margin-top: 3px; color: var(--gold); font-size: 11px; font-weight: 700; }
.streak-penalty { display: block; margin-top: 3px; color: var(--red); font-size: 11px; font-weight: 700; }
.empty-history { margin: 15px 0 0; padding: 24px; color: var(--muted); background: var(--cream); border-radius: 12px; text-align: center; }

.statistics-section { margin-top: 52px; }
.statistics-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px; }
.summary-card { padding: 19px 21px; background: var(--green); border-radius: 17px; color: #fff; }
.summary-card span { display: block; color: rgba(255,255,255,.6); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.summary-card strong { display: block; margin-top: 7px; color: var(--gold); font-family: "Playfair Display", serif; font-size: 27px; }
.stats-card { padding: 13px 20px; }
.completed-games { display: grid; gap: 10px; margin-top: 18px; }
.completed-game { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 20px; background: rgba(255,252,245,.72); border: 1px solid var(--line); border-radius: 15px; }
.completed-game p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.completed-game-result { flex: 1; color: var(--muted); font-size: 13px; text-align: right; }
.completed-game-result strong { color: var(--green); }

dialog { max-width: 430px; padding: 0; border: 0; border-radius: 22px; box-shadow: 0 30px 80px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15,27,23,.56); backdrop-filter: blur(3px); }
.dialog-card { padding: 34px; text-align: center; }
.dialog-icon { display: grid; place-items: center; width: 50px; height: 50px; margin: 0 auto 18px; color: #fff; background: var(--green); border-radius: 50%; font-size: 25px; }
.dialog-card h2 { font-size: 29px; }
.dialog-card p { color: var(--muted); }
.dialog-actions { display: flex; justify-content: center; gap: 10px; margin-top: 24px; }

.finish-dialog { width: min(520px, calc(100% - 28px)); max-width: 520px; color: var(--ink); background: transparent; overflow: visible; }
.finish-card { position: relative; overflow: hidden; padding: 38px; background: var(--paper); border-radius: 25px; text-align: center; }
.finish-card::before { content: ""; position: absolute; inset: 0 0 auto; height: 7px; background: linear-gradient(90deg, var(--green), var(--gold), var(--green)); }
.confetti { position: absolute; top: 20px; left: 24px; right: 24px; display: flex; justify-content: space-between; color: var(--gold); font-size: 20px; opacity: .5; }
.confetti span { color: var(--green-light); transform: translateY(10px); }
.winner-crown { display: grid; place-items: center; width: 68px; height: 68px; margin: 8px auto 16px; color: var(--gold); background: var(--green); border-radius: 50%; font-size: 37px; box-shadow: 0 12px 28px rgba(23,59,51,.22); }
.finish-card h2 { margin-bottom: 8px; font-size: 34px; }
.finish-subtitle { margin-bottom: 24px; color: var(--muted); }
.final-ranking { display: grid; gap: 8px; text-align: left; }
.final-player { display: grid; grid-template-columns: 35px 1fr auto; gap: 10px; align-items: center; padding: 12px 14px; background: var(--cream); border-radius: 12px; }
.final-player:first-child { color: #fff; background: var(--green); }
.final-player:first-child .final-score { color: var(--gold); }
.final-rank { color: var(--muted); font-size: 12px; font-weight: 700; }
.final-player:first-child .final-rank { color: rgba(255,255,255,.55); }
.final-score { color: var(--green-light); font-family: "Playfair Display", serif; font-size: 21px; }
.finish-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 24px; }
.finish-actions .text-button { grid-column: 1 / -1; justify-self: center; color: var(--muted); }

.leaderboard-dialog { width: min(460px, calc(100% - 28px)); max-width: 460px; padding: 0; color: var(--ink); background: transparent; overflow: visible; }
.leaderboard-dialog[open] { position: fixed; inset: 0; margin: auto; }
.leaderboard-dialog.dialog-fallback { z-index: 1000; display: block; }
.quick-ranking-card { padding: 29px; background: var(--paper); border-radius: 23px; }
.quick-ranking-heading { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 20px; }
.quick-ranking-heading h2 { margin: 0; font-size: 32px; }
.dialog-close { display: grid; place-items: center; width: 38px; height: 38px; padding: 0; color: var(--muted); background: var(--cream); border: 0; border-radius: 50%; font-size: 25px; }
.live-leaderboard { display: grid; gap: 8px; margin-bottom: 19px; }
.live-player { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 13px 15px; background: var(--cream); border-radius: 12px; }
.live-player:first-child { color: #fff; background: var(--green); }
.live-player-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-player-score { color: var(--green-light); font-family: "Playfair Display", serif; font-size: 22px; }
.live-player:first-child .live-player-score { color: var(--gold); }
.live-rank { color: var(--muted); font-size: 12px; font-weight: 700; }
.live-player:first-child .live-rank { color: rgba(255,255,255,.58); }
.quick-ranking-card > .button { width: 100%; }

@media (max-width: 700px) {
  .app-shell { width: min(100% - 22px, 1080px); padding-top: 18px; }
  .topbar { margin-bottom: 25px; }
  .setup-card { grid-template-columns: 1fr; gap: 25px; }
  .setup-actions { flex-direction: column-reverse; }
  .setup-actions .button { width: 100%; }
  .round-grid { grid-template-columns: minmax(100px, 1fr) 78px 78px; gap: 8px; }
  .round-instructions { align-items: flex-start; flex-direction: column; }
  .save-round { width: 100%; }
  .leaderboard { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .statistics-summary { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  body { background: #f3efe6; }
  .app-shell { width: 100%; padding: 14px 12px 38px; }
  .topbar { margin-bottom: 20px; padding: 0 3px; }
  .brand { gap: 10px; }
  .brand-mark { width: 42px; height: 42px; font-size: 22px; }
  .brand h1 { font-size: 25px; }
  .brand .eyebrow { font-size: 9px; }
  .topbar .button { padding: 10px 12px; font-size: 13px; }

  h2 { font-size: 29px; }
  .card { border-radius: 18px; box-shadow: 0 10px 30px rgba(31,45,40,.07); }
  .setup-card { padding: 24px 18px; }
  .player-row input { padding: 13px; }

  .game-heading { position: relative; align-items: flex-start; padding: 0 3px; }
  .game-heading h2 { font-size: 27px; }
  .round-meta { min-height: 30px; margin-top: 7px; padding-right: 96px; }
  .round-meta .first-bidder:not(button) { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .quick-ranking-button { position: absolute; right: 3px; bottom: 0; margin-left: 0; }
  .round-card { padding: 20px 14px; }
  .round-instructions { gap: 10px; padding-bottom: 14px; }
  .round-instructions h3 { font-size: 17px; }
  .round-instructions p:not(.tricks-progress) { font-size: 13px; line-height: 1.45; }
  .tricks-progress { align-self: stretch; text-align: center; }

  .round-grid { grid-template-columns: minmax(82px, 1fr) 72px 72px; gap: 7px; }
  .round-grid-header { padding-top: 16px; font-size: 9px; letter-spacing: .04em; }
  .round-player { padding: 6px 0; }
  .player-info strong { font-size: 14px; }
  .streaks { align-items: flex-start; flex-direction: column; gap: 3px; }
  .streak { max-width: 100%; overflow: hidden; padding: 2px 4px; font-size: 8px; text-overflow: ellipsis; }
  .round-player select { min-height: 44px; padding: 8px 5px; font-size: 16px; }
  .bid-hint { line-height: 1.4; }
  .save-round { min-height: 48px; margin-top: 5px; }

  .score-section { margin-top: 34px; }
  .section-heading { padding: 0 3px; }
  .section-heading h2 { font-size: 29px; }
  .saved-status { font-size: 11px; }
  .leaderboard { gap: 8px; }
  .leader { min-width: 0; padding: 16px 14px; border-radius: 15px; }
  .leader:first-child::after { right: 10px; font-size: 23px; }
  .leader-name { font-size: 14px; }
  .leader-score { font-size: 24px; }

  .history-card { padding: 19px 12px; }
  .history-heading { padding: 0 4px; }
  th, td { min-width: 92px; padding: 12px 8px; }
  th:first-child, td:first-child { position: sticky; left: 0; z-index: 1; min-width: 68px; background: var(--paper); }
  .empty-history { padding: 20px 12px; }
  .statistics-section { margin-top: 38px; }
  .statistics-summary { gap: 8px; }
  .summary-card { padding: 15px 17px; }
  .summary-card strong { font-size: 23px; }
  .stats-card { padding: 8px; }
  .completed-game { align-items: flex-start; flex-direction: column; gap: 8px; padding: 16px; }
  .completed-game-result { text-align: left; }

  dialog { width: calc(100% - 28px); }
  .dialog-card { padding: 28px 20px 22px; }
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions .button { width: 100%; min-height: 46px; }
  .finish-card { padding: 31px 17px 20px; border-radius: 20px; }
  .finish-card h2 { font-size: 29px; }
  .winner-crown { width: 59px; height: 59px; font-size: 32px; }
  .final-player { padding: 11px 12px; }
  .finish-actions { grid-template-columns: 1fr; }
  .finish-actions .button { min-height: 47px; }
  .finish-actions .text-button { grid-column: auto; }
  .quick-ranking-card { padding: 23px 16px 17px; border-radius: 19px; }
  .quick-ranking-heading h2 { font-size: 29px; }
  .live-player { padding: 12px; }
}
