:root {
  --bg0: #e7f3ec;
  --bg1: #d4ebe0;
  --ink: #12241a;
  --muted: #4a6356;
  --line: rgba(18, 36, 26, 0.12);
  --court: #0f7a4b;
  --court-deep: #0a5c38;
  --sand: #f4e7c8;
  --warn: #c45c26;
  --panel: rgba(255, 255, 255, 0.82);
  --shadow: 0 12px 40px rgba(10, 60, 40, 0.12);
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  color: var(--ink);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(120% 80% at 10% -10%, #fff8e8 0%, transparent 55%),
    radial-gradient(90% 70% at 100% 0%, #b8e0c8 0%, transparent 50%),
    linear-gradient(165deg, var(--bg0), var(--bg1));
}

body {
  min-height: 100dvh;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(12px + var(--safe-t)) 14px calc(16px + var(--safe-b));
}

h1,
h2,
.brand {
  font-family: Outfit, "IBM Plex Sans", sans-serif;
  letter-spacing: -0.03em;
  margin: 0;
}

.brand {
  font-size: 1.55rem;
  font-weight: 800;
  line-height: 1.1;
}

.sub {
  color: var(--muted);
  font-size: 0.92rem;
  margin: 0.35rem 0 0;
}

.screen {
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: rise 0.35s ease both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.mode-switch {
  display: inline-flex;
  flex-shrink: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.55);
}

.mode-switch button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: Outfit, inherit;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 6px 10px;
  cursor: pointer;
  line-height: 1;
}

.mode-switch button.on {
  background: var(--court);
  color: #fff;
}

.hero-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

body[data-mode="test"] {
  --bg0: #f7ebe3;
  --bg1: #edd9cc;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field input,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 14px;
  padding: 14px 14px;
  font-size: 1.05rem;
  font-family: inherit;
  color: var(--ink);
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--court);
  box-shadow: 0 0 0 3px rgba(15, 122, 75, 0.18);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.choice-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.choice-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 1rem;
  font-weight: 700;
  font-family: Outfit, inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease;
}

.chip:active:not(:disabled) {
  transform: scale(0.97);
}

.chip.selected {
  border-color: var(--court);
  background: #e3f6eb;
  color: var(--court-deep);
  box-shadow: 0 0 0 3px rgba(15, 122, 75, 0.14);
}

.chip.disabled,
.chip:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.chip-ord {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 999px;
  background: var(--court);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 800;
}

.chip-add {
  border-style: dashed;
  color: var(--muted);
  font-weight: 650;
}

.add-player {
  display: grid;
  gap: 8px;
  margin-top: 8px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--line);
}

.add-player input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--ink);
  outline: none;
}

.add-player input:focus {
  border-color: var(--court);
  box-shadow: 0 0 0 3px rgba(15, 122, 75, 0.18);
}

.players {
  display: grid;
  gap: 10px;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 16px;
  padding: 15px 16px;
  font-size: 1.05rem;
  font-weight: 700;
  font-family: Outfit, inherit;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: linear-gradient(160deg, var(--court), var(--court-deep));
  color: #fff;
  box-shadow: var(--shadow);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.btn-warn {
  background: var(--sand);
  color: var(--warn);
}

.btn-block {
  width: 100%;
}

.error {
  color: var(--warn);
  font-size: 0.9rem;
  margin: 0;
}

/* Play layout: pairs left, score right */
.play-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.meta {
  font-size: 0.85rem;
  color: var(--muted);
}

.round-num {
  font-family: Outfit, inherit;
  font-weight: 800;
  font-size: 1.2rem;
}

.play-grid {
  display: grid;
  grid-template-columns: 1fr 108px;
  gap: 10px;
  align-items: stretch;
  min-height: 280px;
}

.pairs {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pair {
  flex: 1;
  border: 2px solid transparent;
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 16px 14px;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}

.pair:active {
  transform: scale(0.985);
}

.pair.selected {
  border-color: var(--court);
  background: #e3f6eb;
}

.pair.winner-done {
  border-color: var(--court-deep);
  background: #d7f0e2;
}

.pair .tag {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 8px;
}

.pair .names {
  font-family: Outfit, inherit;
  font-weight: 700;
  font-size: 1.2rem;
  line-height: 1.25;
}

.pair .names span {
  display: block;
}

.score-panel {
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  background: #123528;
  color: #f2fff7;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.score-panel .label {
  padding: 10px 8px 0;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.75;
  text-align: center;
}

.score-value {
  flex: 0 0 auto;
  font-family: Outfit, inherit;
  font-weight: 800;
  font-size: 2.4rem;
  text-align: center;
  padding: 4px 4px 8px;
  min-height: 52px;
}

.score-value.dim {
  opacity: 0.35;
}

.numpad {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 0 8px 8px;
  flex: 1;
}

.numpad button {
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-family: Outfit, inherit;
  font-weight: 700;
  font-size: 1.15rem;
  min-height: 44px;
  cursor: pointer;
}

.numpad button:active {
  background: rgba(255, 255, 255, 0.22);
}

.numpad .wide {
  grid-column: 1 / -1;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.actions .btn-primary {
  grid-column: 1 / -1;
}

.history {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 28vh;
  overflow: auto;
}

.history h2 {
  font-size: 0.95rem;
}

.hist-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.86rem;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.55);
}

.hist-item .score {
  font-weight: 700;
  color: var(--court-deep);
  white-space: nowrap;
}

.export-box {
  white-space: pre-wrap;
  word-break: break-word;
  background: #10281c;
  color: #e8fff2;
  border-radius: var(--radius);
  padding: 14px;
  font-size: 0.86rem;
  line-height: 1.45;
  max-height: 45vh;
  overflow: auto;
  box-shadow: var(--shadow);
}

.totals {
  display: grid;
  gap: 8px;
}

.total-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--panel);
  font-weight: 600;
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0;
}

.play-screen {
  padding-bottom: 8px;
}

.sticky-top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: linear-gradient(180deg, var(--bg0) 70%, transparent);
  padding-bottom: 8px;
}

.rounds-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.round-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr 64px;
  gap: 6px;
  align-items: stretch;
  padding: 6px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.42);
  border: 1px solid transparent;
}

.round-row.filled {
  border-color: rgba(15, 122, 75, 0.35);
  background: rgba(227, 246, 235, 0.7);
}

.round-row .side {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 12px;
  padding: 10px 8px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 650;
  font-family: Outfit, inherit;
  color: var(--ink);
  text-align: left;
  line-height: 1.25;
  cursor: pointer;
  min-height: 48px;
}

.round-row .side.selected {
  border-color: var(--court);
  background: #e3f6eb;
  color: var(--court-deep);
  box-shadow: 0 0 0 2px rgba(15, 122, 75, 0.16);
}

.round-row .vs {
  align-self: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: lowercase;
}

.round-row .score-input {
  width: 100%;
  border: 1px solid var(--line);
  background: #10281c;
  color: #e8fff2;
  border-radius: 12px;
  padding: 8px 4px;
  font-family: Outfit, inherit;
  font-weight: 800;
  font-size: 1.05rem;
  text-align: center;
  outline: none;
  -moz-appearance: textfield;
}

.round-row .score-input::-webkit-outer-spin-button,
.round-row .score-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.round-row .score-input:focus {
  border-color: var(--court);
  box-shadow: 0 0 0 2px rgba(15, 122, 75, 0.25);
}

.sticky-actions {
  position: sticky;
  bottom: 0;
  display: grid;
  gap: 8px;
  padding-top: 10px;
  padding-bottom: 4px;
  background: linear-gradient(0deg, var(--bg1) 70%, transparent);
}

@media (max-width: 360px) {
  .play-grid {
    grid-template-columns: 1fr 96px;
  }
  .pair .names {
    font-size: 1.05rem;
  }
  .score-value {
    font-size: 2rem;
  }
  .round-row {
    grid-template-columns: 1fr auto 1fr 56px;
  }
  .round-row .side {
    font-size: 0.74rem;
    padding: 8px 6px;
  }
}
