:root {
  --bg: #070708;
  --ink: #f4f1ee;
  --muted: #8a8580;
  --line: rgba(244, 241, 238, 0.1);
  --red: #e23b3b;
  --orchid: #f0a0ae;
  --pass: #5fbf9a;
  --fail: #e07070;
  --locked: #7eb8c4;
  --font-display: "Bebas Neue", "Arial Narrow", sans-serif;
  --font-ui: "Manrope", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  font-family: var(--font-ui);
  background: var(--bg);
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}
.wash {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 55% 45% at 8% -10%, rgba(237, 28, 36, 0.18), transparent 60%),
    radial-gradient(ellipse 40% 35% at 92% 0%, rgba(232, 160, 180, 0.1), transparent 55%),
    linear-gradient(180deg, #0c0b0d 0%, #070708 55%, #050506 100%);
}
.orchid {
  position: absolute;
  inset: 0;
  opacity: 0.07;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220' viewBox='0 0 220 220'%3E%3Cg fill='none' stroke='%23e8a0b4' stroke-width='1.2'%3E%3Cpath d='M110 28c16 22 38 36 64 40-26 6-48 22-64 48-16-26-38-42-64-48 26-4 48-18 64-40z'/%3E%3Cpath d='M110 62c10 14 24 22 40 25-16 4-30 14-40 30-10-16-24-26-40-30 16-3 30-11 40-25z' opacity='.55'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 220px 220px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.7), transparent 75%);
}
.grain {
  position: absolute;
  inset: 0;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.app {
  position: relative;
  z-index: 1;
  height: 100dvh;
  max-height: 100vh;
  width: 100%;
  margin: 0 auto;
  padding: 0.7rem 1.4rem 0.8rem;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0.65rem;
  overflow: hidden;
}

/* header */
.topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 1rem;
  align-items: center;
  animation: rise 0.45s ease both;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}
.brand-logo {
  height: 3.4rem;
  width: auto;
  display: block;
  filter: drop-shadow(0 0 18px rgba(237, 28, 36, 0.35));
  animation: pulse-glow 3.2s ease-in-out infinite;
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 0.95;
}
.brand-title {
  font-family: var(--font-display);
  font-size: 2.1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.brand-sub {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--orchid);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.btn {
  appearance: none;
  border: 1px solid rgba(226, 59, 59, 0.65);
  border-radius: 2px;
  background: var(--red);
  color: #fff;
  font-family: var(--font-ui);
  font-weight: 800;
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.55rem 1rem;
  cursor: pointer;
  white-space: nowrap;
  transition: filter 0.15s ease, transform 0.15s ease;
  clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 8px, 100% 100%, 8px 100%, 0 calc(100% - 8px));
}
.btn:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-1px);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.muted {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.stage-tabs {
  display: flex;
  justify-content: center;
  gap: 0.2rem;
  min-width: 0;
}
.stage-tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-ui);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.4rem 0.85rem;
  cursor: pointer;
  position: relative;
  border-radius: 2px;
}
.stage-tab span {
  display: block;
  font-size: 0.9rem;
}
.stage-tab em {
  display: block;
  margin-top: 0.05rem;
  font-style: normal;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  opacity: 0.7;
}
.stage-tab.active {
  color: var(--ink);
  background: rgba(237, 28, 36, 0.16);
}
.stage-tab.active::after {
  content: "";
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: 0.12rem;
  height: 2px;
  background: var(--red);
  border-radius: 2px;
}
.stage-tab.locked {
  opacity: 0.35;
}

/* overview: 3 players */
.overview {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  border-top: 1px solid var(--line);
  overflow: hidden;
  animation: rise 0.55s ease 0.08s both;
}

.player-col {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 0.85rem 1.25rem 0.7rem;
  border-right: 1px solid var(--line);
  animation: rise 0.5s ease both;
}
.player-col:last-child {
  border-right: 0;
}
.player-col:nth-child(1) {
  animation-delay: 0.1s;
}
.player-col:nth-child(2) {
  animation-delay: 0.18s;
}
.player-col:nth-child(3) {
  animation-delay: 0.26s;
}

.player-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.65rem;
  padding-bottom: 0.55rem;
  margin-bottom: 0.45rem;
  border-bottom: 1px solid var(--line);
}
.player-head strong {
  font-family: var(--font-display);
  font-size: 2.25rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  line-height: 1;
}
.player-head .score {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
  white-space: nowrap;
}
.player-head .score b {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--ink);
  margin: 0 0.15rem;
}

.slots {
  display: grid;
  grid-template-rows: minmax(0, 1.05fr) minmax(0, 2.2fr) minmax(0, 1.05fr);
  gap: 0.55rem;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.slot {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  overflow: hidden;
}
.slot-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.4rem;
  flex: 0 0 auto;
}
.slot-label h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  letter-spacing: 0.14em;
  font-weight: 400;
}
.slot.threeZero .slot-label h3,
.slot.advance .slot-label h3 {
  color: var(--pass);
}
.slot.zeroThree .slot-label h3 {
  color: var(--fail);
}
.slot-label span {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.slot-grid {
  display: grid;
  gap: 0.4rem;
  min-height: 0;
  flex: 1;
  align-content: stretch;
}
.slot.threeZero .slot-grid,
.slot.zeroThree .slot-grid {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: minmax(0, 1fr);
}
.slot.advance .slot-grid {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(3, minmax(0, 1fr));
}

.pick {
  appearance: none;
  width: 100%;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  gap: 0.6rem;
  align-items: center;
  align-content: center;
  min-width: 0;
  min-height: 0;
  height: 100%;
  margin: 0;
  padding: 0.55rem 0.4rem;
  border: 0;
  border-bottom: 1px solid rgba(244, 241, 238, 0.06);
  border-radius: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease;
}
.pick:hover {
  background: rgba(255, 255, 255, 0.045);
}
.pick:focus-visible {
  outline: 1px solid rgba(226, 59, 59, 0.55);
  outline-offset: -1px;
}
.pick img {
  width: clamp(26px, 3.2vh, 34px);
  height: clamp(26px, 3.2vh, 34px);
  object-fit: contain;
  justify-self: center;
}
.pick .name {
  font-size: clamp(1.05rem, 1.7vh + 0.35rem, 1.35rem);
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pick .meta {
  text-align: right;
  font-size: clamp(0.9rem, 1.3vh + 0.3rem, 1.1rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--muted);
  white-space: nowrap;
}
.pick.is-alive .meta {
  color: var(--pass);
}
.pick.is-locked .meta {
  color: var(--locked);
}
.pick.is-dead {
  opacity: 0.42;
}
.pick.is-dead .name {
  text-decoration: line-through;
  text-decoration-color: rgba(224, 112, 112, 0.7);
}
.pick.is-dead .meta {
  color: var(--fail);
}
.pick .kill {
  grid-column: 2 / -1;
  font-size: 0.78rem;
  color: rgba(224, 112, 112, 0.85);
  margin-top: -0.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-stage {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}
.empty-stage h2 {
  margin: 0 0 0.3rem;
  font-family: var(--font-display);
  letter-spacing: 0.12em;
  font-size: 1.8rem;
  color: var(--ink);
  font-weight: 400;
}

body.modal-open {
  overflow: hidden;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.modal[hidden] {
  display: none;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 3, 4, 0.72);
  backdrop-filter: blur(4px);
}
.modal-panel {
  position: relative;
  z-index: 1;
  width: min(560px, 94vw);
  max-height: min(78vh, 640px);
  overflow: auto;
  padding: 1.15rem 1.2rem 1.1rem;
  background: linear-gradient(180deg, #1a1214, #100c0d);
  border: 1px solid rgba(240, 160, 176, 0.28);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  animation: rise 0.22s ease both;
}
.modal-close {
  position: absolute;
  top: 0.55rem;
  right: 0.65rem;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover {
  color: var(--ink);
}
.modal-head {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 0.85rem;
  align-items: center;
  padding-right: 1.5rem;
  margin-bottom: 0.85rem;
}
.modal-head img {
  width: 56px;
  height: 56px;
  object-fit: contain;
}
.modal-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1;
}
.modal-record {
  margin: 0.25rem 0 0;
  color: var(--orchid);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.modal-section {
  margin: 0 0 0.45rem;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 400;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
.modal-matches {
  display: grid;
  gap: 0.4rem;
}
.modal-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}
.modal-match {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto minmax(0, 1fr) 22px;
  gap: 0.4rem;
  align-items: center;
  padding: 0.45rem 0.35rem;
  border-bottom: 1px solid rgba(244, 241, 238, 0.08);
}
.modal-match img {
  width: 18px;
  height: 18px;
  object-fit: contain;
}
.modal-match .side {
  font-size: 0.86rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.modal-match .side.right {
  text-align: right;
}
.modal-match .scoreline {
  font-family: var(--font-display);
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.modal-match.win .scoreline {
  color: var(--pass);
}
.modal-match.loss .scoreline {
  color: var(--fail);
}

.toast {
  position: fixed;
  right: 0.85rem;
  bottom: 0.85rem;
  background: #141316;
  border: 1px solid rgba(226, 59, 59, 0.45);
  color: var(--ink);
  padding: 0.55rem 0.85rem;
  border-radius: 2px;
  font-size: 0.85rem;
  font-weight: 600;
  transform: translateY(120%);
  opacity: 0;
  transition: 0.22s ease;
  z-index: 20;
}
.toast.show {
  transform: none;
  opacity: 1;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@keyframes pulse-glow {
  0%,
  100% {
    filter: drop-shadow(0 0 12px rgba(237, 28, 36, 0.25));
  }
  50% {
    filter: drop-shadow(0 0 22px rgba(237, 28, 36, 0.45));
  }
}

@media (max-height: 760px) {
  .brand-title {
    font-size: 1.7rem;
  }
  .brand-logo {
    height: 2.6rem;
  }
  .player-head strong {
    font-size: 1.55rem;
  }
  .player-head .score b {
    font-size: 1.25rem;
  }
  .pick .name {
    font-size: 0.9rem;
  }
  .pick img {
    width: 20px;
    height: 20px;
  }
}

@media (max-width: 980px) {
  html,
  body {
    overflow: auto;
  }
  .app {
    height: auto;
    max-height: none;
    width: 100%;
    overflow: visible;
  }
  .overview {
    grid-template-columns: 1fr;
  }
  .player-col {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    height: auto;
  }
  .slots {
    height: auto;
    grid-template-rows: auto;
  }
  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "brand actions"
      "stages stages";
    gap: 0.55rem 0.75rem;
    align-items: center;
  }
  .brand {
    grid-area: brand;
  }
  .stage-tabs {
    grid-area: stages;
    width: 100%;
    justify-content: stretch;
  }
  .stage-tab {
    flex: 1;
  }
  .topbar-actions {
    grid-area: actions;
  }
  #syncMeta {
    display: none;
  }
}
