/* flap.fun — the page exists to frame the game. Nothing here competes with it. */

:root {
  --bg: #08080A;
  --ink: #F4F4F2;
  --dim: #7C7C84;
  --dimmer: #4C4C54;
  --line: rgba(255, 255, 255, .09);
  --line-strong: rgba(255, 255, 255, .18);
  --grad: linear-gradient(90deg, #9945FF, #00D2FF, #14F195);
  --font: Archivo, "Segoe UI Variable Display", "Segoe UI", system-ui,
          -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
  --pad: 40px;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; background: var(--bg); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, p, dl, dd { margin: 0; }

:focus-visible { outline: 2px solid rgba(255, 255, 255, .55); outline-offset: 3px; }

.label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--dim);
}
.label.dim { color: var(--dimmer); }

/* ---------- shell ---------- */

.shell {
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 1520px;
  margin-inline: auto;
  padding: 36px var(--pad);
  display: grid;
  grid-template-columns: minmax(224px, 262px) auto minmax(238px, 268px);
  gap: clamp(36px, 4.4vw, 68px);
  align-content: center;
  justify-content: center;
  align-items: stretch;
}

/* ---------- brand rail ---------- */

.brand {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 48px;
  padding-block: 4px;
}

.accent {
  display: block;
  width: 30px;
  height: 3px;
  background: var(--grad);
  margin-bottom: 20px;
}

.wordmark {
  font-size: clamp(44px, 4.3vw, 70px);
  font-weight: 900;
  letter-spacing: -.055em;
  line-height: .85;
}
.wordmark em { display: block; font-style: normal; }

.tld {
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* X link — sits in the page margin, out of the game's way. */
.xlink {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 20;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  color: var(--dim);
  transition: color 140ms ease-out, border-color 140ms ease-out;
}
.xlink:hover { color: var(--ink); border-color: rgba(255, 255, 255, .42); }

.tagline {
  margin-top: 18px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--dim);
}

.stat { padding-bottom: 16px; border-bottom: 1px solid var(--line); }

.stat-num {
  display: block;
  margin-top: 4px;
  font-size: 44px;
  font-weight: 900;
  letter-spacing: -.045em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.rail-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.rail-val { font-size: 12.5px; font-weight: 600; color: #A8A8AF; }

.ghost {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin-top: 18px;
  padding: 0;
  background: none;
  border: 0;
  cursor: pointer;
  color: var(--dim);
  font: 700 10.5px/1 var(--font);
  letter-spacing: .14em;
  text-transform: uppercase;
  transition: color 140ms ease-out;
}
.ghost:hover { color: var(--ink); }
.dot { width: 7px; height: 7px; background: var(--grad); }
.ghost[aria-pressed="false"] .dot { background: var(--dimmer); }

/* ---------- stage ---------- */

.stage-wrap { display: flex; align-items: center; justify-content: center; }

/* Both axes are stated explicitly and derived from one variable. Leaving width
   to `auto` + aspect-ratio lets the grid's auto track size itself from the
   canvas's intrinsic size instead, which feeds back into the height. */
.stage {
  --gh: clamp(440px, 70vh, 660px);
  --gh: clamp(440px, 70dvh, 660px);
  position: relative;
  height: var(--gh);
  width: calc(var(--gh) * 400 / 650);
  border: 1px solid var(--line);
  background: #08080A;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#game { display: block; width: 100%; height: 100%; }
.stage.is-playing #game { cursor: none; }

/* ---------- overlays ---------- */

.ov {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 26px;
  background: rgba(6, 6, 9, .90);
  pointer-events: none;
}
.ov.on { display: flex; }
.ov .inner { pointer-events: auto; width: 100%; max-width: 264px; }
.ov.on .inner { animation: rise 200ms cubic-bezier(.2, .7, .2, 1) both; }
.inner.center { text-align: center; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.ov-title {
  font-size: 30px;
  font-weight: 900;
  letter-spacing: -.038em;
  line-height: .92;
  text-transform: uppercase;
  text-align: center;
}
.ov-title.brandmark { font-size: 40px; letter-spacing: -.055em; text-transform: none; }

.ov-sub {
  margin-top: 12px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--dim);
}

.ov-tag {
  margin-bottom: 12px;
  min-height: 14px;
  text-align: center;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--dim);
}
.ov-tag.is-best {
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.rule { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

#ovOver .label { display: block; text-align: center; }

.ov-score {
  margin-top: 8px;
  text-align: center;
  font-size: 74px;
  font-weight: 900;
  letter-spacing: -.055em;
  line-height: .88;
  font-variant-numeric: tabular-nums;
}

.ov-stats { display: grid; grid-template-columns: 1fr 1fr; }
.ov-stats > div { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.ov-stats > div + div { border-left: 1px solid var(--line); }
.ov-stat {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -.025em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.ov-hint {
  margin-top: 14px;
  text-align: center;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--dimmer);
}

.fieldset + .fieldset { margin-top: 14px; }
.fieldset + .btn { margin-top: 18px; }

.field-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
}
.opt {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: .1em;
  color: var(--dimmer);
}

.field {
  width: 100%;
  padding: 12px 13px;
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  color: var(--ink);
  font: 700 16px var(--font);
  letter-spacing: .01em;
}
.field-addr {
  font: 500 13px var(--mono);
  letter-spacing: 0;
  text-overflow: ellipsis;
}
.field::placeholder {
  color: var(--dimmer);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
}

.field-note {
  margin-top: 7px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--dimmer);
}
.field-note.bad { color: #FF6B6B; }
.field:focus { outline: none; border-color: rgba(255, 255, 255, .45); }
.field.shake { animation: nudge 260ms ease-out; border-color: rgba(255, 96, 96, .65); }

@keyframes nudge {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

.btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 15px 18px;
  background: var(--ink);
  color: #08080A;
  border: 0;
  border-radius: 4px;
  font: 800 13px/1 var(--font);
  letter-spacing: .1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 140ms ease-out, transform 100ms ease-out;
}
.btn:hover { background: #FFFFFF; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .3; cursor: not-allowed; transform: none; }

.linkbtn {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 0;
  background: none;
  border: 0;
  color: var(--dim);
  font: 700 10.5px/1 var(--font);
  letter-spacing: .14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 140ms ease-out;
}
.linkbtn:hover { color: var(--ink); }

/* ---------- leaderboard ---------- */

.board { display: flex; flex-direction: column; justify-content: center; }

.board-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line-strong);
}

.rows { list-style: none; margin: 0; padding: 0; }

.row {
  position: relative;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 12px;
  padding: 7px 6px 7px 10px;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.row .rk { font-size: 11px; font-weight: 700; letter-spacing: .04em; color: var(--dimmer); }
.row .who { min-width: 0; }
.row .nm {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: #C4C4CA;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row .sc { font-size: 15px; font-weight: 800; letter-spacing: -.015em; }

/* Public wallet address — quiet, and the row is the copy target. */
.row .addr {
  display: block;
  margin-top: 1px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--dimmer);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 120ms ease-out;
}
.row .addr.copied {
  font-family: var(--font);
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #14F195;
}
.row.can-copy { cursor: pointer; }
.row.can-copy:hover { background: rgba(255, 255, 255, .04); }
.row.can-copy:hover .addr { color: #A8A8AF; }

.row:first-child { padding-top: 11px; }
.row:first-child .rk { color: var(--dim); }
.row:first-child .nm { font-size: 18px; font-weight: 700; color: var(--ink); }
.row:first-child .sc { font-size: 21px; letter-spacing: -.03em; }

.row.is-you::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--grad);
}
.row.is-you .nm { color: var(--ink); }

.reset-in { color: var(--dim); font-variant-numeric: tabular-nums; }

/* Empty state — a real leaderboard is empty until someone plays. */
.board-empty {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 26px 0 28px;
  border-bottom: 1px solid var(--line);
}
.empty-head { font-size: 17px; font-weight: 800; letter-spacing: -.02em; }
.empty-sub { font-size: 12.5px; font-weight: 500; color: var(--dim); }

/* Last round — same structure, dialled down so the live board stays primary. */
.lastround { margin-top: 22px; }
.lastround-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

/* The one who actually got paid — worth the gradient. */
.winner-tag {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  white-space: nowrap;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.rows-last .row.won .rk {
  color: #14F195;
  -webkit-text-fill-color: #14F195;
}

.rows-last .row { padding: 7px 6px 7px 10px; opacity: .72; }
.rows-last .row:first-child { padding-top: 9px; }
.rows-last .rk { font-size: 10px; }
.rows-last .addr { font-size: 9.5px; }
.rows-last .nm,
.rows-last .row:first-child .nm { font-size: 12.5px; font-weight: 600; color: #A8A8AF; }
.rows-last .sc,
.rows-last .row:first-child .sc { font-size: 12.5px; font-weight: 700; letter-spacing: 0; }
.rows-last .row.won .nm { color: var(--ink); font-weight: 700; }
.rows-last .row.won .sc { color: var(--ink); }

.board-prize {
  margin-top: 16px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.45;
  color: #A6A6AE;
}
.board-prize strong {
  font-weight: 800;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.board-note {
  margin-top: 6px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--dimmer);
}
.board-note.offline { color: #C08A3E; }

.mobile-only { display: none; }

/* ---------- 900–1199: brand becomes a header bar ---------- */

@media (max-width: 1199px) {
  :root { --pad: 32px; }
  .shell {
    grid-template-columns: auto minmax(210px, 258px);
    grid-template-areas: "brand brand" "stage board";
    gap: 30px clamp(28px, 3.6vw, 48px);
    align-content: center;
  }
  .brand {
    grid-area: brand;
    flex-direction: row;
    align-items: flex-end;
    justify-content: space-between;
    gap: 32px;
  }
  .brand-top { display: flex; align-items: baseline; gap: 20px; flex-wrap: wrap; }
  .accent { display: none; }
  .wordmark { font-size: 40px; letter-spacing: -.05em; line-height: 1; }
  .wordmark em { display: inline; }
  .tagline { margin-top: 0; }
  .brand-bottom { display: flex; align-items: baseline; gap: 26px; }
  .stat { display: flex; align-items: baseline; gap: 10px; padding: 0; border: 0; }
  .stat-num { margin-top: 0; font-size: 26px; }
  .rail-row { display: none; }
  .ghost { margin-top: 0; }
  .stage-wrap { grid-area: stage; }
  .board { grid-area: board; justify-content: flex-start; }
  .stage {
    --gh: clamp(420px, 64vh, 600px);
    --gh: clamp(420px, 64dvh, 600px);
  }
}

/* ---------- under 900: single column, game near full width ---------- */

@media (max-width: 899px) {
  :root { --pad: 18px; }
  .shell {
    grid-template-columns: 1fr;
    grid-template-areas: "brand" "stage" "board";
    gap: 22px;
    padding: 20px var(--pad) 40px;
    align-content: start;
  }
  .brand { gap: 16px; }
  .brand-top { gap: 12px; }
  .wordmark { font-size: 30px; }
  .tagline { font-size: 10.5px; }
  .brand-bottom { gap: 18px; }
  .stat-num { font-size: 22px; }
  /* Whichever runs out first — vertical room, or the width of the screen. */
  .stage {
    --gh: min(calc(100vh - 130px), calc((100vw - 2 * var(--pad)) * 1.625));
    --gh: min(calc(100dvh - 130px), calc((100vw - 2 * var(--pad)) * 1.625));
  }
  .mobile-only { display: block; }
  #ovStart .field-label { margin-top: 22px; }
  .board { justify-content: flex-start; }
}

@media (max-width: 380px) {
  .wordmark { font-size: 26px; }
  .stat-num { font-size: 19px; }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
