@font-face {
  font-family: "Rajdhani";
  src: url("assets/Rajdhani-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --navy: #070c1a;
  --panel: #111a2d;
  --panel-2: #17223c;
  --cyan: #18bfff;
  --teal: #20d7c5;
  --pink: #ff4f83;
  --white: #f5f8ff;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #02050c; }
body { font-family: "Rajdhani", system-ui, sans-serif; user-select: none; touch-action: none; }
button { font: inherit; }

#game {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 320px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 42%, rgba(24, 191, 255, .055), transparent 44%),
    linear-gradient(180deg, #080e1e, var(--navy));
}

.topbar {
  position: absolute;
  z-index: 10;
  top: 0;
  left: 0;
  right: 0;
  height: clamp(76px, 15vh, 126px);
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  align-items: center;
  padding: max(10px, env(safe-area-inset-top)) clamp(20px, 6vw, 72px) 8px;
  color: var(--white);
  background: #111a2d;
  border-bottom: 1px solid rgba(75, 113, 177, .28);
  border-radius: 0 0 clamp(26px, 5vw, 54px) clamp(26px, 5vw, 54px);
  box-shadow: 0 10px 35px rgba(0,0,0,.18);
}

.brand-mark {
  color: var(--cyan);
  font-size: clamp(31px, 7vw, 58px);
  line-height: 1;
  transform: rotate(-45deg);
  filter: drop-shadow(0 0 8px rgba(24,191,255,.2));
}

.level-copy { text-align: center; font-size: clamp(22px, 5vw, 38px); letter-spacing: .02em; }
#hearts { color: var(--pink); font-size: .66em; letter-spacing: .14em; min-height: 1.2em; }
.coin-mark { justify-self: end; width: clamp(40px, 10vw, 72px); height: clamp(40px, 10vw, 72px); object-fit: cover; border-radius: 50%; }

.playfield { position: absolute; inset: clamp(76px, 15vh, 126px) 0 0; overflow: hidden; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; }
.pair-count { position: absolute; z-index: 4; top: clamp(14px, 3vh, 30px); left: clamp(20px, 6vw, 70px); font-size: clamp(24px, 5vw, 42px); color: var(--white); text-shadow: 0 2px 0 #000; }

.tutorial {
  position: absolute;
  z-index: 12;
  left: 50%;
  top: 8%;
  transform: translateX(-50%);
  min-width: min(82vw, 420px);
  padding: 12px 18px;
  text-align: center;
  border: 1px solid rgba(32,215,197,.62);
  border-radius: 18px;
  background: rgba(17,26,45,.94);
  box-shadow: 0 10px 36px rgba(0,0,0,.34), 0 0 22px rgba(32,215,197,.11);
  transition: opacity .2s, transform .2s;
}
.tutorial.hidden { opacity: 0; pointer-events: none; transform: translate(-50%, -12px); }
.tutorial-title { color: #f9e93f; font-size: clamp(18px, 4vw, 27px); letter-spacing: .05em; }
.tutorial-text { color: #cbdcff; font-size: clamp(14px, 3vw, 20px); margin-top: 3px; }

.hand {
  position: absolute;
  z-index: 14;
  display: flex;
  flex-direction: column;
  align-items: center;
  color: white;
  pointer-events: none;
  transform: translate(-50%, -28%);
  filter: drop-shadow(0 5px 4px rgba(0,0,0,.5));
  transition: opacity .18s;
  animation: handBob .9s ease-in-out infinite alternate;
}
.hand.hidden { opacity: 0; }
.hand span { font-family: "Segoe UI Emoji", sans-serif; font-size: clamp(36px, 10vw, 70px); }
.hand small { margin-top: -7px; color: #64fff2; letter-spacing: .08em; font-size: clamp(11px, 2.6vw, 16px); }
@keyframes handBob { to { transform: translate(-50%, -12%); } }

.toast {
  position: absolute;
  z-index: 15;
  left: 50%;
  bottom: 7%;
  transform: translate(-50%, 20px);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(17,26,45,.94);
  color: white;
  opacity: 0;
  transition: .2s;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.level-complete {
  position: absolute;
  z-index: 25;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 8px;
  background: rgba(2,5,12,.8);
  color: white;
  opacity: 0;
  pointer-events: none;
  transform: scale(1.05);
  transition: opacity .22s, transform .22s;
}
.level-complete.show { opacity: 1; transform: scale(1); pointer-events: auto; }
.level-complete.show::before,
.level-complete.show::after {
  content: "";
  position: absolute;
  width: min(54vmin, 380px);
  aspect-ratio: 1;
  border: 3px solid rgba(100,255,242,.72);
  border-radius: 50%;
  animation: completionRing .9s ease-out both;
}
.level-complete.show::after { animation-delay: .14s; border-color: rgba(255,79,131,.58); }
.level-complete.show::before, .level-complete.show::after { pointer-events: none; }
@keyframes completionRing { from { opacity: .9; transform: scale(.15); } to { opacity: 0; transform: scale(1.35); } }
.level-complete strong { font-size: clamp(26px, 7vw, 60px); letter-spacing: .06em; }
.level-complete span { color: #64fff2; font-size: clamp(17px, 4vw, 30px); }
.complete-actions { position: relative; z-index: 2; display: flex; flex-direction: column; gap: 10px; margin-top: 18px; width: min(74vw, 340px); }
.complete-actions button { min-height: 52px; padding: 11px 24px; border: 0; border-radius: 16px; color: white; font-size: clamp(18px, 4.4vw, 25px); letter-spacing: .055em; cursor: pointer; }
.complete-download { background: linear-gradient(135deg, #ff7a00, #ff4d00); box-shadow: 0 10px 28px rgba(255,87,0,.28); }
.complete-continue { background: linear-gradient(135deg, #25d7ca, #13aebc); box-shadow: 0 10px 28px rgba(24,191,255,.2); }
.complete-actions button:active { transform: scale(.97); }

.end-card {
  position: absolute;
  z-index: 40;
  inset: 0;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 24px;
  text-align: center;
  background: radial-gradient(circle at 50% 40%, #10254b 0, #070c1a 50%, #02050c 100%);
}
.end-card.show { display: flex; animation: endIn .35s ease-out both; }
@keyframes endIn { from { opacity: 0; transform: scale(1.04); } }
.end-card img { position: relative; width: min(42vmin, 260px); aspect-ratio: 1; object-fit: cover; border-radius: 24%; filter: drop-shadow(0 0 28px rgba(24,191,255,.35)); }
.end-card h1 { margin: 18px 0 0; font-size: clamp(34px, 9vw, 76px); line-height: .9; font-style: italic; }
.end-card p { margin: 12px 0 24px; color: #cbdcff; font-size: clamp(17px, 4vw, 28px); }
#downloadButton {
  position: relative;
  min-width: min(74vw, 360px);
  min-height: 58px;
  padding: 14px 30px;
  border: 0;
  border-radius: 18px;
  background: linear-gradient(135deg, #ff7a00, #ff4d00);
  color: white;
  font-size: clamp(20px, 5vw, 31px);
  letter-spacing: .05em;
  box-shadow: 0 12px 32px rgba(255,87,0,.3), inset 0 1px rgba(255,255,255,.3);
  cursor: pointer;
  animation: ctaPulse 1.1s ease-in-out infinite alternate;
}
@keyframes ctaPulse { to { transform: scale(1.045); box-shadow: 0 15px 42px rgba(255,87,0,.48), inset 0 1px rgba(255,255,255,.3); } }

@media (orientation: landscape) {
  .topbar { height: clamp(64px, 18vh, 94px); padding: 8px max(24px, env(safe-area-inset-left)) 6px max(24px, env(safe-area-inset-right)); }
  .playfield { inset: clamp(64px, 18vh, 94px) 0 0; }
  .tutorial { left: auto; right: 2.5%; top: 5%; transform: none; min-width: 0; width: min(29vw, 300px); }
  .tutorial.hidden { transform: translateY(-12px); }
  .end-card { flex-direction: row; flex-wrap: wrap; column-gap: 5vw; }
  .end-card img { width: min(36vh, 220px); }
  .end-card h1, .end-card p, #downloadButton { width: min(46vw, 460px); }
  .end-card h1 { margin-top: 0; }
  .complete-actions { flex-direction: row; width: min(72vw, 580px); }
  .complete-actions button { flex: 1; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .topbar { height: 58px; border-radius: 0 0 22px 22px; }
  .playfield { inset: 58px 0 0; }
  .level-copy { font-size: 22px; }
  .brand-mark { font-size: 31px; }
  .coin-mark { width: 38px; height: 38px; }
  .tutorial { top: 10px; padding: 8px 12px; }
  .tutorial-title { font-size: 16px; }
  .tutorial-text { font-size: 12px; }
}

@media (max-width: 380px) {
  .topbar { padding-left: 14px; padding-right: 14px; }
  .tutorial { min-width: 88vw; padding: 9px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
}
