:root {
  color-scheme: dark;
  --bg: #101820;
  --panel: #17232d;
  --muted: #9fb0bd;
  --text: #f8fbfd;
  --accent: #f7c948;
  --blue: #2f80ed;
  --red: #eb5757;
  --green: #27ae60;
  --line: rgba(255,255,255,.14);
}

* { box-sizing: border-box; }
html, body, #app { width: 100%; min-height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, Segoe UI, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
  border: 1px solid var(--line);
  background: #111b23;
  border-radius: 8px;
}

button {
  cursor: pointer;
  min-height: 44px;
  padding: 10px 14px;
  font-weight: 800;
}

button:active { transform: translateY(1px); }
input, select, textarea { min-height: 44px; padding: 9px 11px; width: 100%; }
input[type="checkbox"] { min-height: auto; width: auto; transform: scale(1.35); transform-origin: left center; }
textarea { resize: vertical; }
button:disabled, input:disabled, select:disabled, textarea:disabled {
  cursor: not-allowed;
  opacity: .55;
}
label { color: var(--muted); font-size: 13px; display: grid; gap: 6px; }

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(16,24,32,.92);
}

.brand { font-size: 18px; font-weight: 900; letter-spacing: .02em; }
.status { color: var(--muted); font-size: 13px; }
.app-version { color: #5f707d; }
.nav { display: flex; gap: 8px; flex-wrap: wrap; }
.nav button.active { background: var(--accent); color: #101820; }

.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 12px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.form { display: grid; gap: 12px; max-width: 1180px; margin: 0 auto; padding: 16px; }
.form-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.admin-lock {
  display: flex;
  align-items: end;
  gap: 8px;
}

.admin-lock label { flex: 1; }
.admin-state {
  color: var(--accent);
  font-weight: 900;
}

.field-picker {
  min-height: calc(100vh - 64px);
  display: grid;
  align-content: center;
  gap: 18px;
  padding: 20px;
}

.field-buttons { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.field-buttons button { min-height: 96px; font-size: 26px; background: var(--panel); }

.scoreboard {
  height: calc(100vh - 58px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  padding: 12px;
  overflow: hidden;
}

.match-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}

.team-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.timer {
  color: var(--accent);
  font-size: clamp(36px, 7vw, 92px);
  font-weight: 950;
  font-variant-numeric: tabular-nums;
  text-align: center;
  line-height: 1;
}

.time-up {
  color: #ffef9a;
  animation: time-pulse .8s ease-in-out infinite alternate;
}

.time-up.small {
  font-size: inherit;
}

.score-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  min-height: 0;
}

.team-score {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 8px;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  min-width: 0;
}

.team-score.a { background: #12315a; }
.team-score.b { background: #551c20; }
.team-name {
  font-size: clamp(20px, 3.8vw, 54px);
  font-weight: 900;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.points {
  display: grid;
  place-items: center;
  font-size: clamp(120px, 28vw, 420px);
  font-weight: 1000;
  font-variant-numeric: tabular-nums;
  line-height: .82;
}

.score-controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.score-controls button { font-size: 28px; min-height: 64px; }
.primary { background: var(--green); }
.danger { background: #5a1720; }
.ghost { background: transparent; }

.sets {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 18px;
  color: var(--muted);
  font-size: clamp(16px, 2.3vw, 34px);
  font-weight: 800;
}

.monitor {
  min-height: calc(100vh - 58px);
  display: grid;
  grid-template-rows: 1fr auto;
  overflow: hidden;
}

.monitor-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 10px;
  padding: 10px;
}

.monitor-field {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
}

.monitor-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: clamp(18px, 2vw, 32px);
  font-weight: 900;
}

.monitor-scores {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  min-height: 0;
}

.monitor-score {
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 10px;
  border-radius: 8px;
  min-width: 0;
}

.monitor-score.a { background: #12315a; }
.monitor-score.b { background: #551c20; }
.monitor-score .num {
  display: grid;
  place-items: center;
  font-size: clamp(72px, 16vw, 230px);
  line-height: .85;
  font-weight: 1000;
}

.ticker {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 74px;
  background: #f7c948;
  color: #101820;
  font-weight: 950;
  font-size: clamp(22px, 3vw, 44px);
  overflow: hidden;
}

.ticker span {
  animation: sponsor-pop 9s infinite;
  white-space: nowrap;
}

.flash {
  animation: flash-score .58s ease-out;
}

@keyframes flash-score {
  0% { box-shadow: 0 0 0 0 rgba(247,201,72,.95); transform: scale(1.02); }
  100% { box-shadow: 0 0 0 22px rgba(247,201,72,0); transform: scale(1); }
}

@keyframes sponsor-pop {
  0%, 78%, 100% { transform: translateY(0) scale(1); opacity: 1; }
  84% { transform: translateY(-4px) scale(1.06); opacity: .9; }
  90% { transform: translateY(4px) scale(.98); opacity: 1; }
}

@keyframes time-pulse {
  from { opacity: .55; text-shadow: 0 0 0 rgba(247,201,72,0); }
  to { opacity: 1; text-shadow: 0 0 18px rgba(247,201,72,.75); }
}

@media (max-width: 760px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .grid, .form-row, .field-buttons, .monitor-grid { grid-template-columns: 1fr; }
  .scoreboard { height: auto; min-height: calc(100vh - 100px); }
  .match-head, .score-row { grid-template-columns: 1fr; }
  .timer { order: -1; }
  .monitor { overflow: visible; }
}
