: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;
}

.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 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.score-box {
  min-height: 210px;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 10px;
  cursor: pointer;
  text-align: center;
}

.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 {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.score-box strong {
  font-size: clamp(3.25rem, 12vw, 5.5rem);
  line-height: 1;
}

.dealer-name {
  max-width: 100%;
  color: var(--gold);
  font-size: clamp(1.45rem, 4.8vw, 2.25rem);
  font-weight: 900;
  line-height: 1.05;
  overflow-wrap: anywhere;
  text-transform: uppercase;
  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.65rem, 5.5vw, 3rem);
  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;
}

.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;
}

h1,
h2,
p {
  margin: 0;
}

h2 {
  font-size: 1.8rem;
}

#leader-text {
  color: var(--muted);
  min-height: 1.4em;
}

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

.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);
}

.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 {
  min-height: 210px;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  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: 73px;
  border-width: 2px;
  background: transparent;
  font-size: 1.4rem;
  line-height: 1;
}

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

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

#history-btn {
  border-color: var(--line);
  color: var(--yellow);
}

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

.history-panel {
  position: absolute;
  inset: 0;
  padding: 22px;
  border: 0;
  border-radius: 0;
  background: var(--surface);
  box-shadow: var(--shadow);
  z-index: 2;
}

.history-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

#close-history {
  width: 36px;
  min-height: 36px;
  padding: 0;
  background: var(--close-bg);
}

.history-list {
  max-height: min(420px, 62vh);
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
  display: grid;
  gap: 10px;
}

.history-list li {
  padding: 0;
  border: 0;
  color: var(--muted);
}

.history-edit-btn {
  width: 100%;
  min-height: 78px;
  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-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: block;
  margin-top: 4px;
  color: var(--muted);
  font-weight: 400;
}

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

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

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

.history-details .score-value {
  display: inline;
  margin-top: 0;
  color: #ffffff;
  font-weight: 800;
}

.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-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;
}

.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-scores span {
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
}

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

.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;
}

.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);
}

.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: 621px) and (max-width: 900px) {
  .score-panel 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;
  }

  .score-box,
  .score-dashboard .score-box {
    min-height: 170px;
    padding: 18px 10px;
  }

  .team-label {
    font-size: 0.86rem;
  }

  .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;
  }

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

  .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%;
  }
}
