/* ===================== THEME & RESET ===================== */
:root {
    --bg-a: #ffdde1;
    --bg-b: #ee9ca7;
    --glass: rgba(255, 255, 255, 0.45);
    --glass-strong: rgba(255, 255, 255, 0.65);
    --border: rgba(255, 255, 255, 0.6);
    --shadow: 0 15px 35px rgba(0, 0, 0, 0.15);
    --pink: #ff80ab;
    --pink-strong: #ff4081;
    --rose: #f06292;
    --ok: #2ecc71;
    --ok-dark: #27ae60;
    --clear: #ef5350;
    --clear-dark: #e53935;
    --text: #2a2a2a;
    --radius: 20px;
    --radius-sm: 14px;
    --font: "Poppins", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

* {
    box-sizing: border-box;
}
html,
body {
    height: 100%;
}

/* ===================== BACKGROUND (animated gradient) ===================== */
body {
    margin: 0;
    font-family: var(--font);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: radial-gradient(120% 120% at 20% 20%, #fff6 0 30%, transparent 40%), linear-gradient(135deg, var(--bg-a), var(--bg-b));
    background-size: 200% 200%;
    animation: bgShift 12s ease-in-out infinite;
}
@keyframes bgShift {
    0% {
        background-position: 0% 0%, 0% 0%;
    }
    50% {
        background-position: 100% 100%, 100% 100%;
    }
    100% {
        background-position: 0% 0%, 0% 0%;
    }
}

/* ===================== FLOATING DECOR (subtle) ===================== */
body::before,
body::after {
    content: "";
    position: fixed;
    inset: auto auto 10% 6%;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #fff8, #fff0 60%), #ffb6c1aa;
    filter: blur(2px);
    animation: floatBlob 9s ease-in-out infinite;
    pointer-events: none;
    z-index: 0;
}
body::after {
    left: auto;
    right: 8%;
    bottom: 18%;
    background: radial-gradient(circle at 30% 30%, #fff8, #fff0 60%), #ffd54faa;
    animation-duration: 11s;
    animation-delay: 0.6s;
}
@keyframes floatBlob {
    0%,
    100% {
        transform: translateY(0) translateX(0) scale(1);
    }
    50% {
        transform: translateY(-14px) translateX(10px) scale(1.06);
    }
}

/* ===================== CARD (glassmorphism) ===================== */
.container {
    position: relative;
    z-index: 1;
    width: min(560px, 92vw);
    text-align: center;
    padding: clamp(20px, 4vw, 28px) clamp(18px, 4vw, 32px);
    border-radius: var(--radius);
    background: linear-gradient(180deg, var(--glass), var(--glass-strong));
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

/* Title — fancy gradient text */
h1 {
    margin: 0 0 16px;
    font-size: clamp(1.6rem, 4.4vw, 2.2rem);
    line-height: 1.15;
    background: linear-gradient(90deg, var(--pink-strong), #ffb74d);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    letter-spacing: 0.3px;
}

/* ===================== DISPLAY (mask field) ===================== */
.password-display {
    height: 48px;
    font-size: clamp(20px, 3.8vw, 24px);
    letter-spacing: 0.55em;
    margin: 12px auto 18px;
    width: min(420px, 88%);
    border-radius: 999px;
    background: linear-gradient(180deg, #fff, #fff7);
    border: 1px solid rgba(255, 255, 255, 0.8);
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.06), 0 6px 16px rgba(255, 64, 129, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #333;
}

/* ===================== KEYPAD GRID ===================== */
.keypad {
    display: grid;
    /* cột tự co giãn cực mượt với clamp: min 86, max 120 */
    grid-template-columns: repeat(3, minmax(clamp(70px, 17vw, 120px), 1fr));
    gap: clamp(10px, 2.5vw, 14px);
    justify-content: center;
    width: 100%;
    margin: 0 auto;
}

/* Key — 3D, hover lift, active press */
.key {
    position: relative;
    border: none;
    border-radius: var(--radius-sm);
    padding: clamp(14px, 3.2vw, 18px);
    font-size: clamp(18px, 4vw, 22px);
    font-weight: 600;
    cursor: pointer;
    color: #3a3a3a;
    background: radial-gradient(circle at 30% 25%, #fff, #fff0 55%), linear-gradient(180deg, #fff, #f7f7f7);
    box-shadow: 0 10px 18px rgba(0, 0, 0, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.8);
    transition: transform 0.12s ease, box-shadow 0.18s ease, background 0.22s ease;
    will-change: transform;
}
.key:hover {
    transform: translateY(-2px);
    box-shadow: 0 16px 28px rgba(0, 0, 0, 0.16), inset 0 1px 0 rgba(255, 255, 255, 0.85);
}
.key:active {
    transform: translateY(0);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.12), inset 0 2px 4px rgba(0, 0, 0, 0.06);
}

/* Shimmer gloss on hover */
.key::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(120deg, transparent 0%, rgba(255, 255, 255, 0.35) 35%, transparent 70%);
    transform: translateX(-120%);
    transition: transform 0.55s ease;
    border-radius: inherit;
    pointer-events: none;
}
.key:hover::after {
    transform: translateX(120%);
}

/* Special keys */
.key.ok {
    background: radial-gradient(circle at 30% 25%, #fff, #fff0 55%), linear-gradient(180deg, var(--ok), #2ecb70);
    color: #fff;
    box-shadow: 0 12px 20px rgba(46, 204, 112, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
.key.ok:hover {
    box-shadow: 0 18px 28px rgba(46, 204, 112, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.7);
}
.key.ok:active {
    background: linear-gradient(180deg, var(--ok-dark), var(--ok));
}

.key.clear {
    background: radial-gradient(circle at 30% 25%, #fff, #fff0 55%), linear-gradient(180deg, var(--clear), #f66);
    color: #fff;
    box-shadow: 0 12px 20px rgba(239, 83, 80, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
.key.clear:hover {
    box-shadow: 0 18px 28px rgba(239, 83, 80, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.7);
}
.key.clear:active {
    background: linear-gradient(180deg, var(--clear-dark), var(--clear));
}

/* Focus accessibility */
.key:focus-visible {
    outline: 3px solid #ffecb3;
    outline-offset: 2px;
}

/* ===================== ERROR ===================== */
.error {
    min-height: 22px;
    color: #c62828;
    margin-top: 12px;
    font-weight: 600;
    text-shadow: 0 1px 0 #fff;
}

/* Shake khi có lỗi: chỉ cần thêm class .active từ JS khi sai mật khẩu */
.error.active {
    animation: shake 0.38s ease;
}
@keyframes shake {
    0%,
    100% {
        transform: translateX(0);
    }
    20% {
        transform: translateX(-6px);
    }
    40% {
        transform: translateX(6px);
    }
    60% {
        transform: translateX(-4px);
    }
    80% {
        transform: translateX(4px);
    }
}

/* ===================== RESPONSIVE ===================== */
@media (max-width: 600px) {
    .container {
        padding: 22px;
        border-radius: 16px;
    }
    .password-display {
        width: 92%;
        letter-spacing: 0.48em;
    }
}

@media (max-width: 420px) {
    .keypad {
        gap: 10px;
    }
    .key {
        font-size: 18px;
        padding: 14px;
    }
    .password-display {
        height: 44px;
        font-size: 20px;
    }
}
