:root {
  --bg: #f3f6fb;
  --bg-accent: radial-gradient(120% 140% at 0% 0%, #ffffff 5%, #e7edf8 60%, #dbe6f9 100%);
  --card: rgba(255, 255, 255, 0.82);
  --text: #0b1220;
  --muted: #5b687f;
  --line: rgba(26, 37, 58, 0.11);
  --primary: #0f172a;
  --primary-text: #f8fafc;
  --chip: #e9eef8;
  --chip-active: #0f172a;
  --chip-active-text: #f8fafc;
  --radius: 20px;
  --shadow: 0 10px 35px rgba(20, 40, 80, 0.11);
  color-scheme: light;
  font-family: "Avenir Next", "SF Pro Display", "Segoe UI", sans-serif;
}

:root[data-theme='dark'] {
  --bg: #090f1b;
  --bg-accent: radial-gradient(130% 120% at 0% 0%, #1e293b 0%, #0f172a 52%, #050913 100%);
  --card: rgba(15, 23, 42, 0.82);
  --text: #f8fafc;
  --muted: #94a3b8;
  --line: rgba(148, 163, 184, 0.25);
  --primary: #e2e8f0;
  --primary-text: #0f172a;
  --chip: #1d2638;
  --chip-active: #e2e8f0;
  --chip-active-text: #0f172a;
  --shadow: 0 10px 35px rgba(2, 6, 23, 0.45);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #090f1b;
    --bg-accent: radial-gradient(130% 120% at 0% 0%, #1e293b 0%, #0f172a 52%, #050913 100%);
    --card: rgba(15, 23, 42, 0.82);
    --text: #f8fafc;
    --muted: #94a3b8;
    --line: rgba(148, 163, 184, 0.25);
    --primary: #e2e8f0;
    --primary-text: #0f172a;
    --chip: #1d2638;
    --chip-active: #e2e8f0;
    --chip-active-text: #0f172a;
    --shadow: 0 10px 35px rgba(2, 6, 23, 0.45);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  max-width: 100%;
  min-width: 100%;
  overflow-x: hidden;
  background-color: var(--bg);
  background-image: var(--bg-accent);
  background-repeat: no-repeat;
  background-size: cover;
}

body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  min-width: 100%;
  min-height: 100dvh;
  overflow-x: hidden;
  background-color: var(--bg);
  background-image: var(--bg-accent);
  background-repeat: no-repeat;
  background-size: cover;
  color: var(--text);
}

.page {
  width: min(100%, 382px);
  max-width: 382px;
  margin: 0 auto;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-right: max(6px, env(safe-area-inset-right));
  padding-bottom: max(18px, env(safe-area-inset-bottom));
  padding-left: max(6px, env(safe-area-inset-left));
  display: grid;
  gap: 10px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 10px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: flex-start;
  gap: 8px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.topbar-icon-wrap {
  width: 60px;
  height: 60px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background:
    linear-gradient(135deg, rgba(56, 189, 248, 0.15), rgba(14, 165, 233, 0.03)),
    var(--chip);
  display: grid;
  place-items: center;
}

.topbar-icon {
  width: 44px;
  height: 44px;
}

.topbar-main {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.topbar-main h1 {
  font-size: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-date {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  justify-content: flex-start;
  width: 32px;
  margin-right: 20px;
}

.icon-btn,
button {
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  font: inherit;
}

.icon-btn {
  width: 30px;
  height: 30px;
  background: var(--chip);
}

.reset-btn {
  width: 30px;
  height: 30px;
  background: var(--chip);
  color: var(--text);
  font-weight: 600;
  font-size: 19px;
  line-height: 1;
  border: 1px solid var(--line);
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transform: translateY(-1px);
}

.kicker {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.1;
}

h2 {
  font-size: 18px;
  margin-bottom: 10px;
}

.hero p {
  margin-top: 10px;
  color: var(--muted);
}

.hero-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.hero-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.date-pill {
  border: 1px solid var(--line);
  background: var(--chip);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11px;
  color: var(--muted);
}

.lang-btn {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--chip);
  display: grid;
  place-items: center;
  font-size: 15px;
  line-height: 1;
  padding: 0;
}

.hero-body {
  display: grid;
  grid-template-columns: 1fr 128px;
  gap: 12px;
  align-items: center;
}

.hero-visual {
  border: 1px solid var(--line);
  background:
    linear-gradient(135deg, rgba(56, 189, 248, 0.12), rgba(14, 165, 233, 0.03)),
    var(--chip);
  border-radius: 18px;
  padding: 10px;
  display: grid;
  place-items: center;
}

.hero-visual img {
  width: 82px;
  height: 82px;
}

textarea,
input {
  width: 100%;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  padding: 12px;
  font: inherit;
}

#setup-form {
  display: grid;
  gap: 10px;
}

.primary {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: var(--primary-text);
  font-weight: 600;
}

.setup-grid {
  display: grid;
  gap: 10px;
}

.setup-row {
  display: grid;
  grid-template-columns: 26px 1fr 48px;
  gap: 10px;
  align-items: center;
}

.setup-index {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.setup-input {
  height: 48px;
}

.avatar-circle {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--chip);
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--muted);
}

.avatar-circle img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-circle.ready {
  border-color: transparent;
}

.matchup {
  display: grid;
  gap: 10px;
}

.team-row {
  display: grid;
  grid-template-columns: 1fr 62px;
  gap: 8px;
  align-items: center;
}

.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.player-slot {
  background: var(--chip);
  color: var(--text);
  padding: 10px 8px;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  border: 1px solid var(--line);
}

.player-slot img {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  object-fit: cover;
}

.player-slot span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-box {
  text-align: center;
  font-weight: 700;
  padding: 8px 6px;
}

.vs {
  display: block;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.rest {
  color: var(--muted);
}

.row {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

.ghost {
  flex: 1;
  padding: 10px;
  background: var(--chip);
  color: var(--text);
}


.hint {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.score {
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

.score label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.editor {
  animation: rise 0.22s ease;
}

@keyframes rise {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.chips {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 8px 12px;
  background: var(--chip);
  color: var(--text);
}

.chip.active {
  background: var(--chip-active);
  color: var(--chip-active-text);
}

.chip-player {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.chip-player img {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  object-fit: cover;
}

.finish {
  margin-top: 4px;
  transition: opacity 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.finish.disabled {
  opacity: 1;
  background: var(--chip);
  color: var(--muted);
}

.finish.enabled {
  opacity: 1;
  background: var(--primary);
  color: var(--primary-text);
}

.summary-btn {
  margin-top: 12px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.45);
  display: grid;
  place-items: end center;
  padding: 16px;
  z-index: 20;
}

.modal {
  width: min(460px, 100%);
  animation: rise 0.2s ease;
}

.winner {
  place-items: center;
}

.winner .modal {
  width: min(360px, 92vw);
}

.winner-card {
  text-align: center;
  display: grid;
  gap: 10px;
}

.winner-card .row {
  margin-top: 0;
}

.winner-card .row button {
  flex: 1;
  width: auto;
}

.winner-card::before {
  content: '';
  height: 84px;
  border-radius: 14px;
  background:
    linear-gradient(135deg, rgba(14, 165, 233, 0.2), rgba(2, 132, 199, 0.06)),
    url('/assets/padel-player.svg') center/48px 48px no-repeat;
}

.winner-team {
  font-size: 18px;
  font-weight: 700;
}

.winner-score {
  font-size: 28px;
  letter-spacing: 0.06em;
  color: #0ea5e9;
}

.winner-score-strong {
  font-weight: 800;
}

.winner-score-sep {
  margin: 0 4px;
  font-weight: 600;
}

.winner-score-soft {
  font-weight: 500;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.history-table td:nth-child(2) {
  white-space: normal;
}

.history-pairs {
  display: grid;
  justify-items: start;
  gap: 2px;
  width: 100%;
  margin: 0;
}

.history-pair {
  justify-self: start;
  text-align: left;
  line-height: 1.25;
}

.history-vs {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-align: left;
  width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.leader-name {
  color: #0ea5e9;
  font-weight: 800;
}

.leader-metric {
  color: #0ea5e9;
  font-weight: 800;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--primary);
  color: var(--primary-text);
  padding: 10px 14px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 25;
  font-size: 13px;
}

@media (max-width: 360px) {
  h1 {
    font-size: 22px;
  }

  .primary {
    padding: 12px;
  }

  .team-row {
    grid-template-columns: 1fr 62px;
  }

  .hero-body {
    grid-template-columns: 1fr;
  }

  .hero-visual {
    display: grid;
  }
}

@media (max-width: 430px) {
  h1 {
    font-size: 24px;
  }

  .actions .icon-btn {
    width: 30px;
    height: 30px;
  }

  .actions {
    width: 32px;
    gap: 4px;
    margin-right: 18px;
  }

  .reset-btn {
    width: 30px;
    height: 30px;
    font-size: 18px;
  }
}
