:root {
  --bg: #04140d;
  --surface: #071f15;
  --surface-2: #0b2b1d;
  --surface-3: #0f3b28;
  --line: rgba(232, 255, 239, .14);
  --text: #effff4;
  --muted: #9fc1ac;
  --green: #16a05b;
  --green-soft: #113f2b;
  --lime: #d6ff72;
  --danger: #ff776f;
  --shadow: 0 18px 42px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(90deg, transparent calc(50% - 1px), rgba(255,255,255,.06) 50%, transparent calc(50% + 1px)),
    linear-gradient(180deg, rgba(7,63,40,.88), var(--bg) 34rem);
}

button, input { font: inherit; }

button {
  border: 0;
  cursor: pointer;
  color: var(--text);
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(2, 14, 9, .72);
  color: var(--text);
  min-height: 46px;
  padding: 0 12px;
  outline: none;
}

input:focus {
  border-color: rgba(214, 255, 114, .72);
  box-shadow: 0 0 0 3px rgba(214, 255, 114, .12);
}

input::placeholder { color: rgba(239, 255, 244, .42); }

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 3px; font-size: 1.42rem; letter-spacing: 0; }
h2 { margin-bottom: 4px; font-size: 1.18rem; }

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 16px 16px 96px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  min-height: 62px;
}

.topbar p,
.section-head p,
.meta,
.empty span {
  color: var(--muted);
}

.topbar p {
  margin-bottom: 0;
  font-size: .9rem;
  font-weight: 700;
}

.ghost-btn,
.secondary {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 13px;
  background: rgba(255, 255, 255, .08);
  color: var(--text);
  font-weight: 850;
}

.view { display: none; }
.view.active { display: block; }

.match-view {
  display: none;
  gap: 12px;
}

.match-view.active {
  display: grid;
}

.match-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 74px minmax(0, 1fr);
  min-height: clamp(430px, calc(100vh - 260px), 680px);
  border: 1px solid rgba(232, 255, 239, .18);
  border-radius: 8px;
  overflow: hidden;
  background:
    linear-gradient(90deg, transparent calc(50% - 1px), rgba(239,255,244,.22) 50%, transparent calc(50% + 1px)),
    linear-gradient(180deg, var(--surface-3), var(--surface));
  box-shadow: var(--shadow);
}

.team-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 14px;
  min-width: 0;
  padding: 16px;
}

.team-a { border-right: 1px solid rgba(239,255,244,.13); }
.team-b { border-left: 1px solid rgba(239,255,244,.13); }

.team-fields {
  display: grid;
  gap: 8px;
}

.team-name {
  min-height: 50px;
  font-weight: 950;
  font-size: 1.04rem;
}

.partner-name {
  min-height: 38px;
  font-size: .9rem;
}

.score-input {
  align-self: center;
  height: 100%;
  min-height: 180px;
  border: 0;
  background: transparent;
  text-align: center;
  font-size: clamp(6rem, 20vw, 14rem);
  font-weight: 950;
  line-height: 1;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.score-controls {
  display: grid;
  grid-template-columns: .72fr 1.28fr;
  gap: 10px;
}

.score-controls button {
  min-height: 72px;
  border-radius: 8px;
  font-size: 1.6rem;
  font-weight: 950;
}

.score-controls .plus {
  background: var(--lime);
  color: #132006;
}

.score-controls .minus {
  background: rgba(255, 119, 111, .14);
  color: #ffd8d5;
}

.match-center {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, .12);
}

.match-center span {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(239,255,244,.18);
  border-radius: 8px;
  background: rgba(3, 18, 11, .7);
  color: var(--muted);
  font-weight: 950;
}

.match-center small,
.pill {
  color: var(--muted);
  font-weight: 850;
}

.control-strip {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(220px, .7fr);
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(7, 31, 21, .92);
  box-shadow: var(--shadow);
}

.target-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  grid-column: 1 / -1;
}

.target-row button {
  min-width: 62px;
  min-height: 38px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .08);
  color: var(--muted);
  font-weight: 850;
}

.target-row button.active {
  background: var(--green);
  color: #02140b;
}

.finish-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
}

.primary {
  min-height: 48px;
  border-radius: 8px;
  padding: 0 16px;
  background: var(--green);
  color: #02140b;
  font-weight: 950;
}

.page-view {
  padding-top: 10px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.section-head p { margin-bottom: 0; }
.compact { min-height: 38px; }

.panel,
.history-item,
.rank-row,
.empty {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(7, 31, 21, .92);
  box-shadow: var(--shadow);
}

.panel { padding: 14px; margin-bottom: 12px; }

.inline-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.list,
.ranking,
.chips {
  display: grid;
  gap: 10px;
}

.history-item,
.rank-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 14px;
}

.history-score,
.rank-score {
  font-size: 1.48rem;
  font-weight: 950;
  color: var(--lime);
  font-variant-numeric: tabular-nums;
}

.meta {
  margin: 5px 0 0;
  font-size: .9rem;
}

.delete-match {
  display: block;
  margin-left: auto;
  margin-top: 6px;
  background: transparent;
  color: var(--danger);
  font-weight: 850;
  padding: 6px 0;
}

.rank-row {
  grid-template-columns: auto 1fr auto;
}

.rank-pos {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .08);
  color: var(--lime);
  font-weight: 950;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  width: fit-content;
  border-radius: 999px;
  padding: 0 12px;
  background: rgba(255, 255, 255, .08);
  color: var(--text);
  font-weight: 850;
}

.empty {
  display: grid;
  gap: 6px;
  padding: 22px;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 12px;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  width: min(680px, calc(100% - 24px));
  padding: 7px;
  border: 1px solid rgba(232,255,239,.16);
  border-radius: 8px;
  background: rgba(4, 20, 13, .9);
  transform: translateX(-50%);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.tab {
  min-height: 44px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: .84rem;
  font-weight: 900;
}

.tab.active {
  background: var(--green);
  color: #02140b;
}

@media (max-width: 820px) {
  .app-shell { padding: 12px 12px 92px; }
  .topbar { min-height: 54px; }
  h1 { font-size: 1.24rem; }
  .topbar p { font-size: .82rem; }

  .match-card {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .team-panel {
    min-height: calc((100vh - 316px) / 2);
    padding: 12px;
  }

  .team-a {
    border-right: 0;
    border-bottom: 1px solid rgba(239,255,244,.13);
  }

  .team-b {
    border-left: 0;
    border-top: 1px solid rgba(239,255,244,.13);
  }

  .team-fields {
    grid-template-columns: 1fr 1fr;
  }

  .match-center {
    min-height: 40px;
    grid-auto-flow: column;
  }

  .match-center span {
    width: auto;
    height: auto;
    border: 0;
    background: transparent;
  }

  .score-input {
    min-height: 98px;
    font-size: clamp(5.8rem, 28vw, 9rem);
  }

  .score-controls button {
    min-height: 60px;
  }

  .control-strip {
    grid-template-columns: 1fr;
  }

  .target-row {
    grid-column: auto;
  }

  .finish-row,
  .inline-form,
  .history-item {
    grid-template-columns: 1fr;
  }

  .bottom-nav {
    bottom: 8px;
  }
}

@media (max-width: 420px) {
  .team-fields {
    grid-template-columns: 1fr;
  }

  .ghost-btn {
    min-height: 38px;
    padding: 0 10px;
  }

  .tab {
    font-size: .78rem;
  }
}
