@font-face {
  font-family: 'Source Serif 4';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url('/fonts/source-serif-4.woff2') format('woff2');
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #f7f2e8;
  -webkit-text-size-adjust: 100%;
}

.stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  min-height: 480px;
  overflow: hidden;
  background: radial-gradient(120% 90% at 70% 0%, #f7f2e8 0%, #efe7d6 60%, #e6dccb 100%);
  font-family: 'Source Serif 4', 'Iowan Old Style', Georgia, serif;
}

.stage::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(60, 45, 25, 0.05) 1px, transparent 1px);
  background-size: 4px 4px;
  pointer-events: none;
}

/* Sheets (Map) */
.sheet {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--i) * 70px + 120px);
  bottom: -60px;
  border-radius: 8px 8px 0 0;
  box-shadow: 0 -1px 0 rgba(60, 45, 25, 0.10), 0 -10px 30px rgba(60, 45, 25, 0.06);
  transform: translate3d(0, 100vh, 0);
  animation: rise 1.6s cubic-bezier(0.16, 0.84, 0.24, 1) forwards;
  animation-delay: calc(var(--i) * 0.35s + 0.3s);
  z-index: calc(var(--i) + 1);
  will-change: transform;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* Setelah naik awal selesai: transisi interaktif akordion halus */
.stage.ready .sheet {
  animation: none;
  transform: translate3d(0, var(--sheet-y, 0), 0);
  transition: transform 0.65s cubic-bezier(0.16, 0.84, 0.24, 1),
              box-shadow 0.4s ease;
}

/* Modus Pemilihan Map (Akordion Fisik Antar Map) */
/* 1. Mode Passkey (Default: Map 3 Passkey di paling bawah/depan aktif) */
.stage.mode-passkey #sheet1 {
  --sheet-y: 0px;
}
.stage.mode-passkey #sheet2 {
  --sheet-y: 0px;
}
.stage.mode-passkey #sheet3 {
  --sheet-y: 0px;
  box-shadow: 0 -4px 18px rgba(60, 45, 25, 0.16), 0 -22px 44px rgba(60, 45, 25, 0.12);
}

/* 2. Mode Authenticator (Map 1 di atas aktif, Map 2 & Map 3 meluncur turun) */
.stage.mode-auth #sheet1 {
  --sheet-y: -40px;
  box-shadow: 0 -4px 18px rgba(60, 45, 25, 0.16), 0 -22px 44px rgba(60, 45, 25, 0.12);
}
.stage.mode-auth #sheet2 {
  --sheet-y: 190px;
}
.stage.mode-auth #sheet3 {
  --sheet-y: 230px;
}

/* 3. Mode Kode email (Map 2 di tengah aktif, Map 3 meluncur turun) */
.stage.mode-email #sheet1 {
  --sheet-y: 0px;
}
.stage.mode-email #sheet2 {
  --sheet-y: -40px;
  box-shadow: 0 -4px 18px rgba(60, 45, 25, 0.16), 0 -22px 44px rgba(60, 45, 25, 0.12);
}
.stage.mode-email #sheet3 {
  --sheet-y: 200px;
}

.tab {
  position: absolute;
  top: -44px;
  left: var(--x);
  width: var(--w);
  height: 50px;
  border-radius: 14px 14px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.005em;
  color: #2b2318;
  background: inherit;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  border: none;
  outline: none;
  transition: transform 0.2s ease, font-weight 0.2s ease;
}

.tab:active {
  transform: scale(0.98);
}

.s1 {
  background: #f4eee2;
  --x: 5%;
  --w: 36%;
}

.s2 {
  background: #e8dcc7;
  --x: 39%;
  --w: 32%;
}

.s3 {
  background: #d97757;
  color: #fbf5ec;
  --x: 69%;
  --w: 26%;
}

.s3 .tab {
  color: #fbf5ec;
}

/* Keyframes Utama */
@keyframes rise {
  to { transform: translate3d(0, var(--sheet-y, 0), 0); }
}

@keyframes leave {
  to { transform: translate3d(0, -110vh, 0); }
}

/* Berhasil: map keluar ke atas */
.stage.ok .sheet {
  animation: leave 1.2s cubic-bezier(0.7, 0, 0.84, 0.3) forwards !important;
  animation-delay: calc(var(--i) * 0.15s) !important;
}

.redirect {
  position: absolute;
  inset: 0;
  background: #f7f2e8;
  opacity: 0;
  pointer-events: none;
  z-index: 25;
}

.stage.ok .redirect {
  animation: fadein 0.7s ease 1.6s forwards;
}

@keyframes fadein {
  to { opacity: 1; }
}

/* Gagal: map turun terbalik lalu naik lagi otomatis */
.stage.fail .sheet {
  animation: retry 4s linear forwards !important;
  animation-delay: calc((2 - var(--i)) * 0.15s) !important;
}

@keyframes retry {
  0% { transform: translate3d(0, 0, 0); animation-timing-function: cubic-bezier(0.7, 0, 0.84, 0.3); }
  28% { transform: translate3d(0, 100vh, 0); animation-timing-function: linear; }
  40% { transform: translate3d(0, 100vh, 0); animation-timing-function: cubic-bezier(0.16, 0.84, 0.24, 1); }
  70% { transform: translate3d(0, 0, 0); }
  100% { transform: translate3d(0, 0, 0); }
}

/* Challenge passkey: lingkaran 54px berdenyut */
.prompt {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: #2b2318;
  opacity: 0;
  animation: show 0.8s ease forwards, pulse 1.8s ease-in-out 3.2s infinite;
  animation-delay: 2.8s, 2.8s;
  cursor: pointer;
  transition: opacity 0.35s ease, transform 0.35s ease;
  will-change: transform, opacity;
  box-shadow: 0 2px 10px rgba(43, 35, 24, 0.25);
}

.prompt.hidden {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: scale(0.8) !important;
}

.stage.ok .prompt {
  animation: hide 0.3s ease forwards;
}

.stage.fail .prompt {
  animation: promptRetry 4s linear forwards !important;
}

@keyframes promptRetry {
  0%, 68% { opacity: 0; }
  88%, 100% { opacity: 1; }
}

@keyframes show {
  to { opacity: 1; }
}

@keyframes hide {
  to { opacity: 0; }
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(43, 35, 24, 0.35); }
  50% { box-shadow: 0 0 0 14px rgba(43, 35, 24, 0); }
}

/* Sheet interaktif saat dipilih (animasi lanjutan memilih map) */
.sheet.active .tab {
  font-weight: 600;
}

.sheet-content {
  opacity: 0;
  transform: translate3d(0, 14px, 0);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.16, 0.84, 0.24, 1);
  padding: 24px 20px 20px;
  max-width: 340px;
  margin: 0 auto;
  text-align: center;
}

.sheet.active .sheet-content {
  opacity: 1;
  transform: translate3d(0, 0, 0);
  pointer-events: auto;
  transition-delay: 0.18s;
}

/* Komponen Kertas (Paper Component) untuk Menulis Kode */
.paper {
  position: relative;
  background: #fffefb;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(43, 35, 24, 0.08), 0 8px 24px rgba(43, 35, 24, 0.06);
  border: 1px solid rgba(43, 35, 24, 0.12);
  padding: 22px 18px 18px;
  margin: 0 auto;
  text-align: center;
  background-image: repeating-linear-gradient(
    transparent,
    transparent 29px,
    rgba(43, 35, 24, 0.05) 30px
  );
  background-size: 100% 30px;
}

.s3 .paper {
  background: #fffdf8;
  border-color: rgba(60, 45, 25, 0.18);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12), 0 8px 24px rgba(0, 0, 0, 0.10);
}

/* Input tulisan di atas kertas */
.paper input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 2px dashed rgba(43, 35, 24, 0.28);
  border-radius: 0;
  padding: 8px 4px;
  font-family: 'Source Serif 4', Georgia, monospace;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 3px;
  text-align: center;
  color: #1c150d;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.paper input:focus {
  border-bottom: 2px solid #2b2318;
  box-shadow: 0 2px 0 rgba(43, 35, 24, 0.12);
}

.paper input::placeholder {
  color: rgba(43, 35, 24, 0.30);
  letter-spacing: 2px;
}

/* Tombol Aksi di Kertas */
.paper-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}

.paper-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 18px;
  border-radius: 4px;
  border: 1px solid rgba(43, 35, 24, 0.35);
  background: #f7f2e8;
  color: #2b2318;
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: background 0.18s ease, transform 0.12s ease, border-color 0.18s ease;
  box-shadow: 0 1px 2px rgba(43, 35, 24, 0.06);
}

.paper-btn:hover {
  background: #eee6d6;
  border-color: #2b2318;
}

.paper-btn:active {
  transform: scale(0.97);
}

.paper-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.paper-btn-primary {
  background: #2b2318;
  color: #fbf5ec;
  border-color: #2b2318;
}

.paper-btn-primary:hover {
  background: #423626;
}

/* Kertas Passkey dengan Cap Biometrik */
.paper-passkey {
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* Shake feedback jika kode salah */
@keyframes shake {
  0%, 100% { transform: translate3d(0, 0, 0); }
  20%, 60% { transform: translate3d(-6px, 0, 0); }
  40%, 80% { transform: translate3d(6px, 0, 0); }
}

.input-error {
  animation: shake 0.45s ease-in-out !important;
  border-bottom-color: #9a2818 !important;
}

/* Aksesibilitas Prefers Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .sheet, .stage.ok .sheet, .stage.fail .sheet, .prompt, .stage.ok .redirect, .sheet-content {
    animation: none !important;
    transform: none !important;
    transition: opacity 0.35s ease !important;
  }
  .stage.ok {
    opacity: 0;
  }
  .stage.fail .prompt {
    opacity: 1;
  }
}

/* Responsif 375px (Layar Ponsel Kecil) */
@media (max-width: 400px) {
  .stage.mode-auth #sheet1 {
    --sheet-y: -35px;
  }
  .stage.mode-auth #sheet2 {
    --sheet-y: 160px;
  }
  .stage.mode-auth #sheet3 {
    --sheet-y: 190px;
  }
  .stage.mode-email #sheet2 {
    --sheet-y: -35px;
  }
  .stage.mode-email #sheet3 {
    --sheet-y: 170px;
  }
  .tab {
    font-size: 14px;
    top: -38px;
    height: 42px;
  }
  .s1 { --x: 3%; --w: 37%; }
  .s2 { --x: 38%; --w: 33%; }
  .s3 { --x: 69%; --w: 28%; }
  .sheet-content {
    padding: 16px 12px;
  }
  .paper {
    padding: 16px 12px 14px;
  }
  .paper input {
    font-size: 17px;
  }
}
