:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --surface: #141821;
  --surface-2: #1b2130;
  --border: #262e3f;
  --fg: #eef2f8;
  --muted: #93a0b5;
  --accent: #4f8cff;
  --home: #55d6be;
  --away: #ffb020;
  --danger: #ff5d5d;
  --ok: #45d483;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(79, 140, 255, 0.14), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(85, 214, 190, 0.08), transparent 60%),
    var(--bg);
  color: var(--fg);
  font-family: var(--font);
  line-height: 1.45;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.muted {
  color: var(--muted);
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
  min-height: 1.2em;
}

.hidden {
  display: none !important;
}

.shell {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

/* ---------- home ---------- */
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 32px 0 28px;
}

.brand .mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--bg);
  font-size: 1.4rem;
  font-weight: 700;
}

.brand h1 {
  font-size: 1.5rem;
  letter-spacing: 0.01em;
}

.brand p {
  color: var(--muted);
  font-size: 0.95rem;
}

.home .grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
  align-items: start;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.card h2 {
  font-size: 1.02rem;
  margin-bottom: 14px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.card h2:not(:first-child) {
  margin-top: 18px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field label {
  font-size: 0.82rem;
  color: var(--muted);
}

input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--fg);
  font: inherit;
}

input:focus {
  outline: 2px solid rgba(79, 140, 255, 0.45);
  outline-offset: 1px;
  border-color: var(--accent);
}

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--fg);
  border-radius: 10px;
  padding: 9px 14px;
  transition: background 120ms ease, border-color 120ms ease, transform 80ms ease;
}

button:hover:not(:disabled) {
  border-color: #3a465e;
  background: #232b3d;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

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

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #071023;
  font-weight: 650;
}

button.primary:hover:not(:disabled) {
  background: #6a9cff;
  border-color: #6a9cff;
}

button.ghost {
  background: transparent;
}

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

.row input {
  flex: 1;
}

.hint {
  color: var(--muted);
  font-size: 0.84rem;
  margin-top: 10px;
}

.code-input {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-family: var(--mono);
}

.recent {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.recent a {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--fg);
  background: var(--surface-2);
}

.recent a:hover {
  text-decoration: none;
  border-color: var(--accent);
}

.recent .meta {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ---------- game ---------- */
.topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
  font-size: 0.9rem;
}

.topbar .brand-link {
  font-weight: 700;
  color: var(--fg);
  letter-spacing: 0.02em;
}

.topbar .sport {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
}

.topbar .spacer {
  flex: 1;
}

.ghost-link {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--fg);
  background: transparent;
  font-size: 0.9rem;
  white-space: nowrap;
}

.ghost-link:hover {
  text-decoration: none;
  border-color: #3a465e;
  background: #232b3d;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  background: var(--surface);
}

.status.live {
  color: var(--ok);
  border-color: rgba(69, 212, 131, 0.4);
}

.status.final {
  color: var(--muted);
}

.pill[data-mode="live"]::before,
.status.live::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 0 rgba(69, 212, 131, 0.6);
  animation: pulse 1.8s infinite;
}

.pill[data-mode="connecting"],
.pill[data-mode="offline"] {
  color: var(--away);
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(69, 212, 131, 0.55);
  }
  70% {
    box-shadow: 0 0 0 7px rgba(69, 212, 131, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(69, 212, 131, 0);
  }
}

.board {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(190px, 0.62fr) minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
}

.team {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
}

.team.home {
  border-top: 3px solid var(--home);
}

.team.away {
  border-top: 3px solid var(--away);
}

.team-name {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-align: center;
  overflow-wrap: anywhere;
}

.team .score {
  font-size: clamp(3.2rem, 9vw, 6.4rem);
  line-height: 0.95;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.team.home .score {
  color: var(--home);
}

.team.away .score {
  color: var(--away);
}

.score-entry {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.player-input {
  width: 104px;
  padding: 6px 10px;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.86rem;
}

.score-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.score-btn {
  min-width: 52px;
  padding: 10px 12px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.team.home .score-btn {
  border-color: rgba(85, 214, 190, 0.35);
}

.team.away .score-btn {
  border-color: rgba(255, 176, 32, 0.35);
}

.middle {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}

.period {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.76rem;
}

.clock {
  font-family: var(--mono);
  font-size: clamp(1.6rem, 4vw, 2.3rem);
  font-variant-numeric: tabular-nums;
}

.timeout-clock,
.break-clock {
  font-family: var(--mono);
  font-size: 0.92rem;
  border-radius: 999px;
  padding: 4px 12px;
  font-variant-numeric: tabular-nums;
}

.timeout-clock {
  color: var(--away);
  background: rgba(255, 176, 32, 0.12);
  border: 1px solid rgba(255, 176, 32, 0.35);
}

.break-clock {
  color: var(--accent);
  background: rgba(79, 140, 255, 0.12);
  border: 1px solid rgba(79, 140, 255, 0.35);
}

.clock-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  margin-top: 4px;
}

.clock-controls .row {
  width: 100%;
}

.clock-controls button {
  padding: 7px 10px;
  font-size: 0.84rem;
}

.timeout-btn {
  width: 100%;
  border-color: rgba(255, 176, 32, 0.45);
  color: var(--away);
  font-weight: 600;
}

.timeout-btn:hover:not(:disabled) {
  border-color: var(--away);
  background: rgba(255, 176, 32, 0.12);
}

.break-btn {
  width: 100%;
  border-color: rgba(79, 140, 255, 0.45);
  color: var(--accent);
  font-weight: 600;
}

.break-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: rgba(79, 140, 255, 0.12);
}

.clock-controls input {
  min-width: 0;
  font-family: var(--mono);
  text-align: center;
}

.period-controls {
  display: flex;
  gap: 8px;
}

.note-row {
  display: flex;
  gap: 6px;
  width: 100%;
}

.note-row input {
  min-width: 0;
}

.below {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(240px, 1fr);
  gap: 16px;
  margin-top: 16px;
  align-items: start;
}

.feed-wrap h2,
.side .card h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 12px;
}

.feed {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 46vh;
  overflow-y: auto;
}

.feed li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 4px;
  border-bottom: 1px solid rgba(38, 46, 63, 0.6);
  font-size: 0.94rem;
}

.feed li:last-child {
  border-bottom: 0;
}

.event-time {
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--muted);
  flex: none;
  width: 5.2em;
}

.event-body {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.event-author {
  color: var(--muted);
  font-size: 0.76rem;
  flex: none;
}

.feed li.voided .event-body {
  text-decoration: line-through;
  color: var(--muted);
}

.undo {
  padding: 2px 8px;
  font-size: 0.72rem;
  border-radius: 7px;
  flex: none;
  opacity: 0.55;
}

.feed li:hover .undo,
.feed li:focus-within .undo {
  opacity: 1;
}

.code {
  font-family: var(--mono);
  font-size: 1.7rem;
  letter-spacing: 0.22em;
  font-weight: 700;
  color: var(--accent);
  margin: 4px 0 10px;
}

.joined {
  list-style: none;
  padding: 0;
  margin: 10px 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.joined li {
  font-size: 0.78rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
  color: var(--muted);
}

.side {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.who {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #2a1520;
  border: 1px solid rgba(255, 93, 93, 0.5);
  color: #ffd7d7;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.9rem;
  z-index: 50;
  max-width: min(90vw, 480px);
}

.empty {
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 760px) {
  .board {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .middle {
    order: -1;
  }

  .team {
    flex-direction: row;
    padding: 16px;
    gap: 12px;
  }

  .team .score {
    font-size: clamp(2.6rem, 14vw, 4rem);
  }

  .team .score-actions {
    justify-content: flex-end;
  }

  .team .score-entry {
    align-items: flex-end;
  }

  .team-name {
    flex: 1;
    text-align: left;
  }

  .team.home,
  .team.away {
    border-top: 0;
    border-left: 3px solid var(--home);
  }

  .team.away {
    border-left-color: var(--away);
  }

  .below {
    grid-template-columns: 1fr;
  }
}
