/* ── Design Tokens ────────────────────────────────────── */
:root {
    --bg: #f5f6f8;
    --bg-glow: #e4e9f2;
    --surface: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
    --accent: #0d9488;
    --accent-dark: #0f766e;
    --accent-glow: rgba(13, 148, 136, 0.3);
    --error: #ef4444;
    --error-glow: rgba(239, 68, 68, 0.2);
    --key-bg: #ffffff;
    --key-active: #f1f5f9;
    --key-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --dot-border: #cbd5e1;
    --radius: 50%;
}

/* ── Reset & Base ────────────────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    background-image: radial-gradient(ellipse at 50% 0%, var(--bg-glow) 0%, transparent 60%);
    color: var(--text);
    min-height: 100dvh;
    min-height: 100vh; /* fallback */
    display: flex;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
    padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0)
             env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}

/* ── Container ───────────────────────────────────────── */
.container {
    width: 100%;
    max-width: 400px;
    min-height: 100dvh;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 28px 36px;
    gap: 28px;
}

/* ── Header ──────────────────────────────────────────── */
.header {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.store-name {
    font-size: 1.375rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    line-height: 1.3;
    color: var(--text);
}

.instruction {
    font-size: 0.875rem;
    font-weight: 400;
    color: var(--text-muted);
    line-height: 1.5;
    max-width: 260px;
}

/* ── PIN Display ─────────────────────────────────────── */
.pin-display {
    display: flex;
    gap: 22px;
    justify-content: center;
    padding: 8px 0;
}

.pin-dot {
    width: 18px;
    height: 18px;
    border-radius: var(--radius);
    border: 2.5px solid var(--dot-border);
    background: transparent;
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.pin-dot.filled {
    background: var(--accent);
    border-color: var(--accent);
    transform: scale(1.25);
}

.pin-dot.error {
    background: var(--error);
    border-color: var(--error);
    transform: scale(1.25);
}

.pin-dot.success {
    background: var(--accent);
    border-color: var(--accent);
    transform: scale(1.25);
}

/* ── Status ──────────────────────────────────────────── */
.status {
    min-height: 22px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
}

.status-text {
    font-size: 0.8125rem;
    font-weight: 500;
    opacity: 0;
    transition: opacity 0.25s ease;
    letter-spacing: 0.01em;
}

.status-text.visible {
    opacity: 1;
}

.status-text.error {
    color: var(--error);
}

.status-text.success {
    color: var(--accent);
}

.status-text.loading {
    color: var(--text-muted);
}

/* ── Keypad ──────────────────────────────────────────── */
.keypad {
    display: grid;
    grid-template-columns: repeat(3, 76px);
    gap: 14px;
    justify-content: center;
}

.key {
    width: 76px;
    height: 76px;
    border: none;
    border-radius: var(--radius);
    background: var(--key-bg);
    color: var(--text);
    font-family: inherit;
    font-size: 1.5rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--key-shadow);
    transition: transform 0.12s cubic-bezier(0.4, 0, 0.2, 1),
                background 0.12s ease,
                box-shadow 0.12s ease;
    -webkit-tap-highlight-color: transparent;
    outline: none;
    touch-action: manipulation;
}

.key:active {
    transform: scale(0.9);
    background: var(--key-active);
    box-shadow: none;
}

/* Function keys (backspace, submit) */
.key--fn {
    background: transparent;
    box-shadow: none;
    color: var(--text-muted);
}

.key--fn:active {
    background: var(--key-active);
}

/* Submit button — inactive */
.key--submit {
    transition: transform 0.12s cubic-bezier(0.4, 0, 0.2, 1),
                background 0.2s ease,
                box-shadow 0.2s ease,
                opacity 0.2s ease;
}

.key--submit:disabled {
    opacity: 0.25;
    cursor: default;
}

.key--submit:disabled:active {
    transform: none;
    background: transparent;
}

/* Submit button — active */
.key--submit:not(:disabled) {
    background: var(--accent);
    color: #ffffff;
    box-shadow: 0 4px 16px var(--accent-glow);
}

.key--submit:not(:disabled):active {
    background: var(--accent-dark);
    transform: scale(0.9);
    box-shadow: 0 2px 8px var(--accent-glow);
}

/* ── Animations ──────────────────────────────────────── */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    15%, 55% { transform: translateX(-10px); }
    35%, 75% { transform: translateX(10px); }
}

.pin-display.shake {
    animation: shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes pulse {
    0%, 100% { transform: scale(1.25); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.55; }
}

.container.loading .pin-dot.filled {
    animation: pulse 1s infinite ease-in-out;
}

/* Disable keypad during loading */
.container.loading .key {
    pointer-events: none;
    opacity: 0.4;
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 360px) {
    .keypad {
        grid-template-columns: repeat(3, 66px);
        gap: 12px;
    }

    .key {
        width: 66px;
        height: 66px;
        font-size: 1.375rem;
    }

    .container {
        padding: 36px 20px 28px;
    }
}

@media (max-height: 640px) {
    .container {
        padding: 24px 20px 16px;
        gap: 18px;
    }

    .key {
        width: 64px;
        height: 64px;
    }

    .keypad {
        grid-template-columns: repeat(3, 64px);
        gap: 10px;
    }
}

/* Landscape orientation */
@media (orientation: landscape) and (max-height: 500px) {
    .container {
        min-height: auto;
        padding: 16px 28px;
        gap: 12px;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        align-items: center;
        max-width: 680px;
    }

    .header {
        flex: 1 1 100%;
    }

    .pin-section {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 12px;
    }

    .keypad {
        grid-template-columns: repeat(3, 56px);
        gap: 8px;
    }

    .key {
        width: 56px;
        height: 56px;
        font-size: 1.25rem;
    }
}
