:root {
  --bg: #0d1117;
  --panel: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --subtle: #8b949e;
  --accent: #2f81f7;
  --good: #3fb950;
  --bad: #f85149;
  --warn: #d29922;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font:
    16px/1.45 -apple-system,
    "Segoe UI",
    Roboto,
    sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  overscroll-behavior: none;
}

.hidden {
  display: none !important;
}

.view {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) 12px
    max(12px, env(safe-area-inset-bottom));
  gap: 12px;
  max-width: 560px;
  margin: 0 auto;
}

.subtle {
  color: var(--subtle);
  font-size: 14px;
}

.center {
  text-align: center;
  padding: 24px 0;
}

.error {
  color: var(--bad);
  font-size: 14px;
}

.eyebrow {
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--subtle);
}

/* ---- login ---- */

#login-view {
  justify-content: center;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card h1 {
  font-size: 28px;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--subtle);
}

input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 12px 14px;
  font-size: 17px;
  width: 100%;
}

input:focus {
  outline: 2px solid var(--accent);
  border-color: transparent;
}

button {
  font: inherit;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text);
  background: var(--panel);
}

button.primary {
  background: var(--accent);
  padding: 14px;
  font-weight: 600;
  font-size: 17px;
}

button.ghost {
  background: none;
  color: var(--subtle);
  padding: 8px 10px;
  font-size: 14px;
}

a.ghost {
  color: var(--subtle);
  text-decoration: none;
  padding: 8px 10px;
  font-size: 14px;
}

/* ---- bars & pills ---- */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.bar h2 {
  font-size: 18px;
}

.bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ping-time {
  color: var(--subtle);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.pill {
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.pill.muted {
  background: var(--border);
  color: var(--subtle);
}

.pill.good {
  background: rgba(63, 185, 80, 0.18);
  color: var(--good);
}

.pill.bad {
  background: rgba(248, 81, 73, 0.18);
  color: var(--bad);
}

.pill.warn {
  background: rgba(210, 153, 34, 0.18);
  color: var(--warn);
}

.pill.live {
  background: rgba(248, 81, 73, 0.22);
  color: var(--bad);
}

/* ---- match list ---- */

.search input {
  font-size: 16px;
}

.match-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

.match-card {
  position: relative;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.match-card:active {
  border-color: var(--accent);
}

.match-names {
  font-size: 16px;
  font-weight: 600;
  padding-right: 52px;
}

.match-score {
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.match-meta {
  font-size: 13px;
  color: var(--subtle);
}

.match-card .pill.live {
  position: absolute;
  top: 12px;
  right: 12px;
}

/* ---- scoreboard ---- */

.scoreboard {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.score-row {
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 10px;
  align-items: baseline;
}

.score-name {
  font-size: 17px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-sets {
  font-variant-numeric: tabular-nums;
  color: var(--subtle);
  letter-spacing: 0.15em;
}

.score-game {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--accent);
}

/* ---- tap zone ---- */

.tap-zone {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.tap-button {
  flex: 1;
  min-height: 26dvh;
  border-radius: 16px;
  background: var(--panel);
  border: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  -webkit-user-select: none;
  user-select: none;
}

.tap-button:active {
  background: #1c2532;
  border-color: var(--accent);
  transform: scale(0.99);
}

.tap-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.big-hit {
  min-height: 38dvh;
  border-color: rgba(248, 81, 73, 0.45);
}

.big-hit:not(:disabled) {
  background: rgba(248, 81, 73, 0.16);
  border-color: var(--bad);
}

.pitch-row,
.latency-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

.pitch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pitch-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.pitch-actions .tap-button {
  min-height: 24dvh;
}

.pitch-ball:not(:disabled) {
  background: rgba(46, 160, 67, 0.16);
  border-color: var(--good);
}

.pitch-strike:not(:disabled) {
  background: rgba(248, 81, 73, 0.16);
  border-color: var(--bad);
}

.pitch-undo {
  grid-column: 1 / -1;
  min-height: 92px !important;
  background: rgba(210, 153, 34, 0.18);
  border-color: var(--warn);
}

.result-card {
  min-height: 82px;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-align: center;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.result-card strong {
  font-size: 18px;
}

.result-card span {
  color: var(--subtle);
  font-size: 14px;
}

.result-card.waiting {
  background: var(--panel);
}

.result-card.pending,
.result-card.close {
  background: rgba(210, 153, 34, 0.16);
  border-color: var(--warn);
}

.result-card.ahead {
  background: rgba(63, 185, 80, 0.16);
  border-color: var(--good);
}

.result-card.late {
  background: rgba(248, 81, 73, 0.16);
  border-color: var(--bad);
}

.result-card.wrong {
  background: rgba(112, 18, 24, 0.42);
  border-color: #9e2730;
}

.switch-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  font-weight: 700;
}

.switch-label input {
  width: 54px;
  height: 30px;
  accent-color: var(--good);
}

.latency-panel h3 {
  font-size: 14px;
  margin-bottom: 8px;
  color: var(--subtle);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.latency-chip .chip-status {
  font-size: 12px;
  white-space: normal;
  text-align: right;
}

.tap-label {
  font-size: 24px;
  font-weight: 700;
  padding: 0 12px;
  text-align: center;
}

.tap-sub {
  font-size: 13px;
  color: var(--subtle);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* ---- chips ---- */

.tap-chips {
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
  min-height: 44px;
}

.chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px;
}

.chip-label {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-status {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--subtle);
}

.chip[data-status="sending"] .chip-status {
  color: var(--warn);
}

.chip[data-status="pending"] .chip-status {
  color: var(--accent);
  animation: pulse 1.1s ease-in-out infinite;
}

.chip[data-status="green"] {
  border-color: rgba(63, 185, 80, 0.55);
}

.chip[data-status="green"] .chip-status {
  color: var(--good);
  font-weight: 700;
}

.chip[data-status="red"] {
  border-color: rgba(248, 81, 73, 0.55);
}

.chip[data-status="red"] .chip-status {
  color: var(--bad);
  font-weight: 700;
}

.chip[data-status="unconfirmed"] .chip-status,
.chip[data-status="voided"] .chip-status {
  color: var(--subtle);
}

.chip[data-status="failed"] .chip-status,
.chip[data-status="red"] .chip-status {
  color: var(--bad);
}

.chip.mismatch {
  border-color: var(--warn);
}

.chip.corrected {
  opacity: 0.75;
}

.chip-actions {
  display: flex;
  gap: 6px;
}

.chip-actions button {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

/* ---- warning banner ---- */

.warning-banner {
  background: rgba(210, 153, 34, 0.15);
  border: 1px solid var(--warn);
  color: var(--warn);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 600;
}

/* ---- toast ---- */

#toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s,
    transform 0.2s;
  max-width: 90vw;
}

#toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---- admin ---- */

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

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

table.admin th {
  color: var(--subtle);
  font-weight: 600;
}

.admin-scroll {
  overflow-x: auto;
}

.admin-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.admin-form input {
  width: auto;
  flex: 1;
  min-width: 140px;
}

.credentials {
  background: rgba(47, 129, 247, 0.12);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: ui-monospace, monospace;
  font-size: 14px;
  word-break: break-all;
}
