:root {
  color-scheme: dark;
  --bottom-rail-bottom: clamp(16px, 2.8vw, 32px);
  --ink: #fff7df;
  --muted: rgba(255, 247, 223, 0.66);
  --dim: rgba(255, 247, 223, 0.42);
  --panel: rgba(15, 12, 8, 0.66);
  --panel-strong: rgba(10, 8, 6, 0.92);
  --line: rgba(255, 216, 126, 0.18);
  --gold: #f6cc52;
  --hot: #ff7040;
  --acid: #d7ff59;
  --blue: #7ad7ff;
  --shadow: 0 30px 90px rgba(0, 0, 0, 0.42);
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #080704;
  color: var(--ink);
}

button,
input { font: inherit; }

button { cursor: pointer; }

.app-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at 28% 16%, rgba(255, 196, 53, 0.2), transparent 28%),
    radial-gradient(circle at 76% 82%, rgba(122, 215, 255, 0.15), transparent 30%),
    linear-gradient(140deg, #080704 0%, #14100b 48%, #050403 100%);
}

.app-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.026) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(circle at 50% 50%, black, transparent 82%);
  z-index: 2;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  touch-action: none;
}

.brand-lockup,
.bottom-center-actions,
.quick-actions,
.leaderboard-drawer,
.result-sheet,
.account-sheet,
.platform-popover {
  position: absolute;
  z-index: 5;
}

.brand-lockup {
  left: clamp(18px, 3vw, 44px);
  bottom: calc(var(--bottom-rail-bottom) + 10px);
  pointer-events: none;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-copy {
  display: grid;
  gap: 4px;
}

.wordmark {
  pointer-events: auto;
  display: inline-block;
  width: fit-content;
  margin-top: 2px;
  color: var(--muted);
  text-decoration: none;
  letter-spacing: -0.02em;
  font-size: clamp(12px, 1.15vw, 15px);
  font-weight: 850;
  line-height: 1;
  text-shadow: 0 10px 32px rgba(0,0,0,.45);
}

.account-chip {
  pointer-events: auto;
  display: grid;
  place-items: center;
  width: clamp(34px, 4vw, 42px);
  height: clamp(34px, 4vw, 42px);
  flex: 0 0 clamp(34px, 4vw, 42px);
  padding: 0;
  border: 1px solid rgba(255, 247, 223, .24);
  border-radius: 999px;
  background: rgba(255, 247, 223, .08);
  color: var(--ink);
  box-shadow: 0 10px 32px rgba(0,0,0,.28);
  overflow: hidden;
}

.account-chip.has-account {
  border-color: rgba(246, 204, 82, .58);
  background: rgba(246, 204, 82, .14);
}

.account-avatar {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: rgba(255, 247, 223, .62);
  font-size: 13px;
  font-weight: 900;
}

.account-avatar::before {
  content: "";
  width: 13px;
  height: 13px;
  border-radius: 999px;
  border: 2px solid rgba(255, 247, 223, .44);
  box-shadow: 0 11px 0 -4px rgba(255, 247, 223, .22);
}

.account-chip.has-account .account-avatar::before {
  content: none;
}

.account-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.wordmark span {
  color: var(--gold);
  font-size: 1em;
  letter-spacing: -0.03em;
}

.brand-line {
  margin: 0;
  color: var(--ink);
  letter-spacing: -0.045em;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(14px, 1.55vw, 22px);
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 10px 40px rgba(0,0,0,.55);
}

.run-rank-line {
  margin: 0 0 5px;
  color: rgba(255, 247, 223, .58);
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: clamp(10px, .9vw, 12px);
  font-weight: 850;
  letter-spacing: 0.02em;
  line-height: 1;
  text-shadow: 0 8px 28px rgba(0,0,0,.5);
}

.run-rank-line[hidden] {
  display: none;
}

.brand-subline {
  margin: 0;
  color: rgba(255, 247, 223, .68);
  font-size: clamp(11px, 1.05vw, 14px);
  font-weight: 850;
  letter-spacing: 0.01em;
  line-height: 1;
  text-shadow: 0 8px 28px rgba(0,0,0,.48);
}

.rule-card {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  margin: 0 0 12px;
  padding: 0 0 12px;
  border: 1px solid rgba(255, 216, 126, .14);
  border-width: 0 0 1px;
  border-radius: 0;
  background: transparent;
  backdrop-filter: none;
  box-shadow: none;
  text-shadow: none;
}

.rule-card strong {
  color: var(--gold);
  font-size: 10px;
  font-weight: 950;
  letter-spacing: 0.16em;
  line-height: 1;
  text-transform: uppercase;
}

.rule-card span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  line-height: 1.1;
  white-space: nowrap;
}

.control-hint,
.drawer-card,
.result-card,
.platform-popover {
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(18px) saturate(140%);
  box-shadow: var(--shadow);
}

.control-hint {
  width: min(420px, calc(100vw - 236px));
  min-width: 220px;
  padding: 13px 16px 12px;
  border-radius: 999px;
  text-align: center;
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.3);
}

.bottom-center-actions {
  left: 50%;
  bottom: calc(var(--bottom-rail-bottom) - 6px);
  display: flex;
  align-items: center;
  gap: 10px;
  transform: translateX(-50%);
}

.hint-copy {
  flex: 1;
  min-width: 0;
}

.micro-label {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.game-prompt,
.form-note,
.platform-popover p {
  color: var(--muted);
}

.power-meter {
  height: 5px;
  margin: 0 0 9px;
  border-radius: 999px;
  background: rgba(255,255,255,.12);
  overflow: hidden;
}

.power-meter span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--hot), var(--acid));
  transition: width 80ms linear;
}

.game-prompt {
  margin: 0;
  font-size: 12px;
  font-weight: 850;
}

.quick-actions {
  right: clamp(16px, 2.8vw, 34px);
  bottom: var(--bottom-rail-bottom);
  display: flex;
  gap: 9px;
  align-items: center;
}

.pill-button {
  border: 1px solid rgba(255, 216, 126, .18);
  border-radius: 999px;
  padding: 10px 13px;
  color: var(--ink);
  background: rgba(12, 10, 7, .58);
  backdrop-filter: blur(16px) saturate(135%);
  box-shadow: 0 18px 54px rgba(0, 0, 0, .32);
  font-size: 12px;
  font-weight: 900;
}

.pill-button.hot {
  color: #160f05;
  border-color: transparent;
  background: linear-gradient(135deg, var(--gold), var(--hot));
}

.builder-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-width: clamp(34px, 4vw, 42px);
  height: clamp(34px, 4vw, 42px);
  padding: 6px;
  border: 1px solid rgba(255, 247, 223, .24);
  border-radius: 999px;
  background: rgba(255, 247, 223, .08);
  color: var(--ink);
  box-shadow: 0 10px 32px rgba(0,0,0,.28);
  text-decoration: none;
  overflow: hidden;
  transition: min-width .18s ease, padding .18s ease, border-color .18s ease, background .18s ease;
}

.builder-link:hover,
.builder-link:focus-visible {
  min-width: 156px;
  padding-left: 13px;
  border-color: rgba(246, 204, 82, .58);
  background: rgba(246, 204, 82, .14);
}

.builder-label {
  display: none;
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.builder-link:hover .builder-label,
.builder-link:focus-visible .builder-label {
  display: inline;
}

.builder-avatar {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  overflow: hidden;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), var(--hot));
}

.builder-avatar img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.leaderboard-drawer {
  right: clamp(16px, 2.8vw, 36px);
  bottom: clamp(16px, 2.8vw, 34px);
  width: min(420px, calc(100vw - 32px));
  display: grid;
  gap: 12px;
  max-height: calc(100vh - 32px);
  overflow: auto;
}

.leaderboard-drawer[hidden],
.result-sheet[hidden],
.account-sheet[hidden],
.platform-popover[hidden] {
  display: none;
}

.drawer-close {
  position: sticky;
  top: 0;
  justify-self: end;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 999px;
  color: var(--ink);
  background: rgba(12, 10, 7, .74);
  backdrop-filter: blur(14px);
  font-size: 22px;
  line-height: 1;
  z-index: 2;
}

.drawer-card {
  border-radius: 28px;
  padding: 18px;
}

.result-card h2,
.platform-popover h2 {
  margin: 0 0 10px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 33px;
  line-height: 0.94;
  letter-spacing: -0.06em;
}

.form-note,
.platform-popover p {
  margin: 0 0 14px;
  line-height: 1.45;
}

.primary-button,
.ghost-button {
  border: 0;
  border-radius: 999px;
  font-weight: 900;
}

.primary-button {
  padding: 14px 18px;
  color: #160f05;
  background: linear-gradient(135deg, var(--gold), var(--hot));
  box-shadow: 0 18px 38px rgba(255, 112, 46, .25);
}

.ghost-button {
  padding: 10px 13px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255,255,255,.12);
}

.leaderboard-list {
  list-style: none;
  display: grid;
  gap: 8px;
  max-height: 280px;
  margin: 0;
  padding: 0;
  overflow: auto;
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: 34px 42px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-radius: 17px;
  background: rgba(255,255,255,.055);
  cursor: pointer;
  transition: background .18s ease, transform .18s ease;
}

.leaderboard-list li:hover {
  background: rgba(255,255,255,.085);
  transform: translateY(-1px);
}

.leaderboard-list .rank {
  color: var(--gold);
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 12px;
  font-weight: 900;
}

.leaderboard-list strong,
.player-name-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  font-size: 14px;
}

.player-name-line span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-id {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.player-avatar {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  overflow: hidden;
  border-radius: 50%;
  color: #170f05;
  background: linear-gradient(135deg, var(--gold), var(--hot));
  font-size: 14px;
  font-weight: 950;
}

.player-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.player-copy {
  min-width: 0;
}

.leaderboard-list small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.28;
}

.leaderboard-list .score-time {
  color: rgba(255, 247, 223, .48);
  font-size: 11px;
  margin-top: 2px;
}

.leaderboard-list em {
  color: var(--blue);
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 12px;
  font-style: normal;
  font-weight: 900;
}

.result-sheet,
.account-sheet {
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 2, 1, .62);
}

.result-card {
  position: relative;
  width: min(420px, 100%);
  padding: 22px;
  border-radius: 30px;
  background: var(--panel-strong);
}

.sheet-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  border: 1px solid rgba(255, 247, 223, .16);
  border-radius: 999px;
  background: rgba(255, 247, 223, .06);
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

.sheet-close:hover {
  color: var(--ink);
  border-color: rgba(255, 247, 223, .34);
}

.result-card .micro-label {
  display: none;
}

.result-card h2 {
  margin-bottom: 8px;
  font-size: clamp(42px, 8vw, 64px);
  line-height: .88;
}

#result-copy {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 18px;
  font-weight: 850;
}

.result-card label {
  display: grid;
  gap: 7px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0;
  font-weight: 850;
}

.result-card label[hidden],
.result-card button[hidden] {
  display: none;
}

.result-card input {
  width: 100%;
  border: 1px solid rgba(255, 216, 126, .22);
  border-radius: 17px;
  padding: 13px 14px;
  color: var(--ink);
  background: rgba(255,255,255,.07);
  outline: none;
}

.result-card input:focus {
  border-color: rgba(246, 204, 82, .74);
  box-shadow: 0 0 0 4px rgba(246, 204, 82, .12);
}

.result-actions {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
  margin-top: 12px;
}

.result-actions .primary-button {
  grid-column: 1 / -1;
}

.result-card.has-account .result-actions .primary-button {
  display: none;
}

.result-card.has-account .result-actions {
  grid-template-columns: 1fr 1fr;
}

.form-note {
  min-height: 20px;
  margin-bottom: 0;
  font-size: 15px;
  font-weight: 850;
}

.platform-popover {
  left: 14px;
  top: 14px;
  width: min(360px, calc(100vw - 32px));
  transform: none;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  backdrop-filter: none;
  box-shadow: none;
  pointer-events: none;
}

.platform-popover-list {
  max-height: none;
  overflow: visible;
}

.platform-popover-list li {
  border: 1px solid rgba(255, 216, 126, .2);
  background: rgba(12, 10, 7, .9);
  backdrop-filter: blur(18px) saturate(140%);
  box-shadow: 0 22px 70px rgba(0, 0, 0, .48);
  cursor: default;
}

.platform-popover-list li:hover {
  background: rgba(12, 10, 7, .94);
  transform: none;
}

@media (max-width: 900px) {
  .leaderboard-drawer {
    left: 14px;
    right: 14px;
    bottom: 14px;
    width: auto;
    grid-template-columns: 1fr;
  }

}

@media (max-width: 700px) {
  .brand-lockup {
    left: 12px;
    top: auto;
    bottom: 12px;
  }

  .wordmark { font-size: 24px; }

  .brand-line {
    font-size: 12px;
  }

  .run-rank-line {
    margin-bottom: 4px;
    font-size: 9px;
  }

  .rule-card {
    max-width: none;
    gap: 6px;
    margin-bottom: 10px;
    padding: 0 0 10px;
  }

  .rule-card strong {
    font-size: 9px;
  }

  .rule-card span {
    overflow: hidden;
    font-size: 10px;
    text-overflow: ellipsis;
  }

  .control-hint {
    width: min(306px, calc(100vw - 104px));
    min-width: 148px;
    padding: 8px 10px 7px;
    border-radius: 18px;
    background: rgba(12, 10, 7, .5);
    border-color: rgba(255, 216, 126, .12);
    box-shadow: 0 12px 36px rgba(0, 0, 0, .22);
  }

  .account-chip {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
  }

  .builder-link {
    min-width: 32px;
    height: 32px;
    padding: 4px;
  }

  .builder-link:hover,
  .builder-link:focus-visible {
    min-width: 32px;
    padding: 4px;
  }

  .builder-label {
    display: none !important;
  }

  .builder-avatar {
    width: 24px;
    height: 24px;
    flex-basis: 24px;
  }

  .bottom-center-actions {
    bottom: 58px;
    gap: 8px;
  }

  .control-hint .power-meter {
    height: 4px;
    margin-bottom: 6px;
  }

  .game-prompt {
    display: block;
    font-size: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .quick-actions {
    right: 12px;
    bottom: 12px;
    gap: 6px;
  }

  .pill-button {
    padding: 9px 10px;
    font-size: 11px;
  }

  .leaderboard-drawer {
    top: auto;
    left: 10px;
    right: 10px;
    bottom: 10px;
    max-height: min(78vh, 620px);
    width: auto;
  }

  .drawer-card,
  .result-card {
    border-radius: 22px;
    padding: 14px;
  }

  .result-card h2 {
    font-size: 28px;
  }
}
