:root {
  --page-bg: #0f172a;
  --panel-bg: rgba(15, 23, 42, 0.78);
  --panel-border: rgba(148, 163, 184, 0.24);
  --text-main: #f8fafc;
  --text-muted: #cbd5e1;
  --button-bg: rgba(255, 255, 255, 0.1);
  --button-border: rgba(255, 255, 255, 0.14);
  --positive: #16a34a;
  --negative: #dc2626;
  --warning: #f59e0b;
  --shadow: 0 24px 80px rgba(15, 23, 42, 0.45);
  color-scheme: dark;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #1e293b 0%, #0f172a 45%, #020617 100%);
  color: var(--text-main);
}

body.viewer-body {
  overflow: hidden;
}

.page-shell {
  width: min(1600px, calc(100vw - 2rem));
  margin: 0 auto;
  padding: 1rem 0 2rem;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  margin: 1rem 0 1.5rem;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.page-header h1,
.page-header h2,
.page-header p {
  margin: 0;
}

.page-header h1,
.page-header h2 {
  font-size: clamp(1.8rem, 3vw, 3rem);
}

.page-header p,
.status-text,
.updated-at {
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.team-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.team-card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 320px;
  padding: 1.1rem;
  border-radius: 26px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--team-color) 26%, rgba(15, 23, 42, 0.96)) 0%, rgba(15, 23, 42, 0.96) 100%);
  border: 1px solid color-mix(in srgb, var(--team-color) 65%, white 8%);
  box-shadow: var(--shadow);
}

.team-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.team-name {
  font-size: clamp(1.15rem, 2vw, 1.7rem);
  font-weight: 700;
}

.score-box {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 132px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.score-value {
  font-size: clamp(3.6rem, 10vw, 7rem);
  font-weight: 800;
  line-height: 1;
}

.button-row,
.custom-controls,
.viewer-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}

button,
input {
  border-radius: 14px;
  border: 1px solid var(--button-border);
  background: var(--button-bg);
  color: var(--text-main);
  font: inherit;
}

button {
  min-height: 48px;
  padding: 0.7rem 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

button:hover,
button:focus-visible {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.22);
}

button.positive {
  background: color-mix(in srgb, var(--positive) 55%, rgba(15, 23, 42, 0.7));
}

button.negative {
  background: color-mix(in srgb, var(--negative) 55%, rgba(15, 23, 42, 0.7));
}

button.warning {
  background: color-mix(in srgb, var(--warning) 55%, rgba(15, 23, 42, 0.7));
}

button.secondary {
  background: rgba(148, 163, 184, 0.16);
}

input {
  flex: 1 1 120px;
  min-height: 48px;
  padding: 0.7rem 0.9rem;
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-top: auto;
}

.viewer-page {
  height: 100vh;
  height: 100dvh;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  overflow: auto;
}

.viewer-page .page-header {
  margin: 0 0 1rem;
}

.viewer-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  min-height: 0;
}

.viewer-card {
  min-height: 0;
}

.viewer-card .score-box {
  flex: 1;
  min-height: 0;
}

.viewer-card .score-value {
  font-size: clamp(2rem, min(13vw, 13vh), 10rem);
}

.viewer-card .team-name {
  font-size: clamp(0.9rem, min(2vw, 2vh), 2rem);
}

.hidden {
  display: none !important;
}

@media (max-width: 1100px) {
  .button-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .viewer-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  body.viewer-body {
    overflow: auto;
  }

  .page-shell {
    width: min(100vw - 1rem, 100%);
  }

  .page-header {
    padding: 1rem;
    border-radius: 18px;
    flex-direction: column;
    align-items: flex-start;
  }

  .header-actions {
    width: 100%;
    justify-content: stretch;
  }

  .header-actions > * {
    width: 100%;
  }

  .team-grid,
  .viewer-grid {
    grid-template-columns: 1fr;
    grid-template-rows: none;
  }

  .viewer-card .score-value {
    font-size: clamp(2rem, 15vw, 4rem);
  }

  .viewer-card .team-name {
    font-size: clamp(1rem, 5vw, 1.5rem);
  }

  .viewer-page {
    height: auto;
    overflow: auto;
  }
}
