:root {
  --ink: #04301e;
  --ink-soft: #0b5237;
  --extrude: #067a4e;
  --extrude-deep: #03492e;
  --fill-top: #ffffff;
  --fill-bottom: #e4ff7a;
  --btn-1: #4dffb0;
  --btn-2: #00c97c;
  --btn-lip: #007a4b;
  --btn-ink: #04301e;
  --card: #fbfff2;
  --c1: #d4ff3f;
  --c2: #2ee59d;
  --c3: #1fc7b6;
  --gold-1: #ffe45c;
  --gold-2: #ffb300;
  --gold-lip: #b86b00;
  --dark-1: #243042;
  --dark-2: #0c1320;
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  --head: "Bagel Fat One", "Inter", system-ui, sans-serif;
  --ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

body[data-skin="sol"] {
  --ink: #180748;
  --ink-soft: #2f1a7c;
  --extrude: #3a0fb0;
  --extrude-deep: #210770;
  --fill-bottom: #a9ffdd;
  --btn-1: #c37bff;
  --btn-2: #7a1fff;
  --btn-lip: #40089e;
  --btn-ink: #ffffff;
  --card: #fbf7ff;
  --c1: #dc1fff;
  --c2: #33ceff;
  --c3: #19fb9b;
}

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

html { overflow-x: clip; scroll-behavior: smooth; }

body {
  margin: 0;
  overflow-x: clip;
  font-family: var(--ui);
  font-weight: 600;
  color: var(--ink);
  background: #00d884;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body[data-skin="sol"] { background: #6a1bff; }

button, input { font: inherit; }
a { color: inherit; }
p { margin: 0; }

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

/* Background */
.bg { position: fixed; inset: 0; z-index: -1; }
.bg i { position: absolute; inset: 0; transition: opacity .6s ease; }
.bg-pump {
  background:
    radial-gradient(60vmax 44vmax at 50% 42%, rgba(255, 255, 255, .72), transparent 70%),
    linear-gradient(155deg, #00d884 0%, #b8ff3c 52%, #16d3be 100%);
}
.bg-sol {
  opacity: 0;
  background:
    radial-gradient(60vmax 44vmax at 50% 42%, rgba(255, 255, 255, .55), transparent 70%),
    linear-gradient(150deg, #6a1bff 0%, #c21dff 42%, #33a8ff 74%, #14e8b4 100%);
}
body[data-skin="sol"] .bg-sol { opacity: 1; }
.bg-grid {
  background-image: radial-gradient(circle at 50% 50%, rgba(255, 255, 255, .16) 0 3px, transparent 3.5px);
  background-size: 34px 34px;
}

/* Headings: outlined base, layered extrude, gradient face on a pseudo element */
.fx {
  position: relative;
  display: inline-block;
  margin: 0;
  font-family: var(--head);
  font-weight: 400;
  line-height: 1.04;
  letter-spacing: .025em;
  word-spacing: .14em;
  color: var(--ink);
  -webkit-text-stroke: var(--stroke, 8px) var(--ink);
  paint-order: stroke fill;
  text-shadow:
    0 1px 0 var(--extrude), 0 2px 0 var(--extrude), 0 3px 0 var(--extrude),
    0 4px 0 var(--extrude), 0 5px 0 var(--extrude), 0 6px 0 var(--extrude-deep),
    0 7px 0 var(--extrude-deep), 0 8px 0 var(--extrude-deep),
    0 16px 22px rgba(0, 0, 0, .28);
}
.fx::after {
  content: attr(data-t);
  position: absolute;
  inset: 0;
  -webkit-text-stroke: 0;
  text-shadow: none;
  color: transparent;
  background: linear-gradient(180deg, var(--fill-top) 18%, var(--fill-bottom) 62%, #fff 96%);
  -webkit-background-clip: text;
  background-clip: text;
}
.fx-xl { font-size: clamp(38px, 6.2vw, 92px); --stroke: clamp(7px, .9vw, 12px); }
.fx-lg { font-size: clamp(38px, 5vw, 68px); --stroke: 9px; }
.fx-md { font-size: clamp(26px, 2.3vw, 31px); --stroke: 3.5px; text-shadow: 0 2px 0 var(--extrude), 0 4px 0 var(--extrude-deep), 0 8px 10px rgba(0, 0, 0, .22); }
.logo .fx { font-size: 24px; --stroke: 5px; text-shadow: 0 2px 0 var(--extrude), 0 3px 0 var(--extrude-deep); }

/* Rubber buttons */
.rb {
  --c1: var(--btn-1);
  --c2: var(--btn-2);
  --lip: var(--btn-lip);
  --fg: var(--btn-ink);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 56px;
  padding: 0 28px;
  border: 0;
  border-radius: 20px;
  font-family: var(--head);
  font-size: 22px;
  font-weight: 400;
  letter-spacing: .02em;
  text-decoration: none;
  color: var(--fg);
  background: linear-gradient(180deg, var(--c1), var(--c2));
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, .55),
    inset 0 -3px 0 rgba(0, 0, 0, .1),
    0 7px 0 var(--lip),
    0 13px 18px rgba(0, 0, 0, .25);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: box-shadow .12s, translate .12s;
}
.rb:active {
  translate: 0 4px;
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, .55),
    0 3px 0 var(--lip),
    0 6px 10px rgba(0, 0, 0, .25);
}
.rb:focus-visible, .name:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.rb:disabled { filter: grayscale(.5); cursor: progress; }
.rb-big { min-height: 66px; padding: 0 42px; font-size: 28px; border-radius: 24px; }
.rb-small { min-height: 44px; padding: 0 18px; font-size: 16px; border-radius: 16px; box-shadow: inset 0 2px 0 rgba(255, 255, 255, .5), 0 5px 0 var(--lip), 0 9px 12px rgba(0, 0, 0, .22); }
.rb-gold { --c1: var(--gold-1); --c2: var(--gold-2); --lip: var(--gold-lip); --fg: #4a2a00; }
.rb-dark { --c1: var(--dark-1); --c2: var(--dark-2); --lip: #000; --fg: #fff; }
.rb-dark { box-shadow: inset 0 2px 0 rgba(255, 255, 255, .2), 0 5px 0 var(--lip), 0 9px 12px rgba(0, 0, 0, .22); }
.rb-alt { --c1: #fff; --c2: #e6ebe9; --lip: #98a5a0; --fg: var(--ink); }
.rb-icon { --c1: #fff; --c2: #e6ebe9; --lip: #98a5a0; width: 44px; min-height: 44px; padding: 0; font-size: 18px; border-radius: 14px; box-shadow: inset 0 2px 0 #fff, 0 4px 0 var(--lip), 0 8px 10px rgba(0, 0, 0, .2); }
.rb-key { width: 66px; min-height: 62px; padding: 0; font-size: 26px; border-radius: 18px; }
.rb-alt.rb-key.on { --c1: var(--gold-1); --c2: var(--gold-2); --lip: var(--gold-lip); --fg: #4a2a00; }
#pad-undo { width: 92px; font-size: 19px; }

@media (hover: hover) {
  .rb:hover { animation: wobble .5s ease; }
}
@keyframes wobble {
  20% { rotate: -2.2deg; scale: 1.03; }
  45% { rotate: 1.8deg; }
  70% { rotate: -1deg; }
  100% { rotate: 0deg; }
}

/* Hero */
.hero {
  position: relative;
  height: 100vh;
  height: 100svh;
  min-height: 620px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 72px 16px 26px;
  overflow: hidden;
  pointer-events: none;
}
.hero a, .hero button, .hero input, .hero form { pointer-events: auto; }

#gl {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  pointer-events: auto;
  cursor: grab;
}
#gl:active { cursor: grabbing; }

.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 20px;
}
.logo { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; pointer-events: auto; }
.logo img { filter: drop-shadow(0 3px 0 rgba(0, 0, 0, .3)); }
.top-right { display: flex; align-items: center; gap: 12px; }
.live { display: none; position: relative; z-index: 2; gap: 10px; flex-wrap: wrap; justify-content: center; margin-bottom: 8px; }
body:not([data-phase="name"]) .live { display: flex; }
.live-pill {
  padding: 6px 14px;
  border-radius: 99px;
  background: #fff;
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .22);
  white-space: nowrap;
}
.live-pill.gold { background: linear-gradient(180deg, var(--gold-1), var(--gold-2)); color: #4a2a00; }
.dot { font-weight: 400; animation: pulse 1.3s ease-in-out infinite; display: inline-block; }
@keyframes pulse { 50% { opacity: .35; } }

.rivals {
  position: absolute;
  left: 20px;
  top: 50%;
  z-index: 2;
  display: none;
  gap: 8px;
  width: 210px;
  margin: 0;
  padding: 12px;
  list-style: none;
  border-radius: 20px;
  background: rgba(255, 255, 255, .88);
  box-shadow: inset 0 2px 0 #fff, 0 5px 0 rgba(0, 0, 0, .22);
  transform: translateY(-50%);
}
body:not([data-phase="name"]) .rivals { display: grid; }
.rival { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: 13px; font-weight: 800; }
.rival b { font-variant-numeric: tabular-nums; }
.rival .bar { grid-column: 1 / -1; margin: 0; height: 6px; }

.title-block { position: relative; z-index: 2; text-align: center; margin-top: 2px; }
.tag {
  margin-top: 16px;
  font-size: clamp(15px, 1.5vw, 20px);
  font-weight: 800;
}

.stage { position: relative; flex: 1 1 0; min-height: 0; width: 100%; }

.start-form {
  position: relative;
  z-index: 2;
  display: flex;
  gap: 14px;
  align-items: center;
  width: min(560px, 100%);
}
.name {
  flex: 1;
  min-width: 0;
  height: 66px;
  padding: 0 22px;
  border: 4px solid var(--ink);
  border-radius: 22px;
  background: #fff;
  color: var(--ink);
  font-size: 20px;
  font-weight: 800;
  box-shadow: inset 0 4px 0 rgba(0, 0, 0, .08), 0 6px 0 var(--ink);
}
.name::placeholder { color: #6f807a; font-weight: 700; }

.tools { position: relative; z-index: 2; display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 18px; }
.skin-toggle { display: inline-flex; gap: 6px; padding: 5px; border-radius: 99px; background: rgba(0, 0, 0, .28); }
.rb-toggle {
  --c1: transparent;
  --c2: transparent;
  --fg: #fff;
  min-height: 36px;
  padding: 0 18px;
  border-radius: 99px;
  font-size: 15px;
  box-shadow: none;
}
.rb-toggle.on { --c1: #fff; --c2: #e3ebe7; --fg: var(--ink); box-shadow: inset 0 2px 0 #fff, 0 3px 0 rgba(0, 0, 0, .35); }
.rb-toggle:active { translate: none; box-shadow: none; }

.hud {
  position: relative;
  z-index: 2;
  display: none;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 22px;
  background: rgba(255, 255, 255, .9);
  box-shadow: inset 0 2px 0 #fff, 0 5px 0 rgba(0, 0, 0, .22);
}
.stat { min-width: 92px; text-align: center; }
.stat small { display: block; font-size: 11px; font-weight: 800; letter-spacing: .08em; color: var(--ink-soft); }
.stat b { display: block; font-family: var(--head); font-weight: 400; font-size: 30px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-progress { min-width: 150px; }
.bar { display: block; height: 7px; margin-top: 3px; border-radius: 9px; background: rgba(0, 0, 0, .13); overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--c1), var(--c2)); transform: scaleX(0); transform-origin: left; transition: transform .25s var(--spring); }

.pad { position: relative; z-index: 2; display: none; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 16px; padding-bottom: 8px; }
.scramble-note { display: none; position: absolute; left: 0; right: 0; bottom: 118px; z-index: 2; text-align: center; font-family: var(--head); font-size: 22px; }
.play-only { display: none; }

/* Phases */
body:not([data-phase="name"]) .title-block,
body:not([data-phase="name"]) .start-form { display: none; }
body:not([data-phase="name"]) .hud { display: flex; }
body:not([data-phase="name"]) .pad,
body:not([data-phase="name"]) .play-only { display: inline-flex; }
body[data-phase="name"] .tools { margin-bottom: 2px; }
body[data-phase="scrambling"] .pad,
body[data-phase="solved"] .pad { opacity: .5; pointer-events: none; }
body[data-phase="scrambling"] .scramble-note { display: block; }
body[data-phase="scrambling"] .pad { visibility: hidden; }
body[data-phase="name"] .pad { display: none; }

/* Sections */
.section { width: min(1120px, 100%); margin: 0 auto; padding: 70px 16px 10px; text-align: center; }
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 26px; margin-top: 44px; text-align: left; }
.card {
  position: relative;
  padding: 58px 26px 30px;
  border-radius: 34px;
  background: var(--card);
  box-shadow: inset 0 4px 0 #fff, 0 12px 0 var(--lip-c, var(--btn-lip)), 0 22px 26px rgba(0, 0, 0, .22);
  transition: transform .3s var(--spring);
}
@media (hover: hover) { .card:hover { transform: translateY(-6px) rotate(-1deg); } }
.card p { margin-top: 12px; font-size: 16px; line-height: 1.5; font-weight: 600; }
.num {
  position: absolute;
  top: -24px;
  left: 26px;
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  font-family: var(--head);
  font-size: 34px;
  color: var(--ink);
  background: linear-gradient(180deg, #fff -30%, var(--tone));
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, .7), 0 6px 0 rgba(0, 0, 0, .3);
}
.c1 { --tone: var(--c1); }
.c2 { --tone: var(--c2); }
.c3 { --tone: var(--c3); }

.rules {
  margin-top: 36px;
  padding: 32px 36px;
  border-radius: 34px;
  text-align: left;
  background: var(--card);
  box-shadow: inset 0 4px 0 #fff, 0 12px 0 var(--btn-lip), 0 22px 26px rgba(0, 0, 0, .22);
}
.rules ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 16px; }
.rules li { padding-left: 34px; position: relative; font-size: 17px; line-height: 1.5; font-weight: 600; }
.rules li::before { content: "🏆"; position: absolute; left: 0; top: 0; }
.rules b { font-weight: 900; }

.board-sub { margin-top: 18px; font-weight: 800; }
.slot.bot { background: rgba(255, 255, 255, .86); border: 3px solid rgba(0, 0, 0, .18); }
.board { margin: 26px auto 0; padding: 0; list-style: none; display: grid; gap: 10px; max-width: 720px; }
.slot {
  display: grid;
  grid-template-columns: 48px 1fr auto 96px;
  align-items: center;
  gap: 12px;
  padding: 11px 18px 11px 11px;
  border-radius: 20px;
  text-align: left;
  background: rgba(255, 255, 255, .62);
  border: 3px dashed rgba(0, 0, 0, .28);
}
.slot.taken { background: linear-gradient(180deg, #fff9d0, var(--gold-1)); border: 3px solid var(--gold-lip); box-shadow: 0 5px 0 var(--gold-lip); }
.rank { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px; font-family: var(--head); font-size: 20px; color: #4a2a00; background: linear-gradient(180deg, var(--gold-1), var(--gold-2)); box-shadow: inset 0 2px 0 rgba(255, 255, 255, .6), 0 3px 0 var(--gold-lip); }
.who { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot:not(.taken) .who { font-family: var(--head); letter-spacing: .06em; color: var(--ink-soft); }
.time { font-family: var(--head); font-size: 20px; font-variant-numeric: tabular-nums; }
.count { font-size: 13px; font-weight: 700; text-align: right; }

.footer { width: min(820px, 100%); margin: 0 auto; padding: 64px 16px 36px; text-align: center; font-size: 14px; line-height: 1.55; font-weight: 700; }
.footer > p { margin-top: 20px; }
.market {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 22px;
  margin-bottom: 30px;
  padding: 18px;
  border-radius: 26px;
  background: var(--card);
  color: var(--ink);
  box-shadow: inset 0 3px 0 #fff, 0 8px 0 var(--btn-lip);
}
.market .note { width: 100%; margin-top: 2px; }
.footer-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; }
.soon { filter: saturate(.55); opacity: .85; cursor: not-allowed; }
.copy { opacity: .75; }
body[data-skin="sol"] .footer, body[data-skin="sol"] .board-sub { color: #fff; }

/* Modals */
.modal {
  width: min(560px, calc(100vw - 28px));
  max-height: calc(100dvh - 28px);
  padding: 30px 28px;
  border: 0;
  border-radius: 34px;
  text-align: center;
  color: var(--ink);
  background: var(--card);
  box-shadow: inset 0 4px 0 #fff, 0 12px 0 var(--btn-lip), 0 30px 50px rgba(0, 0, 0, .4);
  overflow-x: clip;
  overflow-y: auto;
}
.modal[open] { animation: pop .45s var(--spring); }
@keyframes pop { from { transform: scale(.7); opacity: 0; } }
.modal::backdrop { background: rgba(4, 16, 12, .6); }
.modal-share { width: min(760px, calc(100vw - 28px)); }
.badge {
  display: inline-block;
  margin-top: 16px;
  padding: 9px 18px;
  border-radius: 14px;
  font-family: var(--head);
  font-size: 19px;
  color: #4a2a00;
  background: linear-gradient(180deg, var(--gold-1), var(--gold-2));
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .7), 0 4px 0 var(--gold-lip);
}
.badge[hidden] { display: none; }
.solved-stats { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin-top: 20px; }
.note { margin-top: 12px; font-size: 14px; font-weight: 700; color: var(--ink-soft); }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; margin-top: 22px; padding-bottom: 10px; }
.modal-actions [hidden] { display: none; }
.share-preview { margin-top: 16px; }
.share-canvas { display: block; width: 100%; height: auto; border-radius: 16px; box-shadow: 0 6px 0 rgba(0, 0, 0, .2); }

.toast {
  position: fixed;
  left: 50%;
  top: 74px;
  z-index: 20;
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border-radius: 14px;
  background: #0c1320;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -12px);
  transition: opacity .2s, transform .3s var(--spring);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; margin: 0; padding: 0; border: 0; background: transparent; pointer-events: none; }

/* Tablet and phone */
@media (max-width: 860px) {
  .cards { grid-template-columns: 1fr; gap: 44px; }
  body:not([data-phase="name"]) .rivals { display: none; }
  .slot { grid-template-columns: 44px 1fr auto; }
  .count { display: none; }
}

@media (max-width: 640px), (max-height: 760px) {
  .hero { padding: 62px 12px 12px; }
  .topbar { padding: 10px 12px; gap: 6px; }
  .logo { gap: 4px; }
  .logo img { width: 30px; height: 30px; }
  .logo .fx { font-size: 19px; --stroke: 4px; }
  .top-right { gap: 8px; }
  .top-right .rb-icon { width: 36px; min-height: 36px; font-size: 15px; border-radius: 12px; }
  .top-right .rb-small { min-height: 36px; padding: 0 10px; font-size: 13px; border-radius: 12px; white-space: nowrap; }
  .fx-xl { font-size: clamp(38px, 11.5vw, 62px); }
  .title-block .fx { max-width: 340px; text-wrap: balance; }
  .tag { margin-top: 12px; font-size: 15px; }
  .live { gap: 6px; margin-bottom: 4px; }
  .live-pill { padding: 3px 9px; font-size: 11.5px; }
  .start-form { gap: 10px; }
  .name { height: 58px; padding: 0 14px; font-size: 17px; border-radius: 18px; }
  .rb-big { min-height: 58px; padding: 0 22px; font-size: 22px; border-radius: 18px; }
  .hud { gap: 2px; padding: 5px 8px; border-radius: 16px; width: 100%; justify-content: space-around; }
  .stat { min-width: 72px; }
  .stat small { font-size: 9.5px; }
  .stat b { font-size: 22px; }
  .stat-progress { min-width: 120px; }
  .bar { height: 5px; }
  .tools { gap: 8px; margin-top: 8px; }
  .rb-toggle { min-height: 32px; padding: 0 12px; font-size: 13px; }
  .play-only.rb-small { min-height: 36px; padding: 0 12px; font-size: 13px; }
  .modal { padding: 22px 16px; }
  .stat { min-width: 84px; }
}

@media (max-width: 640px) {
  /* The whole hero scrolls on the landing screen; only canvas drags are captured. */
  body[data-phase="name"] #gl { pointer-events: none; }

  body:not([data-phase="name"]) .hero { padding-bottom: 150px; }
  .pad {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 5;
    display: none;
    grid-template-columns: repeat(4, 1fr);
    gap: 9px 8px;
    margin: 0;
    padding: 8px 10px calc(12px + env(safe-area-inset-bottom));
    transition: translate .25s ease;
  }
  body:not([data-phase="name"]) .pad { display: grid; }
  body[data-phase="name"] .pad { display: none; }
  .hero-gone .pad { translate: 0 110%; }
  .rb-key, #pad-undo { width: 100%; min-height: 56px; font-size: 22px; border-radius: 16px; }
  #pad-undo { font-size: 17px; }
  .scramble-note { bottom: 158px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
}
