* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  background: #003153;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

canvas {
  display: block;
  width: 100vw;
  height: 100vh;
  cursor: grab;
  touch-action: none;
}

canvas:active {
  cursor: grabbing;
}

.livePanel {
  position: fixed;
  top: calc(18px + env(safe-area-inset-top));
  right: calc(18px + env(safe-area-inset-right));
  z-index: 2;
  display: grid;
  gap: 7px;
  width: min(270px, calc(100vw - 36px));
  max-height: calc(100vh - 36px);
  overflow: hidden;
  padding: 9px;
  border: 1px solid rgba(248, 251, 255, 0.18);
  border-radius: 8px;
  background: rgba(0, 49, 83, 0.88);
  color: #f8fbff;
  box-shadow: 0 18px 60px rgba(0, 14, 28, 0.28);
  backdrop-filter: blur(10px);
  pointer-events: auto;
  transition:
    border-color 180ms ease,
    opacity 180ms ease,
    transform 180ms ease;
}

.livePanel[data-expanded="true"] {
  gap: 10px;
  width: min(390px, calc(100vw - 36px));
  padding: 12px;
}

.livePanel[data-state="active"],
.livePanel[data-state="running"] {
  border-color: rgba(235, 128, 49, 0.82);
}

.liveHeader {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
}

.liveTitle {
  color: #EB8031;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1;
  text-transform: uppercase;
}

.livePhase {
  color: rgba(248, 251, 255, 0.7);
  font-size: 11px;
  font-weight: 900;
  line-height: 1.2;
  text-align: right;
  text-transform: uppercase;
  white-space: nowrap;
}

.liveToggle {
  min-height: 25px;
  border: 1px solid rgba(235, 128, 49, 0.58);
  border-radius: 8px;
  padding: 0 8px;
  background: rgba(235, 128, 49, 0.14);
  color: #f8fbff;
  cursor: pointer;
  font: inherit;
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
  transition:
    background 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.liveToggle:hover,
.liveToggle:focus-visible {
  background: #EB8031;
  color: #003153;
  outline: none;
}

.liveToggle:active {
  transform: translateY(1px) scale(0.98);
}

.liveEntrant {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 7px 0 0;
  border-top: 1px solid rgba(248, 251, 255, 0.14);
}

.livePanel[data-expanded="true"] .liveEntrant {
  padding: 10px 0;
  border-bottom: 1px solid rgba(248, 251, 255, 0.14);
}

.liveEntrant span:first-child,
.liveGroupLabel {
  color: rgba(248, 251, 255, 0.62);
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
}

.liveEntrant strong {
  color: #f8fbff;
  font-size: 14px;
  font-weight: 900;
  line-height: 1.12;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.livePanel[data-expanded="true"] .liveEntrant strong {
  font-size: 17px;
  overflow-wrap: anywhere;
  white-space: normal;
}

.liveEntrant span:last-child {
  color: rgba(248, 251, 255, 0.72);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.livePanel[data-expanded="true"] .liveEntrant span:last-child {
  font-size: 12px;
  white-space: normal;
}

.liveGroups {
  display: grid;
  gap: 8px;
  min-height: 0;
  overflow: hidden;
}

.liveGroup {
  display: grid;
  gap: 5px;
}

.liveRankRow {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 44px;
  gap: 7px;
  align-items: center;
  min-height: 24px;
  color: rgba(248, 251, 255, 0.8);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.15;
}

.liveRankRow[data-entrant="true"] {
  color: #f8fbff;
}

.liveRankRow[data-winner="true"] .liveRank,
.liveRankRow[data-winner="true"] .liveRankName {
  color: #EB8031;
}

.liveRank {
  color: rgba(248, 251, 255, 0.58);
  font-weight: 900;
}

.liveRankName {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.liveDelta {
  justify-self: end;
  color: rgba(248, 251, 255, 0.7);
  font-weight: 900;
}

.liveDelta[data-sign="positive"] {
  color: #EB8031;
}

.liveEmpty {
  color: rgba(248, 251, 255, 0.66);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.3;
}

.historyControls {
  position: fixed;
  top: calc(18px + env(safe-area-inset-top));
  left: calc(18px + env(safe-area-inset-left));
  z-index: 2;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.historyControls[data-open="true"] {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.historyExit {
  border: 1.5px solid #EB8031;
  border-radius: 8px;
  padding: 9px 12px;
  background: #003153;
  color: #f8fbff;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
  transition:
    background 180ms ease,
    color 180ms ease,
    transform 180ms ease;
}

.historyExit:hover,
.historyExit:focus-visible {
  background: #EB8031;
  color: #003153;
  outline: none;
}

.historyExit:active {
  transform: translateY(1px) scale(0.98);
}

.memoryOverlay {
  --origin-x: 50vw;
  --origin-y: 50vh;
  --origin-size: 0px;
  position: fixed;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: clamp(24px, 7vw, 88px);
  background: #003153;
  color: #f8fbff;
  opacity: 0;
  pointer-events: none;
  clip-path: circle(var(--origin-size) at var(--origin-x) var(--origin-y));
  transition:
    clip-path 520ms cubic-bezier(0.16, 1, 0.3, 1),
    opacity 220ms ease;
}

.memoryOverlay[data-open="true"] {
  opacity: 1;
  pointer-events: auto;
  clip-path: circle(150vmax at var(--origin-x) var(--origin-y));
}

.overlayFrame {
  width: min(940px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 0;
  background: #003153;
  opacity: 0;
  scrollbar-width: none;
  transform: translateY(18px) scale(0.985);
  transition:
    opacity 360ms ease 120ms,
    transform 520ms cubic-bezier(0.16, 1, 0.3, 1) 90ms;
}

.memoryOverlay[data-open="true"] .overlayFrame {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.overlayFrame::-webkit-scrollbar {
  display: none;
}

.detailHeader {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 46px;
  gap: 18px;
  align-items: start;
  max-width: 820px;
  margin: 0 auto 28px;
}

.overlayClose {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 1.5px solid #EB8031;
  border-radius: 8px;
  background: #003153;
  color: #f8fbff;
  cursor: pointer;
  font: inherit;
  font-size: 30px;
  font-weight: 500;
  line-height: 1;
  transition:
    background 180ms ease,
    color 180ms ease,
    transform 180ms ease,
    border-color 180ms ease;
}

.overlayClose:hover,
.overlayClose:focus-visible {
  background: #EB8031;
  color: #003153;
  outline: none;
}

.overlayClose:active {
  transform: scale(0.94);
}

.popupContent {
  max-width: 820px;
  margin: 0 auto;
}

.detailTitle h2,
.memoryOverlay p {
  margin: 0;
}

.detailTitle h2 {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: baseline;
  font-size: clamp(28px, 4vw, 54px);
  line-height: 1.05;
  font-weight: 900;
  text-wrap: balance;
}

.detailHeadingText {
  min-width: 0;
}

.detailElo {
  display: inline-flex;
  align-items: center;
  border: 1.5px solid #EB8031;
  border-radius: 999px;
  padding: 6px 10px 5px;
  color: #EB8031;
  font-size: clamp(13px, 1.45vw, 18px);
  line-height: 1;
  white-space: nowrap;
}

.detailSeed {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-radius: 8px;
  padding: 6px 9px 5px;
  background: #EB8031;
  color: #003153;
  font-size: clamp(12px, 1.35vw, 16px);
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
}

.detailSeed strong {
  font: inherit;
  color: inherit;
}

.detailPhase {
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(235, 128, 49, 0.78);
  border-radius: 8px;
  padding: 5px 8px 4px;
  color: #f8fbff;
  font-size: clamp(12px, 1.3vw, 15px);
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
}

.detailContext {
  display: grid;
  gap: 4px;
  margin: 0 0 14px;
  padding: 11px 12px;
  border: 1px solid rgba(248, 251, 255, 0.18);
  border-radius: 8px;
  background: rgba(248, 251, 255, 0.07);
}

.detailContextLabel {
  color: #EB8031;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1;
  text-transform: uppercase;
}

.detailContextTitle {
  appearance: none;
  width: fit-content;
  max-width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  color: #f8fbff;
  font: inherit;
  font-size: clamp(15px, 1.6vw, 20px);
  font-weight: 900;
  line-height: 1.15;
  text-align: left;
}

button.detailContextTitle {
  cursor: pointer;
}

button.detailContextTitle:hover {
  color: #EB8031;
}

.detailContextMeta {
  color: rgba(248, 251, 255, 0.68);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.25;
}

.detailAge {
  display: inline-flex;
  align-items: center;
  color: rgba(248, 251, 255, 0.72);
  font-size: clamp(12px, 1.3vw, 16px);
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
}

.memoryOverlay p {
  max-width: 760px;
  margin-top: 18px;
  font-size: clamp(16px, 1.8vw, 22px);
  line-height: 1.42;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.inlineSources {
  display: inline-flex;
  gap: 0.38em;
  margin-left: 0.42em;
  vertical-align: super;
}

.evalActions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 28px;
}

.evalActions button {
  border: 1.5px solid #EB8031;
  border-radius: 8px;
  padding: 7px 9px;
  background: transparent;
  color: #f8fbff;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  transition:
    background 180ms ease,
    color 180ms ease,
    transform 180ms ease;
}

.evalActions button:hover,
.evalActions button:focus-visible {
  background: #EB8031;
  color: #003153;
  outline: none;
}

.evalActions button:active {
  transform: translateY(1px) scale(0.985);
}

.inlineSource {
  display: inline-grid;
  place-items: center;
  min-width: 1.22em;
  height: 1.22em;
  margin-left: 0.22em;
  border: 1px solid rgba(235, 128, 49, 0.76);
  border-radius: 999px;
  color: #EB8031;
  font-size: 0.52em;
  font-weight: 900;
  line-height: 1;
  text-decoration: none;
  opacity: 0.84;
  vertical-align: super;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease,
    opacity 160ms ease,
    transform 160ms ease;
}

.inlineSource:hover,
.inlineSource:focus-visible {
  background: #EB8031;
  border-color: #EB8031;
  color: #003153;
  opacity: 1;
  outline: none;
  transform: translateY(-1px);
}

.detailTitle,
.popupContent > *,
.evalActions button {
  animation: detailRise 540ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.popupContent > :nth-child(1) {
  animation-delay: 80ms;
}

.popupContent > :nth-child(2) {
  animation-delay: 130ms;
}

.popupContent > :nth-child(3) {
  animation-delay: 180ms;
}

@keyframes detailRise {
  from {
    opacity: 0;
    transform: translateY(18px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 680px) {
  .livePanel {
    top: auto;
    right: calc(12px + env(safe-area-inset-right));
    bottom: calc(12px + env(safe-area-inset-bottom));
    left: calc(12px + env(safe-area-inset-left));
    width: auto;
    max-height: 28vh;
    padding: 8px;
    border-color: rgba(248, 251, 255, 0.32);
    background: rgba(0, 49, 83, 0.97);
    box-shadow: 0 16px 54px rgba(0, 14, 28, 0.46);
  }

  .livePanel[data-expanded="true"] {
    width: auto;
    max-height: 44vh;
    padding: 10px;
  }

  .liveEntrant strong {
    font-size: 13px;
  }

  .liveEntrant span:first-child {
    color: rgba(248, 251, 255, 0.78);
  }

  .liveEntrant span:last-child {
    color: rgba(248, 251, 255, 0.86);
  }

  .livePanel[data-expanded="true"] .liveEntrant strong {
    font-size: 15px;
  }

  .liveRankRow {
    grid-template-columns: 30px minmax(0, 1fr) 40px;
    font-size: 11px;
  }

  .historyControls {
    top: calc(12px + env(safe-area-inset-top));
    left: calc(12px + env(safe-area-inset-left));
  }

  .memoryOverlay {
    align-items: flex-start;
    padding: 56px 24px 28px;
  }

  .overlayFrame {
    width: 100%;
    max-height: 100%;
  }

  .detailHeader {
    grid-template-columns: minmax(0, 1fr) 42px;
    gap: 12px;
    align-items: start;
    margin-bottom: 26px;
  }

  .overlayClose {
    width: 42px;
    height: 42px;
    font-size: 28px;
  }

  .detailTitle h2 {
    font-size: 34px;
    line-height: 1.08;
  }

  .detailElo {
    padding: 5px 9px 4px;
    font-size: 14px;
  }

  .detailSeed,
  .detailPhase {
    padding: 5px 8px 4px;
    font-size: 13px;
  }

  .memoryOverlay p {
    font-size: 16px;
  }

  .evalActions {
    display: grid;
  }

  .evalActions button {
    width: 100%;
  }

  .overlayFrame {
    -ms-overflow-style: none;
    scrollbar-width: none;
  }
}
