:root {
  color-scheme: light;
  --bg: #f5f0e4;
  --bg-glow: rgba(176, 208, 173, 0.34);
  --page-surface: #ffffff;
  --panel-soft: #eef5f8;
  --panel-active: #e5f4ef;
  --border: #c8d9e2;
  --border-strong: #8ed9eb;
  --text: #133942;
  --muted: #4a8090;
  --primary: #2399a6;
  --primary-strong: #1e8c97;
  --primary-soft: #b7dde0;
  --phase-set: #ff9a6d;
  --phase-run: #2399a6;
  --danger: #f22823;
  --danger-soft: #ffe3e0;
  --accent-warm: #ff8a4b;
  --notice: #fed050;
  --notice-soft: #fff5d6;
  --shadow-card: 0 14px 32px rgba(24, 67, 77, 0.12);
  --shadow-soft: 0 10px 22px rgba(24, 67, 77, 0.08);
  --radius-shell: 28px;
  --radius-card: 18px;
  --radius-pill: 999px;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 50% 20%, rgba(193, 221, 190, 0.38), transparent 26%),
    radial-gradient(circle at 50% 50%, rgba(250, 234, 188, 0.3), transparent 48%),
    linear-gradient(180deg, #f7f2e8 0%, var(--bg) 100%);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

input {
  touch-action: manipulation;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

#app {
  min-height: 100vh;
}

.page {
  width: min(calc(100% - 22px), 1920px);
  margin: 0 auto;
}

.button {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 16px;
  padding: 14px 20px;
  color: var(--text);
  background: var(--page-surface);
  box-shadow: var(--shadow-soft);
  transition:
    transform 140ms ease,
    box-shadow 140ms ease,
    background-color 140ms ease,
    border-color 140ms ease,
    color 140ms ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  box-shadow: none;
}

.player-token,
.phase-player-dot {
  display: inline-block;
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-pill);
  background: var(--player-color);
  border: 1px solid rgba(19, 57, 66, 0.12);
}

.player-token-large {
  width: 32px;
  height: 32px;
}

.player-name-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 14px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.dealer-badge,
.winner-badge {
  color: #ffffff;
  background: var(--primary);
}

.text-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  color: var(--text);
  background: #fffdf8;
  box-shadow: 0 2px 8px rgba(24, 67, 77, 0.08);
}

.text-input:focus {
  outline: 2px solid rgba(35, 153, 166, 0.24);
  outline-offset: 2px;
}

.page-setup {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.setup-shell {
  width: min(840px, 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-shell);
  background: var(--page-surface);
  box-shadow: 0 20px 40px rgba(24, 67, 77, 0.16);
  padding: 30px 40px 40px;
}

.setup-header {
  text-align: center;
  margin-bottom: 28px;
}

.setup-header h1 {
  margin: 0;
  color: var(--primary);
  font-size: clamp(3rem, 6vw, 4.2rem);
  line-height: 0.98;
  letter-spacing: -0.04em;
}

.setup-header p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: clamp(1.5rem, 2vw, 1.8rem);
}

.setup-count-card {
  border-radius: 18px;
  background: #f1f6f9;
  padding: 34px 24px 28px;
}

.setup-count-card h2 {
  margin: 0;
  text-align: center;
  font-size: clamp(1.8rem, 2vw, 2.3rem);
}

.setup-count-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 46px;
  margin-top: 24px;
}

.count-control-button {
  width: 62px;
  height: 62px;
  padding: 0;
  border-color: #a9dceb;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  font-size: 2rem;
  box-shadow: inset 0 0 0 1px rgba(169, 220, 235, 0.16);
}

.setup-count-value {
  min-width: 72px;
  text-align: center;
  font-size: clamp(3.5rem, 7vw, 4.6rem);
  font-weight: 800;
  letter-spacing: -0.04em;
}

.saved-game-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px 20px;
  background: #fffdf8;
}

.saved-game-banner p {
  margin: 6px 0 0;
  color: var(--muted);
}

.saved-game-actions {
  display: flex;
  gap: 12px;
}

.setup-player-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px 18px;
  margin-top: 26px;
}

.setup-player-field {
  display: flex;
  align-items: center;
  gap: 16px;
}

.setup-player-input {
  font-size: 1.05rem;
}

.setup-start-button {
  width: 100%;
  margin-top: 28px;
  border-color: rgba(25, 123, 134, 0.26);
  color: #ffffff;
  background: var(--primary);
  box-shadow: 0 16px 26px rgba(35, 153, 166, 0.24);
  font-size: 1.2rem;
  font-weight: 800;
  padding-block: 20px;
}

.page-game {
  min-height: 100vh;
  padding: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(10px);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar-brand h1 {
  margin: 0;
  color: var(--primary);
  font-size: clamp(1.9rem, 3vw, 2.6rem);
  letter-spacing: -0.05em;
}

.topbar-brand p {
  margin: 0;
  color: #3b6f82;
  font-size: 1.2rem;
}

.topbar-divider {
  width: 1px;
  height: 26px;
  background: var(--border);
}

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

.toolbar-button,
.enter-scores-button {
  min-width: 110px;
  padding: 12px 18px;
  border-color: var(--border);
  background: #ffffff;
  font-weight: 700;
}

.dealer-toolbar-button {
  min-width: 138px;
}

.dealer-toolbar-button-on {
  border-color: #e2bd4a;
  background: var(--notice);
  color: #19313a;
}

.enter-scores-button {
  min-width: 142px;
  color: #ffffff;
  border-color: rgba(35, 153, 166, 0.3);
  background: var(--primary);
}

.scoreboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(320px, 0.8fr);
  gap: 0;
  align-items: start;
  min-height: calc(100vh - 62px);
}

.scoreboard-column {
  display: grid;
  align-content: start;
  gap: 2px;
  padding: 8px 8px 6px;
}

.player-overview-shell {
  border: 1px solid transparent;
  border-radius: 18px;
}

.player-overview-shell-expanded {
  border-color: #d8e7ed;
  background: rgba(255, 255, 255, 0.72);
}

.player-overview-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 96px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #ffffff;
  padding: 14px 20px 14px 16px;
  width: 100%;
  text-align: left;
}

.player-overview-card-active {
  background: #eaf7f1;
  border-color: #22d0ea;
  box-shadow: inset 0 0 0 1px rgba(34, 208, 234, 0.16);
}

.player-overview-copy {
  min-width: 0;
}

.player-overview-identity {
  display: grid;
  grid-template-columns: minmax(120px, 180px) minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.player-name-block {
  min-width: 0;
}

.player-overview-name {
  margin: 0;
  color: var(--player-color);
  font-size: clamp(1.5625rem, 2.375vw, 2.1875rem);
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.player-phase-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  margin-top: 0;
}

.player-overview-dealer-badge {
  margin-top: 6px;
  padding: 3px 8px;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
}

.phase-number-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-width: 35px;
  height: 35px;
  margin-top: 2px;
  border-radius: 8px;
  background: #edf4f6;
  color: var(--primary);
  font-size: 1.25rem;
  font-weight: 800;
}

.player-phase-text {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.16em 0.28em;
  min-width: 0;
  color: var(--text);
  font-size: clamp(2.0625rem, 2.6875vw, 2.6875rem);
  font-weight: 650;
  line-height: 1.12;
}

.player-overview-score,
.round-entry-score,
.winner-score-value,
.scoreboard-total {
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.05em;
}

.player-overview-score {
  font-size: clamp(3.25rem, 5vw, 4.5rem);
  font-weight: 800;
}

.player-overview-meta {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.player-history-toggle {
  color: var(--muted);
  font-size: 1.075rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.player-history-panel {
  margin: -6px 10px 10px;
  border: 1px solid #dbe7ec;
  border-top: 0;
  border-radius: 0 0 18px 18px;
  background: #f8fbfc;
  padding: 14px 16px 16px;
}

.player-history-title {
  margin: 0 0 10px;
  color: #4f8293;
  font-size: 0.92rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.player-history-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.player-history-row {
  display: grid;
  grid-template-columns: minmax(74px, auto) minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border-radius: 12px;
  background: #ffffff;
  padding: 10px 12px;
}

.player-history-round {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.player-history-score {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.history-bonus-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  padding: 4px 9px;
  background: var(--notice-soft);
  color: #6b5f1d;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.player-history-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  min-width: 62px;
  padding: 6px 10px;
  color: #ffffff;
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
}

.player-history-status-pass {
  background: var(--primary);
}

.player-history-status-fail {
  background: var(--danger);
}

.player-history-empty {
  margin: 0;
  color: var(--muted);
}

.phase-reference-panel {
  border-left: 1px solid var(--border);
  padding: 8px 10px 8px 8px;
}

.phase-reference-panel h2 {
  margin: 0 0 6px;
  padding-left: 6px;
  color: #4f8293;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.phase-reference-list {
  display: grid;
  align-content: start;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.phase-reference-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  border: 1px solid #d7e2e7;
  border-radius: 12px;
  background: #ffffff;
  padding: 8px 12px;
}

.phase-reference-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: #edf4f6;
  color: #5a8795;
  font-size: 1.1rem;
  font-weight: 800;
}

.phase-reference-text {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.14em 0.24em;
  min-width: 0;
  font-size: 1.08rem;
  font-weight: 800;
  line-height: 1.14;
}

.phase-fragment {
  display: inline-flex;
  align-items: baseline;
  white-space: nowrap;
}

.phase-fragment-set {
  color: var(--phase-set);
}

.phase-fragment-run {
  color: var(--phase-run);
}

.phase-fragment-separator {
  letter-spacing: -0.03em;
}

.phase-reference-players {
  display: flex;
  gap: 6px;
  min-height: 12px;
}

.phase-player-dot {
  width: 16px;
  height: 16px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(20, 45, 52, 0.18);
  z-index: 30;
}

.modal-shell {
  width: min(1120px, calc(100% - 28px));
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: #ffffff;
  box-shadow: 0 26px 50px rgba(24, 67, 77, 0.18);
}

.discard-confirmation-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 45, 52, 0.42);
}

.discard-confirmation {
  width: min(440px, 100%);
  border: 1px solid var(--border);
  border-radius: 22px;
  background: #ffffff;
  padding: 28px;
  box-shadow: 0 26px 50px rgba(24, 67, 77, 0.24);
}

.discard-confirmation h2 { margin: 0; font-size: 1.5rem; }
.discard-confirmation p { color: var(--muted); line-height: 1.4; }
.discard-confirmation-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 24px; }
.discard-confirmation-actions .button { flex: 1 1 150px; padding: 12px; border-radius: 12px; font-weight: 800; }
.discard-confirm-button { background: var(--danger); color: #ffffff; }

.modal-header,
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px;
}

.modal-header {
  align-items: flex-start;
  border-bottom: 1px solid var(--border);
}

.modal-body {
  min-height: 0;
  flex: 1 1 auto;
  padding: 18px 24px 22px;
  overflow: auto;
}

.modal-copy {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 1rem;
}

.icon-button {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  padding: 0;
  border-color: transparent;
  box-shadow: none;
  color: var(--muted);
  font-size: 2rem;
  line-height: 1;
  background: transparent;
}

.round-modal-header h2,
.final-scoreboard-header h2 {
  margin: 0;
  color: var(--primary);
  font-size: clamp(2rem, 3vw, 2.7rem);
  letter-spacing: -0.05em;
}

.round-modal-header {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: space-between;
  padding-top: 16px;
  padding-bottom: 16px;
}

.round-modal-header > :first-child {
  min-width: 0;
}

.round-modal-header .icon-button {
  margin-top: -2px;
  align-self: flex-start;
}

.round-modal-body {
  padding-top: 12px;
  padding-bottom: 14px;
}

.round-modal-content {
  display: grid;
  gap: 20px;
}

.round-entry-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(248px, 0.42fr);
  gap: 24px;
  align-items: center;
  border: 1px solid #b7e5f2;
  border-radius: 20px;
  background: #ffffff;
  padding: 20px 20px 20px 22px;
}

.round-entry-row-dealer {
  background: #f3fbff;
}

.round-entry-player {
  min-width: 0;
}

.round-entry-name-block {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.round-entry-name {
  margin: 0;
  color: var(--player-color);
  font-size: clamp(1.7rem, 2.4vw, 2rem);
}

.round-entry-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.modal-dealer-bonus-badge {
  color: #6b5f1d;
  background: var(--notice-soft);
  border: 1px solid #efd8a2;
}

.round-entry-main {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.round-entry-controls {
  display: flex;
  align-items: center;
  gap: 14px 18px;
  min-width: 0;
}

.sign-toggle {
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  padding: 0;
  border-radius: var(--radius-pill);
  font-size: 2rem;
  line-height: 1;
}

.sign-toggle-positive {
  border-color: #d4e4ea;
  background: #ffffff;
}

.sign-toggle-negative {
  color: #ffffff;
  background: var(--danger);
}

.score-chip-row {
  display: flex;
  flex-wrap: wrap;
  flex: 1 1 auto;
  gap: 10px;
  min-width: 0;
}

.score-chip {
  min-width: 42px;
  padding: 14px 15px;
  border-color: #f38b52;
  color: #102d38;
  background: var(--accent-warm);
  box-shadow: none;
  font-size: 1.1rem;
  font-weight: 800;
}

.round-entry-score {
  min-width: 98px;
  flex: 0 0 auto;
  text-align: center;
  font-size: clamp(2rem, 3vw, 3rem);
  font-weight: 800;
}

.round-entry-actions {
  display: grid;
  gap: 12px;
  align-self: center;
  align-content: start;
}

.round-entry-status-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 12px;
  min-width: 0;
  align-items: start;
}

.status-button {
  min-height: 52px;
  padding-block: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  box-shadow: none;
}

.status-button-neutral {
  border-color: #d8e2e7;
  color: #617b85;
  background: #ffffff;
}

.status-button-pass-active {
  color: #ffffff;
  border-color: rgba(35, 153, 166, 0.26);
  background: var(--primary);
}

.status-button-fail-active {
  color: #ffffff;
  border-color: rgba(242, 40, 35, 0.26);
  background: var(--danger);
}

.dealer-bonus-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-color: #efd8a2;
  background: #fff8e2;
  box-shadow: none;
  color: #5f5a2e;
  font-weight: 800;
}

.dealer-bonus-copy {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.dealer-bonus-icon {
  font-size: 1rem;
}

.dealer-bonus-button-on {
  border-color: #e2bd4a;
  background: var(--notice);
  color: #19313a;
}

.dealer-bonus-helper {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid #f2d898;
  border-radius: 14px;
  background: var(--notice-soft);
  padding: 14px 16px;
  color: var(--text);
  font-size: 0.98rem;
}

.dealer-bonus-helper strong {
  color: #f29f7d;
}

.dealer-bonus-helper-icon {
  font-size: 1.1rem;
}

.round-modal-footer {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
}

.modal-validation {
  margin: 0;
  font-size: 1rem;
}

.modal-validation-error {
  color: var(--danger);
}

.modal-validation-ready {
  color: var(--muted);
}

.submit-round-button {
  min-width: 255px;
  border-color: rgba(35, 153, 166, 0.22);
  color: #ffffff;
  background: var(--primary);
  font-size: 1.25rem;
  font-weight: 800;
  padding-block: 18px;
}

.submit-round-button:disabled {
  background: #8bcbd0;
  color: rgba(255, 255, 255, 0.9);
}

.page-winner {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px 18px 22px;
  overflow: hidden;
}

.page-winner::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at center, color-mix(in srgb, var(--winner-color) 32%, white) 0%, transparent 34%),
    radial-gradient(circle at center, rgba(255, 230, 182, 0.24) 0%, transparent 52%);
  pointer-events: none;
  z-index: 0;
}

.winner-stage {
  position: relative;
  z-index: 2;
  width: min(880px, 100%);
  display: grid;
  justify-items: center;
  gap: 12px;
  text-align: center;
}

.winner-trophy {
  display: grid;
  place-items: center;
  width: 104px;
  height: 104px;
  border: 4px solid #ffffff;
  border-radius: var(--radius-pill);
  background: var(--winner-color);
  color: #ffffff;
  box-shadow: 0 18px 34px rgba(161, 204, 166, 0.34);
  font-size: 2.85rem;
}

.page-winner h1 {
  margin: 0;
  color: var(--text);
  font-size: clamp(2.9rem, 6vw, 4.4rem);
  line-height: 0.96;
  letter-spacing: -0.06em;
}

.winner-nameplate {
  margin: 0 0 6px;
  color: var(--winner-color);
  text-shadow: 0 5px 14px rgba(117, 173, 121, 0.32);
  font-size: clamp(3rem, 7vw, 4.9rem);
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: -0.08em;
}

.winner-score-card {
  width: min(550px, 100%);
  display: grid;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: #ffffff;
  padding: 26px 24px;
  box-shadow: var(--shadow-card);
}

.winner-score-label {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.winner-score-value {
  font-size: clamp(3.8rem, 7vw, 5.5rem);
  font-weight: 900;
}

.winner-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
}

.winner-secondary-button,
.winner-primary-button,
.scoreboard-close-button {
  min-width: 268px;
  border-radius: 999px;
  padding-block: 15px;
  font-size: 1.05rem;
  font-weight: 800;
}

.winner-secondary-button {
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.92);
}

.winner-primary-button,
.scoreboard-close-button {
  color: #ffffff;
  background: var(--primary);
}

.final-scoreboard-modal {
  width: min(640px, calc(100% - 20px));
}

.final-scoreboard-body {
  display: grid;
  gap: 12px;
}

.scoreboard-detail-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) minmax(128px, auto) auto;
  align-items: center;
  gap: 16px;
  border: 1px solid #d6e3e8;
  border-radius: 18px;
  background: #ffffff;
  padding: 14px 16px;
}

.scoreboard-detail-row-winner {
  border-color: #9fd5a8;
  box-shadow: inset 0 0 0 1px rgba(159, 213, 168, 0.6);
}

.scoreboard-rank {
  color: #4c8697;
  font-size: 1.35rem;
  font-weight: 800;
  text-align: center;
}

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

.scoreboard-player-copy {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.scoreboard-player-copy strong {
  color: var(--player-color);
  font-size: 1.2rem;
}

.scoreboard-phase-status {
  display: grid;
  gap: 4px;
  color: var(--primary);
  justify-items: start;
}

.scoreboard-phase-status span {
  color: var(--muted);
}

.scoreboard-total {
  font-size: 2rem;
  font-weight: 900;
}

.final-scoreboard-footer {
  justify-content: stretch;
}

.scoreboard-close-button {
  width: 100%;
}

.confetti-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}

.confetti-piece {
  position: absolute;
  top: -40px;
  left: var(--confetti-left);
  width: 14px;
  height: 24px;
  border-radius: 4px;
  background: var(--confetti-color);
  opacity: 1;
  transform: translate3d(0, 0, 0) rotate(var(--confetti-rotation));
}

.confetti-layer-playing .confetti-piece {
  animation: confetti-fall var(--confetti-duration) linear var(--confetti-delay) forwards;
}

.confetti-layer-reduced .confetti-piece {
  top: 10%;
  opacity: 0.85;
  transform: rotate(var(--confetti-rotation));
}

.confetti-layer-reduced .confetti-piece:nth-child(3n) { top: 24%; }
.confetti-layer-reduced .confetti-piece:nth-child(4n) { top: 48%; }
.confetti-layer-reduced .confetti-piece:nth-child(5n) { top: 72%; }

.confetti-layer-reduced::after {
  content: "";
  position: absolute;
  inset: 6% 18%;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.46), transparent 64%);
}

@keyframes confetti-fall {
  0% {
    opacity: 0;
    transform: translate3d(0, 0, 0) rotate(var(--confetti-rotation));
  }

  10% {
    opacity: 1;
  }

  100% {
    opacity: 0.96;
    transform: translate3d(var(--confetti-drift), var(--confetti-fall-distance), 0) rotate(var(--confetti-end-rotation));
  }
}

@media (prefers-reduced-motion: reduce) {
  .button,
  .confetti-piece {
    transition: none;
    animation: none;
  }

  .confetti-layer-playing .confetti-piece { animation: none; }
}

@media (max-width: 1024px) {
  .scoreboard-grid {
    grid-template-columns: 1fr;
  }

  .phase-reference-panel {
    border-left: 0;
    border-top: 1px solid var(--border);
  }

  .round-entry-row {
    grid-template-columns: 1fr;
  }

  .round-entry-actions,
  .round-entry-status-panel {
    grid-template-columns: 1fr 1fr;
  }

  .dealer-bonus-button {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .setup-shell {
    padding: 22px 20px 24px;
  }

  .setup-player-grid,
  .scoreboard-detail-row {
    grid-template-columns: 1fr;
  }

  .saved-game-banner,
  .modal-header,
  .modal-footer,
  .winner-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
  }

  .topbar-brand {
    flex: 1 1 auto;
    flex-wrap: nowrap;
    gap: 8px;
    min-width: 0;
  }

  .topbar-brand h1 {
    font-size: 1.35rem;
  }

  .topbar-brand p {
    min-width: 0;
    font-size: 0.95rem;
    white-space: nowrap;
  }

  .topbar-divider {
    height: 18px;
  }

  .topbar-actions {
    flex: 0 0 auto;
    gap: 8px;
  }

  .player-overview-card {
    gap: 10px;
    min-height: 78px;
    padding: 10px 14px 10px 12px;
  }

  .player-overview-meta {
    gap: 4px;
  }

  .player-name-row {
    gap: 10px;
  }

  .player-overview-identity {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .player-overview-name {
    font-size: 1.25rem;
  }

  .badge {
    padding: 4px 8px;
    font-size: 0.72rem;
  }

  .player-overview-dealer-badge {
    margin-top: 4px;
    padding: 2px 7px;
    font-size: 0.775rem;
  }

  .player-phase-row {
    gap: 6px;
    margin-top: 0;
  }

  .phase-number-chip {
    min-width: 30px;
    height: 30px;
    font-size: 1.125rem;
  }

  .player-phase-text {
    font-size: 1.875rem;
  }

  .player-overview-score {
    font-size: 2.875rem;
  }

  .toolbar-button,
  .enter-scores-button {
    min-width: 92px;
    padding: 10px 12px;
    font-size: 0.95rem;
  }

  .dealer-toolbar-button {
    min-width: 116px;
  }

  .enter-scores-button {
    min-width: 118px;
  }

  .round-modal-header {
    flex-direction: row;
    align-items: flex-start;
  }

  .round-entry-controls,
  .round-entry-actions,
  .round-entry-status-panel {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: stretch;
  }

  .round-entry-score {
    text-align: left;
  }

  .player-history-row {
    grid-template-columns: 1fr;
    justify-items: start;
  }
}

@media (max-width: 600px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

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

  .topbar-actions .button {
    min-width: 0;
    width: 100%;
  }
}

@media (max-height: 820px) {
  .page-winner {
    padding: 12px 16px 16px;
  }

  .winner-stage {
    gap: 8px;
  }

  .winner-trophy {
    width: 88px;
    height: 88px;
    font-size: 2.35rem;
  }

  .page-winner h1 {
    font-size: clamp(2.4rem, 5vw, 3.6rem);
  }

  .winner-nameplate {
    margin-bottom: 8px;
    font-size: clamp(2.4rem, 6vw, 4rem);
  }

  .winner-score-card {
    gap: 8px;
    padding: 18px 20px;
  }

  .winner-score-label {
    font-size: 0.92rem;
  }

  .winner-score-value {
    font-size: clamp(3rem, 6vw, 4.6rem);
  }

  .winner-actions {
    gap: 10px;
  }

  .winner-secondary-button,
  .winner-primary-button,
  .scoreboard-close-button {
    min-width: 220px;
    padding-block: 13px;
    font-size: 0.98rem;
  }
}

@media (orientation: landscape) and (min-width: 900px) and (max-width: 1400px) {
  .page-game {
    width: min(calc(100% - 10px), 1400px);
  }

  .scoreboard-grid {
    grid-template-columns: minmax(0, 1.55fr) minmax(300px, 0.75fr);
  }

  .player-overview-card {
    min-height: 88px;
  }

  .player-overview-identity {
    grid-template-columns: minmax(108px, 172px) minmax(0, 1fr);
    gap: 12px;
  }

  .player-overview-name {
    font-size: 1.6875rem;
  }

  .player-phase-text {
    font-size: 2.025rem;
  }

  .player-overview-score {
    font-size: 3.625rem;
  }

  .phase-reference-card {
    min-height: 52px;
  }
}
