#app {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
}

.screen {
  min-height: 100%;
  padding: calc(env(safe-area-inset-top) + 20px) calc(env(safe-area-inset-right) + 20px) calc(env(safe-area-inset-bottom) + 20px) calc(env(safe-area-inset-left) + 20px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 720px;
  margin: 0 auto;
}

h1 {
  font-size: clamp(22px, 4vw, 30px);
  letter-spacing: 0.04em;
  margin: 0;
  text-align: center;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.top-bar h1 { text-align: left; }

.btn {
  min-height: 60px;
  padding: 0 24px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 18px;
  font-weight: 600;
}
.btn:disabled { opacity: 0.35; }
.btn-primary {
  background: #4da3ff;
  color: #061019;
}
.btn-danger {
  background: rgba(255, 77, 90, 0.14);
  border: 1px solid rgba(255, 77, 90, 0.5);
  color: #ff4d5a;
}
.btn-large {
  width: 100%;
  font-size: 20px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 24px;
}
.modal-box {
  width: 100%;
  max-width: 420px;
  background: #14171f;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 18px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.modal-message {
  margin: 0;
  font-size: 18px;
  line-height: 1.4;
  text-align: center;
}
.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modal-actions .btn {
  width: 100%;
}

.input-row {
  display: flex;
  gap: 12px;
}
.name-input {
  flex: 1;
  min-height: 60px;
  font-size: 20px;
  border-radius: 14px;
  border: none;
  padding: 0 16px;
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.name-chip {
  min-height: 48px;
  padding: 0 18px;
  border-radius: 24px;
  background: rgba(77, 163, 255, 0.18);
  border: 1px solid rgba(77, 163, 255, 0.5);
  font-size: 16px;
}

.races-per-player-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 16px;
  opacity: 0.85;
}
.races-input {
  width: 72px;
  min-height: 48px;
  font-size: 18px;
  text-align: center;
  border-radius: 12px;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
}

.summary {
  opacity: 0.75;
  text-align: center;
  font-size: 16px;
}

.repeat-note {
  opacity: 0.6;
  font-size: 14px;
  text-align: center;
}

.race-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.race-card {
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 16px;
  min-height: 60px;
}
.race-card.done {
  border-color: rgba(61, 220, 132, 0.4);
  background: rgba(61, 220, 132, 0.07);
}
.race-card.next {
  border-color: #ffcc33;
  box-shadow: 0 0 24px rgba(255, 204, 51, 0.15);
}
.race-card-title {
  font-weight: 700;
  font-size: 16px;
  opacity: 0.7;
  margin-bottom: 4px;
}
.race-card-names {
  font-size: 18px;
}
.race-card-result {
  margin-top: 8px;
  font-size: 15px;
  opacity: 0.85;
}
.race-card-hint {
  margin-top: 8px;
  font-size: 14px;
  color: #ffcc33;
}

.order-line {
  min-height: 32px;
  font-size: 18px;
  text-align: center;
  opacity: 0.9;
}

.player-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.player-button {
  min-height: 72px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 20px;
  font-weight: 600;
}
.player-button.placed {
  opacity: 0.3;
}

.entry-actions {
  display: flex;
  gap: 12px;
}
.entry-actions .btn { flex: 1; }

.tiebreak-note {
  opacity: 0.8;
  font-size: 15px;
  line-height: 1.4;
}

.standings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 16px;
}
.standings-table th, .standings-table td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.standings-table tr.qualifying {
  background: rgba(77, 163, 255, 0.1);
}

.qualifier-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.qualifier-row {
  min-height: 60px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-radius: 14px;
  background: rgba(77, 163, 255, 0.12);
  font-size: 20px;
  font-weight: 600;
}

.champion-screen {
  align-items: center;
  justify-content: center;
  text-align: center;
}
.champion-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 400px;
}
.champion-row {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 18px;
}
.champion-row.winner {
  background: rgba(255, 204, 51, 0.18);
  border: 1px solid #ffcc33;
  font-size: 24px;
  font-weight: 700;
}

.bracket-screen {
  max-width: none;
}

.bracket-flow {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 56px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 12px;
}

.bracket-lines {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  overflow: visible;
}
.bracket-line {
  fill: none;
  stroke: rgba(255, 255, 255, 0.18);
  stroke-width: 2;
}
.bracket-line.done {
  stroke: rgba(61, 220, 132, 0.6);
  stroke-width: 2.5;
}

.bracket-column {
  display: flex;
  flex-direction: column;
  min-width: 180px;
  flex-shrink: 0;
}
.bracket-column-narrow {
  min-width: 150px;
}
.bracket-column-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.6;
  text-align: center;
  margin-bottom: 2px;
}
.bracket-column-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
}

.bracket-race,
.bracket-node {
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 10px 12px;
}
.bracket-race.done {
  border-color: rgba(61, 220, 132, 0.4);
  background: rgba(61, 220, 132, 0.07);
}
.bracket-node.ready {
  border-color: rgba(77, 163, 255, 0.5);
  background: rgba(77, 163, 255, 0.08);
}
.bracket-node.champion-node.ready {
  border-color: #ffcc33;
  background: rgba(255, 204, 51, 0.12);
}
.bracket-node-small {
  padding: 12px;
}
.bracket-race-title,
.bracket-node-title {
  font-weight: 700;
  font-size: 13px;
  opacity: 0.65;
  margin-bottom: 4px;
}
.bracket-name {
  font-size: 15px;
  padding: 2px 0;
}
.bracket-name.pending {
  opacity: 0.55;
}
.bracket-name.winner {
  color: #ffcc33;
  font-weight: 700;
}

#fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 500;
}
