:root {
  --bg: #262626;
  --surface: #343434;
  --surface-2: #3f3f3f;
  --surface-3: #4a4a4a;
  --border: #4d4d4d;
  --text: #ffffff;
  --muted: #b9b9b9;
  --placeholder: #7a7a7a;
  --accent: #cbd42d;
  --accent-strong: #dbe43a;
  --accent-ink: #1e1e1e;
  --accent-soft: rgba(203, 212, 45, 0.14);
  --danger: #ff7a66;
  --radius: 16px;
  --radius-sm: 10px;
  --font-display: 'Bebas Neue', 'Oswald', 'Arial Narrow', sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

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

button:disabled {
  cursor: not-allowed;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.06em;
  line-height: 1.1;
}

h2 {
  font-size: 1.6rem;
}

h3 {
  font-size: 1.35rem;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: rgba(38, 38, 38, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--surface-2);
}

.app-logo {
  flex: none;
  width: 44px;
  height: 44px;
}

.app-title {
  display: flex;
  flex-direction: column;
  font-family: var(--font-display);
  letter-spacing: 0.18em;
  line-height: 1;
}

.header-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  margin-left: auto;
  padding: 0 14px 0 12px;
  border: 1px solid var(--surface-3);
  border-radius: 999px;
  background: var(--surface);
  font-weight: 600;
  font-size: 0.9rem;
}

.header-btn[hidden] {
  display: none;
}

.header-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.header-btn.is-active {
  border-color: var(--accent);
  color: var(--accent);
}

.app-club {
  font-size: 1rem;
  color: var(--muted);
}

.app-format {
  font-size: 1.6rem;
  color: var(--accent);
}

.app-main {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 32px);
}

.stack,
.view {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius);
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.muted {
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 0.9rem;
  letter-spacing: normal;
  margin: 0;
}

.center {
  text-align: center;
}

.view-title {
  font-size: 2rem;
}

.view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.standings-title {
  margin-top: 16px;
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  font-weight: 600;
  background: var(--surface-2);
  transition: transform 0.08s ease, background-color 0.15s ease, opacity 0.15s ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

.btn-primary:disabled {
  background: var(--surface-2);
  color: var(--muted);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
}

.btn-danger {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  align-self: flex-start;
}

.btn-link {
  background: none;
  border: 0;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  min-height: 44px;
  padding: 0 12px;
}

.redraw {
  align-self: center;
}

.btn-block {
  width: 100%;
}

.btn-large {
  min-height: 56px;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 400;
  letter-spacing: 0.1em;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 1.6rem;
  line-height: 1;
}

.icon-btn:active:not(:disabled) {
  background: var(--surface-3);
}

.icon-btn:disabled {
  opacity: 0.35;
}

/* Setup */

.option-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}

.option-card {
  position: relative;
  cursor: pointer;
}

.option-card input,
.segment input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.option-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  height: 100%;
  padding: 14px 16px;
  border: 2px solid var(--surface-3);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.option-name {
  font-family: var(--font-display);
  font-size: 1.6rem;
  letter-spacing: 0.08em;
  line-height: 1;
}

.option-description {
  color: var(--muted);
  font-size: 0.88rem;
}

.option-card input:checked + .option-body {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.option-card input:checked + .option-body .option-name {
  color: var(--accent);
}

.option-card input:focus-visible + .option-body,
.segment input:focus-visible + span {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

textarea,
input[type='text'],
input[type='number'] {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--surface-3);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 1rem;
}

textarea {
  resize: vertical;
  min-height: 200px;
  line-height: 1.6;
}

textarea:focus,
input:focus {
  outline: none;
  border-color: var(--accent);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
}

.segment {
  cursor: pointer;
}

.segment span {
  display: grid;
  place-items: center;
  height: 48px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-family: var(--font-display);
  font-size: 1.5rem;
}

.segment input:checked + span {
  background: var(--accent);
  color: var(--accent-ink);
}

.points-custom {
  display: flex;
  align-items: center;
  gap: 12px;
}

.points-custom input {
  width: 96px;
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.5rem;
  padding: 6px 8px;
}

.chips {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

.chip {
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--surface-2);
  font-family: var(--font-display);
  font-size: 1.35rem;
}

.chip.is-selected {
  background: var(--accent);
  color: var(--accent-ink);
}

.setup-summary {
  margin: 4px 0 0;
  text-align: center;
  color: var(--muted);
}

/* Matches */

.round-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.round-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.round-title h2 {
  font-size: 2.2rem;
}

.round-badge {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
}

.courts {
  display: grid;
  gap: 12px;
}

@media (min-width: 640px) {
  .courts {
    grid-template-columns: 1fr 1fr;
  }
}

.court {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  padding: 14px 16px 16px;
  border: 2px solid transparent;
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  transition: border-color 0.15s ease, transform 0.08s ease;
}

.court:active {
  transform: scale(0.985);
}

.court:not(.is-done) {
  border-color: var(--surface-3);
  border-style: dashed;
}

.court-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.court-label {
  font-family: var(--font-display);
  font-size: 1.4rem;
  letter-spacing: 0.12em;
  color: var(--accent);
}

.court-status {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.court:not(.is-done) .court-status {
  color: var(--accent);
}

.team {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.team-names {
  display: flex;
  flex-direction: column;
  font-weight: 600;
  min-width: 0;
}

.team-names span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.team-score {
  font-family: var(--font-display);
  font-size: 2.4rem;
  line-height: 1;
  color: var(--muted);
}

.team.is-winner {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.team-score.is-placeholder,
.score-value.is-placeholder {
  color: var(--placeholder);
}

.team.is-winner .team-score {
  color: var(--accent);
}

.court-vs {
  align-self: center;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--muted);
}

.resting {
  margin: 0;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--surface);
}

.resting-label {
  margin-right: 6px;
  font-family: var(--font-display);
  font-size: 1.2rem;
  letter-spacing: 0.12em;
  color: var(--accent);
}

.round-actions {
  position: sticky;
  bottom: calc(env(safe-area-inset-bottom) + 8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px;
  margin: 0 -4px;
  border-radius: var(--radius);
  background: rgba(38, 38, 38, 0.94);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* Standings */

.table-card {
  padding: 4px 0;
  overflow-x: auto;
}

.standings {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.standings th,
.standings td {
  padding: 10px 6px;
  text-align: left;
  border-bottom: 1px solid var(--surface-2);
}

.standings tr:last-child td {
  border-bottom: 0;
}

.standings th {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.standings th:first-child,
.standings td:first-child {
  padding-left: 14px;
}

.standings th:last-child,
.standings td:last-child {
  padding-right: 14px;
}

.standings .num {
  text-align: right;
  white-space: nowrap;
}

.standings .name {
  width: 100%;
  font-weight: 600;
}

.standings .points {
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: var(--accent);
}

.standings .rank {
  width: 1%;
  text-align: center;
}

.rank-badge {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-family: var(--font-display);
  font-size: 1.3rem;
  line-height: 1;
  padding-top: 2px;
  color: var(--muted);
}

.podium .rank-badge {
  background: var(--podium);
  color: var(--accent-ink);
}

.podium-1 {
  --podium: var(--accent);
}

.podium-2 {
  --podium: #d9d9d9;
}

.podium-3 {
  --podium: #c99a6b;
}

.is-paused .name,
.player-name.is-paused {
  color: var(--muted);
}

.tag {
  margin-left: 4px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
}

.legend {
  padding: 0 4px;
}

/* Players */

.inline-form {
  display: flex;
  gap: 8px;
}

.inline-form input {
  flex: 1;
  min-width: 0;
}

.player-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.player-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  border-bottom: 1px solid var(--surface-2);
}

.player-list li:last-child {
  border-bottom: 0;
}

.player-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex: none;
  cursor: pointer;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch-track {
  position: relative;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--surface-3);
  transition: background-color 0.15s ease;
}

.switch-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 0.15s ease;
}

.switch input:checked + .switch-track {
  background: var(--accent);
}

.switch input:checked + .switch-track::after {
  transform: translateX(20px);
  background: var(--accent-ink);
}

.switch input:focus-visible + .switch-track {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.switch-label {
  width: 52px;
  font-size: 0.85rem;
  color: var(--muted);
}

.stepper {
  display: flex;
  align-items: center;
  gap: 16px;
}

.stepper-value {
  min-width: 40px;
  text-align: center;
  font-family: var(--font-display);
  font-size: 2.2rem;
}

/* Score dialog */

.score-dialog {
  width: min(560px, 100%);
  max-width: 100%;
  max-height: 100dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 24px 24px 0 0;
  background: var(--surface);
  color: var(--text);
}

@media (min-width: 600px) {
  .score-dialog {
    margin: auto;
    border-radius: 24px;
  }
}

.score-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.score-dialog[open] {
  animation: sheet-in 0.2s ease-out;
}

@keyframes sheet-in {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
}

.score-sheet {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 100dvh;
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
}

.score-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.score-header h2 {
  font-size: 2rem;
  color: var(--accent);
}

.score-board {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
}

.score-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 8px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 2px solid transparent;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.score-side.is-winner {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.score-names {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-weight: 600;
  font-size: 0.95rem;
  text-align: center;
  min-height: 2.9em;
  max-width: 100%;
}

.score-names span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-value {
  font-family: var(--font-display);
  font-size: 4rem;
  line-height: 1;
}

.score-side.is-winner .score-value {
  color: var(--accent);
}

.score-steps {
  display: flex;
  gap: 10px;
}

.score-steps .icon-btn {
  background: var(--surface-3);
}

.score-dash {
  font-family: var(--font-display);
  font-size: 2.5rem;
  color: var(--muted);
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
  gap: 6px;
  overflow-y: auto;
  min-height: 0;
  max-height: 34dvh;
  padding: 2px;
}

.score-chip {
  height: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-family: var(--font-display);
  font-size: 1.3rem;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.score-chip.is-selected {
  background: var(--accent);
  color: var(--accent-ink);
}

.score-footer {
  display: flex;
  gap: 10px;
}

.score-footer .btn {
  flex: 1;
}

/* Toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 96px);
  z-index: 100;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--text);
  color: var(--accent-ink);
  font-weight: 600;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
