:root {
  color-scheme: dark;
  --bg: #000000;
  --panel: #1c1c1e;
  --panel-line: rgba(255, 255, 255, 0.08);
  --text: #ffffff;
  --muted: #9a9aa2;
  --blue: #0a84ff;
  --danger: #ff453a;
  --green: #30d158;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  overflow-x: hidden;
  touch-action: manipulation;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: 100%;
  max-width: 560px;
  min-height: 100dvh;
  margin: 0 auto;
  background: #000;
  padding-top: env(safe-area-inset-top);
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 88px;
  padding: 18px 20px 12px;
  background: rgba(12, 12, 13, 0.98);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: transparent;
  color: var(--blue);
  font-size: 42px;
  line-height: 1;
}

.icon-button svg,
.trash-button svg {
  width: 34px;
  height: 34px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.group-chip {
  min-width: 0;
  max-width: 170px;
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--blue);
  font-size: 16px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.players-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 13px 34px;
}

.player-card {
  position: relative;
  min-height: 302px;
  overflow: hidden;
  border-radius: 20px;
  background: var(--card-color, #459bf2);
  color: #fff;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  isolation: isolate;
}

.players-list.single-player .player-card {
  min-height: calc(100dvh - 142px);
}

.player-card.is-updating {
  opacity: 0.82;
}

.player-card-header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: 20px 24px 16px;
  background: rgba(0, 0, 0, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.player-name {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: #fff;
  font-size: 30px;
  font-weight: 800;
  line-height: 1.12;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-button {
  flex: 0 0 auto;
  width: 48px;
  height: 42px;
  border-radius: 14px;
  background: transparent;
  color: #fff;
  font-size: 34px;
  font-weight: 900;
  line-height: 1;
}

.score-value {
  position: absolute;
  inset: 50% auto auto 50%;
  z-index: 1;
  transform: translate(-50%, -43%);
  width: min(58%, 280px);
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 150px;
  font-weight: 900;
  line-height: 0.9;
  text-align: center;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.05);
  user-select: none;
}

.score-value:active {
  opacity: 0.78;
}

.score-control {
  position: absolute;
  top: 50%;
  z-index: 3;
  width: 94px;
  height: 118px;
  transform: translateY(-34%);
  border-radius: 22px;
  background: transparent;
  color: #fff;
  font-size: 58px;
  font-weight: 300;
  line-height: 1;
}

.score-control:active {
  background: rgba(255, 255, 255, 0.12);
}

.score-control.minus {
  left: 24px;
}

.score-control.plus {
  right: 24px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: calc(100dvh - 150px);
  padding: 24px;
  text-align: center;
}

.empty-state h2 {
  margin: 0 0 10px;
  font-size: 28px;
}

.empty-state p {
  max-width: 320px;
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.5;
}

.primary-button,
.save-button {
  min-height: 54px;
  padding: 0 22px;
  border-radius: 16px;
  background: var(--blue);
  color: #fff;
  font-size: 19px;
  font-weight: 800;
}

.screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  overflow-y: auto;
  background: #000;
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 180ms ease, visibility 180ms ease;
  padding-top: env(safe-area-inset-top);
}

.screen.is-open {
  transform: translateX(0);
  visibility: visible;
}

.screen-header {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 88px;
  padding: 18px 20px 12px;
  background: rgba(12, 12, 13, 0.98);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.back-button,
.text-button,
.trash-button {
  background: transparent;
  color: var(--blue);
  font-size: 22px;
  font-weight: 700;
}

.back-button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 0;
}

.back-button span {
  font-size: 48px;
  font-weight: 500;
  line-height: 0.7;
}

.trash-button {
  display: inline-grid;
  place-items: center;
  width: 52px;
  height: 52px;
  color: var(--danger);
}

.trash-button[hidden] {
  display: none;
}

.settings-content,
.editor-content {
  padding: 26px 20px 46px;
}

.section-title {
  margin: 10px 40px 14px;
  color: var(--muted);
  font-size: 18px;
  font-weight: 800;
}

.settings-panel {
  overflow: hidden;
  margin-bottom: 36px;
  border-radius: 18px;
  background: var(--panel);
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  min-height: 64px;
  padding: 14px 26px;
  color: #fff;
  border-bottom: 1px solid var(--panel-line);
  font-size: 22px;
  font-weight: 750;
  text-align: left;
}

.settings-row:last-child {
  border-bottom: 0;
}

.row-button {
  background: transparent;
}

.row-button strong {
  display: flex;
  align-items: center;
  min-width: 0;
  color: var(--muted);
  font-weight: 800;
}

.row-button strong span:first-child {
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chevron {
  margin-left: 8px;
  color: rgba(255, 255, 255, 0.28);
  font-size: 38px;
  line-height: 0.7;
}

.split-row,
.sort-row {
  align-items: flex-start;
  flex-direction: column;
}

.segmented-control,
.number-setting,
.sort-actions {
  display: flex;
  width: 100%;
  gap: 8px;
}

.number-setting {
  align-items: stretch;
}

.step-input-wrap {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
  height: 50px;
  padding: 0 14px;
  border: 0;
  outline: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.step-input-wrap:focus-within {
  background: rgba(10, 132, 255, 0.15);
  box-shadow: inset 0 0 0 2px rgba(10, 132, 255, 0.85);
}

.step-input-wrap input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: #fff;
  font-size: 20px;
  font-weight: 850;
}

.step-input-wrap input::placeholder {
  color: rgba(255, 255, 255, 0.35);
}

.step-input-wrap span {
  flex: 0 0 auto;
  color: rgba(255, 255, 255, 0.5);
  font-size: 13px;
  font-weight: 800;
}

.number-setting button {
  flex: 0 0 74px;
  min-height: 50px;
  border-radius: 12px;
  background: var(--blue);
  color: #fff;
  font-size: 16px;
  font-weight: 850;
  box-shadow: 0 8px 18px rgba(10, 132, 255, 0.22);
}

.segmented-control button,
.sort-actions button {
  flex: 1;
  min-height: 42px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
}

.segmented-control button.is-active,
.sort-actions button.is-active {
  background: var(--blue);
}

.danger-row {
  color: var(--danger);
}

.switch-row {
  cursor: pointer;
}

.switch {
  position: relative;
  flex: 0 0 auto;
  width: 66px;
  height: 40px;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #3a3a42;
  transition: background 150ms ease;
}

.switch-slider::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: #fff;
  transition: transform 150ms ease;
}

.switch input:checked + .switch-slider {
  background: var(--green);
}

.switch input:checked + .switch-slider::after {
  transform: translateX(26px);
}

.group-list {
  margin-bottom: 0;
}

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

.group-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.group-action {
  min-height: 38px;
  padding: 0 12px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
}

.group-action.current {
  background: var(--blue);
}

.group-action.danger {
  color: var(--danger);
}

.name-card {
  min-height: 138px;
  margin-bottom: 22px;
  padding: 30px 28px;
  border-radius: 20px;
  background: #459bf2;
  display: flex;
  align-items: center;
}

.name-input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: #fff;
  font-size: 44px;
  font-weight: 900;
  line-height: 1.08;
}

.name-input::placeholder {
  color: rgba(255, 255, 255, 0.92);
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.color-swatch {
  min-height: 64px;
  aspect-ratio: 1;
  border-radius: 18px;
  background: var(--swatch);
  box-shadow: inset 0 0 0 2px transparent;
}

.color-swatch.is-selected {
  box-shadow: inset 0 0 0 4px #fff, 0 0 0 2px var(--blue);
}

.color-swatch.custom {
  background:
    radial-gradient(circle at 25% 25%, #7cf16d 0, transparent 34%),
    radial-gradient(circle at 72% 28%, #04d9ff 0, transparent 34%),
    radial-gradient(circle at 70% 74%, #ff5fa2 0, transparent 34%),
    radial-gradient(circle at 28% 76%, #ffe45c 0, transparent 34%),
    #ffffff;
}

#customColorInput {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.save-button {
  width: 100%;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  align-items: end;
  justify-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.score-entry-backdrop {
  position: fixed;
  inset: 0;
  z-index: 75;
  display: grid;
  align-items: center;
  justify-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.66);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.score-entry-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.score-entry-card {
  position: relative;
  width: min(100%, 360px);
  padding: 0 0 16px;
  border-radius: 22px;
  background: #459bf2;
  color: #fff;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.45);
}

.score-entry-modes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  overflow: hidden;
  border-radius: 22px 22px 0 0;
}

.score-entry-modes button {
  height: 64px;
  background: rgba(0, 0, 0, 0.14);
  color: #fff;
  font-size: 40px;
  font-weight: 500;
}

.score-entry-modes button.is-active {
  background: rgba(255, 255, 255, 0.16);
}

.score-entry-display {
  display: block;
  margin: 0 18px 14px;
  padding: 18px 18px 20px;
  border-radius: 0 0 18px 18px;
  background: rgba(255, 255, 255, 0.1);
}

.score-entry-display span {
  display: block;
  max-width: 100%;
  margin-bottom: 4px;
  overflow: hidden;
  color: rgba(255, 255, 255, 0.72);
  font-size: 16px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-entry-display input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: #fff;
  font-size: 86px;
  font-weight: 900;
  line-height: 1;
  text-align: center;
}

.score-entry-display input::placeholder {
  color: rgba(255, 255, 255, 0.45);
}

.score-entry-submit {
  display: block;
  width: calc(100% - 36px);
  min-height: 70px;
  margin: 0 auto;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 34px;
  font-weight: 900;
}

.score-entry-close {
  position: absolute;
  top: -14px;
  right: -14px;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  background: #2c2c2e;
  color: #fff;
  font-size: 26px;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}

.sheet-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.action-sheet {
  width: min(100%, 520px);
  overflow: hidden;
  border-radius: 20px;
  background: #202023;
  box-shadow: var(--shadow);
}

.action-sheet button {
  display: block;
  width: 100%;
  min-height: 58px;
  background: transparent;
  color: #fff;
  border-bottom: 1px solid var(--panel-line);
  font-size: 19px;
  font-weight: 760;
}

.action-sheet button:last-child {
  border-bottom: 0;
  color: var(--blue);
}

.action-sheet button.danger {
  color: var(--danger);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  z-index: 100;
  width: min(calc(100% - 36px), 500px);
  padding: 13px 16px;
  border-radius: 16px;
  background: rgba(36, 36, 38, 0.94);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  transform: translate(-50%, 18px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 420px) {
  .top-bar,
  .screen-header {
    padding-left: 16px;
    padding-right: 16px;
  }

  .top-actions {
    gap: 4px;
  }

  .icon-button {
    width: 40px;
    height: 40px;
  }

  .icon-button svg,
  .trash-button svg {
    width: 30px;
    height: 30px;
  }

  .group-chip {
    max-width: 118px;
    padding-left: 10px;
    padding-right: 10px;
  }

  .players-list {
    padding-left: 10px;
    padding-right: 10px;
  }

  .player-card {
    min-height: 286px;
    border-radius: 18px;
  }

  .player-card-header {
    padding-left: 20px;
    padding-right: 18px;
  }

  .player-name {
    font-size: 28px;
  }

  .score-value {
    font-size: 132px;
  }

  .score-control {
    width: 72px;
    font-size: 52px;
  }

  .score-control.minus {
    left: 18px;
  }

  .score-control.plus {
    right: 18px;
  }

  .settings-content,
  .editor-content {
    padding-left: 14px;
    padding-right: 14px;
  }

  .settings-row {
    padding-left: 20px;
    padding-right: 20px;
    font-size: 20px;
  }

  .number-setting {
    gap: 7px;
  }

  .number-setting button {
    flex-basis: 66px;
  }

  .step-input-wrap {
    padding-left: 12px;
    padding-right: 10px;
  }

  .step-input-wrap input {
    font-size: 18px;
  }

  .step-input-wrap span {
    font-size: 12px;
  }

  .name-input {
    font-size: 38px;
  }

  .color-grid {
    gap: 10px;
  }
}

body.compact-rows .player-card {
  min-height: 174px;
}

body.compact-rows .players-list.single-player .player-card {
  min-height: 260px;
}

body.compact-rows .player-card-header {
  min-height: 58px;
  padding-top: 14px;
  padding-bottom: 12px;
}

body.compact-rows .player-name {
  font-size: 24px;
}

body.compact-rows .score-value {
  width: min(54%, 220px);
  font-size: 82px;
  transform: translate(-50%, -33%);
}

body.compact-rows .score-control {
  height: 82px;
  transform: translateY(-18%);
  font-size: 44px;
}
