:root {
  color-scheme: light;
  --bg: #f4f7f5;
  --surface: #ffffff;
  --text: #17211c;
  --muted: #66726c;
  --line: #dce4df;
  --green: #1d7f5f;
  --green-dark: #125a43;
  --green-soft: #e5f6ee;
  --yellow: #d6a400;
  --yellow-soft: #fff6cf;
  --gold: #d79a24;
  --orange: #ea7a18;
  --orange-soft: #fff0dc;
  --pink: #d9468f;
  --pink-soft: #ffe8f3;
  --lead-red: #d72f2f;
  --lead-red-soft: #ffe3e3;
  --light-purple: #9b5de5;
  --light-purple-soft: #f0e7ff;
  --dark-purple: #4c1d95;
  --dark-purple-soft: #eadcff;
  --blue: #2563eb;
  --blue-soft: #eef5ff;
  --red: #c2413a;
  --card-red: #d12f42;
  --soft-blue: #eef5ff;
  --soft-blue-text: #27405f;
  --input-bg: #fbfcfb;
  --close-bg: #5a655f;
  --shadow: 0 18px 45px rgba(23, 33, 28, 0.12);
}

body[data-theme="night"] {
  color-scheme: dark;
  --bg: #101412;
  --surface: #1a211d;
  --text: #edf4ef;
  --muted: #aab8b0;
  --line: #334138;
  --green: #35b984;
  --green-dark: #78d6ae;
  --green-soft: #10291e;
  --yellow: #f0c94a;
  --yellow-soft: #342b10;
  --gold: #f3b13a;
  --orange: #ff9f43;
  --orange-soft: #331d08;
  --pink: #ff6fb1;
  --pink-soft: #351225;
  --lead-red: #ff5d5d;
  --lead-red-soft: #351010;
  --light-purple: #c084fc;
  --light-purple-soft: #26143d;
  --dark-purple: #8b5cf6;
  --dark-purple-soft: #1f1235;
  --blue: #6ca4ff;
  --blue-soft: #17283d;
  --red: #e36b64;
  --card-red: #ff6677;
  --soft-blue: #17283d;
  --soft-blue-text: #d9e9ff;
  --input-bg: #111713;
  --close-bg: #435049;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.08), transparent 35%),
    linear-gradient(315deg, rgba(29, 127, 95, 0.12), transparent 38%),
    var(--bg);
}

button,
input {
  font: inherit;
}

.icon-sprite {
  display: none;
}

.ui-icon {
  width: 1.2em;
  height: 1.2em;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.15;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell {
  width: min(960px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 32px 0;
  display: grid;
  align-content: start;
  gap: 28px;
}

.online-entry {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  margin: 14px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
}
.online-entry:hover { border-color: var(--green); }

.app-header {
  min-height: 92px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.brand {
  width: min(560px, 100%);
  display: grid;
  grid-template-columns: 122px minmax(0, 1fr) 76px;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.card-icon {
  width: 68px;
  height: 68px;
  flex: 0 0 auto;
  border-radius: 8px;
  object-fit: contain;
}

.card-mode-toggle:focus-visible {
  outline: 3px solid rgba(29, 127, 95, 0.22);
  outline-offset: 3px;
}

.brand-kicker {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  text-align: center;
}

.brand h1 {
  margin: 0;
  font-size: clamp(2rem, 8vw, 3.1rem);
  line-height: 0.95;
  text-align: center;
}

.header-control {
  width: 76px;
  height: 76px;
  min-height: 76px;
  padding: 8px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
  display: grid;
  gap: 2px;
  align-content: center;
  justify-items: center;
}

.header-control .ui-icon {
  width: 1.75rem;
  height: 1.75rem;
}

.header-control span {
  font-size: 0.8rem;
  line-height: 1;
}

.header-control:hover {
  filter: none;
  border-color: var(--green);
}

.card-mode-toggle {
  width: 76px;
  min-height: 76px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  overflow: visible;
}

.card-mode-toggle .card-icon {
  width: 186px;
  height: 186px;
  max-width: none;
  transform: translateX(10px);
}

.theme-icon-day {
  display: none;
}

body[data-theme="night"] .theme-icon-night {
  display: none;
}

body[data-theme="night"] .theme-icon-day {
  display: block;
}

.score-dashboard {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.score-box {
  position: relative;
  min-height: 185px;
  padding: 56px 22px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: minmax(66px, auto) auto minmax(38px, auto);
  align-content: center;
  justify-items: center;
  gap: 3px;
  cursor: pointer;
  text-align: center;
}

.score-setup-icon {
  position: absolute;
  bottom: 4px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  color: var(--muted);
}

.score-setup-icon .ui-icon {
  width: 20px;
  height: 20px;
}

.score-box-a .score-setup-icon {
  left: 6px;
}

.score-box-b .score-setup-icon {
  right: 6px;
}

.score-box-a {
  border-top: 6px solid var(--green);
  background: linear-gradient(180deg, var(--green-soft), var(--surface) 72%);
}

.score-box-b {
  border-top: 6px solid var(--yellow);
  background: linear-gradient(180deg, var(--yellow-soft), var(--surface) 72%);
}

.score-box.is-leading {
  border-top-color: var(--green);
  background: linear-gradient(180deg, var(--green-soft), var(--surface) 72%);
}

.score-box.is-tied {
  border-top-color: var(--blue);
  background: linear-gradient(180deg, var(--blue-soft), var(--surface) 72%);
}

.score-box.is-trailing.lead-under-10 {
  border-top-color: var(--yellow);
  background: linear-gradient(180deg, var(--yellow-soft), var(--surface) 72%);
}

.score-box.is-trailing.lead-10-19 {
  border-top-color: var(--orange);
  background: linear-gradient(180deg, var(--orange-soft), var(--surface) 72%);
}

.score-box.is-trailing.lead-20-29 {
  border-top-color: var(--pink);
  background: linear-gradient(180deg, var(--pink-soft), var(--surface) 72%);
}

.score-box.is-trailing.lead-30-39 {
  border-top-color: var(--lead-red);
  background: linear-gradient(180deg, var(--lead-red-soft), var(--surface) 72%);
}

.score-box.is-trailing.lead-40-49 {
  border-top-color: var(--light-purple);
  background: linear-gradient(180deg, var(--light-purple-soft), var(--surface) 72%);
}

.score-box.is-trailing.lead-50-plus {
  border-top-color: var(--dark-purple);
  background: linear-gradient(180deg, var(--dark-purple-soft), var(--surface) 72%);
}

.score-box:hover {
  filter: none;
  border-color: var(--green);
  transform: translateY(-1px);
}

.score-box:focus-visible {
  outline: 3px solid rgba(29, 127, 95, 0.22);
  outline-offset: 3px;
}

.team-label {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--muted);
  font-size: 1.61rem;
  font-weight: 900;
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.score-box strong {
  font-size: 6.24rem;
  line-height: 1;
  min-width: 0;
  max-width: 100%;
}

.dealer-name {
  max-width: 100%;
  min-height: 66px;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.15;
  overflow-wrap: anywhere;
  text-transform: uppercase;
  display: grid;
  align-content: start;
  justify-items: center;
  gap: 2px;
}

.dealer-name .is-dealer-player {
  color: var(--gold);
  font-size: clamp(1.74rem, 5.76vw, 2.7rem);
  font-weight: 900;
  line-height: 1.05;
  text-shadow: 0 2px 0 rgba(67, 39, 4, 0.35);
}

.dealer-badge {
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  color: var(--gold);
  font-family: Algerian, "Copperplate Gothic Bold", Copperplate, Georgia, "Times New Roman", serif;
  font-size: clamp(1.45rem, 4.8vw, 2.6rem);
  font-weight: 900;
  line-height: 0.9;
  text-transform: uppercase;
  text-shadow:
    1px 1px 0 #111111,
    2px 2px 0 rgba(145, 67, 0, 0.9);
  display: inline-flex;
  align-items: center;
  text-align: center;
  overflow-wrap: anywhere;
}

.score-panel {
  position: relative;
  max-width: 560px;
  width: 100%;
  margin: 20px auto 0;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-heading {
  display: grid;
  gap: 8px;
  margin-bottom: 22px;
  text-align: center;
}

.hokm-finish-label {
  margin-bottom: 16px;
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
}

.round-team-summary,
.score-entry-card {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #ffffff;
  font-size: 0.92rem;
  font-weight: 800;
  line-height: 1.15;
  text-transform: uppercase;
  overflow-wrap: anywhere;
  isolation: isolate;
}

.round-team-summary {
  background:
    linear-gradient(90deg, var(--summary-soft, transparent) 0 var(--summary-fill, 0%), transparent var(--summary-fill, 0%) 100%),
    var(--surface);
}

.round-team-summary::after {
  content: "";
  position: absolute;
  inset: -1px;
  z-index: 0;
  border: 5px solid var(--summary-accent, var(--line));
  border-radius: inherit;
  clip-path: inset(0 calc(100% - max(8px, var(--summary-fill, 0%))) 0 0);
  pointer-events: none;
}

#round-group-a-summary,
#edit-group-a-summary {
  --summary-accent: var(--green);
  --summary-soft: var(--green-soft);
}

#round-group-b-summary,
#edit-group-b-summary {
  --summary-accent: var(--yellow);
  --summary-soft: var(--yellow-soft);
}

h1,
h2,
p {
  margin: 0;
}

h2 {
  font-size: 1.8rem;
}

#leader-text {
  width: 100%;
  min-height: 1.1em;
  margin: 0 auto;
  color: #ffffff;
  font-size: clamp(1.05rem, 3.3vw, 1.8rem);
  font-weight: 400;
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
  text-shadow: none;
}

.score-leader strong {
  font-weight: 900;
}

.lead-ring-display {
  position: absolute;
  left: 50%;
  bottom: 26px;
  z-index: 1;
  transform: translateX(-50%);
  display: inline-grid;
  width: clamp(74px, 11vw, 104px);
  height: clamp(74px, 11vw, 104px);
  place-items: center;
  color: #ffffff;
  font-size: clamp(1.45rem, 4.8vw, 2.4rem);
  font-weight: 800;
  line-height: 1;
  isolation: isolate;
}

.lead-ring-display[hidden] {
  display: none;
}

.lead-ring-display::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
  border-radius: 50%;
  background: conic-gradient(from var(--lead-ring-start, 162deg), var(--lead-group-a-color, var(--green)) 0 var(--lead-group-a-arc, 216deg), var(--lead-group-b-color, var(--yellow)) var(--lead-group-a-arc, 216deg) 360deg);
}

.lead-ring-display::after {
  content: "";
  position: absolute;
  inset: 0.2em;
  z-index: -1;
  border-radius: 50%;
  background: var(--surface);
}

.score-form {
  display: grid;
  gap: 16px;
}

.score-input-layout,
.score-fields {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.score-keypad {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(4, 52px);
  gap: 8px;
  width: min(320px, 100%);
  justify-self: center;
  align-self: center;
}

.score-keypad button {
  min-width: 0;
  min-height: 52px;
  height: 52px;
  padding: 8px;
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--text);
  font-size: 1.5rem;
  touch-action: manipulation;
  user-select: none;
}

.score-keypad button[data-key="next"] {
  font-size: 1.1rem;
}

.score-keypad button:active {
  background: var(--close-bg);
  color: #ffffff;
}

.score-keypad button:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.keypad-status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.score-input-error {
  color: var(--red);
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
}

.round-target-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: end;
  gap: 10px;
}

.round-target-row[hidden] {
  display: none;
}

.round-target-row #soor-field {
  width: min(220px, 100%);
  justify-self: center;
}

.remaining-scores {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.remaining-scores[hidden] {
  display: none;
}

.remaining-score {
  position: relative;
  isolation: isolate;
  min-height: 78px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, var(--summary-soft, transparent) 0 var(--summary-fill, 0%), transparent var(--summary-fill, 0%) 100%),
    var(--surface);
  color: var(--muted);
  display: grid;
  place-items: center;
  gap: 4px;
  text-align: center;
  text-transform: uppercase;
}

.remaining-score[hidden] {
  display: none;
}

.remaining-progress-outline {
  position: absolute;
  inset: -1px;
  width: calc(100% + 2px);
  height: calc(100% + 2px);
  fill: none;
  stroke: var(--summary-accent, var(--line));
  stroke-width: 10px;
  stroke-linecap: round;
  pointer-events: none;
}

.remaining-score span {
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1.1;
}

.remaining-score strong {
  color: var(--muted);
  font-size: 1.8rem;
  line-height: 1;
}

.score-entry-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: var(--input-bg);
  font-size: 1.1rem;
}

input:focus {
  outline: 3px solid rgba(29, 127, 95, 0.18);
  border-color: var(--green);
}

.keypad-input {
  cursor: pointer;
  caret-color: transparent;
  appearance: textfield;
}

.keypad-input::-webkit-inner-spin-button,
.keypad-input::-webkit-outer-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

.keypad-input.is-keypad-active {
  border-color: var(--blue);
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

.keypad-input[aria-invalid="true"] {
  border-color: var(--red);
  outline-color: var(--red);
}

.score-entry-card {
  grid-template-rows: auto minmax(42px, 1fr) auto;
  gap: 8px;
  min-width: 0;
  padding: 12px 8px 8px;
  border-color: var(--summary-accent, var(--line));
  border-bottom: 6px solid var(--summary-accent, var(--line));
  background: linear-gradient(0deg, var(--summary-soft, var(--surface)), var(--surface) 72%);
  text-transform: none;
}

.score-entry-heading {
  color: var(--muted);
  font-size: 1.5rem;
  font-weight: 700;
}

.score-entry-names {
  min-width: 0;
  color: #ffffff;
  text-align: center;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.score-entry-card input {
  min-width: 0;
  padding-inline: 6px;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  text-align: center;
}

#score-form .score-entry-row input::placeholder {
  color: var(--muted);
  font-size: 1.3rem;
  font-weight: 700;
  opacity: 1;
}

.actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

button {
  min-height: 46px;
  border: 0;
  border-radius: 6px;
  padding: 10px 14px;
  color: #ffffff;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button:hover {
  filter: brightness(0.96);
}

.score-dashboard .score-box {
  position: relative;
  min-height: 185px;
  padding: 56px 22px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  grid-template-rows: minmax(66px, auto) auto minmax(38px, auto);
  align-content: center;
  justify-items: center;
  color: var(--text);
  text-align: center;
}

.score-dashboard .score-box-a {
  border-top: 6px solid var(--green);
}

.score-dashboard .score-box-b {
  border-top: 6px solid var(--yellow);
}

.score-dashboard .score-box.is-leading {
  border-top-color: var(--green);
}

.score-dashboard .score-box.is-tied {
  border-top-color: var(--blue);
}

.score-dashboard .score-box.is-trailing.lead-under-10 {
  border-top-color: var(--yellow);
}

.score-dashboard .score-box.is-trailing.lead-10-19 {
  border-top-color: var(--orange);
}

.score-dashboard .score-box.is-trailing.lead-20-29 {
  border-top-color: var(--pink);
}

.score-dashboard .score-box.is-trailing.lead-30-39 {
  border-top-color: var(--lead-red);
}

.score-dashboard .score-box.is-trailing.lead-40-49 {
  border-top-color: var(--light-purple);
}

.score-dashboard .score-box.is-trailing.lead-50-plus {
  border-top-color: var(--dark-purple);
}

.primary-btn {
  border: 1px solid #ffffff;
  background: #303630;
}

.secondary-btn {
  border: 1px solid #ffffff;
  background: #303630;
}

.danger-btn {
  border: 1px solid #ffffff;
  background: #303630;
}

#submit-score {
  border-color: var(--green);
  background: transparent;
  color: var(--green);
}

#delete-score {
  border-color: var(--red);
  background: transparent;
  color: var(--red);
}

#submit-delete {
  border-color: var(--red);
  background: transparent;
  color: var(--red);
}

.actions button {
  min-height: 95px;
  border-width: 2px;
  background: transparent;
  font-size: 1.4rem;
  line-height: 1;
}

.actions .ui-icon {
  width: 1.4em;
  height: 1.4em;
}

#open-round-btn {
  border-color: var(--line);
  color: var(--green);
}

#add-score-btn {
  border-color: var(--green);
  background: transparent;
  color: var(--green);
}

#history-btn {
  border-color: var(--line);
  color: var(--yellow);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 8px;
  padding-inline: 12px;
}

.history-button-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.history-win-count {
  min-width: 0;
  font-size: 1.7rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.18em;
}

#group-a-wins {
  text-align: left;
}

#group-b-wins {
  text-align: right;
}

#reset-btn {
  border-color: var(--line);
  color: var(--red);
}

#open-round-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.history-panel {
  --history-round-width: 104px;
  position: fixed;
  inset: 0;
  width: min(560px, calc(100% - 20px));
  height: min(680px, calc(100dvh - 20px));
  max-height: calc(100dvh - 20px);
  margin: auto;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.history-panel[open] {
  display: grid;
}

.history-heading {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.history-heading-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.dialog-icon-btn {
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  background: var(--close-bg);
}

.dialog-icon-btn .ui-icon {
  width: 22px;
  height: 22px;
}

.win-settings-dialog {
  width: min(480px, calc(100% - 20px));
  max-height: calc(100dvh - 20px);
  margin: auto;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.win-settings-dialog[open],
#win-settings-form {
  display: grid;
  gap: 20px;
}

.win-settings-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.win-settings-heading h2 {
  font-size: 1.6rem;
}

.win-rule-section {
  min-width: 0;
  margin: 0;
  padding: 16px 0 0;
  border: 0;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 14px;
}

.win-rule-section legend {
  padding-right: 12px;
  font-size: 1.2rem;
  font-weight: 800;
}

.win-rule-toggle {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.win-rule-toggle input {
  appearance: none;
  position: relative;
  width: 52px;
  height: 30px;
  min-height: 30px;
  padding: 0;
  margin: 0;
  border: 1px solid var(--muted);
  border-radius: 20px;
  background: var(--input-bg);
  cursor: pointer;
}

.win-rule-toggle input::before {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  top: 3px;
  left: 3px;
  border-radius: 50%;
  background: var(--muted);
}

.win-rule-toggle input:checked {
  background: var(--green);
  border-color: var(--green);
}

.win-rule-toggle input:checked::before {
  left: 25px;
  background: #ffffff;
}

.win-rule-toggle input:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 3px;
}

.win-rule-section input:disabled {
  opacity: 0.5;
}

.win-settings-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.win-settings-actions button,
#reset-wins-btn {
  min-height: 56px;
  font-size: 1.15rem;
}

#save-win-settings {
  color: var(--green);
  border-color: var(--green);
  background: transparent;
}

#reset-wins-btn,
#confirm-reset-wins {
  color: var(--red);
  border-color: var(--red);
  background: transparent;
}

.history-column-heading {
  --history-card-inset: 17px;
  display: grid;
  grid-template-columns: var(--history-round-width) repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 0 calc(var(--history-card-inset) + var(--history-scrollbar-width, 0px)) 8px var(--history-card-inset);
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
}

.history-heading-actions button {
  width: 100%;
  min-width: 0;
  height: 40px;
  min-height: 40px;
  padding: 0;
  background: var(--close-bg);
}

#history-reset-wins-btn {
  color: var(--red);
}

.history-list {
  min-height: 0;
  margin: 0;
  padding: 0 0 22px;
  overflow: auto;
  list-style: none;
  display: grid;
  align-content: start;
  gap: 10px;
}

.history-list li {
  padding: 0;
  border: 0;
  color: var(--muted);
  display: grid;
  grid-template-columns: var(--history-round-width) minmax(0, 1fr);
  align-items: stretch;
  gap: 10px;
}

.history-edit-btn {
  width: 100%;
  min-height: 92px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  text-align: left;
  cursor: pointer;
  display: block;
  box-shadow: 0 8px 22px rgba(23, 33, 28, 0.08);
}

.history-round-label {
  min-width: 0;
  padding-top: 18px;
  display: grid;
  align-content: start;
  gap: 8px;
  color: var(--text);
  font-size: 1rem;
  font-weight: 900;
  line-height: 1.1;
  text-transform: uppercase;
}

.history-round-scores {
  min-width: 0;
  direction: ltr;
  font-size: 1.75rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
  text-align: left;
  white-space: nowrap;
}

.history-edit-btn:hover {
  filter: none;
  border-color: var(--gold);
  transform: translateY(-1px);
}

.history-edit-btn:hover strong,
.history-edit-btn:hover .history-details {
  text-decoration: none;
}

.history-list strong {
  color: var(--text);
  font-weight: 800;
}

.history-details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  color: var(--muted);
  font-weight: 400;
}

.history-team {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 8px;
  text-align: center;
}

.history-team-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
  text-transform: uppercase;
}

.history-team-players {
  min-height: 18px;
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 800;
  line-height: 1.15;
  text-transform: uppercase;
  display: grid;
  align-content: start;
  gap: 2px;
  overflow-wrap: anywhere;
}

.title-score {
  margin-left: 12px;
  color: var(--muted);
  font-weight: 400;
}

.title-dealer {
  color: var(--gold);
  font-weight: 900;
  text-transform: uppercase;
}

.hokm-details {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 28px;
}

.history-details .score-value {
  display: block;
  margin-top: 0;
  color: #ffffff;
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
}

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

.confirm-panel {
  position: fixed;
  inset: 0;
  z-index: 5;
  padding: 20px;
  background: rgba(10, 14, 12, 0.48);
  display: grid;
  place-items: center;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.confirm-panel[hidden] {
  display: none;
}

.confirm-panel.is-editing {
  place-items: start center;
}

.confirm-card {
  width: min(420px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  display: grid;
  gap: 18px;
}

.confirm-card h2 {
  text-align: center;
}

.confirm-message {
  color: var(--muted);
  text-align: center;
}

.score-dashboard .score-box.is-game-winner {
  box-shadow: 0 0 0 2px var(--winner-color), 0 0 28px color-mix(in srgb, var(--winner-color) 32%, transparent);
}

.score-box.is-celebrating {
  animation: winner-glow 1s ease-in-out 5;
}

body.has-winner-dialog,
body.has-hokm-finish-dialog,
body.has-round-dialog,
body.has-win-settings-dialog,
body.has-history-dialog {
  overflow: hidden;
}

.round-dialog {
  width: min(560px, calc(100% - 20px));
  max-width: calc(100% - 20px);
  max-height: calc(100dvh - 20px);
  margin: auto;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.round-dialog[open] {
  display: grid;
  gap: 22px;
}

.round-dialog h2 {
  text-align: center;
}

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

.round-dialog .round-entry-actions button {
  min-width: 0;
  font-size: 1.2rem;
}

.hokm-finish-dialog {
  width: min(420px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow-y: auto;
}

.hokm-finish-dialog[open] {
  display: grid;
  gap: 14px;
}

.hokm-finish-dialog::backdrop,
.win-settings-dialog::backdrop,
.round-dialog::backdrop,
.history-panel::backdrop {
  background: rgba(10, 14, 12, 0.62);
}

.hokm-finish-dialog h2 {
  font-size: 1.75rem;
  text-align: center;
}

.hokm-finish-dialog button {
  min-height: 64px;
  font-size: 1.35rem;
}

.winner-dialog {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 16px;
  border: 0;
  background: transparent;
  color: var(--text);
  overflow: hidden;
}

.winner-dialog[open] {
  display: grid;
  place-items: center;
}

.winner-dialog::backdrop {
  background: rgba(10, 14, 12, 0.62);
}

.winner-card {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 18px;
  width: min(460px, 100%);
  min-width: 0;
  max-height: 100%;
  padding: 28px 22px;
  border: 2px solid var(--winner-color);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.winner-toolbar {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  justify-items: center;
  width: 100%;
}

.winner-sound-toggle {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--gold);
  background: var(--surface);
}

.winner-sound-toggle[aria-pressed="false"] {
  color: var(--muted);
}

.winner-sound-toggle:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

.winner-sound-toggle .ui-icon {
  width: 24px;
  height: 24px;
}

.winner-trophy {
  grid-column: 2;
  width: 64px;
  height: 64px;
  color: var(--gold);
  stroke-width: 1.7;
}

.winner-game {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
}

#winner-title {
  color: var(--winner-color);
  font-size: 2rem;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.winner-players {
  display: grid;
  gap: 12px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  color: var(--gold);
  font-size: 5.2rem;
  font-weight: 800;
  line-height: 1.1;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

.winner-name {
  display: block;
  min-width: 0;
  color: var(--gold);
  background: linear-gradient(110deg, #e7a322 20%, #ffd65c 38%, #fff7cf 47%, #ffffff 50%, #ffdf79 53%, #e7a322 68%);
  background-size: 250% 100%;
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 8px rgba(243, 177, 58, 0.55));
  animation: winner-name-shine 2.4s linear infinite;
}

.winner-scores {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 18px 0;
  border-block: 1px solid var(--line);
}

.winner-scores div {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.winner-scores span {
  color: var(--muted);
  font-weight: 700;
}

.winner-scores strong {
  font-size: 2.8rem;
  line-height: 1;
  overflow-wrap: anywhere;
}

.winner-dialog[data-winner="groupA"] #winner-score-a,
.winner-dialog[data-winner="groupB"] #winner-score-b {
  color: var(--winner-color);
}

.winner-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
}

.winner-actions button {
  min-height: 58px;
  padding: 12px 8px;
  font-size: 1.1rem;
}

#winner-new-game {
  border-color: var(--winner-color);
  color: var(--winner-color);
  background: transparent;
}

.winner-confetti {
  position: absolute;
  z-index: 2;
  inset: 0;
  overflow: hidden;
  opacity: 0.65;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -32px;
  width: 14px;
  height: 26px;
  animation: confetti-fall var(--confetti-duration) linear var(--confetti-delay) infinite;
}

@keyframes confetti-fall {
  from { transform: translate3d(0, 0, 0) rotate(0); opacity: 1; }
  to { transform: translate3d(var(--confetti-drift), calc(100dvh + 64px), 0) rotate(var(--confetti-spin)); opacity: 0; }
}

@keyframes winner-name-shine {
  from { background-position: 150% 0; }
  to { background-position: -150% 0; }
}

@keyframes winner-glow {
  50% { box-shadow: 0 0 0 3px var(--winner-color), 0 0 42px color-mix(in srgb, var(--winner-color) 55%, transparent); }
}

@media (prefers-reduced-motion: reduce) {
  .score-box.is-celebrating,
  .winner-name,
  .confetti-piece {
    animation: none;
  }

  .winner-confetti {
    display: none;
  }
}

.edit-score-fields {
  display: grid;
  gap: 14px;
}

.edit-score-fields[hidden] {
  display: none;
}

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

.confirm-scores div {
  min-height: 110px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input-bg);
  display: grid;
  place-items: center;
  gap: 8px;
}

.confirm-team-label {
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
}

.confirm-team-players {
  min-height: 20px;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.confirm-scores strong {
  font-size: 2.8rem;
  line-height: 1;
}

.confirm-soor {
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1.3;
  text-align: center;
  overflow-wrap: anywhere;
}

.confirm-soor strong {
  color: var(--text);
  font-size: 1.5rem;
}

.confirm-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
}

.confirm-actions button {
  min-height: 73px;
  font-size: 1.56rem;
}

.confirm-panel.is-editing .confirm-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.confirm-panel.is-editing #submit-score {
  grid-column: 1 / -1;
}

.players-card {
  align-items: stretch;
  width: min(500px, 100%);
}

.dealer-table-preview {
  position: relative;
  width: min(100%, 430px);
  aspect-ratio: 1.28;
  margin: 0 auto 6px;
  border: 2px solid rgba(9, 24, 31, 0.72);
  border-radius: 44px;
  background: #176c88;
  color: #f6fbff;
  overflow: hidden;
}

.table-seat {
  position: absolute;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: #f8fbff;
  font-size: clamp(1.05rem, 4.6vw, 1.85rem);
  line-height: 1;
  text-align: center;
  overflow-wrap: anywhere;
}

.table-seat-top {
  top: 0;
  left: 20%;
  right: 16%;
  height: 24%;
}

.table-seat-bottom {
  bottom: 2%;
  left: 18%;
  right: 18%;
  height: 24%;
}

.table-seat-left {
  top: 11%;
  bottom: 15%;
  left: 0;
  width: 18%;
  writing-mode: vertical-rl;
  text-orientation: mixed;
}

.table-seat-right {
  top: 12%;
  bottom: 14%;
  right: 0;
  width: 18%;
  writing-mode: vertical-rl;
  text-orientation: mixed;
}

.dealer-table-preview.is-two-players .table-seat-left,
.dealer-table-preview.is-two-players .table-seat-right {
  display: none;
}

.table-turn-arrow {
  position: absolute;
  inset: 25% 24% 25%;
  overflow: hidden;
  text-indent: 100%;
  white-space: nowrap;
  background: url("counter-clockwise-arrow.png?v=41") center / contain no-repeat;
  opacity: 0.9;
}

.table-turn-arrow.is-counter {
  background-image: url("clockwise-arrow.png?v=41");
}

.player-list {
  display: grid;
  gap: 12px;
}

.player-count-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.player-count-btn {
  min-height: 46px;
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--muted);
  font-weight: 900;
}

.player-count-btn.is-selected {
  border-color: var(--gold);
  background: var(--gold);
  color: #1d1305;
}

.people-btn {
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--gold);
  font-weight: 900;
}

.final-score-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: -4px;
}

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

.dealer-start-btn {
  width: 42px;
  min-height: 42px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--input-bg);
  color: var(--muted);
  font-weight: 900;
}

.dealer-start-btn.is-selected {
  border-color: var(--gold);
  background: var(--gold);
  color: #1d1305;
}

.direction-card {
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--text);
  font-weight: 900;
}

.players-card .confirm-actions {
  padding-top: 10px;
  background: var(--surface);
}

.people-card {
  width: min(460px, 100%);
}

.saved-people-list {
  max-height: 260px;
  overflow: auto;
  display: grid;
  gap: 10px;
}

.saved-person-row {
  min-height: 54px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input-bg);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.saved-person-row span {
  color: var(--text);
  font-weight: 900;
  overflow-wrap: anywhere;
}

.saved-person-delete {
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--red);
  background: transparent;
  color: var(--red);
  font-size: 0.92rem;
}

.dealer-picker {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
}

.dealer-picker legend {
  padding: 0 6px;
  color: var(--muted);
  font-weight: 800;
}

.dealer-picker label {
  grid-template-columns: auto 1fr;
  align-items: center;
  color: var(--text);
}

.dealer-picker input {
  width: 20px;
  min-height: 20px;
  padding: 0;
  accent-color: var(--green);
}

.form-error {
  color: var(--red);
  font-weight: 800;
  text-align: center;
}

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

@media (min-width: 901px) {
  .history-button-label {
    flex-direction: column;
    gap: 4px;
  }
}

@media (min-width: 621px) and (max-width: 900px) {
  .round-dialog input,
  .edit-score-fields input {
    min-height: 72px;
    font-size: 1.35rem;
  }

  .confirm-card {
    width: min(520px, calc(100% - 48px));
  }

  .confirm-scores div {
    min-height: 165px;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 20px, 960px);
    padding: 18px 0;
    gap: 18px;
  }

  .app-header {
    padding: 14px;
    justify-content: center;
  }

  .brand {
    grid-template-columns: 104px minmax(0, 1fr) 72px;
    gap: 6px;
  }

  .score-dashboard {
    gap: 10px;
  }

  .lead-ring-display {
    bottom: 14px;
    width: 62px;
    height: 62px;
    font-size: 1.35rem;
  }

  .score-box,
  .score-dashboard .score-box {
    min-height: 150px;
    padding: 48px 8px 12px;
    grid-template-rows: minmax(54px, auto) auto minmax(32px, auto);
  }

  .dealer-name {
    min-height: 54px;
  }

  .team-label {
    top: 13px;
    font-size: 1.372rem;
  }

  .score-box strong {
    font-size: 3.6rem;
  }

  .card-mode-toggle {
    width: 72px;
    min-height: 72px;
    height: 72px;
    padding: 0;
    border-color: transparent;
    background: transparent;
    box-shadow: none;
    overflow: visible;
  }

  .card-icon,
  .card-mode-toggle .card-icon {
    width: 177px;
    height: 177px;
    max-width: none;
    transform: translateX(8px);
  }

  button {
    gap: 7px;
  }

  .score-panel {
    margin-top: 0;
    padding: 18px;
  }

  .round-dialog {
    padding: 18px;
  }

  .confirm-panel {
    padding: 10px;
    place-items: start center;
  }

  #confirm-panel:not(.is-editing) {
    place-items: end center;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  #confirm-panel:not(.is-editing) .confirm-card {
    max-height: calc(100dvh - 10px - max(10px, env(safe-area-inset-bottom)));
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .confirm-card {
    padding: 16px;
  }

  .players-card {
    gap: 14px;
  }

  .player-row {
    grid-template-columns: 44px minmax(74px, 0.34fr) minmax(0, 1fr);
    gap: 8px;
  }

  .dealer-start-btn {
    width: 42px;
    border-radius: 50%;
  }
}

@media (min-width: 480px) and (max-width: 620px) {
  .score-box strong {
    font-size: 4.8rem;
  }
}

@media (max-width: 360px) {
  .team-label {
    gap: 4px;
  }

  .round-dialog {
    padding: 14px;
  }

  .score-entry-card {
    padding-inline: 5px;
  }

  .history-panel {
    padding: 14px;
  }

  .history-column-heading {
    --history-card-inset: 11px;
    font-size: 0.82rem;
  }

  .history-edit-btn {
    padding-inline: 10px;
  }

  .history-details {
    column-gap: 8px;
  }

  #score-form .score-entry-card input {
    padding-inline: 1px;
  }
}

@media (min-width: 600px) and (max-height: 600px) {
  .round-dialog {
    width: min(820px, calc(100% - 20px));
    padding: 12px;
  }

  .round-dialog[open],
  .round-dialog .score-form {
    gap: 12px;
  }

  .confirm-panel.is-editing .confirm-card {
    width: min(820px, 100%);
  }

  .score-input-layout {
    grid-template-columns: minmax(0, 1.25fr) minmax(220px, 1fr);
    align-items: center;
  }

  .score-fields {
    gap: 10px;
  }

  .round-target-row #soor-field,
  #edit-soor-field {
    width: 100%;
    grid-template-columns: minmax(0, 1fr) 90px;
    align-items: center;
  }

  .round-dialog input,
  .edit-score-fields input {
    min-height: 48px;
    font-size: 1.1rem;
  }

  .score-keypad {
    grid-template-rows: repeat(4, 44px);
    gap: 6px;
  }

  .score-keypad button {
    min-height: 44px;
    height: 44px;
  }
}
