:root {
  color-scheme: light;
  --red: #ef2838;
  --red-dark: #a50d19;
  --navy: #06395f;
  --navy-deep: #021d3d;
  --sky: #079ce5;
  --yellow: #ffd234;
  --glass: rgba(3, 53, 88, 0.86);
  --app-safe-top: max(env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 0px));
  --app-safe-right: max(env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px), var(--tg-content-safe-area-inset-right, 0px));
  --app-safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px), var(--tg-content-safe-area-inset-bottom, 0px));
  --app-safe-left: max(env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px), var(--tg-content-safe-area-inset-left, 0px));
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--sky);
  font-family: Arial, Helvetica, sans-serif;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

#app {
  position: fixed;
  inset: 0;
  min-width: 280px;
  overflow: hidden;
  isolation: isolate;
}

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

.hidden {
  visibility: hidden;
  opacity: 0;
}

.hud {
  position: fixed;
  z-index: 5;
  top: calc(var(--app-safe-top) + 14px);
  left: calc(var(--app-safe-left) + 14px);
  width: clamp(124px, 12vw, 162px);
  display: grid;
  gap: 9px;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.brand,
.start-logo {
  transform: rotate(-2deg);
}

.brand img,
.start-logo img {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 6px 10px rgba(0, 30, 60, 0.3));
}

.brand {
  width: clamp(96px, 10vw, 138px);
}

.stat {
  min-height: 70px;
  padding: 10px 13px;
  overflow: hidden;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  background: linear-gradient(145deg, rgba(8, 78, 122, 0.94), var(--glass));
  box-shadow: 0 9px 24px rgba(0, 38, 68, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(10px);
}

.stat small {
  display: block;
  margin-bottom: 2px;
  color: #a9e4ff;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.stat strong {
  display: block;
  overflow: hidden;
  font-size: 29px;
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
  text-overflow: ellipsis;
}

.stat.compact {
  min-height: 62px;
}

.stat.compact strong {
  font-size: 23px;
}

.lives {
  display: flex;
  gap: 5px;
  margin-top: 7px;
}

.lives i {
  position: relative;
  width: 20px;
  height: 18px;
  transform: rotate(-45deg);
  border-radius: 3px 0 5px 3px;
  background: linear-gradient(145deg, #ff5561, #d90f20);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.22);
}

.lives i::before,
.lives i::after {
  position: absolute;
  width: 20px;
  height: 18px;
  content: "";
  border-radius: 50%;
  background: inherit;
}

.lives i::before {
  top: -9px;
  left: 0;
}

.lives i::after {
  top: 0;
  left: 9px;
}

.lives i.lost {
  opacity: 0.3;
  filter: saturate(0.2);
}

.trophy {
  color: var(--yellow);
  text-shadow: 0 2px 7px rgba(255, 205, 28, 0.35);
}

.actions {
  position: fixed;
  z-index: 8;
  top: calc(var(--app-safe-top) + 14px);
  right: calc(var(--app-safe-right) + 14px);
  display: flex;
  gap: 8px;
  transition: opacity 180ms ease;
}

.round-button {
  position: relative;
  width: 48px;
  height: 48px;
  padding: 0;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  background: linear-gradient(160deg, rgba(12, 79, 121, 0.96), rgba(2, 36, 67, 0.96));
  box-shadow: 0 7px 18px rgba(0, 34, 60, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.16);
  font-size: 21px;
  font-weight: 1000;
  cursor: pointer;
}

.round-button:active {
  transform: translateY(2px) scale(0.96);
}

.round-button.muted {
  opacity: 0.55;
}

.round-button.muted::after {
  position: absolute;
  width: 24px;
  height: 3px;
  content: "";
  transform: translate(-18px, 10px) rotate(-45deg);
  border-radius: 3px;
  background: #ff5a63;
}

.combo {
  position: fixed;
  z-index: 7;
  top: calc(var(--app-safe-top) + 20px);
  left: 50%;
  color: var(--yellow);
  font-size: clamp(24px, 4vw, 42px);
  font-weight: 1000;
  text-shadow: 0 3px 0 #9f4f00, 0 5px 15px rgba(0, 41, 74, 0.3);
  transform: translate(-50%, -130%) scale(0.8);
  opacity: 0;
  pointer-events: none;
  transition: transform 180ms cubic-bezier(0.2, 1.4, 0.4, 1), opacity 120ms ease;
}

.combo.visible {
  transform: translate(-50%, 0) scale(1);
  opacity: 1;
}

.combo.pop {
  transform: translate(-50%, 0) scale(1.2);
}

.effects {
  position: fixed;
  z-index: 7;
  right: calc(var(--app-safe-right) + 14px);
  bottom: calc(var(--app-safe-bottom) + 14px);
  display: grid;
  justify-items: end;
  gap: 8px;
  pointer-events: none;
}

.effect {
  min-width: 146px;
  padding: 10px 13px;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 14px;
  box-shadow: 0 7px 18px rgba(0, 31, 55, 0.2);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.02em;
  text-align: right;
  backdrop-filter: blur(8px);
}

.effect b {
  display: inline-block;
  min-width: 26px;
  font-size: 18px;
}

.magnet-effect {
  background: linear-gradient(135deg, rgba(234, 35, 50, 0.92), rgba(119, 13, 26, 0.9));
}

.ice-effect {
  background: linear-gradient(135deg, rgba(66, 186, 241, 0.93), rgba(21, 95, 165, 0.9));
}

.overlay {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--app-safe-top) + 18px) calc(var(--app-safe-right) + 18px) calc(var(--app-safe-bottom) + 18px) calc(var(--app-safe-left) + 18px);
  visibility: hidden;
  opacity: 0;
  background: rgba(0, 35, 67, 0.35);
  backdrop-filter: blur(7px);
  transition: opacity 180ms ease, visibility 180ms ease;
}

.overlay.visible {
  visibility: visible;
  opacity: 1;
}

.card {
  width: min(92vw, 480px);
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - var(--app-safe-top) - var(--app-safe-bottom) - 36px);
  padding: clamp(22px, 4vh, 34px);
  overflow: auto;
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 28px;
  background: linear-gradient(165deg, rgba(8, 72, 116, 0.98), rgba(2, 27, 59, 0.98));
  box-shadow: 0 28px 90px rgba(0, 25, 48, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  text-align: center;
}

.start-logo {
  display: block;
  width: clamp(150px, 26vw, 185px);
  margin: 2px auto 18px;
}

.card h1,
.card h2,
.card h3,
.card p {
  margin-top: 0;
}

.card h1 {
  margin-bottom: 8px;
  font-size: clamp(24px, 6vw, 32px);
}

.lead {
  margin-bottom: 18px;
  color: #d8f2ff;
  font-size: 16px;
  line-height: 1.35;
}

.rules {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 16px 0 20px;
  text-align: left;
}

.rules > div {
  display: grid;
  grid-template-columns: 38px 1fr;
  align-items: center;
  min-height: 50px;
  padding: 7px 9px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.07);
  font-size: 12px;
  line-height: 1.2;
}

.rule-icon {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 25px;
  color: #fff;
  font-weight: 1000;
}

.zap-icon {
  border: 3px solid #bd671c;
  border-radius: 7px;
  background: radial-gradient(circle at 23% 46%, #b42525 0 12%, transparent 13%), radial-gradient(circle at 68% 62%, #b42525 0 13%, transparent 14%), #f5bb45;
  transform: rotate(-5deg);
}

.gold-icon {
  color: #fff5a4;
  font-size: 28px;
  text-shadow: 0 0 10px #ffd400;
}

.magnet-icon {
  color: #fff;
  border: 7px solid #ef2e39;
  border-top: 0;
  border-radius: 0 0 15px 15px;
  background: transparent;
  font-size: 0;
}

.magnet-icon::before,
.magnet-icon::after {
  position: absolute;
  width: 7px;
  height: 7px;
  content: "";
  transform: translateY(-10px);
  background: #dff1f7;
}

.magnet-icon::before {
  margin-left: -23px;
}

.magnet-icon::after {
  margin-left: 23px;
}

.ice-icon {
  color: #dffaff;
  border: 2px solid #c9f4ff;
  border-radius: 7px;
  background: linear-gradient(145deg, #c8f5ff, #3dace8);
  box-shadow: 0 0 11px rgba(141, 228, 255, 0.8);
  transform: rotate(45deg) scale(0.76);
}

.primary {
  width: 100%;
  min-height: 58px;
  padding: 14px 20px;
  color: #fff;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(#ff4550, #e11525);
  box-shadow: 0 6px 0 var(--red-dark), 0 13px 24px rgba(0, 0, 0, 0.22);
  font-size: 21px;
  font-weight: 1000;
  letter-spacing: 0.02em;
  cursor: pointer;
}

.primary:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--red-dark), 0 7px 16px rgba(0, 0, 0, 0.2);
}

.primary:disabled {
  cursor: progress;
  filter: saturate(0.45);
  opacity: 0.7;
}

.card .controls-hint {
  display: flex;
  justify-content: center;
  gap: 7px;
  margin: 26px 0 0;
  color: #bfe9ff;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.controls-hint span {
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.pause-overlay {
  z-index: 18;
  background: rgba(0, 29, 57, 0.48);
}

.ios-fullscreen-help {
  z-index: 30;
  background: rgba(0, 29, 57, 0.58);
}

.ios-help-card {
  width: min(92vw, 410px);
}

.ios-help-card h2 {
  margin-bottom: 10px;
  font-size: clamp(25px, 7vw, 34px);
  line-height: 1.02;
}

.ios-help-lead,
.ios-help-note {
  color: #d8f2ff;
  line-height: 1.35;
}

.ios-help-lead {
  margin-bottom: 16px;
}

.ios-help-steps {
  display: grid;
  gap: 8px;
  margin: 0 0 15px;
  padding: 0;
  list-style: none;
  text-align: left;
}

.ios-help-steps li {
  display: grid;
  grid-template-columns: 36px 1fr;
  align-items: center;
  min-height: 54px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.07);
  line-height: 1.25;
}

.ios-help-steps li > b {
  display: grid;
  place-items: center;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 3px 8px rgba(121, 0, 13, 0.32);
}

.ios-help-steps i {
  color: #9ee3ff;
  font-size: 20px;
  font-style: normal;
  font-weight: 1000;
}

.ios-help-note {
  margin-bottom: 19px;
  font-size: 13px;
}

.standalone #fullscreenBtn {
  display: none;
}

.pause-card {
  width: min(88vw, 340px);
}

.pause-card h2 {
  margin-bottom: 25px;
  font-size: 46px;
}

.eyebrow {
  margin-bottom: 5px;
  color: #9ee3ff;
  font-weight: 900;
  letter-spacing: 0.18em;
}

.result-card h2 {
  margin-bottom: 8px;
  font-size: clamp(23px, 6vw, 31px);
}

.score-caption {
  margin-bottom: 0;
  color: var(--yellow);
  font-size: 20px;
  font-weight: 1000;
}

.final-score {
  color: #fff;
  font-size: clamp(64px, 18vw, 90px);
  font-weight: 1000;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}

.best-line {
  margin: 7px 0 16px !important;
  color: var(--yellow);
  font-size: 19px;
  font-weight: 900;
}

.leaderboard {
  margin-bottom: 13px;
  padding: 13px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  background: rgba(0, 20, 43, 0.48);
}

.leaderboard h3 {
  margin-bottom: 8px;
  font-size: 15px;
}

.record-row {
  display: grid;
  grid-template-columns: 38px 1fr 1fr;
  align-items: center;
  min-height: 34px;
  padding: 6px 9px;
  border-radius: 9px;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.record-row.current {
  background: var(--red);
  font-weight: 1000;
  box-shadow: 0 4px 10px rgba(130, 2, 16, 0.28);
}

.record-head {
  min-height: 27px;
  color: #8bdcff;
  font-size: 11px;
  font-weight: 900;
}

.result-message {
  margin-bottom: 13px;
  color: #d7f2ff;
  font-size: 14px;
}

noscript {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 30px;
  color: #fff;
  background: #073c66;
  text-align: center;
}

@media (orientation: portrait) {
  .hud {
    width: 112px;
    gap: 6px;
  }

  .brand {
    width: 102px;
  }

  .stat {
    min-height: 60px;
    padding: 8px 10px;
    border-radius: 13px;
  }

  .stat small {
    font-size: 10px;
  }

  .stat strong {
    font-size: 24px;
  }

  .stat.compact {
    min-height: 51px;
  }

  .stat.compact strong {
    font-size: 18px;
  }

  .lives {
    gap: 4px;
    margin-top: 5px;
  }

  .lives i,
  .lives i::before,
  .lives i::after {
    width: 16px;
    height: 14px;
  }

  .lives i::before {
    top: -7px;
  }

  .lives i::after {
    left: 7px;
  }

  .actions {
    gap: 6px;
  }

  .round-button {
    width: 43px;
    height: 43px;
    font-size: 19px;
  }

  .effects {
    right: calc(var(--app-safe-right) + 10px);
    bottom: calc(var(--app-safe-bottom) + 10px);
  }

  .effect {
    min-width: 128px;
    padding: 8px 10px;
    font-size: 11px;
  }
}

@media (max-width: 520px) {
  .card {
    width: min(94vw, 440px);
    padding: 21px;
    border-radius: 23px;
  }

  .rules {
    grid-template-columns: 1fr;
  }

  .rules > div {
    min-height: 42px;
  }
}

@media (max-height: 650px) {
  .start-logo {
    width: 150px;
    margin-bottom: 12px;
  }

  .card h1 {
    font-size: 22px;
  }

  .lead {
    margin-bottom: 10px;
  }

  .rules {
    margin: 10px 0 14px;
  }

  .rules > div {
    min-height: 42px;
  }

  .primary {
    min-height: 50px;
  }

  .controls-hint {
    display: none;
  }

  .result-card {
    padding-block: 16px;
  }

  .final-score {
    font-size: 55px;
  }

  .leaderboard {
    padding: 8px 12px;
  }

  .record-row {
    min-height: 28px;
    padding-block: 4px;
    font-size: 14px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .start-card {
    width: min(94vw, 760px);
    display: grid;
    grid-template-columns: 0.78fr 1.22fr;
    column-gap: 22px;
    align-items: center;
  }

  .start-logo,
  .start-card h1,
  .start-card .lead {
    grid-column: 1;
  }

  .start-card .rules,
  .start-card .primary,
  .start-card .controls-hint {
    grid-column: 2;
  }

  .start-logo {
    grid-row: 1 / span 2;
  }

  .start-card h1 {
    align-self: end;
  }

  .start-card .lead {
    align-self: start;
  }

  .start-card .rules {
    grid-row: 1 / span 2;
    margin: 0;
  }

  .start-card .primary {
    grid-row: 3;
  }

  .start-card .controls-hint {
    grid-row: 4;
  }

  .result-card {
    width: min(94vw, 700px);
    display: grid;
    grid-template-columns: 0.8fr 1.2fr;
    column-gap: 20px;
    align-items: center;
  }

  .result-card h2,
  .score-caption,
  .final-score,
  .best-line {
    grid-column: 1;
  }

  .leaderboard,
  .result-message,
  .result-card .primary {
    grid-column: 2;
  }

  .result-card h2 {
    grid-row: 1;
  }

  .score-caption {
    grid-row: 2;
  }

  .final-score {
    grid-row: 3;
  }

  .best-line {
    grid-row: 4;
  }

  .leaderboard {
    grid-row: 1 / span 3;
    margin-bottom: 8px;
  }

  .result-message {
    grid-row: 4;
    margin-bottom: 8px;
  }

  .result-card .primary {
    grid-row: 5;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
