* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #101114;
  color: white;
  overscroll-behavior: none;
}

body.landing-mode {
  background: #020203;
}

body.landing-mode::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: var(--landing-background);
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% auto;
  opacity: 0.2;
  pointer-events: none;
}

button,
a,
input {
  font: inherit;
}

.scorekeeper {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.side {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
  padding: 1rem;
}

.left,
.viewer-left {
  background: #991408;
}

.right,
.viewer-right {
  background: #3a0ca3;
}

.team-input {
  width: min(90%, 340px);
  font-size: clamp(1.1rem, 5vw, 2rem);
  text-align: center;
  padding: 0.65rem 0.8rem;
  border: 0;
  border-radius: 14px;
  margin-bottom: 1rem;
  color: #111;
  font-weight: 800;
}

.embedded-viewer-name {
  display: none;
}

.score {
  font-size: clamp(7rem, 31vw, 20rem);
  font-weight: 950;
  line-height: 0.9;
}

.games {
  font-size: clamp(0.95rem, 3vw, 1.35rem);
  margin-top: 0.75rem;
  font-weight: 700;
  line-height: 1;
}

.game-button {
  margin-top: 0.7rem;
}

button,
a {
  padding: 0.72rem 1rem;
  border-radius: 999px;
  border: 0;
  background: white;
  color: #111;
  text-decoration: none;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(0,0,0,0.22);
}

.controls {
  position: fixed;
  left: 50%;
  bottom: calc(var(--games-bar-height) + 0.75rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
  justify-content: center;
  width: min(96%, 760px);
  pointer-events: auto;
}

.viewer-mode .scorekeeper-only {
  display: none;
}

.viewer-mode .embedded-viewer-name {
  display: block;
}

.scorekeeper-mode .viewer-only {
  display: none;
}

.viewer-mode .score {
  font-size: clamp(9rem, 34vw, 26rem);
}

.viewer-mode .games {
  font-size: clamp(1rem, 3vw, 1.55rem);
}

.viewer-mode-button {
  position: fixed;
  right: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  opacity: 0.75;
}

.viewer {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  text-align: center;
}

.viewer-team {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.viewer-name {
  width: 90%;
  text-overflow: ellipsis;
  font-size: clamp(2rem, 8vw, 7rem);
  font-weight: 950;
  line-height: 1;
}

.viewer-score {
  font-size: clamp(9rem, 34vw, 26rem);
  font-weight: 1000;
  line-height: 0.9;
}

.viewer-games {
  font-size: clamp(1.4rem, 4vw, 2.4rem);
  font-weight: 800;
}

.set-label,
.connection-status,
.sync-status {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.45);
  padding: 0.65rem 1rem;
  border-radius: 999px;
  font-weight: 850;
  backdrop-filter: blur(6px);
}

.set-label,
.sync-status {
  top: calc(1rem + env(safe-area-inset-top));
}

.connection-status {
  bottom: calc(1rem + env(safe-area-inset-bottom));
  font-size: 0.9rem;
  opacity: 0.8;
}

.sync-status {
  font-size: 0.9rem;
  opacity: 0.85;
  pointer-events: none;
}

.sync-status.changed {
  background: rgba(255,255,255,0.9);
  color: #111;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(0,0,0,0.66);
  z-index: 20;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-card {
  width: min(92vw, 440px);
  color: white;
  background: #181b24;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 24px;
  box-shadow: 0 22px 70px rgba(0,0,0,0.45);
  padding: 1.35rem;
}

.modal-card h1 {
  margin: 0 0 0.6rem;
  font-size: 1.6rem;
}

.modal-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.6rem;
}

.modal-heading h1 {
  margin: 0;
}

.link-button {
  flex: 0 0 auto;
  padding: 0.25rem 0;
  background: transparent;
  color: #f7d046;
  border-radius: 0;
  box-shadow: none;
  font-size: 0.9rem;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.modal-logo {
  display: block;
  width: min(12rem, 52%);
  height: auto;
  max-height: 5.25rem;
  object-fit: contain;
  margin: 0 auto 1.1rem;
}

.modal-card p {
  margin: 0 0 1.25rem;
  color: rgba(255,255,255,0.78);
  line-height: 1.4;
}

.mode-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

.mode-actions button {
  width: 100%;
  padding: 1rem;
  font-size: 1.1rem;
}

.mode-primary {
  background: #f7d046;
}

@media (orientation: landscape) and (min-width: 700px) {
  .mode-actions {
    grid-template-columns: 1fr 1fr;
  }
}

@media (orientation: portrait) {
  .controls {
    font-size: 0.9rem;
  }

  button,
  a {
    padding: 0.62rem 0.75rem;
  }
}

:root {
  --left-color: #991408;
  --right-color: #3a0ca3;
  --games-bar-height: clamp(2.25rem, 6dvh, 3.25rem);
}

.left,
.viewer-left {
  background: var(--left-color);
}

.right,
.viewer-right {
  background: var(--right-color);
}

.scorekeeper[hidden] {
  display: none;
}

.modal-card label {
  display: grid;
  gap: 0.35rem;
  margin: 0 0 0.85rem;
  color: rgba(255,255,255,0.84);
  font-weight: 800;
}

.modal-card input[type="text"],
.modal-card input:not([type]) {
  width: 100%;
}

.modal-card input {
  border: 0;
  border-radius: 14px;
  padding: 0.8rem;
  color: #111;
  font-weight: 800;
}

.color-picker-button {
  width: 3.8rem;
  height: 3.8rem;
  padding: 0.32rem;
  border: 3px solid rgba(255,255,255,0.9);
  border-radius: 14px;
  background: linear-gradient(var(--selected-color), var(--selected-color)) content-box, #111827;
  box-shadow: none;
  cursor: pointer;
}

.color-picker-button:focus-visible {
  outline: 3px solid #f7d046;
  outline-offset: 3px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(5rem + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(1rem);
  opacity: 0;
  pointer-events: none;
  background: rgba(255,255,255,0.95);
  color: #111;
  border-radius: 999px;
  padding: 0.75rem 1rem;
  font-weight: 900;
  z-index: 30;
  transition: opacity 160ms ease, transform 160ms ease;
}

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

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 5rem;
  gap: 0.75rem;
  align-items: end;
}

.field-row .color-field {
  min-width: 0;
}

.color-picker-panel {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 0.5rem;
  margin: -0.15rem 0 1rem;
  padding: 0.7rem;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 18px;
  background: rgba(12,14,20,0.92);
}

.color-picker-panel.hidden {
  display: none;
}

.color-picker-panel button {
  width: 100%;
  aspect-ratio: 1;
  min-height: 2.35rem;
  padding: 0;
  border: 2px solid rgba(255,255,255,0.8);
  border-radius: 10px;
  background: var(--preset-color);
  box-shadow: none;
}

.color-picker-panel button:focus-visible {
  outline: 3px solid #f7d046;
  outline-offset: 2px;
}

@media (max-width: 420px) {
  .field-row {
    grid-template-columns: minmax(0, 1fr) 4.25rem;
  }

  .color-picker-panel {
    grid-template-columns: repeat(4, 1fr);
  }
}

.viewer-mode .side {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  justify-items: center;
  align-items: center;
  padding: calc(1rem + env(safe-area-inset-top)) 1rem calc(1rem + env(safe-area-inset-bottom));
}

.viewer-mode .embedded-viewer-name {
  --team-name-max-size: 96;
  --team-name-min-size: 24;
  align-self: start;
  display: block;
  margin: 0;
  max-width: 100%;
  overflow: hidden;
  text-align: center;
  text-wrap: balance;
  white-space: nowrap;
}

.viewer-mode .score {
  align-self: center;
  justify-self: center;
  margin: 0;
}

.viewer-mode .games {
  align-self: end;
  justify-self: center;
  margin: 0;
  padding-bottom: 0.25rem;
  text-align: center;
}

@media (max-width: 680px) {
  .viewer-mode .embedded-viewer-name {
    --team-name-max-size: 72;
    --team-name-min-size: 18;
  }
}

.scorekeeper-mode .side,
.viewer-mode .side {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  justify-items: center;
  align-items: stretch;
  padding: calc(0.75rem + env(safe-area-inset-top)) 0 0;
}

.team-header {
  align-self: start;
  display: grid;
  min-height: clamp(4.5rem, 14dvh, 7.5rem);
  place-items: center;
  width: 100%;
  padding: 0.75rem clamp(0.5rem, 2vw, 1.25rem);
}

.scorekeeper-mode .team-input {
  width: min(100%, 34rem);
  margin: 0;
}

.scorekeeper-mode .score,
.viewer-mode .score {
  align-self: center;
  justify-self: center;
  margin: 0;
}

.scorekeeper-mode .games,
.viewer-mode .games {
  align-self: end;
  justify-self: stretch;
  margin: 0;
  min-height: var(--games-bar-height);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.18em;
  padding: 0.35rem 0.75rem calc(0.35rem + env(safe-area-inset-bottom));
  text-align: center;
  touch-action: pan-x;
  white-space: nowrap;
}

.left .game-tracker {
  background: color-mix(in srgb, var(--left-color), white 14%);
}

.right .game-tracker {
  background: color-mix(in srgb, var(--right-color), black 14%);
}

.chrome-button,
.icon-button {
  display: grid;
  place-items: center;
  width: 3.25rem;
  height: 3.25rem;
  padding: 0;
  border-radius: 999px;
  z-index: 10;
}

.chrome-button svg,
.icon-button svg {
  width: 1.55rem;
  height: 1.55rem;
  fill: currentColor;
}

.top-left,
.top-right {
  position: fixed;
  top: calc(0.75rem + env(safe-area-inset-top));
}

.top-left {
  left: 0.75rem;
}

.top-right {
  right: 0.75rem;
}


.controls {
  width: auto;
  align-items: center;
  gap: 0.65rem;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.modal-actions button {
  width: 100%;
  padding: 1rem;
  font-size: 1.1rem;
}

.text-button {
  min-width: 8.5rem;
  height: 3.25rem;
  padding: 0 1.15rem;
  z-index: 10;
}

.danger-button {
  background: #fee2e2;
  color: #8a1111;
}

.tutorial-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  pointer-events: none;
}

.tutorial-overlay.hidden {
  display: none;
}

.tutorial-scrim {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.32);
  z-index: 0;
  animation: tutorial-fade-in 180ms ease both;
}

.tutorial-spotlight {
  position: fixed;
  top: 0;
  left: 0;
  border: 4px solid rgba(247,208,70,0.95);
  border-radius: 20px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.34), 0 0 26px rgba(247,208,70,0.55);
  pointer-events: none;
  z-index: 1;
  transition: transform 220ms ease, width 220ms ease, height 220ms ease;
  animation: tutorial-highlight-pulse 1200ms ease-in-out infinite;
}

.tutorial-popover {
  position: fixed;
  top: 0;
  left: 0;
  color: white;
  background: rgba(24,27,36,0.96);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 22px;
  box-shadow: 0 22px 70px rgba(0,0,0,0.5);
  padding: 1rem;
  pointer-events: auto;
  z-index: 2;
  transition: transform 220ms ease;
  animation: tutorial-pop-in 220ms ease both;
}

.tutorial-meta {
  margin-bottom: 0.35rem;
  color: #f7d046;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tutorial-popover h1 {
  margin: 0 0 0.4rem;
  font-size: 1.35rem;
}

.tutorial-popover p {
  margin: 0 0 1rem;
  color: rgba(255,255,255,0.82);
  line-height: 1.4;
  font-weight: 650;
}

.tutorial-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.tutorial-actions button {
  padding: 0.8rem 1rem;
}

.tutorial-highlight {
  z-index: 11;
}

.tutorial-gesture {
  position: absolute;
  right: 1rem;
  top: 1rem;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 999px;
  background: rgba(247,208,70,0.16);
  border: 2px solid rgba(247,208,70,0.8);
}

.tutorial-gesture span,
.tutorial-gesture::before,
.tutorial-gesture::after {
  content: "";
  position: absolute;
  background: #f7d046;
}

.tutorial-gesture span {
  left: 50%;
  top: 50%;
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 999px;
  transform: translate(-50%, -50%);
}

.tutorial-gesture::before {
  left: 50%;
  top: 50%;
  width: 1.15rem;
  height: 0.22rem;
  border-radius: 999px;
  transform: translate(-50%, -50%);
}

.tutorial-gesture::after {
  left: 50%;
  top: 50%;
  width: 0.22rem;
  height: 1.15rem;
  border-radius: 999px;
  transform: translate(-50%, -50%);
}

.tutorial-gesture.up span {
  animation: tutorial-swipe-up 1100ms ease-in-out infinite;
}

.tutorial-gesture.down span {
  animation: tutorial-swipe-down 1100ms ease-in-out infinite;
}

.tutorial-gesture.horizontal span {
  animation: tutorial-swipe-horizontal 1300ms ease-in-out infinite;
}

.tutorial-gesture.pulse span {
  animation: tutorial-tap 1000ms ease-in-out infinite;
}

@keyframes tutorial-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes tutorial-pop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes tutorial-highlight-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(247,208,70,0.48); }
  50% { box-shadow: 0 0 0 14px rgba(247,208,70,0); }
}

@keyframes tutorial-swipe-up {
  0%, 100% { transform: translate(-50%, 0.55rem); opacity: 0.35; }
  45% { transform: translate(-50%, -0.7rem); opacity: 1; }
}

@keyframes tutorial-swipe-down {
  0%, 100% { transform: translate(-50%, -0.7rem); opacity: 0.35; }
  45% { transform: translate(-50%, 0.55rem); opacity: 1; }
}

@keyframes tutorial-swipe-horizontal {
  0%, 100% { transform: translate(-1rem, -50%); opacity: 0.35; }
  50% { transform: translate(0.55rem, -50%); opacity: 1; }
}

@keyframes tutorial-tap {
  0%, 100% { transform: translate(-50%, -50%) scale(0.8); opacity: 0.4; }
  45% { transform: translate(-50%, -50%) scale(1.8); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .tutorial-popover,
  .tutorial-spotlight,
  .tutorial-gesture span,
  .tutorial-scrim {
    animation: none;
    transition: none;
  }
}

@media (pointer: coarse), (max-width: 820px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .scorekeeper,
  .viewer {
    min-height: 100svh;
    height: 100dvh;
    overflow: hidden;
  }

  .scorekeeper-mode .side,
  .viewer-mode .side {
    grid-template-rows: minmax(3.8rem, auto) minmax(0, 1fr) minmax(3.4rem, auto);
    min-height: 0;
  }

  .scorekeeper-mode .team-header {
    min-height: 3.8rem;
    padding-top: 0.55rem;
    padding-bottom: 0.35rem;
  }

  .scorekeeper-mode .team-input {
    font-size: clamp(1rem, 4vw, 1.45rem);
    padding: 0.55rem 0.65rem;
  }

  .scorekeeper-mode .score {
    font-size: clamp(5.8rem, 27vw, 14rem);
    min-width: 0;
  }

  .scorekeeper-mode .games,
  .viewer-mode .games {
    min-height: 3.4rem;
    padding: 0.45rem 0.6rem calc(0.45rem + env(safe-area-inset-bottom));
  }

  .scorekeeper-mode .controls {
    top: calc(4.15rem + env(safe-area-inset-top));
    bottom: auto;
    flex-direction: row;
    gap: 0.45rem;
    width: min(94%, 24rem);
    z-index: 12;
  }

  .scorekeeper-mode .text-button {
    min-width: 0;
    height: 2.55rem;
    padding: 0 0.75rem;
    font-size: 0.82rem;
  }
}
