:root {
  --night: #140F3A;
  --night-2: #2A1A6B;
  --ink: #14112E;
  --cream: #FFF4E0;
  --orange: #FF6B35;
  --pink: #FF3D7F;
  --lime: #C6FF3D;
  --yellow: #FFD23F;
  --sky: #7FE7FF;
  --wa: #25D366;
  --tg: #2AABEE;

  --display: "Unbounded", system-ui, sans-serif;
  --text: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;

  /* Set from JS: height of the fixed header and footer */
  --top: 104px;
  --bottom: 64px;
}

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

html, body { height: 100%; }

body {
  overflow: hidden;
  background: var(--night);
  color: var(--cream);
  font: 500 16px/1.5 var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--lime); outline-offset: 3px; }

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

body.is-playing #game { cursor: none; }

/* ---------- Header: hazard tape + bar ---------- */

.top {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 5;
  padding-top: env(safe-area-inset-top);
}

.tape {
  position: relative;
  overflow: hidden;
  background: var(--yellow);
  color: var(--ink);
  border-block: 6px solid transparent;
  border-image: repeating-linear-gradient(-45deg, var(--ink) 0 10px, var(--yellow) 10px 20px) 6;
}

.tape__track {
  display: flex;
  width: max-content;
  animation: tape 40s linear infinite;
}

.tape__track span {
  padding: 6px 22px;
  font: 800 12px/1.2 var(--display);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.tape__track span::after { content: "●"; margin-left: 44px; font-size: 8px; vertical-align: 2px; }

@keyframes tape { to { transform: translateX(-50%); } }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
}

.logo {
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  font: 800 26px/1 var(--display);
  letter-spacing: -0.04em;
  color: var(--cream);
}

.logo__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--orange);
  box-shadow: 0 0 14px var(--orange);
}

.bar__right { display: flex; gap: 8px; }

.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: rgba(255, 244, 224, 0.08);
  border: 2px solid rgba(255, 244, 224, 0.16);
  font-size: 17px;
  transition: background 0.15s, transform 0.15s;
}

.icon-btn:hover { background: rgba(255, 244, 224, 0.16); }
.icon-btn:active { transform: scale(0.92); }

.hud {
  display: flex;
  gap: 6px;
  padding: 5px;
  border-radius: 18px;
  background: rgba(20, 17, 46, 0.6);
  border: 2px solid rgba(255, 244, 224, 0.14);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.hud__cell {
  min-width: 84px;
  padding: 4px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-radius: 12px;
}

.hud__key {
  font: 700 10px/1.3 var(--text);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255, 244, 224, 0.55);
}

.hud__val {
  font: 800 20px/1.2 var(--display);
  font-variant-numeric: tabular-nums;
}

.hud__cell--combo .hud__val { color: var(--lime); }

.hud__val.is-bump { animation: bump 0.3s ease-out; }
@keyframes bump { 40% { transform: scale(1.35); } }

.hud__lives { display: flex; gap: 4px; align-items: center; height: 24px; }

.hud__lives i {
  width: 16px;
  height: 16px;
  background: var(--pink);
  clip-path: path("M8 15 L1.6 8.6 A3.9 3.9 0 0 1 8 3.2 A3.9 3.9 0 0 1 14.4 8.6 Z");
  transition: background 0.2s, transform 0.2s;
}

.hud__lives i.is-lost { background: rgba(255, 244, 224, 0.18); transform: scale(0.8); }

/* Conversion meter: red zone below the stage threshold, green above */

.hud__meter {
  min-width: 200px;
  align-items: stretch;
  gap: 4px;
  transition: background 0.2s;
}

.meter__head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.meter__head b { font: 800 16px/1.2 var(--display); font-variant-numeric: tabular-nums; }

.meter {
  position: relative;
  display: block;
  height: 10px;
  border-radius: 99px;
  background: linear-gradient(90deg, #2BD96B, var(--lime));
}

.meter__red {
  position: absolute;
  inset: 0 auto 0 0;
  width: 20%;
  border-radius: 99px 0 0 99px;
  background: repeating-linear-gradient(-45deg, #FF3B5C 0 5px, #C8173F 5px 10px);
  box-shadow: 2px 0 0 var(--cream);
  transition: width 0.5s cubic-bezier(0.3, 1.4, 0.5, 1);
}

.meter__mark {
  position: absolute;
  top: -5px;
  bottom: -5px;
  left: 98%;
  width: 6px;
  margin-left: -3px;
  border-radius: 3px;
  background: #fff;
  box-shadow: 0 0 0 2px var(--ink);
  transition: left 0.25s ease-out;
}

.meter__thr { font: 700 10px/1.2 var(--text); color: rgba(255, 244, 224, 0.55); }
.meter__thr b { color: #FF8FA3; }

.hud__meter.is-danger { background: rgba(255, 59, 92, 0.28); animation: danger 0.5s ease-in-out infinite alternate; }
.hud__meter.is-danger .meter__head b { color: #FF8FA3; }
@keyframes danger { to { background: rgba(255, 59, 92, 0.08); } }

.side-meter { display: none; }

/* Stage timeline */

.timeline {
  display: flex;
  align-items: center;
  list-style: none;
  max-width: 860px;
  margin: 0 auto;
  padding: 0 24px 12px;
}

.tl__step { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.tl__step:last-child { flex: 0 0 auto; }

.tl__dot {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 244, 224, 0.06);
  border: 2px solid rgba(255, 244, 224, 0.22);
  font: 800 12px/1 var(--display);
  color: rgba(255, 244, 224, 0.45);
  transition: background 0.3s, border-color 0.3s, color 0.3s;
}

.tl__text { display: flex; flex-direction: column; line-height: 1.2; white-space: nowrap; }
.tl__text b { font: 800 12px/1.2 var(--display); color: rgba(255, 244, 224, 0.45); }
.tl__text small { font: 700 10px/1.3 var(--text); color: rgba(255, 244, 224, 0.35); }

.tl__bar {
  flex: 1;
  min-width: 12px;
  height: 4px;
  margin: 0 6px;
  border-radius: 99px;
  overflow: hidden;
  background: rgba(255, 244, 224, 0.12);
}

.tl__fill {
  display: block;
  width: var(--p, 0%);
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--orange), var(--yellow));
  transition: width 0.3s ease-out;
}

.tl__finish { flex: 0 0 auto; }
.tl__finish .tl__dot { font-size: 14px; filter: grayscale(1); opacity: 0.6; }
.tl__finish.is-done .tl__dot { filter: none; opacity: 1; background: var(--yellow); border-color: var(--yellow); }

.tl__step.is-done .tl__dot { background: var(--lime); border-color: var(--lime); color: var(--ink); }
.tl__step.is-done .tl__text b { color: var(--cream); }
.tl__step.is-done .tl__fill { --p: 100% !important; background: var(--lime); }

.tl__step.is-current .tl__dot {
  background: var(--orange);
  border-color: var(--cream);
  color: #fff;
  animation: ring 1.4s ease-out infinite;
}
.tl__step.is-current .tl__text b { color: var(--cream); }
.tl__step.is-current .tl__text small { color: var(--yellow); }

@keyframes ring {
  0% { box-shadow: 0 0 0 0 rgba(255, 107, 53, 0.7); }
  70%, 100% { box-shadow: 0 0 0 10px rgba(255, 107, 53, 0); }
}

/* ---------- Screens & cards ---------- */

.screen {
  position: fixed;
  inset: var(--top) 0 var(--bottom) 0;
  z-index: 4;
  display: flex;
  padding: 16px;
  overflow-y: auto;
  animation: fade-in 0.25s ease-out;
}

/* Still scrollable on tiny screens, just without a visible scrollbar over the game */
.screen { scrollbar-width: none; }
.screen::-webkit-scrollbar { display: none; }

@keyframes fade-in { from { opacity: 0; } }

.card {
  width: 100%;
  max-width: 720px;
  margin: auto; /* centers, yet stays scrollable when taller than the screen */
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 18px;
  padding: 34px;
  border-radius: 30px;
  background: var(--cream);
  color: var(--ink);
  border: 3px solid var(--ink);
  box-shadow: 10px 10px 0 var(--orange), 0 30px 80px rgba(0, 0, 0, 0.45);
  animation: pop-in 0.4s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.card--small { max-width: 420px; align-items: center; text-align: center; }

@keyframes pop-in { from { transform: translateY(24px) scale(0.94); opacity: 0; } }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 99px;
  background: var(--yellow);
  border: 2px solid var(--ink);
  font: 800 11px/1 var(--display);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  transform: rotate(-2deg);
}

.badge--lime { background: var(--lime); }
.badge--pink { background: var(--pink); color: var(--cream); }

.card__title {
  font: 800 clamp(26px, 4.6vw, 40px)/1.08 var(--display);
  letter-spacing: -0.03em;
}

.card__title em {
  font-style: normal;
  background: linear-gradient(transparent 58%, var(--lime) 58% 92%, transparent 92%);
  padding: 0 4px;
  margin: 0 -4px;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

.card__text { font-size: 17px; line-height: 1.55; color: #3B3654; }
.card__text b { color: var(--ink); }

.rules { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.rule {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border-radius: 20px;
  border: 2px solid var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

.rule--good { background: #E9FFC2; }
.rule--bad { background: #FFD9E3; }

.rule--meter { background: #FFF0C7; }

.mini-meter {
  flex-shrink: 0;
  position: relative;
  width: 84px;
  height: 14px;
  margin: 11px 0;
  border-radius: 99px;
  border: 2px solid var(--ink);
  background: linear-gradient(90deg, #FF3B5C 0 35%, #2BD96B 35%);
}

.mini-meter i {
  position: absolute;
  top: -6px;
  bottom: -6px;
  left: 62%;
  width: 5px;
  border-radius: 3px;
  background: var(--ink);
}

.rule__icons { display: flex; gap: 4px; }

.rule__icons span {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--ink);
  font-size: 18px;
}

.rule--bad .rule__icons span { background: var(--ink); border-style: dashed; border-color: var(--pink); }

.card__actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 4px;
}

.card__actions--wrap { flex-wrap: wrap; gap: 10px; }

.card__hint {
  display: flex;
  flex-direction: column;
  font-size: 13px;
  line-height: 1.4;
  color: #6B6585;
}

.hint--touch { display: none; }
@media (pointer: coarse) {
  .hint--fine { display: none; }
  .hint--touch { display: inline; }
}

.card__best { font-weight: 800; color: var(--ink); }

.btn {
  min-height: 54px;
  padding: 0 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 18px;
  border: 3px solid var(--ink);
  box-shadow: 0 6px 0 var(--ink);
  font: 800 16px/1 var(--display);
  color: var(--ink);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
}

.btn:hover { filter: brightness(1.06); transform: translateY(-1px); box-shadow: 0 7px 0 var(--ink); }
.btn:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--ink); }

.btn--play { background: var(--orange); color: #fff; font-size: 18px; padding: 0 32px; }
.btn--wa { background: var(--wa); color: #fff; }
.btn--ghost { background: #fff; }
.btn--tg { background: var(--tg); color: #fff; }

.score { display: flex; align-items: baseline; gap: 12px; }

.score__num {
  font: 800 clamp(56px, 11vw, 88px)/1 var(--display);
  letter-spacing: -0.04em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.score__unit { font: 800 14px/1 var(--display); text-transform: uppercase; color: var(--orange); }

.stats { width: 100%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stats--3 { grid-template-columns: repeat(3, 1fr); }
.stats .is-record { background: var(--yellow); }

.card--win { box-shadow: 10px 10px 0 var(--lime), 0 30px 80px rgba(0, 0, 0, 0.45); }

.stats div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border-radius: 16px;
  background: #fff;
  border: 2px solid var(--ink);
}

.stats span { font-size: 12px; color: #6B6585; }
.stats b { font: 800 22px/1.2 var(--display); }

/* ---------- Footer contacts ---------- */

.bottom {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(10, 7, 32, 0.85) 40%);
}

.bottom__label { font-size: 14px; color: rgba(255, 244, 224, 0.6); }

.contacts { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

.pill {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 16px;
  border-radius: 99px;
  background: rgba(255, 244, 224, 0.08);
  border: 2px solid rgba(255, 244, 224, 0.18);
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.pill:hover { background: rgba(255, 244, 224, 0.16); border-color: rgba(255, 244, 224, 0.4); transform: translateY(-2px); }
.pill--wa:hover { background: var(--wa); border-color: var(--wa); }
.pill--tg:hover { background: var(--tg); border-color: var(--tg); }

.pill__short { display: none; }

/* Footer stays out of the way while playing */
body.is-playing .bottom { opacity: 0.35; }
body.is-playing .bottom:hover { opacity: 1; }

/* ---------- Mobile ---------- */

@media (max-width: 760px) {
  .bar { padding: 10px 12px; gap: 8px; }
  .logo { font-size: 22px; }

  body.is-playing .logo { display: none; }

  .hud { flex: 1; flex-wrap: wrap; justify-content: space-between; gap: 2px; padding: 4px; border-radius: 14px; }
  .hud__cell { min-width: 0; flex: 1; padding: 3px 4px; }
  .hud__meter { display: none; }

  .side-meter {
    position: fixed;
    z-index: 5;
    left: 6px;
    top: calc(var(--top) + 6px);
    bottom: calc(var(--bottom) + 10px);
    width: 42px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 10px 0 8px;
    border-radius: 16px;
    background: rgba(20, 17, 46, 0.6);
    border: 2px solid rgba(255, 244, 224, 0.14);
    transition: background 0.2s;
  }

  .side-meter__val { font: 800 11px/1 var(--display); font-variant-numeric: tabular-nums; }

  .side-meter__bar {
    position: relative;
    flex: 1;
    width: 14px;
    border-radius: 99px;
    background: linear-gradient(0deg, #2BD96B, var(--lime));
  }

  .side-meter__red {
    position: absolute;
    inset: auto 0 0 0;
    height: 20%;
    border-radius: 0 0 99px 99px;
    background: repeating-linear-gradient(-45deg, #FF3B5C 0 5px, #C8173F 5px 10px);
    box-shadow: 0 -2px 0 var(--cream);
    transition: height 0.5s cubic-bezier(0.3, 1.4, 0.5, 1);
  }

  .side-meter__mark {
    position: absolute;
    left: -6px;
    right: -6px;
    bottom: 98%;
    height: 6px;
    margin-bottom: -3px;
    border-radius: 3px;
    background: #fff;
    box-shadow: 0 0 0 2px var(--ink);
    transition: bottom 0.25s ease-out;
  }

  .side-meter__thr {
    display: flex;
    flex-direction: column;
    align-items: center;
    font: 700 8px/1.2 var(--text);
    color: rgba(255, 244, 224, 0.55);
  }

  .side-meter__thr b { font: 800 10px/1.2 var(--display); color: #FF8FA3; }

  .side-meter.is-danger { background: rgba(255, 59, 92, 0.32); animation: danger 0.5s ease-in-out infinite alternate; }
  .side-meter.is-danger .side-meter__val { color: #FF8FA3; }

  /* Phones: the stage timeline becomes a vertical column on the right edge,
     mirroring the conversion meter on the left. Stages flow top → bottom, toward the funnel. */
  .timeline {
    position: fixed;
    z-index: 5;
    right: 6px;
    top: calc(var(--top) + 6px);
    bottom: calc(var(--bottom) + 10px);
    width: 42px;
    max-width: none;
    margin: 0;
    padding: 8px 0;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    border-radius: 16px;
    background: rgba(20, 17, 46, 0.6);
    border: 2px solid rgba(255, 244, 224, 0.14);
  }

  .tl__step {
    flex: 1;
    width: 100%;
    display: grid;
    grid-template-columns: auto auto;
    grid-template-rows: auto 1fr;
    justify-content: center;
    gap: 6px 4px;
  }

  .tl__dot { grid-column: 1 / -1; justify-self: center; width: 24px; height: 24px; font-size: 10px; }
  .tl__text { grid-column: 1; grid-row: 2; writing-mode: vertical-rl; align-self: start; }
  .tl__text b { font-size: 9px; letter-spacing: 0.04em; }
  .tl__text small { display: none; }

  .tl__bar { grid-column: 2; grid-row: 2; align-self: stretch; width: 8px; height: auto; min-width: 0; margin: 0; }
  .tl__fill {
    width: 100%;
    height: var(--p, 0%);
    background: linear-gradient(180deg, var(--orange), var(--yellow));
    transition: height 0.3s ease-out;
  }
  .tl__step.is-done .tl__fill { background: var(--lime); }
  .hud__key { font-size: 9px; letter-spacing: 0.06em; }
  .hud__val { font-size: 17px; }
  .hud__lives i { width: 13px; height: 13px; clip-path: path("M6.5 12.2 L1.3 7 A3.2 3.2 0 0 1 6.5 2.6 A3.2 3.2 0 0 1 11.7 7 Z"); }

  .icon-btn { width: 40px; height: 40px; border-radius: 12px; font-size: 15px; }

  .card { padding: 22px; gap: 14px; border-radius: 24px; box-shadow: 6px 6px 0 var(--orange), 0 20px 50px rgba(0, 0, 0, 0.45); }
  .card__text { font-size: 15px; }
  .rules { grid-template-columns: 1fr; gap: 8px; }
  .rule { padding: 12px; font-size: 13px; flex-direction: row; align-items: center; }
  .rule__icons span { width: 28px; height: 28px; font-size: 14px; }
  .rule__icons { flex-shrink: 0; }
  .rule__icons span:nth-child(n + 3) { display: none; }

  .card__actions { width: 100%; }
  .btn--play { flex-shrink: 0; }
  .card__actions--wrap .btn { flex: 1 1 0; min-width: 0; padding: 0 8px; font-size: 13px; }
  .card__actions--wrap .btn--play { flex-basis: 100%; }

  .mini-meter { width: 60px; margin: 0; }

  .stats { gap: 6px; grid-template-columns: 1fr 1fr; }
  .stats--3 { grid-template-columns: repeat(3, 1fr); }
  .card--win { box-shadow: 6px 6px 0 var(--lime), 0 20px 50px rgba(0, 0, 0, 0.45); }
  .tl__finish .tl__dot { font-size: 11px; }
  .stats div { padding: 10px; }
  .stats b { font-size: 18px; }
  .stats span { font-size: 11px; }

  .bottom { padding-top: 10px; }
  .bottom__label { display: none; }
  .contacts { gap: 6px; flex-wrap: nowrap; }
  .pill { min-height: 38px; padding: 0 12px; font-size: 13px; gap: 5px; }
  .pill__long { display: none; }
  .pill__short { display: inline; }
}

/* Short laptop screens: keep the play button above the fold */
@media (max-height: 780px) and (min-width: 761px) {
  .card { padding: 26px 30px; gap: 13px; }
  .card__title { font-size: clamp(26px, 3.4vw, 34px); }
  .card__text { font-size: 16px; }
  .rule { padding: 12px 14px; gap: 8px; font-size: 13px; }
  .rule__icons span { width: 30px; height: 30px; font-size: 15px; }
  .mini-meter { margin: 8px 0; }
  .btn { min-height: 50px; }
}

/* Short phones (iPhone SE etc.) */
@media (max-width: 760px) and (max-height: 740px) {
  .card { padding: 18px; gap: 10px; }
  .card__title { font-size: 22px; }
  #menu .card__text { display: none; }
  .score__num { font-size: 44px; }
  .card__text { font-size: 13px; line-height: 1.45; }
  .stats div { padding: 7px 10px; }
  .stats b { font-size: 16px; }
  .rule { padding: 8px 10px; font-size: 12px; line-height: 1.35; }
  .rule__icons span { width: 24px; height: 24px; font-size: 12px; }
  .btn { min-height: 46px; }
}

@media (max-width: 380px) {
  .card__actions--wrap .btn:not(.btn--play) { font-size: 11px; padding: 0 4px; border-width: 2px; }
  .pill > span[aria-hidden] { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .tape__track { animation: none; }
  .card, .screen { animation: none; }
  .tl__step.is-current .tl__dot, .hud__meter.is-danger, .side-meter.is-danger { animation: none; }
}
