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

:root {
  color-scheme: light only;
  --bg: #0E2110;
  --canvas-bg: #132B16;
  --card: #F2C4B2;
  --dark: #1A1030;
  --lime: #8FD400;
  --coral: #E8503A;
  --cream: #FDF5EE;
  --gold: #C4933F;
  --border: #2A4A30;
}

html {
  height: 100%;
}

body {
  background: var(--bg) !important;
  color: var(--cream) !important;
  font-family: "Nunito", sans-serif;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 0.6rem;
  padding: 1.25rem 16px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='52' height='60'%3E%3Cpolygon points='26,4 48,18 48,42 26,56 4,42 4,18' fill='none' stroke='rgba(143%2C212%2C0%2C0.06)' stroke-width='1'/%3E%3Cline x1='26' y1='4' x2='26' y2='56' stroke='rgba(143%2C212%2C0%2C0.03)' stroke-width='0.5'/%3E%3Cline x1='4' y1='18' x2='48' y2='42' stroke='rgba(143%2C212%2C0%2C0.03)' stroke-width='0.5'/%3E%3Cline x1='48' y1='18' x2='4' y2='42' stroke='rgba(143%2C212%2C0%2C0.03)' stroke-width='0.5'/%3E%3C/svg%3E") !important;
}

header {
  text-align: center;
  margin-bottom: 0.4rem;
  min-height: 55px;
}

.eyebrow {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--cream);
  margin-bottom: 0.15rem;
}

h1 {
  font-family: "Nunito", sans-serif;
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 900;
  letter-spacing: 0.01em;
  color: var(--cream);
  line-height: 1;
  padding-bottom: 8px;
}

h1 span {
  color: var(--gold);
  font-weight: 900;
}

.hud-right {
  text-align: right;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 8px;
  transition: opacity 0.4s;
}

.hud.pre-game {
  opacity: 0;
}

.score-label {
  /* font-size: 0.5rem; */
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--lime);
  line-height: 1;
  margin-bottom: 0.1rem;
}

.score-val {
  font-family: "Nunito", sans-serif;
  font-size: 1.6rem;
  font-weight: 900;
  line-height: 1;
  color: var(--cream);
  transition: transform 0.12s cubic-bezier(0.22, 1, 0.36, 1);
}

.hint-label {
  display: none;
}

.game-wrap {
  position: relative;
}

canvas#game {
  display: block;
  border-radius: 16px;
  border: none;
  box-shadow: 0 0 0 4px #1C3820, 0 0 0 5px var(--border), 0 16px 48px rgba(0, 0, 0, 0.5);
  background: var(--canvas-bg);
  touch-action: none;
}

@media (max-width: 600px) {
  canvas#game {
    box-shadow: 0 0 0 3px #1C3820, 0 0 0 4px var(--border), 0 8px 20px rgba(0, 0, 0, 0.4);
  }
}

.overlay {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  background: rgba(11, 26, 13, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.overlay.hidden {
  display: none !important;
}

.snake-peek-mask {
  position: absolute;
  top: 0;
  left: 0;
  width: 38px;
  height: 50px;
  overflow: hidden;
  pointer-events: none;
  z-index: 5;
  border-radius: 16px;
  /* WebKit fails to clip a transformed child via overflow:hidden + border-radius
     alone (all iOS browsers use WebKit) — the mask-image forces real clipping. */
  -webkit-mask-image: -webkit-radial-gradient(white, black);
}

.peek-outer {
  position: absolute;
  width: 38px;
  height: 50px;
  top: 0;
  left: 0;
  transition: transform 5s cubic-bezier(0.45, 0, 0.55, 1);
  transform: translate(-100%, -100%);
}

.peek-outer.peek {
  transform: translate(0, -20%);
}

.peek-inner {
  position: absolute;
  inset: 0;
}

.peek-inner img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.35));
}

.overlay-title {
  font-family: "Nunito", sans-serif;
  font-size: 2.2rem;
  font-weight: 900;
  text-align: center;
  line-height: 1.05;
  color: var(--gold);
  letter-spacing: -0.03em;
}

.overlay-title span {
  color: var(--gold);
  font-weight: 900;
}

.overlay-sub {
  font-size: 1.4rem;
  font-weight: 900;
  color: rgba(253, 245, 238, 0.8);
  text-align: center;
  max-width: 350px;
  line-height: 1.6;
  margin-bottom: 1.25rem;
  padding: 0 1.25rem;
}

@media (max-width: 600px) {
  .overlay-sub {
    font-size: 1.2rem;
  }
}

.overlay-score {
  font-family: "Nunito", sans-serif;
  font-size: 2.4rem;
  font-weight: 900;
  color: var(--lime);
  letter-spacing: -0.01em;
}

.overlay-score.hidden {
  display: none;
}

.btn-play {
  background: #FDF5EE;
  color: var(--dark);
  border: none;
  border-radius: 100px;
  padding: 0.8rem 2.4rem;
  font-size: 0.85rem;
  font-weight: 900;
  cursor: pointer;
  font-family: "Nunito", sans-serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  transition: transform 0.1s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.1s;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
}

.btn-play:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
}

.controls-hint {
  font-size: 0.62rem;
  color: rgba(253, 245, 238, 0.45);
  opacity: 1;
  letter-spacing: 0.05em;
  margin-top: 0.5rem;
}

.score-val.pulse {
  transform: scale(1.16);
  color: var(--lime);
}

.streak {
  font-size: 0.7rem;
  font-weight: 900;
  color: var(--lime);
  letter-spacing: 0.05em;
  min-height: 1.2rem;
  text-align: right;
}

.streak.active {
  animation: streakPop 0.25s ease-out;
}

@keyframes streakPop {
  0% {
    transform: translateX(6px);
    opacity: 0
  }

  100% {
    transform: translateX(0);
    opacity: 1
  }
}

.float-text {
  position: absolute;
  pointer-events: none;
  font-family: "Nunito", sans-serif;
  font-size: 1.2rem;
  font-weight: 900;
  color: var(--lime);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  animation: floatUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  z-index: 10;
}

@keyframes floatUp {
  0% {
    opacity: 1;
    transform: translateY(0)
  }

  100% {
    opacity: 0;
    transform: translateY(-34px)
  }
}

.edge-flash {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  pointer-events: none;
  border: 6px solid var(--lime);
  opacity: 0;
  animation: edgeFlash 0.5s ease forwards;
  z-index: 5;
}

@keyframes edgeFlash {
  0% {
    opacity: 1
  }

  100% {
    opacity: 0
  }
}

.confetti-piece {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  pointer-events: none;
  animation: confettiFall 1s ease forwards;
  z-index: 20;
}

.tutorial {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  background: rgba(11, 26, 13, 0.96);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 30;
}

.tutorial.hidden {
  display: none;
}

.tutorial-icon {
  font-size: 3rem;
  animation: tutBounce 3.2s ease-in-out infinite alternate;
}

@keyframes tutBounce {
  0% {
    transform: translateY(0)
  }

  100% {
    transform: translateY(-3px)
  }
}

.tutorial-title {
  font-family: "Nunito", sans-serif;
  font-size: 1.2rem;
  font-weight: 900;
  color: var(--cream);
  text-align: center;
}

.tutorial-sub {
  font-family: "Nunito", sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  color: rgba(253, 245, 238, 0.65);
  text-align: center;
  max-width: 200px;
  line-height: 1.5;
}

.tutorial-btn {
  background: var(--lime);
  color: var(--dark);
  border: none;
  border-radius: 100px;
  padding: 0.65rem 1.8rem;
  font-size: 0.85rem;
  font-weight: 900;
  cursor: pointer;
  font-family: "Nunito", sans-serif;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
  margin-top: 1.25rem;
}

.tutorial-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
}

.countdown {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  background: rgba(11, 26, 13, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
}

.countdown.hidden {
  display: none;
}

.countdown-num {
  font-family: "Nunito", sans-serif;
  font-size: 6rem;
  font-weight: 900;
  color: var(--cream);
  animation: countPop 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.countdown-num.go {
  color: var(--lime);
}

@keyframes countPop {
  0% {
    transform: scale(0.85);
    opacity: 0
  }

  100% {
    transform: scale(1);
    opacity: 1
  }
}

@keyframes confettiFall {
  0% {
    opacity: 1;
    transform: translateY(0) rotate(0deg) scale(1)
  }

  100% {
    opacity: 0;
    transform: translateY(60px) rotate(360deg) scale(0.3)
  }
}

.tut-swipe-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.tut-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tut-finger-area {
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tut-finger-svg {
  overflow: visible;
}

.tut-arrow {
  font-size: 1.2rem;
  font-weight: 900;
  color: rgba(143, 212, 0, 0.25);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}

.tut-arrow.active {
  color: #8FD400;
  background: rgba(143, 212, 0, 0.15);
}

.kopi-hint-inline-text {
  /* font-size: 0.84rem; */
  font-size: 16px;
  font-weight: 700;
  color: rgba(253, 245, 238, 0.6);
  line-height: 1.4;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
}

.kopi-hint-inline-text span {
  color: var(--gold);
}

/* ── Leaderboard overlay ── */
.overlay-lb {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  background: rgba(11, 26, 13, 0.97);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.overlay-lb.hidden {
  display: none;
}

.lb-header {
  padding: 0.8rem 1.1rem 0.5rem;
  flex-shrink: 0;
}

.lb-gameover-label {
  /* font-size: 0.85rem; */
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: none;
  color: var(--coral);
  margin-bottom: 0.2rem;
  text-align: center;
}

.lb-gameover-label.gold {
  color: var(--gold);
}

.lb-final-score {
  font-size: 3rem;
  font-weight: 900;
  color: #8FD400;
  line-height: 1;
  letter-spacing: -0.02em;
  text-align: center;
}

.lb-score-unit {
  /* font-size: 0.65rem; */
  font-size: 12px;
  font-weight: 700;
  color: rgba(253, 245, 238, 0.5);
  letter-spacing: 0.03em;
  margin-top: 0.1rem;
  margin-bottom: 0.8rem;
  text-align: center;
}

.lb-name-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(253, 245, 238, 0.06);
  border: 1px solid rgba(253, 245, 238, 0.08);
  border-radius: 10px;
  padding: 0.5rem 0.7rem;
}

.lb-name-text {
  flex: 1;
  font-size: 0.85rem;
  font-weight: 700;
  color: #FDF5EE;
}

.lb-edit-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(253, 245, 238, 0.45);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.2rem 0.4rem;
  border-radius: 6px;
  font-family: "Nunito", sans-serif;
  transition: color 0.15s, background 0.15s;
}

.lb-edit-btn:active {
  color: #8FD400;
  background: rgba(143, 212, 0, 0.1);
}

#lbScore.hidden,
#lbAteLabel.hidden,
#lbNameRow.hidden {
  display: none;
}

.lb-divider-line {
  height: 1px;
  background: rgba(253, 245, 238, 0.07);
  margin: 0.6rem 0;
  flex-shrink: 0;
}

.lb-section-label {
  /* font-size: 0.52rem; */
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(253, 245, 238, 0.4);
  padding: 0 1.1rem;
  margin-bottom: 0.35rem;
  flex-shrink: 0;
}

.lb-scroll-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

.lb-scroll {
  height: 100%;
  overflow-y: auto;
  padding: 0 0.7rem 60px;
  -webkit-overflow-scrolling: touch;
}

.lb-scroll::-webkit-scrollbar {
  display: none;
}

/* scroll hint fade — absolute inside overlay-lb, repositioned by JS */
.lb-fade-hint {
  position: absolute;
  left: 0;
  right: 0;
  height: 40px;
  background: linear-gradient(to bottom, transparent, #0D1F0F);
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.3s;
  z-index: 4;
}

.lb-fade-hint.hidden {
  opacity: 0;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.4rem 0.4rem;
  border-radius: 8px;
  margin-bottom: 2px;
}

.lb-row.you {
  background: rgba(143, 212, 0, 0.1);
  border: 1px solid rgba(143, 212, 0, 0.2);
}

.lb-rank {
  /* font-size: 0.62rem; */
  font-size: 12px;
  font-weight: 900;
  color: rgba(253, 245, 238, 0.4);
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.lb-rank.gold {
  color: #F5C842;
}

.lb-rank.silver {
  color: #C0C8D0;
}

.lb-rank.bronze {
  color: #C47A3A;
}

.lb-row.you .lb-rank {
  color: #8FD400;
}

.lb-entry-name {
  flex: 1;
  /* font-size: 0.78rem; */
  font-size: 14px;
  font-weight: 700;
  color: #FDF5EE;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-row.you .lb-entry-name {
  color: #8FD400;
}

.lb-entry-score {
  /* font-size: 0.78rem; */
  font-size: 14px;
  font-weight: 900;
  color: #FDF5EE;
  flex-shrink: 0;
}

.lb-row.you .lb-entry-score {
  color: #8FD400;
}

.lb-ellipsis {
  text-align: center;
  font-size: 0.6rem;
  color: rgba(253, 245, 238, 0.25);
  padding: 0.2rem 0;
  letter-spacing: 0.15em;
}

/* sticky you bar — overlaps scroll list */
.lb-sticky-you {
  position: absolute;
  bottom: 58px;
  left: 0;
  right: 0;
  padding: 0.3rem 1.1rem 0.4rem;
  background: #0D1F0F;
  border-top: 1px solid rgba(143, 212, 0, 0.15);
  transition: opacity 0.2s;
  z-index: 5;
}

.lb-sticky-you.hidden {
  opacity: 0;
  pointer-events: none;
}

.lb-sticky-you .lb-row {
  background: rgba(143, 212, 0, 0.12);
  border: 1px solid rgba(143, 212, 0, 0.25);
  margin-bottom: 0;
  pointer-events: none;
}

.lb-footer {
  padding: 0.5rem 1.1rem 0.75rem;
  flex-shrink: 0;
}

.btn-play-again {
  width: 100%;
  background: #FDF5EE;
  color: #1A1030;
  border: none;
  border-radius: 100px;
  padding: 0.7rem;
  font-size: 0.8rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  font-family: "Nunito", sans-serif;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
}

.btn-play-again:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
}

/* ── Kopi hint animations ── */
@keyframes kopiPulse {

  0%,
  100% {
    filter: drop-shadow(0 0 0px rgba(196, 147, 63, 0));
    opacity: 0.85;
  }

  50% {
    filter: drop-shadow(0 0 6px rgba(196, 147, 63, 0.85));
    opacity: 1;
  }
}

@keyframes kopiHintBounceIn {
  0% {
    opacity: 0;
    transform: translateY(12px) scale(0.82);
  }

  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.kopi-hint-icon {
  animation: kopiPulse 2.5s ease-in-out infinite;
  transform-origin: center;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  margin: 8px;
}

.kopi-hint-inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: -0.2rem;
  margin-bottom: 2.4rem;
  animation: kopiHintBounceIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.3s both;
  flex-direction: column;
  justify-content: flex-start;
}

/* ── Combo display ── */
@keyframes comboBurst {
  0% {
    transform: translate(-50%, -50%) scale(0.4);
    opacity: 0;
  }

  18% {
    transform: translate(-50%, -50%) scale(1.2);
    opacity: 1;
  }

  32% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }

  82% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }

  100% {
    transform: translate(-50%, -50%) scale(1.05);
    opacity: 0;
  }
}

.combo-burst {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-family: "Nunito", sans-serif;
  font-weight: 900;
  letter-spacing: -0.02em;
  text-align: center;
  pointer-events: none;
  z-index: 40;
  white-space: nowrap;
  animation: comboBurst 1.2s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.combo-burst.outlined {
  font-style: italic;
  font-size: 2.4rem;
  color: #fff;
  -webkit-text-stroke: 8px #3FA9E8;
  paint-order: stroke fill;
}

.combo-burst.plain {
  font-style: normal;
  font-size: 1.6rem;
}


/* ── Name edit overlay ── */
.overlay-edit {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  background: #0D1F0F;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1.25rem;
  gap: 0;
}

.overlay-edit.hidden {
  display: none;
}

.edit-title {
  font-size: 1rem;
  font-weight: 900;
  color: #FDF5EE;
  margin-bottom: 0.3rem;
  align-self: flex-start;
}

.edit-sub {
  font-size: 0.72rem;
  color: rgba(253, 245, 238, 0.5);
  line-height: 1.5;
  margin-bottom: 1.1rem;
  align-self: flex-start;
}

.name-input {
  width: 100%;
  background: rgba(253, 245, 238, 0.06);
  border: 1.5px solid rgba(143, 212, 0, 0.45);
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  font-size: 1rem;
  font-weight: 700;
  color: #FDF5EE;
  font-family: "Nunito", sans-serif;
  outline: none;
  margin-bottom: 0.4rem;
}

.name-input::placeholder {
  color: rgba(253, 245, 238, 0.3);
}

.char-count {
  font-size: 0.58rem;
  color: rgba(253, 245, 238, 0.35);
  text-align: right;
  width: 100%;
  margin-bottom: 1.1rem;
  letter-spacing: 0.05em;
}

.name-error {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--coral);
  align-self: flex-start;
  margin-top: -0.6rem;
  margin-bottom: 0.9rem;
}

.name-error.hidden {
  display: none;
}

.btn-confirm {
  width: 100%;
  background: #8FD400;
  color: #1A1030;
  border: none;
  border-radius: 100px;
  padding: 0.7rem;
  font-size: 0.8rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  font-family: "Nunito", sans-serif;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
  margin-bottom: 0.5rem;
}

.btn-confirm:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
}

.btn-cancel-edit {
  width: 100%;
  background: transparent;
  color: rgba(253, 245, 238, 0.4);
  border: none;
  padding: 0.4rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  font-family: "Nunito", sans-serif;
}

/* ── Bottom icon buttons ── */
.bottom-btns {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.btn-icon {
  background: #FDF5EE;
  color: var(--dark);
  border: none;
  border-radius: 100px;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
  transition: transform 0.1s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.1s, opacity 0.15s;
  flex-shrink: 0;
}

.btn-icon:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
}

.btn-music.muted {
  opacity: 0.55;
}

.bottom-btns.hidden {
  display: none;
}