:root {
  --bg: #000;
  --fg: #fff;
  --accent: #ffe600;
  --muted: #c8c8c8;
  --live: #7cff6b;
  --warn: #ffc107;
  --us: #ffe600;
  --them: #ffffff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
  font-family: Arial Black, Arial, Helvetica, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.board {
  height: 100dvh;
  width: 100vw;
  display: grid;
  grid-template-columns: 1fr minmax(200px, 28vw) 1fr;
  grid-template-rows: auto auto 1fr auto;
  grid-template-areas:
    "status status status"
    "uslab call themlab"
    "us mid them"
    "actions actions actions";
  padding: 8px 12px 10px;
  gap: 4px 12px;
}

.status-row {
  grid-area: status;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 28px;
}

.conn {
  font-size: 14px;
  letter-spacing: 0.12em;
  font-weight: 700;
  font-family: Arial, Helvetica, sans-serif;
}
.conn.live { color: var(--live); }
.conn.reconnecting { color: var(--warn); }

.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid #444;
  padding: 4px 10px;
  font-size: 12px;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.label {
  font-size: clamp(18px, 3.2vw, 42px);
  letter-spacing: 0.08em;
  text-align: center;
  align-self: end;
}
.us-label { grid-area: uslab; color: var(--us); }
.them-label { grid-area: themlab; color: var(--them); }

.call-wrap {
  grid-area: call;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
}

.call {
  font-size: clamp(28px, 7.2vw, 96px);
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: 0.04em;
  color: var(--accent);
  white-space: nowrap;
}

.serve-line {
  font-family: Arial, Helvetica, sans-serif;
  font-size: clamp(12px, 1.6vw, 22px);
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 2px;
}

.score-btn {
  background: transparent;
  border: 6px solid transparent;
  color: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
}
.score-btn.us { grid-area: us; }
.score-btn.them { grid-area: them; }
.score-btn.serving {
  border-color: var(--accent);
  box-shadow: inset 0 10px 0 var(--accent);
}

.score {
  font-size: clamp(72px, 22vw, 280px);
  font-weight: 900;
  line-height: 0.85;
  font-variant-numeric: tabular-nums;
}

.serve-mark {
  font-family: Arial, Helvetica, sans-serif;
  font-size: clamp(14px, 1.8vw, 24px);
  letter-spacing: 0.16em;
  color: var(--accent);
  opacity: 0;
  height: 1.4em;
}
.score-btn.serving .serve-mark { opacity: 1; }

.dot {
  display: inline-block;
  width: 0.7em;
  height: 0.7em;
  margin-left: 0.35em;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.7); }
}

.mid {
  grid-area: mid;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-width: 0;
}

.court {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: min(100%, 240px);
  height: min(22vh, 140px);
  border: 3px solid #fff;
  background: #111;
}
.box {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  letter-spacing: 0.1em;
  color: #888;
  border-right: 3px solid #fff;
}
.box:last-child { border-right: 0; }
.box.active {
  background: var(--accent);
  color: #000;
  font-weight: 900;
}

.server-num {
  font-family: Arial, Helvetica, sans-serif;
  font-size: clamp(14px, 2vw, 28px);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.server-num.hide { visibility: hidden; }

.actions {
  grid-area: actions;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  padding: 4px 0 2px;
}

.actions button, .panel button, .panel input, .panel select {
  font-family: Arial, Helvetica, sans-serif;
}

.actions button {
  background: #161616;
  color: #fff;
  border: 2px solid #555;
  min-height: 52px;
  font-size: 18px;
  letter-spacing: 0.12em;
  font-weight: 800;
  cursor: pointer;
}
.actions button:disabled {
  opacity: 0.35;
}

.banner {
  position: fixed;
  inset: 12vh 6vw auto;
  background: var(--accent);
  color: #000;
  text-align: center;
  padding: 18px 16px 14px;
  z-index: 5;
  pointer-events: none;
}
.banner.hidden { display: none; }
.banner #bannerText {
  font-size: clamp(36px, 8vw, 96px);
  font-weight: 900;
  letter-spacing: 0.06em;
}
.banner-sub {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 18px;
  font-weight: 700;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.86);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.overlay.hidden { display: none; }

.panel {
  background: #111;
  border: 2px solid #ffe600;
  max-width: 720px;
  width: 100%;
  max-height: 96dvh;
  overflow: auto;
  padding: 18px 20px 16px;
  color: #fff;
}
.panel h2 {
  margin: 0 0 12px;
  color: var(--accent);
  letter-spacing: 0.08em;
}
.panel form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
}
.panel label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  letter-spacing: 0.04em;
}
.panel input, .panel select {
  background: #000;
  color: #fff;
  border: 1px solid #666;
  padding: 8px;
  font-size: 16px;
}
.panel .check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.row-btns {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
}
.row-btns button {
  flex: 1;
  min-height: 44px;
  background: var(--accent);
  color: #000;
  border: 0;
  font-weight: 900;
  letter-spacing: 0.1em;
  cursor: pointer;
}
#closeSettings { background: #333; color: #fff; }
.settings-error {
  grid-column: 1 / -1;
  color: var(--accent);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  margin: 0;
}
.settings-error.hidden { display: none; }
.court-code-row { grid-column: 1 / -1; }
.court-code-row input { letter-spacing: 0.08em; }

.net {
  margin-top: 14px;
  font-family: Arial, Helvetica, sans-serif;
}
.lan {
  color: var(--accent);
  font-size: 22px;
  font-weight: 900;
  margin-top: 4px;
  word-break: break-all;
}
.phone-setup {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  padding-left: 20px;
}
.wake-note {
  font-family: Arial, Helvetica, sans-serif;
  color: var(--muted);
  font-size: 13px;
}

body.flash .board {
  outline: 12px solid #fff;
  outline-offset: -12px;
}

@media (max-width: 900px) and (orientation: portrait) {
  .board {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto 1fr auto;
    grid-template-areas:
      "status status"
      "call call"
      "uslab themlab"
      "us them"
      "actions actions";
  }
  .mid { display: none; }
  .score { font-size: min(28vw, 28vh); }
  .call { font-size: min(10vw, 8vh); }
}
