:root {
  --tg-inset-top: env(safe-area-inset-top, 0px);
  --tg-inset-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
  font-family: Manrope, "Segoe UI", sans-serif;
  background: #0e1621;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: var(--app-height, 100dvh);
  margin: 0;
  overflow: hidden;
  background: #0e1621;
  color: #fff;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
button:disabled { cursor: default; opacity: 0.65; }
button:focus-visible, input:focus-visible { outline: 2px solid #9fd4ff; outline-offset: 2px; }

.tgme_background_wrap, .scene {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.tgme_background_wrap { background: #6ba587; }
#tgme_background {
  position: absolute;
  inset: -12%;
  width: 124%;
  height: 124%;
  filter: blur(40px);
}
.tgme_background_pattern {
  position: absolute;
  inset: 0;
  opacity: 0.28;
  background: url("pattern.svg") 0 0 / 220px 220px;
  mix-blend-mode: soft-light;
}
.scene {
  background:
    radial-gradient(640px 420px at 50% -10%, rgba(38, 120, 140, 0.45), transparent 60%),
    radial-gradient(520px 480px at 80% 110%, rgba(10, 40, 58, 0.8), transparent 55%),
    linear-gradient(180deg, #0c3d4a 0%, #0a2c38 42%, #071e28 100%);
}
.scene::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 35%, rgba(4, 10, 16, 0.28) 68%, rgba(4, 10, 16, 0.72) 100%);
}

.app {
  position: relative;
  z-index: 1;
  height: 100dvh;
  max-width: 440px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: calc(var(--tg-inset-top) + 8px) 16px calc(var(--tg-inset-bottom) + 10px);
}

.screen {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  animation: rise 0.35s ease;
}
.code-screen { justify-content: flex-start; overflow: hidden; padding-top: 6px; }
.screen:not([data-view="welcome"]) { justify-content: flex-start; padding-top: 18px; }
.code-screen { padding-top: 4px; }

.invite {
  width: min(100%, 380px);
  border-radius: 16px;
  background: rgba(23, 23, 23, 0.92);
  padding: 28px 22px 20px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
}
.avatar {
  width: 120px;
  height: 120px;
  margin: 0 auto;
  display: block;
  border-radius: 50%;
  object-fit: cover;
}
.invite h1 {
  margin: 14px 0 0;
  font-size: 28px;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.meta {
  margin: 6px 0 0;
  color: rgba(255, 255, 255, 0.55);
  font-size: 15px;
}
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 180px;
  height: 42px;
  margin-top: 18px;
  padding: 0 28px;
  border-radius: 22px;
  background: #3390ec;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  position: relative;
  overflow: hidden;
}
.pill.shine::after {
  content: "";
  position: absolute;
  top: 0;
  left: -40%;
  width: 30%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.45), transparent);
  animation: shine 2.8s ease-in-out infinite;
}
.pill:active:not(:disabled) { filter: brightness(0.95); }
.hint {
  min-height: 18px;
  margin: 16px auto 0;
  max-width: 28ch;
  color: rgba(255, 255, 255, 0.55);
  font-size: 14px;
  line-height: 1.4;
}
.hint strong { color: #fff; font-weight: 700; }

.emoji { display: block; object-fit: contain; }
.emoji.sm { width: 56px; height: 56px; }
h2 {
  margin: 8px 0 0;
  text-align: center;
  font-size: 24px;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.code-screen h2 { font-size: 22px; margin-top: 6px; font-weight: 700; }
.sub {
  margin: 6px 0 0;
  max-width: 320px;
  text-align: center;
  color: rgba(255, 255, 255, 0.62);
  font-size: 15px;
  line-height: 1.35;
}
#masked {
  display: block;
  margin-top: 2px;
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}
#masked:empty { display: none; }

.note, .error {
  width: 100%;
  margin: 12px 0 0;
  text-align: center;
  font-size: 13.5px;
  line-height: 1.35;
}
.note {
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.08);
  padding: 10px 12px;
}
.error { min-height: 0; margin-top: 8px; color: #e7a8b0; font-size: 14px; }
.error:empty { display: none; }
.busy-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 8px 0 0;
  color: rgba(255, 255, 255, 0.78);
  font-size: 14px;
}
.mini-spin {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}

.btn {
  width: 100%;
  height: 48px;
  margin-top: 18px;
  border-radius: 14px;
  background: linear-gradient(180deg, #6eb6ea 0%, #4b97d4 55%, #3d8bc8 100%);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.btn:active:not(:disabled) { transform: scale(0.99); }

.cells {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
  margin-top: 18px;
}
.cell {
  height: 54px;
  border-radius: 16px;
  background: rgba(6, 24, 32, 0.28);
  box-shadow: inset 0 0 0 1.5px rgba(232, 238, 244, 0.38);
  display: grid;
  place-items: center;
  font-size: 26px;
  font-weight: 600;
}
.cell.filled { box-shadow: inset 0 0 0 1.5px rgba(232, 238, 244, 0.72); }
.cells.bad .cell {
  box-shadow: inset 0 0 0 1.5px rgba(232, 164, 170, 0.95);
  color: #f0b4b8;
}
.cells.shake { animation: shake 0.42s ease; }

.timer { margin: 6px 0 0; color: rgba(255, 255, 255, 0.55); font-size: 14px; text-align: center; }
.timer button {
  color: rgba(255, 255, 255, 0.82);
  font-size: 14px;
  font-weight: 600;
}
.lookup {
  width: 100%;
  height: 48px;
  margin-top: 12px;
  border-radius: 14px;
  background: linear-gradient(180deg, #6eb6ea 0%, #4b97d4 55%, #3d8bc8 100%);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.lookup:disabled { opacity: 0.7; }

.keypad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(52px, 1fr));
  gap: 10px;
  width: 100%;
  min-height: 280px;
  flex: 1;
  margin-top: 14px;
}
.key {
  border-radius: 18px;
  background: rgba(12, 36, 48, 0.55);
  color: #fff;
  font-size: 28px;
  font-weight: 500;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.key:active:not(:disabled) { transform: scale(0.97); background: rgba(20, 52, 66, 0.72); }
.key:disabled { opacity: 0.45; }

.pass {
  position: relative;
  width: 100%;
  margin-top: 24px;
}
.pass input {
  width: 100%;
  height: 56px;
  border: 0;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
  padding: 0 48px 0 16px;
  font-size: 16px;
  outline: none;
}
.pass input:focus { box-shadow: inset 0 0 0 2px rgba(186, 230, 253, 0.8); }
.pass.bad input { box-shadow: inset 0 0 0 1px rgba(252, 165, 165, 0.75); }
.eye {
  position: absolute;
  top: 8px;
  right: 8px;
  height: 40px;
  padding: 0 8px;
  color: rgba(255, 255, 255, 0.8);
  font-size: 13px;
  font-weight: 700;
}

.success-art { position: relative; width: 160px; height: 150px; }
.success-art img:first-child { width: 132px; height: 132px; }
.success-art .badge { position: absolute; right: 0; bottom: 0; width: 64px; height: 64px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shine {
  0% { left: -40%; }
  55%, 100% { left: 130%; }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: none; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

@media (prefers-reduced-motion: reduce) {
  .screen, .cells.shake, .mini-spin, .pill.shine::after { animation: none; }
}
