:root {
  /* Maze world = greens. Everything around it = the complementary rose family. */
  --bg: #fbf2f1;          /* blush cream */
  --card: #fffdfc;
  --ink: #3d2630;         /* plum-brown text */
  --muted: #8a6b74;
  --rose: #e5798a;        /* primary accent */
  --accent: #b04a62;      /* deep rose */
  --berry: #7a2e48;       /* outlines, strong text */
  --blush: #f8dde2;
  --sage: #7da86a;        /* maze lawn */
  --moss: #376b40;        /* maze hedge */
  --red: #b3261e;
  --radius: 26px;
  --shadow: 0 8px 26px rgba(122, 46, 72, 0.10);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { min-height: 100vh; min-height: 100dvh; }
[hidden] { display: none !important; }

h1, h2, h3 { line-height: 1.15; }
h2 { font-size: 1.25rem; margin: 0 0 0.75rem; }
h3 { font-size: 0.95rem; margin: 0 0 0.4rem; }
.small { font-size: 0.9rem; }
.hint, .muted { color: var(--muted); }
.error { color: var(--red); font-weight: 600; margin: 0.4rem 0 0; }
kbd {
  font: inherit; font-size: 0.85em; padding: 0 0.35em; border-radius: 4px;
  border: 1px solid #efc9d1; background: #fff;
}

/* ---------- soap-bubble theme ---------- */
/* Shared look: translucent body, iridescent rim, glossy highlight, gentle wobble. */
@property --spin { syntax: "<angle>"; inherits: false; initial-value: 0deg; }
@keyframes bubble-spin { to { --spin: 360deg; } }
@keyframes bubble-wobble {
  0%, 100% { border-radius: 50% 50% 50% 50% / 50% 50% 50% 50%; }
  25% { border-radius: 53% 47% 51% 49% / 48% 52% 49% 51%; }
  50% { border-radius: 48% 52% 47% 53% / 52% 48% 53% 47%; }
  75% { border-radius: 51% 49% 53% 47% / 49% 51% 47% 53%; }
}
@keyframes bubble-pop {
  0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.85); }
  100% { box-shadow: 0 0 0 18px rgba(255, 255, 255, 0); }
}

.bubble, .btn, .icon-btn, .pill, .dpad .arm {
  position: relative; isolation: isolate;
  background:
    radial-gradient(120% 120% at 30% 22%, rgba(255,255,255,0.95) 0 7%, rgba(255,255,255,0.35) 13%, rgba(255,255,255,0) 32%),
    radial-gradient(130% 130% at 50% 50%, rgba(255,255,255,0.14) 45%, rgba(255, 214, 224, 0.4) 75%, rgba(229, 121, 138, 0.45) 100%);
  box-shadow:
    inset 0 0 0 1.5px rgba(255,255,255,0.7),
    inset -6px -8px 16px rgba(176, 74, 98, 0.22),
    inset 6px 6px 14px rgba(255, 200, 215, 0.35),
    0 6px 14px rgba(122, 46, 72, 0.16);
  -webkit-backdrop-filter: blur(3px) saturate(1.4);
  backdrop-filter: blur(3px) saturate(1.4);
  border: 0;
}
/* iridescent rim */
.bubble::before, .btn::before, .icon-btn::before, .pill::before, .dpad .arm::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; z-index: -1; pointer-events: none;
  padding: 3px;
  background: conic-gradient(from var(--spin), #f7a1b3, #ffd9a8, #c9e6b0, #a9d8e8, #d6b4f0, #f7a1b3);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  opacity: 0.75;
  animation: bubble-spin 7s linear infinite;
}
/* small secondary glint */
.bubble::after, .icon-btn::after, .dpad .arm::after {
  content: ""; position: absolute; right: 18%; bottom: 16%; width: 14%; height: 9%;
  border-radius: 50%; background: rgba(255,255,255,0.7); transform: rotate(-35deg); pointer-events: none;
}

.btn {
  font: inherit; font-weight: 800; cursor: pointer; letter-spacing: 0.01em;
  padding: 0.75rem 1.5rem; border-radius: 999px; min-height: 48px;
  color: var(--berry);
  transition: transform 120ms cubic-bezier(.3,1.6,.5,1), filter 120ms;
}
.btn.primary {
  color: #fff;
  text-shadow: 0 1px 2px rgba(122, 46, 72, 0.6);
  background:
    radial-gradient(120% 120% at 30% 22%, rgba(255,255,255,0.9) 0 7%, rgba(255,255,255,0.3) 13%, rgba(255,255,255,0) 32%),
    radial-gradient(130% 130% at 50% 50%, rgba(236, 132, 150, 0.85) 40%, rgba(214, 98, 122, 0.9) 75%, rgba(176, 74, 98, 0.95) 100%);
}
.btn:hover, .icon-btn:hover { filter: brightness(1.05) saturate(1.15); transform: scale(1.04); }
.btn:active, .icon-btn:active { transform: scale(0.92, 0.88); animation: bubble-pop 380ms ease-out; }
.btn:focus-visible, .icon-btn:focus-visible, input:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 3px;
}
.buttons { display: flex; gap: 0.7rem; flex-wrap: wrap; margin-top: 1rem; }

/* ---------- cover ---------- */
.screen.cover { padding: 1.25rem 1rem 1.5rem; }
.cover-inner { max-width: 1040px; margin: 0 auto; }
.cover-inner.narrow { max-width: 560px; padding-top: 2rem; }
.hero { display: flex; align-items: center; gap: 1rem; margin: 0.5rem 0 1.25rem; }
.hero h1 {
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, sans-serif;
  font-size: clamp(2.1rem, 6.5vw, 3.6rem); font-weight: 900; margin: 0; letter-spacing: 0.01em;
  color: #ee8a9a;
  -webkit-text-stroke: 2px var(--berry);
  text-shadow: 0 4px 0 var(--berry), 0 8px 18px rgba(122, 46, 72, 0.25);
}
.tagline { margin: 0.25rem 0 0; font-size: 1.1rem; }
.cover-amber { width: 150px; height: 150px; flex: none; }
@media (max-width: 520px) { .cover-amber { width: 110px; height: 110px; } }

.cover-grid {
  display: grid; gap: 1rem;
  grid-template-columns: 1fr 1fr;
  grid-template-areas: "start board" "how board";
}
.start-card { grid-area: start; }
.board-card { grid-area: board; }
.how-card { grid-area: how; }
@media (max-width: 760px) {
  .cover-grid { grid-template-columns: 1fr; grid-template-areas: "start" "board" "how"; }
}

.card {
  background: var(--card); border-radius: var(--radius);
  padding: 1.25rem; box-shadow: var(--shadow);
}
label { display: block; font-weight: 600; margin-bottom: 0.35rem; }
input#username {
  width: 100%; font: inherit; font-size: 1.15rem; padding: 0.7rem 1.1rem;
  border: 2px solid #efc9d1; border-radius: 999px; background: #fffafa;
  box-shadow: inset 0 2px 6px rgba(122, 46, 72, 0.08);
}

.leaderboard { list-style: none; margin: 0; padding: 0; counter-reset: rank; }
.leaderboard li {
  display: grid; grid-template-columns: 2.2rem 1fr auto; align-items: center;
  padding: 0.5rem 0.4rem; border-bottom: 1px solid #f5e1e4;
  font-variant-numeric: tabular-nums;
}
.leaderboard li:last-child { border-bottom: 0; }
.leaderboard li .rank-n { font-weight: 700; color: var(--muted); }
.leaderboard li:nth-child(1) .rank-n { color: #c9a227; }
.leaderboard li:nth-child(2) .rank-n { color: #9aa1a8; }
.leaderboard li:nth-child(3) .rank-n { color: #b0703a; }
.leaderboard li .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.leaderboard li.empty, .leaderboard li.muted { display: block; color: var(--muted); }
.leaderboard li.me { background: var(--blush); border-radius: 8px; }

.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin-top: 0.75rem; }
.legend ul { list-style: none; padding: 0; margin: 0; font-size: 0.9rem; }
.legend li { margin: 0.3rem 0; }
.legend .emo { font-size: 1.2rem; margin-right: 0.3rem; }

/* ---------- game ---------- */
.screen.game {
  position: fixed; inset: 0; background: var(--sage); overflow: hidden;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 0.5rem;
  padding: calc(0.5rem + env(safe-area-inset-top)) 0.6rem 0.5rem; pointer-events: none;
}
.hud-left, .hud-right { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.hud-right { pointer-events: auto; }
.pill {
  border-radius: 999px; padding: 0.4rem 0.9rem;
  font-variant-numeric: tabular-nums; white-space: nowrap; color: #2c1d0e;
  text-shadow: 0 1px 0 rgba(255,255,255,0.8);
  background-color: rgba(255, 255, 255, 0.35);
}
.pill .short { display: none; }
.pill .label { color: var(--accent); font-size: 0.8rem; }
.icon-btn {
  width: 50px; height: 50px; border-radius: 50%; cursor: pointer; font-size: 1.2rem;
  animation: bubble-wobble 4.5s ease-in-out infinite;
  transition: transform 120ms cubic-bezier(.3,1.6,.5,1);
}
.hud-right .icon-btn:nth-child(2) { animation-delay: -2s; }
.hud-right .icon-btn:nth-child(3) { animation-delay: -3.2s; }
.icon-btn.off { opacity: 0.55; filter: grayscale(0.7); }
.hud-effects { display: flex; gap: 0.35rem; flex-wrap: wrap; justify-content: center; }
.effect {
  display: inline-flex; align-items: center; gap: 0.3rem;
  background: rgba(255, 235, 235, 0.92); border-radius: 999px; padding: 0.3rem 0.75rem;
  font-size: 0.85rem; font-weight: 700; box-shadow: 0 4px 12px rgba(0,0,0,0.15), inset 0 0 0 2px rgba(220, 70, 70, 0.6);
}
.effect.good { background: rgba(235, 255, 230, 0.92); box-shadow: 0 4px 12px rgba(0,0,0,0.15), inset 0 0 0 2px rgba(60, 170, 80, 0.6); }
.effect .secs { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 500; }
@media (max-width: 520px) { .hide-narrow { display: none; } .effect .name { display: none; } }

/* ---------- D-pad (touch devices): four soap bubbles ---------- */
.dpad-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: calc(236px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: none; align-items: center; justify-content: center;
  background:
    radial-gradient(60% 90% at 50% 0%, rgba(255,255,255,0.7), rgba(255,255,255,0) 70%),
    linear-gradient(#fdecef, #f6d2da 55%, #efc0cb);
  border-radius: 34px 34px 0 0;
  box-shadow: 0 -8px 22px rgba(122, 46, 72, 0.2), inset 0 3px 0 rgba(255,255,255,0.75);
  overflow: hidden;
}
/* a few drifting decorative bubbles in the panel */
.dpad-panel::before, .dpad-panel::after {
  content: ""; position: absolute; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle at 30% 25%, rgba(255,255,255,0.9) 0 10%, rgba(255,255,255,0.15) 35%, rgba(229,121,138,0.3) 100%);
  box-shadow: inset 0 0 0 1.5px rgba(255,255,255,0.7);
}
.dpad-panel::before { width: 46px; height: 46px; left: 9%; top: 26%; animation: drift 7s ease-in-out infinite; }
.dpad-panel::after { width: 28px; height: 28px; right: 10%; top: 58%; animation: drift 9s ease-in-out -3s infinite; }
@keyframes drift { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(6px, -14px); } }
@media (pointer: coarse) { .dpad-panel { display: flex; } }
body.touch .dpad-panel { display: flex; }

.dpad { position: relative; width: 216px; height: 216px; touch-action: none; }
.dpad .hub { display: none; }
.dpad .arm {
  position: absolute; width: 82px; height: 82px; border-radius: 50%;
  animation: bubble-wobble 4s ease-in-out infinite;
  transition: transform 90ms cubic-bezier(.3,1.6,.5,1), filter 90ms;
}
.dpad .up    { left: 67px; top: 0; }
.dpad .down  { left: 67px; top: 134px; animation-delay: -1s; }
.dpad .left  { left: 0;    top: 67px; animation-delay: -2s; }
.dpad .right { left: 134px; top: 67px; animation-delay: -3s; }
.dpad .arrow {
  position: absolute; left: 50%; top: 50%; width: 0; height: 0;
  border: 13px solid transparent; filter: drop-shadow(0 2px 2px rgba(122, 46, 72, 0.35));
}
.dpad .up .arrow    { border-bottom: 18px solid var(--accent); border-top-width: 0; transform: translate(-50%, -60%); }
.dpad .down .arrow  { border-top: 18px solid var(--accent); border-bottom-width: 0; transform: translate(-50%, -40%); }
.dpad .left .arrow  { border-right: 18px solid var(--accent); border-left-width: 0; transform: translate(-60%, -50%); }
.dpad .right .arrow { border-left: 18px solid var(--accent); border-right-width: 0; transform: translate(-40%, -50%); }
.dpad .arm.active {
  transform: scale(0.88, 0.84);
  filter: brightness(1.12) saturate(1.5);
  animation: bubble-pop 360ms ease-out;
}
.dpad .up.active .arrow    { border-bottom-color: var(--moss); }
.dpad .down.active .arrow  { border-top-color: var(--moss); }
.dpad .left.active .arrow  { border-right-color: var(--moss); }
.dpad .right.active .arrow { border-left-color: var(--moss); }

.overlay {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(40, 25, 10, 0.45); padding: 1rem;
}
.overlay.clear { background: transparent; pointer-events: none; }
.dialog { border-radius: 32px; text-align: center; min-width: min(320px, 90vw); display: grid; gap: 0.5rem; justify-items: center; }
.dialog h2 { margin: 0; }
.big-time { font-size: 2.4rem; font-weight: 800; margin: 0.25rem 0; font-variant-numeric: tabular-nums; color: var(--accent); }
.countdown-box { text-align: center; }
.countdown-box .small {
  background: rgba(255,250,250,0.94); color: var(--berry); padding: 0.3rem 0.9rem; border-radius: 999px; display: inline-block; font-weight: 700;
}
.countdown-num {
  font-size: 4.6rem; font-weight: 900; margin: 0.4rem auto 0; color: #fff;
  width: 170px; height: 170px; display: grid; place-items: center;
  text-shadow: 0 3px 0 var(--accent), 0 6px 18px rgba(122,46,72,0.35);
}

/* ---------- summary ---------- */
.rank { font-weight: 700; font-size: 1.1rem; }
.splits { width: 100%; border-collapse: collapse; margin: 0.75rem 0; font-variant-numeric: tabular-nums; }
.splits th, .splits td { text-align: left; padding: 0.35rem 0.4rem; border-bottom: 1px solid #f5e1e4; }
.splits td.pb { color: #1f7a2e; font-weight: 700; }
.fact { background: var(--blush); border-radius: 10px; padding: 0.6rem 0.8rem; }

.credits {
  text-align: center; font-size: 0.85rem; color: var(--muted);
  padding: 0 1rem calc(1rem + env(safe-area-inset-bottom));
}
body.playing .credits {
  position: fixed; left: 0.6rem; bottom: calc(0.5rem + env(safe-area-inset-bottom)); z-index: 2; padding: 0.25rem 0.7rem;
  background: rgba(255,255,255,0.85); border-radius: 999px; font-size: 0.75rem; color: var(--ink);
  pointer-events: none;
}
.noscript { text-align: center; padding: 2rem; }

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

/* ---------- about / FAQ ---------- */
.about-card { margin-top: 1rem; }
.promises { list-style: none; padding: 0; margin: 0.75rem 0 1rem; display: grid; gap: 0.45rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.promises li { background: #fff4f6; border-radius: 999px; padding: 0.5rem 0.9rem; box-shadow: inset 0 0 0 1.5px #f6d3da; }
details { border-radius: 18px; background: #fffafa; padding: 0.6rem 1rem; margin: 0.45rem 0; box-shadow: inset 0 0 0 1.5px #f3dde1; }
details summary { cursor: pointer; font-weight: 700; }
details p { margin: 0.5rem 0 0.2rem; }
a { color: var(--accent); }
body.playing .footer-links { display: none; }

/* ---------- privacy page ---------- */
.prose h1 { color: var(--accent); margin: 0.25rem 0; }
.prose h2 { margin-top: 1.4rem; }
.prose ul { padding-left: 1.2rem; }
.prose li { margin: 0.3rem 0; }

/* ---------- resume card ---------- */
.resume-card { margin-bottom: 1rem; display: grid; gap: 0.25rem 1rem; grid-template-columns: 1fr auto; align-items: center; }
.resume-card h2 { margin: 0 0 0.25rem; }
.resume-card .buttons { margin-top: 0; }
.resume-card .hint { grid-column: 1 / -1; margin: 0.25rem 0 0; }
@media (max-width: 620px) { .resume-card { grid-template-columns: 1fr; } }

@media (max-width: 520px) {
  .hud { gap: 0.3rem; padding-left: 0.4rem; padding-right: 0.4rem; }
  .hud-left, .hud-right { flex-wrap: nowrap; gap: 0.25rem; }
  .icon-btn { width: 40px; height: 40px; font-size: 0.95rem; }
  .pill { padding: 0.3rem 0.6rem; font-size: 0.9rem; }
  .pill .label { display: none; }
  .pill .short { display: inline; color: var(--accent); font-size: 0.78rem; margin-right: 0.15rem; }
  .hud-effects { position: absolute; top: calc(3.4rem + env(safe-area-inset-top)); left: 0; right: 0; }
}

/* ---------- fit the controls around the maze on every screen ---------- */
/* short portrait phones: smaller pad, more room for the maze */
@media (pointer: coarse) and (orientation: portrait) and (max-height: 760px) {
  .dpad-panel { height: calc(196px + env(safe-area-inset-bottom)); }
  .dpad { transform: scale(0.82); }
}
/* phones and tablets held sideways: pad on the right, maze gets the full height */
@media (pointer: coarse) and (orientation: landscape) {
  .dpad-panel {
    top: 0; bottom: 0; left: auto; right: 0;
    width: calc(236px + env(safe-area-inset-right)); height: auto;
    padding: 0 env(safe-area-inset-right) 0 0;
    border-radius: 34px 0 0 34px;
    box-shadow: -8px 0 22px rgba(122, 46, 72, 0.2), inset 3px 0 0 rgba(255,255,255,0.75);
  }
  .hud { right: calc(236px + env(safe-area-inset-right)); }
}
@media (pointer: coarse) and (orientation: landscape) and (max-height: 420px) {
  .dpad-panel { width: calc(200px + env(safe-area-inset-right)); }
  .dpad { transform: scale(0.8); }
  .hud { right: calc(200px + env(safe-area-inset-right)); }
}

/* ---------- concept credit placement ---------- */
/* pop-ups always sit above the credit line */
.overlay { z-index: 10; }
body.playing .credits { z-index: 1; }

/* phones & tablets: credit at the very base of the screen, inside the pad panel, below the bubbles */
@media (pointer: coarse) {
  body.playing .credits, body.touch.playing .credits {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 3;
    padding: 0.2rem 1rem calc(0.35rem + env(safe-area-inset-bottom));
    background: none; border-radius: 0; text-align: center;
    font-size: 0.72rem; color: var(--berry); opacity: 0.85;
  }
  .dpad-panel { padding-bottom: calc(1.3rem + env(safe-area-inset-bottom)); height: calc(252px + env(safe-area-inset-bottom)); }
}
@media (pointer: coarse) and (orientation: portrait) and (max-height: 760px) {
  .dpad-panel { height: calc(214px + env(safe-area-inset-bottom)); }
}
/* sideways: credit at the base of the side panel */
@media (pointer: coarse) and (orientation: landscape) {
  .dpad-panel { height: auto; }
  body.playing .credits, body.touch.playing .credits {
    left: auto; right: 0; width: calc(236px + env(safe-area-inset-right)); padding-left: 0.4rem; padding-right: 0.4rem;
  }
}
@media (pointer: coarse) and (orientation: landscape) and (max-height: 420px) {
  body.playing .credits, body.touch.playing .credits { width: calc(200px + env(safe-area-inset-right)); }
}
