/* ================= COMMON & UTILS ================= */
:root {
    --bg-color: #ffffff; 
    --text-color: white;
    --border-color-1: #dd2476; 
    --border-color-2: #ff512f; 
    --btn-bg-inner: rgba(20, 20, 20, 0.95);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; outline: none; }

/* Fix font boosting on Android & Text rendering on iOS */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Noto Sans Thai', 'Kanit', sans-serif;
    overflow: hidden;
    background-color: #ffffff;
    /* Prevent rubber-banding effect on iOS */
    overscroll-behavior: none;
    /* Full height fallback */
    min-height: 100vh;
    min-height: 100dvh;
    width: 100%;
    position: fixed; /* Prevent body scroll entirely */
}

.hidden { display: none !important; }
.fade-out { opacity: 0; pointer-events: none; transition: opacity 0.5s ease; }

/* GPU Acceleration Class for smoother animations */
.gpu-accelerated {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
    will-change: transform, opacity;
}

/* ================= INDEX 1 (Landing) ================= */
#view-landing {
    position: fixed; inset: 0; z-index: 10;
    background: #ffffff;
    display: flex; justify-content: center; align-items: center;
    transition: transform 0.5s ease, opacity 0.5s ease;
    will-change: transform, opacity; /* Optimize transition */
}
.glow-effect {
    position: absolute; top: 30%; left: 50%; transform: translate3d(-50%, -50%, 0); /* Force GPU */
    width: 100vw; height: 100vw;
    background: radial-gradient(circle, rgba(255, 20, 147, 0.5) 0%, rgba(38, 197, 243, 0.3) 120%, transparent 100%);
    filter: blur(100px); z-index: 0; opacity: 0;
    animation: glowAppear 2s ease-in-out forwards 2.5s, glowPulse 1.7s infinite alternate 2s;
    pointer-events: none; /* Improve performance */
}
.mascot-layer {
    position: absolute; top: 53%; left: 50%; clip-path: inset(0 0 2% 0);
    width: 380px; max-width: 90vw; z-index: 1; opacity: 0;
    /* Combined transform for better performance */
    transform: translate3d(-50%, -55%, 0); 
    animation: slideUpFade 3s cubic-bezier(0.3, 1, 0.1, 1) forwards; animation-delay: 1.3s;
}
.content-stack {
    position: relative; z-index: 10; display: flex; flex-direction: column;
    align-items: center; justify-content: center; margin-top: 150px;
}
.text-back-glow {
    position: absolute; top: 40%; left: 50%; transform: translate3d(-50%, -50%, 0);
    width: 140%; height: 80%;
    background: radial-gradient(ellipse at center, var(--border-color-1) 0%, var(--border-color-2) 50%, transparent 70%);
    filter: blur(45px); z-index: -1; opacity: 0;
    animation: textGlowAppear 2s ease forwards; animation-delay: 3s; pointer-events: none;
}
.text-hello {
    font-size: 8rem; font-weight: 900; line-height: 1;
    background: linear-gradient(90deg, var(--border-color-1), var(--border-color-2), var(--border-color-1));
    background-size: 200% 100%; -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text; animation: gradientFlow 5s infinite; margin-bottom: -30px; z-index: 3; position: relative;
    will-change: background-position;
}
.text-partners {
    font-size: 5rem; font-weight: 900;
    background: linear-gradient(90deg, var(--border-color-1), var(--border-color-2), var(--border-color-1));
    background-size: 200% 200%; -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text; animation: gradientFlow 5s infinite; line-height: 1; margin-bottom: -25px; z-index: 2; position: relative;
    will-change: background-position;
}
.google-btn {
    position: relative; display: flex; align-items: center; gap: 12px;
    padding: 18px 40px; border-radius: 50px; font-size: 1.3rem; font-weight: 600;
    color: white; background: var(--bg-color); border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 10px 30px rgba(0,0,0,0.8); z-index: 4; overflow: hidden; cursor: pointer;
    -webkit-user-select: none; user-select: none;
    touch-action: manipulation;
}
.google-btn::before {
    content: ''; position: absolute; top: 50%; left: 50%; width: 300%; height: 300%; 
    background: conic-gradient(from 0deg, transparent 0%, transparent 70%, var(--border-color-2) 85%, var(--border-color-1) 100%);
    transform: translate(-50%, -50%); z-index: -2; opacity: 0; transition: opacity 0.3s ease;
    will-change: transform;
}
.google-btn::after {
    content: ''; position: absolute; inset: 3px; background: var(--btn-bg-inner); border-radius: 50px; z-index: -1;
}
.google-btn:hover::before, .google-btn.simulate-hover::before { opacity: 1; animation: snakeRotate 2s linear infinite; }
.google-icon { width: 28px; height: 28px; }

/* Optimized Keyframes */
@keyframes slideUpFade { from { opacity: 0; transform: translate3d(-50%, -55%, 0); } to { opacity: 1; transform: translate3d(-50%, -65%, 0); } }
@keyframes glowPulse { 0% { opacity: 0.9; } 100% { opacity: 1; } }
@keyframes gradientFlow { 0%, 100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
@keyframes snakeRotate { from { transform: translate(-50%, -50%) rotate(0deg); } to { transform: translate(-50%, -50%) rotate(360deg); } }
@keyframes textGlowAppear { from { opacity: 0; } to { opacity: 0.6; } }

@media (max-width: 480px) {
    .text-hello { font-size: 6rem; margin-bottom: -10px; }
    .text-partners { font-size: 4rem; margin-bottom: -80px; }
    .google-btn { padding: 14px 30px; width: 280px; font-size: 1rem; margin-top: 80px;}
    .mascot-layer { width: 300px; transform: translate3d(-50%, -60%, 0); margin-top: -70px; }
    .content-stack { margin-top: 120px; }
    @keyframes slideUpFade { from { opacity: 0; transform: translate3d(-50%, -50%, 0); } to { opacity: 1; transform: translate3d(-50%, -60%, 0); } }
}

/* ================= INDEX 2 (Auth/PIN) ================= */
#view-auth {
    position: fixed; inset: 0; z-index: 20;
    background-color: rgb(248, 250, 252);
    display: flex; justify-content: center; align-items: center;
    transform: translateZ(0); /* Fix for iOS rendering */
}
.particles { position:absolute; inset:0; z-index:0; pointer-events:none; }
.particle { position:absolute; border-radius:50%; background:rgba(155,37,249,.1); animation:float 15s infinite linear; will-change:transform; }
@keyframes float { 0%{transform:translateY(0) rotate(0deg);opacity:0} 50%{opacity:.5} 100%{transform:translateY(-100vh) rotate(360deg);opacity:0} }

.auth-container { position:absolute; inset:0; display:flex; flex-direction:column; justify-content:center; align-items:center; transition:opacity .3s ease; z-index:10; padding:1rem; background-color:rgb(248, 250, 252); }
.page-hidden { opacity:0; pointer-events:none; visibility:hidden; display: none; }
.page-visible { opacity:1; visibility:visible; display: flex; }

.welcome-title { font-size:2.25rem; background:linear-gradient(90deg,#9b25f9,#26c5f3); -webkit-background-clip:text; -webkit-text-fill-color:transparent; margin:0 0 2rem 0; text-align:center; font-weight:700; }
.title-sm { font-size:1.5rem; }
.text-muted { color:#64748b; font-size:.9rem; }
.text-center { text-align:center; }

.input-wrapper { position:relative; width:300px; max-width:100%; height:56px; z-index:20; }
.input-wrapper.error { animation:shake .4s cubic-bezier(.36,.07,.19,.97) both; }
/* iOS Input Reset */
.input-box { 
    width:100%; height:100%; padding:0 20px; font-size:1.25rem; border:none; border-radius:16px; 
    background:#1e293b; color:#fff; text-align:center; letter-spacing:2px; 
    box-shadow:0 4px 6px -1px rgba(0,0,0,.1); transition:box-shadow .2s;
    -webkit-appearance: none; appearance: none; /* Remove iOS styles */
    margin: 0;
}
.input-box:focus { outline:none; box-shadow:0 10px 15px -3px rgba(0,0,0,.2); }
.input-box::placeholder { color:#94a3b8; letter-spacing:normal; font-size:1rem; }

.animated-gradient-border { position:absolute; inset:-2px; z-index:-1; border-radius:18px; background:linear-gradient(90deg,#9b25f9,#26c5f3,#9b25f9); background-size:200% 100%; opacity:0; transition:opacity .3s; will-change: opacity, background-position; }
.input-wrapper:focus-within .animated-gradient-border { opacity:1; animation:gradientFlow 3s linear infinite; }

.btn-group { display:flex; gap:1rem; width:300px; margin-top:1.5rem; }
.btn-pin { flex:1; padding:.875rem; border-radius:12px; font-weight:600; border:none; cursor:pointer; font-family:inherit; transition:transform .1s; -webkit-appearance: none; }
.btn-pin:active { transform:scale(.98); }
.btn-pin:disabled { opacity:.5; cursor:not-allowed; }
.btn-primary-pin { background:linear-gradient(135deg,#9b25f9,#26c5f3); color:#fff; }
.btn-secondary-pin { background:#fff; color:#0f172a; border:1px solid #e2e8f0; }

.top-notification { position:fixed; top:16px; left:16px; right:16px; width:auto; background:#fff; padding:16px; border-radius:16px; box-shadow:0 20px 25px -5px rgba(0,0,0,.1); z-index:9999; transform:translateY(-150%); transition:transform .4s cubic-bezier(.34,1.56,.64,1); display:flex; align-items:center; justify-content:center; font-weight:500; will-change: transform; }
.top-notification.visible { transform:translateY(0); }
.top-notification.success { border-left:6px solid #10B981; color:#065F46; }
.top-notification.error { border-left:6px solid #EF4444; color:#7F1D1D; }
.debug-link { position:fixed; bottom:20px; color:#cbd5e1; font-size:.75rem; text-decoration:none; -webkit-tap-highlight-color: transparent; }
@keyframes shake { 10%,90%{transform:translate3d(-1px,0,0)} 20%,80%{transform:translate3d(2px,0,0)} 30%,50%,70%{transform:translate3d(-4px,0,0)} 40%,60%{transform:translate3d(4px,0,0)} }

/* ================= REGISTRATION OVERLAY ================= */
#reg-overlay {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
    opacity: 0; visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}
#reg-overlay.active { opacity: 1; visibility: visible; }

#reg-sheet {
    position: absolute; bottom: 0; left: 0; right: 0;
    height: 85%;
    background: #ffffff;
    border-top-left-radius: 20px; border-top-right-radius: 20px;
    box-shadow: 0 -5px 30px rgba(0,0,0,0.2);
    transform: translateY(100%);
    transition: transform 0.5s cubic-bezier(0.19, 1, 0.22, 1);
    display: flex; flex-direction: column;
    will-change: transform;
}
#reg-overlay.active #reg-sheet { transform: translateY(0); }

.sheet-handle { width: 40px; height: 5px; background: #e2e8f0; border-radius: 10px; margin: 12px auto; flex-shrink: 0; }

.reg-app { flex: 1; padding: 0 1.5rem 5rem 1.5rem; overflow-y: auto; position: relative; color: #334155; -webkit-overflow-scrolling: touch; }

.step-card { display: none; flex-direction: column; padding-top: 2rem; animation: slideFadeIn 0.6s ease; }
.step-card.active { display: flex; }

.step-header {
    display: flex; align-items: center; gap: 1rem;
    position: sticky; top: 0; left: 0; right: 0;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    padding: 0.75rem 1rem; border-radius: 12px;
    border: 1px solid #e2e8f0; z-index: 10;
    margin-bottom: 1rem;
}
.step-number { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 600; color: white; background: linear-gradient(135deg, #f97316, #fb923c); flex-shrink: 0; }
.progress-container { flex: 1; }
.progress-bar { height: 8px; background: #f1f5f9; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(135deg, #f97316, #fb923c); border-radius: 999px; transition: width 0.6s ease; width: 0%; will-change: width; }
.step-title { font-size: 14px; color: #64748b; }

.welcome-hero h1 { font-size: 3rem; font-weight: 700; background: linear-gradient(135deg, #f87171, #60a5fa, #fb923c); -webkit-background-clip: text; -webkit-text-fill-color: transparent; text-align: center; margin-bottom: 1rem; }
.welcome-hero p { text-align: center; color: #64748b; line-height: 1.6; margin-bottom: 2rem; }

.form-group { margin-bottom: 1.5rem; display: flex; flex-direction: column; }
.form-label { font-size: 14px; color: #64748b; margin-bottom: 0.5rem; font-weight: 500; }
/* Input reset for consistency */
.form-input, .form-select, .form-textarea { 
    padding: 1rem; border: 1px solid #e2e8f0; 
    background: #f8fafc; border-radius: 12px; color: #1e293b; font-size: 16px; width: 100%; 
    -webkit-appearance: none; appearance: none;
}
.form-input:focus { outline: none; border-color: #3b82f6; background: white; }

.button-group { position: absolute; bottom: 0; left: 0; right: 0; padding: 1rem 1.5rem; background: linear-gradient(to top, #ffffff 50%, rgba(255,255,255,0)); z-index: 101; }
.button-group-grid { display: grid; gap: 0.75rem; }

.btn-reg { padding: 1rem; border: none; border-radius: 12px; font-size: 16px; font-weight: 600; cursor: pointer; width: 100%; display: flex; justify-content: center; align-items: center; transition: transform 0.1s ease; }
.btn-reg:active { transform: scale(0.98); }
.btn-primary-reg { background: linear-gradient(135deg, #3b82f6, #60a5fa); color: white; box-shadow: 0 4px 12px rgba(59,130,246,0.3); }
.btn-secondary-reg { background: white; color: #64748b; border: 1px solid #cbd5e1; }
.btn-reg:disabled { opacity: 0.5; cursor: not-allowed; background: #e2e8f0; color: #94a3b8; box-shadow: none; }

.preview-card { background: #f8fafc; padding: 1.5rem; border-radius: 12px; margin-top: 1rem; color: #64748b; border: 1px solid #e2e8f0; }

@keyframes slideFadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }