:root {
  color-scheme: dark;
  --bg: #08111f;
  --bg-accent: #12213f;
  --card: rgba(10, 18, 34, 0.82);
  --card-border: rgba(173, 198, 255, 0.14);
  --text: #eef4ff;
  --muted: #9fb0d0;
  --accent: #7dd3fc;
  --accent-strong: #38bdf8;
  --ok: #2dd4bf;
  --warn: #f59e0b;
  --danger: #fb7185;
  --shadow: 0 30px 90px rgba(0, 0, 0, 0.42);
  --radius: 24px;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(56, 189, 248, 0.18), transparent 32%),
    radial-gradient(circle at top right, rgba(249, 115, 22, 0.16), transparent 24%),
    linear-gradient(180deg, #050912 0%, var(--bg) 40%, #050912 100%);
}

.page-shell {
  position: relative;
  overflow: hidden;
  min-height: 100vh;
}

.orb {
  position: fixed;
  inset: auto;
  width: 28rem;
  height: 28rem;
  filter: blur(80px);
  opacity: 0.24;
  pointer-events: none;
}

.orb-a {
  top: -6rem;
  left: -8rem;
  background: rgba(56, 189, 248, 0.42);
}

.orb-b {
  right: -8rem;
  bottom: -8rem;
  background: rgba(249, 115, 22, 0.34);
}

.hidden {
  display: none !important;
}

.app {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 calc(4rem + 96px);
}

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.lobby-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
}

.lobby-card {
  width: min(520px, 100%);
  padding: 2rem;
  text-align: center;
}

.hero {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
  margin-bottom: 1rem;
  padding: 1.25rem;
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--accent);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.78rem;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.6rem);
  line-height: 0.95;
}

.lede {
  max-width: 62ch;
  margin-top: 0.8rem;
  color: var(--muted);
  line-height: 1.55;
}

.pill-row,
.button-row,
.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.hero-actions {
  align-items: end;
  justify-content: flex-end;
  flex-direction: column;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border-radius: 999px;
  padding: 0.55rem 0.9rem;
  background: rgba(125, 211, 252, 0.12);
  color: var(--text);
  border: 1px solid rgba(125, 211, 252, 0.22);
  font-size: 0.92rem;
}

.pill[data-tone="ok"] {
  background: rgba(45, 212, 191, 0.14);
  border-color: rgba(45, 212, 191, 0.32);
}

.pill[data-tone="warn"] {
  background: rgba(245, 158, 11, 0.14);
  border-color: rgba(245, 158, 11, 0.32);
}

.pill[data-tone="danger"] {
  background: rgba(251, 113, 133, 0.14);
  border-color: rgba(251, 113, 133, 0.32);
}

.pill-muted {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.1);
  color: var(--muted);
}

.player-pill {
  border-color: rgba(255, 255, 255, 0.18);
  font-weight: 700;
  background: rgba(255, 255, 255, 0.06);
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: 1rem;
  align-items: start;
}

.side-stack {
  display: grid;
  gap: 1rem;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: baseline;
  margin-bottom: 1rem;
}

h2 {
  font-size: 1.1rem;
}

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

.note {
  margin-top: 0.9rem;
  line-height: 1.5;
}

.camera-card,
.leaderboard-card,
.activity-card {
  padding: 1.25rem;
}

.camera-stage {
  position: relative;
  width: min(100%, 560px);
  aspect-ratio: 4 / 3;
  min-height: 0;
  max-height: min(52vh, 420px);
  margin: 0 auto;
  border-radius: 20px;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: contain;
  -webkit-user-select: none;
  user-select: none;
  background:
    linear-gradient(180deg, rgba(7, 14, 28, 0.2), rgba(7, 14, 28, 0.82)),
    linear-gradient(135deg, rgba(56, 189, 248, 0.14), rgba(249, 115, 22, 0.06));
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.camera-stage.has-camera-output {
  border-color: transparent;
}

.camera-stage video,
.camera-stage canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  display: block;
}

.camera-scan-viewport {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
}

.camera-scan-viewport video,
.camera-scan-viewport canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  display: block;
}

.camera-placeholder {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  padding: 1.25rem;
  text-align: center;
  color: var(--muted);
  line-height: 1.5;
}

.camera-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

.camera-overlay__frame {
  position: absolute;
  inset: 50% auto auto 50%;
  width: min(66%, 320px);
  height: min(42%, 180px);
  transform: translate(-50%, -50%);
  border: 3px solid rgba(255, 59, 48, 0.98);
  border-radius: 18px;
  box-shadow:
    0 0 0 9999px rgba(5, 9, 18, 0.18),
    0 0 0 1px rgba(255, 59, 48, 0.45);
}

.camera-overlay__crosshair {
  position: absolute;
  inset: 50% auto auto 50%;
  width: 82px;
  height: 82px;
  transform: translate(-50%, -50%);
  background:
    linear-gradient(rgba(255, 59, 48, 0.98), rgba(255, 59, 48, 0.98)) center / 64px 2px no-repeat,
    linear-gradient(rgba(255, 59, 48, 0.98), rgba(255, 59, 48, 0.98)) center / 2px 64px no-repeat;
  opacity: 0.95;
}

.button-row {
  margin-top: 0.95rem;
  margin-bottom: 0.2rem;
}

button {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border-radius: 16px;
  padding: 0.85rem 1rem;
  font: inherit;
  cursor: pointer;
}

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

button.primary {
  border-color: rgba(56, 189, 248, 0.35);
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.24), rgba(59, 130, 246, 0.18));
}

.start-cta {
  margin-top: 1.4rem;
  width: min(320px, 100%);
  padding: 1rem 1.25rem;
  font-size: 1.05rem;
}

.finish-btn {
  border-color: rgba(251, 113, 133, 0.35);
  background: linear-gradient(135deg, rgba(251, 113, 133, 0.22), rgba(244, 63, 94, 0.12));
}

.leaderboard-list {
  display: grid;
  gap: 0.75rem;
}

.activity-list {
  display: grid;
  gap: 0.65rem;
}

.player-card {
  --player-color: var(--accent-strong);
  position: relative;
  overflow: hidden;
  border-radius: 20px;
  padding: 0.9rem 1rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.player-top {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  align-items: center;
}

.player-name {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-size: 1rem;
  font-weight: 700;
  min-width: 0;
}

.player-dot {
  width: 0.95rem;
  height: 0.95rem;
  border-radius: 999px;
  background: var(--player-color);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.04);
  flex: 0 0 auto;
}

.player-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-start;
}

.player-count {
  font-size: 1.2rem;
  font-weight: 800;
}

.player-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: 999px;
  padding: 0.24rem 0.55rem;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 0.82rem;
}

.empty-state {
  padding: 1rem;
  color: var(--muted);
  text-align: center;
  border-radius: 18px;
  border: 1px dashed rgba(255, 255, 255, 0.12);
}

.activity-item {
  --activity-flash: rgba(56, 189, 248, 0.38);
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.85rem;
  align-items: center;
  border-radius: 18px;
  padding: 0.85rem 1rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.activity-item--deletable {
  grid-template-columns: auto 1fr auto auto;
}

.activity-item--flash {
  border-color: var(--activity-flash);
  box-shadow: 0 0 0 1px var(--activity-flash), 0 0 0 6px rgba(56, 189, 248, 0.08);
  animation: activity-flash 1200ms ease-out;
}

.activity-dot {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 999px;
  background: var(--activity-color, var(--accent-strong));
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.04);
}

.activity-main {
  min-width: 0;
}

.activity-name {
  font-weight: 700;
}

.activity-value {
  color: var(--muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.activity-meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.activity-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.scan-delete-btn {
  display: inline-grid;
  place-items: center;
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(251, 113, 133, 0.24);
  background: rgba(251, 113, 133, 0.08);
  color: #fb7185;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}

.scan-delete-btn svg {
  width: 1rem;
  height: 1rem;
  fill: currentColor;
}

.scan-delete-btn:hover {
  transform: translateY(-1px);
  background: rgba(251, 113, 133, 0.14);
  border-color: rgba(251, 113, 133, 0.38);
}

.scan-delete-btn:focus-visible {
  outline: 2px solid rgba(251, 113, 133, 0.4);
  outline-offset: 2px;
}

.scanner-drawer {
  --scanner-drawer-peek: 90px;
  --scanner-drawer-height: min(72vh, calc(100vh - 1rem));
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 18;
  width: min(1180px, calc(100% - 2rem));
  height: var(--scanner-drawer-height);
  max-height: calc(100vh - 1rem);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border-radius: 28px 28px 0 0;
  box-shadow: var(--shadow);
  background: rgba(10, 18, 34, 0.94);
  border: 1px solid rgba(173, 198, 255, 0.14);
  transform: translateX(-50%) translateY(calc(100% - var(--scanner-drawer-peek)));
  transition: transform 260ms cubic-bezier(0.2, 0.8, 0.2, 1);
  backdrop-filter: blur(14px);
}

.scanner-drawer.is-open {
  transform: translateX(-50%) translateY(0);
}

.scanner-drawer__tab {
  width: 100%;
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0;
  background:
    linear-gradient(180deg, rgba(125, 211, 252, 0.12), rgba(255, 255, 255, 0.02));
  color: inherit;
  padding: 1rem 1.25rem 0.85rem;
  display: grid;
  gap: 0.4rem;
  text-align: left;
}

.scanner-drawer__tab:hover {
  background:
    linear-gradient(180deg, rgba(125, 211, 252, 0.16), rgba(255, 255, 255, 0.03));
}

.scanner-drawer__tab:focus-visible {
  outline: 2px solid rgba(125, 211, 252, 0.42);
  outline-offset: -2px;
}

.scanner-drawer__head {
  margin-bottom: 0;
  flex-direction: row;
  align-items: baseline;
  width: 100%;
}

.scanner-drawer__head .muted {
  margin-left: auto;
  text-align: right;
}

.scanner-drawer__hint {
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}

.scanner-drawer__panel {
  min-height: 0;
  overflow: auto;
  padding: 1.25rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(10px);
}

.modal-card {
  width: min(520px, 100%);
  padding: 1.5rem;
}

.name-field {
  display: grid;
  gap: 0.35rem;
  margin-top: 1rem;
  color: var(--muted);
}

.name-field input {
  width: 100%;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(6, 12, 24, 0.72);
  color: var(--text);
  padding: 0.9rem 1rem;
  font: inherit;
}

.name-field input:focus {
  outline: 2px solid rgba(125, 211, 252, 0.42);
  outline-offset: 2px;
}

.toast-layer {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  z-index: 30;
  display: grid;
  gap: 0.6rem;
  width: min(520px, calc(100vw - 2rem));
  pointer-events: none;
}

.toast {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 0.9rem 1rem;
  border-radius: 18px;
  background: rgba(8, 17, 31, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.32);
  transform: translateY(24px);
  opacity: 0;
  animation: toast-in 180ms ease forwards;
  pointer-events: none;
}

.toast .toast-name {
  font-weight: 700;
}

.toast .toast-plus {
  font-weight: 800;
  color: var(--player-color, var(--accent));
}

.toast[data-tone="rfid"] {
  --player-color: #fb923c;
}

@keyframes toast-in {
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes activity-flash {
  0% {
    transform: translateY(0) scale(1);
  }
  25% {
    transform: translateY(-1px) scale(1.01);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 860px) {
  .grid {
    grid-template-columns: 1fr;
  }

  .section-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .scanner-drawer__head {
    flex-direction: row;
    align-items: baseline;
  }

  .hero {
    align-items: flex-start;
  }

  .hero-actions {
    align-items: flex-start;
    justify-content: flex-start;
    width: 100%;
  }

  .side-stack {
    gap: 0.75rem;
  }

  .camera-stage {
    width: min(100%, 460px);
    max-height: min(38vh, 320px);
  }

  .scanner-drawer {
    width: calc(100% - 1rem);
    border-radius: 24px 24px 0 0;
  }

  .scanner-drawer__tab,
  .scanner-drawer__panel {
    padding-left: 1rem;
    padding-right: 1rem;
  }
}
